public static void CreateExteriorSkeleton <MESH>(Polygon2f polygon, IMeshConstructor <MESH> constructor, float maxOffset, bool includeBorder = true) { if (!polygon.IsSimple) { throw new ArgumentException("Polygon must be simple."); } if (!polygon.IsCCW) { throw new ArgumentException("Polygon must have counter clock wise orientation."); } CGAL_LoadPoints(polygon.Positions, polygon.Positions.Length); AddHoles(polygon); MeshDescriptor descriptor; if (CGAL_CreateExteriorSkeleton(maxOffset, includeBorder, out descriptor) != SUCCESS) { throw new Exception("Error creating interior skeleton."); } CreateLine(constructor, descriptor); CGAL_Clear(); }
public static void Triangulate <MESH>(Polygon2f polygon, IMeshConstructor <MESH> constructor, ConformingCriteria crit = new ConformingCriteria()) { InsertPolygon(polygon); InsertSeeds(crit.seeds); Box2f bounds = Box2f.CalculateBounds(polygon.Positions); CGAL_InsertSeed(bounds.Min - 0.1f); MeshDescriptor des = Triangulate(crit.iterations, crit.angBounds, crit.lenBounds); CreateMesh(constructor, des); CGAL_Clear(); }
public static void Triangulate <MESH>(Polygon2f polygon, IMeshConstructor <MESH> constructor) { Insert(polygon); MeshDescriptor descriptor; if (CGAL_Triangulate(out descriptor) != SUCCESS) { throw new Exception("Error triangulating points."); } PolygonIntersection2.PushPolygon(polygon); CreateMesh(constructor, descriptor); PolygonIntersection2.PopPolygon(); CGAL_Clear(); }
private static void CreateMesh <MESH>(IMeshConstructor <MESH> constructor, MeshDescriptor des) { constructor.PushTriangleMesh(des.Vertices, des.Faces); for (int i = 0; i < des.Vertices; i++) { constructor.AddVertex(CGAL_GetPoint2f(i)); } for (int i = 0; i < des.Faces; i++) { TriangleIndex triangle = CGAL_GetTriangle(i); constructor.AddFace(triangle); } for (int i = 0; i < des.Faces; i++) { TriangleIndex triangle = CGAL_GetNeighbor(i); constructor.AddFaceConnection(i, triangle); } }
private static void CreateLine <MESH>(IMeshConstructor <MESH> constructor, MeshDescriptor des) { constructor.PushEdgeMesh(des.Vertices, des.Edges); for (int i = 0; i < des.Vertices; i++) { Vector2f v = CGAL_GetSkeletonPoint(i); constructor.AddVertex(v); } for (int i = 0; i < des.Edges; i++) { EdgeIndex edge = CGAL_GetSkeletonEdge(i); constructor.AddEdge(edge); } int numConnections = CGAL_NumEdgeConnection(); for (int i = 0; i < numConnections; i++) { EdgeConnection con = CGAL_GetEdgeConnection(i); constructor.AddEdgeConnection(con); } }
private static void CreateMesh <MESH>(IMeshConstructor <MESH> constructor, MeshDescriptor des) { constructor.PushTriangleMesh(des.Vertices, des.Faces); for (int i = 0; i < des.Vertices; i++) { constructor.AddVertex(CGAL_GetPoint2f(i)); } for (int i = 0; i < des.Faces; i++) { TriangleIndex triangle = CGAL_GetTriangle(i); Vector2f a = CGAL_GetPoint2f(triangle.i0); Vector2f b = CGAL_GetPoint2f(triangle.i1); Vector2f c = CGAL_GetPoint2f(triangle.i2); Vector2f p = (a + b + c) / 3.0f; if (PolygonIntersection2.ContainsPoint(p)) { constructor.AddFace(triangle); } } }