-
Notifications
You must be signed in to change notification settings - Fork 43
Polyhedron3 Mesh
Justin edited this page Mar 15, 2022
·
7 revisions
CGAL provides a polyhedron3 mesh that can have polygonal faces. This mesh is based on a DCEL data structure and allows for editing of the mesh by splitting/merging of faces and edges.
The following shows how to create a polyhedron3 mesh. The mesh default's to triangles when a int array is used for the indices.
//Create one triangle
var indices = new int[3]
{
0, 1, 2
};
//The triangles points.
var points = new Point3d[3]
{
new Point3d(0, 0, 0),
new Point3d(1, 0, 0),
new Point3d(1, 1, 0)
};
var mesh = new Polyhedron3<EIK>(points, indices);
Factory methods are also provided that can create a variety of meshes. Here we create a cube that has quad faces instead of triangles.
//Allow quads to be used.
//If false only triangles will be created.
bool allowQuads = true;
var mesh = PolyhedronFactory<EIK>.CreateCube(1, allowQuads);
Other polygons can be created in the mesh by using the PolygonalIndices object that supports triangles up to hexagons. A mixture of polygons is allowed.
//Create the object that holds the indices
var indices = new PolygonalIndices();
//quads indices is null so create.
indices.quads = new int[]
{
0, 1, 2, 3
};
//Create the points for a single quad
var points = new Point3d[]
{
new Point3d(0, 0, 0),
new Point3d(1, 0, 0),
new Point3d(1, 1, 0),
new Point3d(0, 1, 0)
};
//Create the mesh.
var mesh = new Polyhedron3<EIK>(points, indices);
Once created the mesh provides a variety of functions to edit the mesh.
//subdive the mesh twice.
mesh.Subdive(2);
//Simplify the mesh by removing %50 of the points.
mesh.Simplify(0.5);
//Refine by adding new points.
mesh.Refine();
//If the has unconnected components the split them
var meshes = new List<Polyhedron3<K>>();
mesh.Spilt(meshes);
//Add much more...
Below is image of some of the meshes produced by the PolyhedronFactory object.