public static AreaContent getFromOutline(List<AreaVertex> outline) { var content = new AreaContent(); if (!isRightHanded(outline)) { outline.Reverse(); } outline=outline.Select(x => { x.Center = 1; return x; }).ToList(); content.Vertices.AddRange(outline); //var bottomRing = new List<AreaVertex>(outline); var bottomRing = outline.Select(x => { var y = new AreaVertex(); y.X = x.X; y.Y = x.Y; y.Z = x.Z; y.W = x.W; y.Center = 0; return y; }).ToList(); content.Vertices.AddRange(bottomRing); var innerRing = getInnerRing(outline); content.Vertices.AddRange(innerRing); var triangles = getTriangles(outline, 0, outline.Count - 1); content.Triangles.AddRange(triangles); var borderTriangles = getBorderTriangles(outline.Count); content.Triangles.AddRange(borderTriangles); AreaClipped ac = new AreaClipped(); ac.StartTriangle = 0; ac.StartVertex = 0; ac.TriangleCount = triangles.Count; ac.VertexCount = outline.Count; //ac.TriangleCount = content.Triangles.Count; //ac.VertexCount = content.Vertices.Count; content.ClippedAreas.Add(ac); AreaClipped ac2 = new AreaClipped(); content.ClippedAreas.Add(ac2); AreaClipped bt = new AreaClipped(); bt.StartTriangle = triangles.Count; bt.StartVertex = outline.Count; bt.TriangleCount = borderTriangles.Count; bt.VertexCount = 2 * outline.Count; content.BorderTriangle = bt; AreaClipped bv = new AreaClipped(); bv.StartTriangle = 0; bv.StartVertex = 2*outline.Count; bv.TriangleCount = 0; bv.VertexCount = outline.Count; content.BorderVertex = bv; //Console.Write("vertices=["); //var scen = content; /*foreach (var v in scen.Vertices) { Console.WriteLine("{0:G},{1:G},{2:G};", (int)v.X, (int)v.Y, (int)v.Center); } Console.WriteLine("]"); Console.Write("tri=["); foreach (var v in scen.Triangles) { Console.WriteLine("{0},{1},{2};", (int)v.Point1, (int)v.Point2, (int)v.Point3); } Console.WriteLine("]"); Console.WriteLine("bt=[{0:G},{1:G},{2:G},{3:G}]", scen.BorderTriangle.StartTriangle, scen.BorderTriangle.StartVertex, scen.BorderTriangle.TriangleCount, scen.BorderTriangle.VertexCount); Console.WriteLine("bv=[{0:G},{1:G},{2:G},{3:G}]", scen.BorderVertex.StartTriangle, scen.BorderVertex.StartVertex, scen.BorderVertex.TriangleCount, scen.BorderVertex.VertexCount); var k = 0; foreach (var a in scen.ClippedAreas) { Console.WriteLine("t{4}=[{0:G},{1:G},{2:G},{3:G}]", a.StartTriangle, a.StartVertex, a.TriangleCount, a.VertexCount, k++); } */ return content; }
public static List<Point> getOutline(AreaContent content) { var outline=content.Vertices.GetRange(content.BorderVertex.StartVertex,content.BorderVertex.VertexCount); return outline.ConvertAll(x => new Point((int)x.X / scaleFactor, (int)x.Y / scaleFactor)); }