public static IEnumerable<Calculation> BuildTriCalculations(SampleTri t) { int minX = t.U.Point.X < t.V.Point.X && t.U.Point.X < t.W.Point.X ? t.U.Point.X : (t.V.Point.X < t.W.Point.X ? t.V.Point.X : t.W.Point.X); int minY = t.U.Point.Y < t.V.Point.Y && t.U.Point.Y < t.W.Point.Y ? t.U.Point.Y : (t.V.Point.Y < t.W.Point.Y ? t.V.Point.Y : t.W.Point.Y); int maxX = t.U.Point.X > t.V.Point.X && t.U.Point.X > t.W.Point.X ? t.U.Point.X : (t.V.Point.X > t.W.Point.X ? t.V.Point.X : t.W.Point.X); int maxY = t.U.Point.Y > t.V.Point.Y && t.U.Point.Y > t.W.Point.Y ? t.U.Point.Y : (t.V.Point.Y > t.W.Point.Y ? t.V.Point.Y : t.W.Point.Y); for (int x = minX; x < maxX + 1; x++) { for (int y = minY; y < maxY + 1; y++) { Point p = new Point(x, y); Calculation c = new Calculation(); c.A = t.U.Point; c.B = t.V.Point; c.C = t.W.Point; c.P = p; c.Tri = t; yield return c; } } }
public void Fill(SampleTri t, PixelMap map) { Point center = t.CenterPoint; int radius = (int)t.Samples.Max(s => dist(s.Point, center)); for (int x = center.X - radius; x < center.X + radius; x++) { for (int y = center.Y - radius; y < center.Y + radius; y++) { Point fillPoint = new Point(x, y); double theta = Math.PI+Math.Atan2(fillPoint.Y - center.Y,fillPoint.X - center.X); double distance = dist(fillPoint, center); if (map.Inside(fillPoint) && distance < ShapeFunction(theta)*radius) { map[fillPoint] = t.CenterColor; //map[fillPoint] = new Pixel(theta*180/Math.PI,0.5,0.5); } if (distance > 1000) { Console.WriteLine("wat"); } } } }
public void Fill(SampleTri t, PixelMap map) { foreach (var drawPoint in t.Points) { Pixel gradedColor = Grader.Grade(t.U, t.V, t.W, drawPoint); map[drawPoint.Point] = gradedColor; } }
/// <summary> Loads a TrigradCompressed image from a stream. </summary> public TrigradCompressed(Stream s) { using (BZip2InputStream dezipper = new BZip2InputStream(s)) using (BinaryReader reader = new BinaryReader(dezipper)) { Width = reader.ReadUInt16(); Height = reader.ReadUInt16(); uint count = reader.ReadUInt32(); Point[] points = new Point[count]; for (int i = 0; i < count; i++) points[i].X = reader.ReadUInt16(); for (int i = 0; i < count; i++) points[i].Y = reader.ReadUInt16(); ColorStruct[] colors = new ColorStruct[count]; for (int i = 0; i < count; i++) colors[i].R = reader.ReadByte(); for (int i = 0; i < count; i++) colors[i].G = reader.ReadByte(); for (int i = 0; i < count; i++) colors[i].B = reader.ReadByte(); for (int i = 0; i < count; i++) { SampleTable.Add(points[i],colors[i].Color); } uint meshCount = reader.ReadUInt32(); SampleTri[] tris = new SampleTri[meshCount]; for (int i = 0; i < meshCount; i++) tris[i] = new SampleTri(); for (int i = 0; i < meshCount; i++) tris[i].U = new Sample(points[reader.ReadInt32()], new Pixel(Color.Black)); for (int i = 0; i < meshCount; i++) tris[i].V = new Sample(points[reader.ReadInt32()], new Pixel(Color.Black)); for (int i = 0; i < meshCount; i++) tris[i].W = new Sample(points[reader.ReadInt32()], new Pixel(Color.Black)); foreach (var tri in tris) { tri.U.Color = SampleTable[tri.U.Point]; tri.V.Color = SampleTable[tri.V.Point]; tri.W.Color = SampleTable[tri.W.Point]; } Mesh = tris.ToList(); } }
public void Fill(SampleTri t, PixelMap map) { foreach (var drawPoint in t.Points) { Pixel gradedColor = t.CenterColor; map[drawPoint.Point] = gradedColor; } }
public static IEnumerable<DrawPoint> PointsInTriangle(SampleTri t) { int minX = t.U.Point.X < t.V.Point.X && t.U.Point.X < t.W.Point.X ? t.U.Point.X : (t.V.Point.X < t.W.Point.X ? t.V.Point.X : t.W.Point.X); int minY = t.U.Point.Y < t.V.Point.Y && t.U.Point.Y < t.W.Point.Y ? t.U.Point.Y : (t.V.Point.Y < t.W.Point.Y ? t.V.Point.Y : t.W.Point.Y); int maxX = t.U.Point.X > t.V.Point.X && t.U.Point.X > t.W.Point.X ? t.U.Point.X : (t.V.Point.X > t.W.Point.X ? t.V.Point.X : t.W.Point.X); int maxY = t.U.Point.Y > t.V.Point.Y && t.U.Point.Y > t.W.Point.Y ? t.U.Point.Y : (t.V.Point.Y > t.W.Point.Y ? t.V.Point.Y : t.W.Point.Y); for (int x = minX; x < maxX + 1; x++) { for (int y = minY; y < maxY + 1; y++) { Point p = new Point(x, y); var coords = Barycentric.GetCoordinates(p, t.U.Point,t.V.Point,t.W.Point); if (Barycentric.ValidCoords(coords)) { yield return new DrawPoint(coords, p); } } } }
public static List<SampleTri> BuildMesh(Dictionary<Point, Pixel> pointIndex) { InputGeometry g = new InputGeometry(); foreach (var value in pointIndex) { g.AddPoint(value.Key.X, value.Key.Y); } Mesh m = new Mesh(); m.Triangulate(g); List<SampleTri> sampleMesh = new List<SampleTri>(); Dictionary<ITriangle, SampleTri> table = new Dictionary<ITriangle, SampleTri>(); Dictionary<Point, Sample> sampleTable = new Dictionary<Point, Sample>(); foreach (var mTri in m.Triangles) { SampleTri tri = new SampleTri(mTri); for (int i = 0; i < 3; i++) tri.TriangleNeighbours.Add(mTri.GetNeighbor(i)); sampleMesh.Add(tri); table.Add(mTri, tri); if (sampleTable.ContainsKey(tri.U.Point)) tri.U = sampleTable[tri.U.Point]; else sampleTable[tri.U.Point] = tri.U; if (sampleTable.ContainsKey(tri.V.Point)) tri.V = sampleTable[tri.V.Point]; else sampleTable[tri.V.Point] = tri.V; if (sampleTable.ContainsKey(tri.W.Point)) tri.W = sampleTable[tri.W.Point]; else sampleTable[tri.W.Point] = tri.W; } foreach (var tri in sampleMesh) { foreach (var triangleNeighbour in tri.TriangleNeighbours) { if (triangleNeighbour != null) tri.SampleTriNeighbours.Add(table[triangleNeighbour]); } tri.U.Triangles.Add(tri); tri.V.Triangles.Add(tri); tri.W.Triangles.Add(tri); tri.U.Color = pointIndex[tri.U.Point]; tri.V.Color = pointIndex[tri.V.Point]; tri.W.Color = pointIndex[tri.W.Point]; tri.CenterColor = tri.U.Color; } return sampleMesh; }