I am creating a mesh utility library, and one of the functionalities that I would like to include is the ability to break apart disjoint partitions of a mesh. To that end, I am trying to write a method that takes in a CGAL::Surface_mesh
and returns a std::vector<CGAL::Surface_mesh>
, where each element is a connected component of the input mesh.
I see that CGAL has CGAL::Polygon_mesh_processing::connected components
function, but that just seems to assign a label to each face indicating which component it's a part of. How can I use the result of that operation to construct a new CGAL::Surface_mesh
from every group of faces with the same label?
One way of doing this is to use the result of connected_components()
as input parameter for the Face_filtered_graph.
You can do something like that I believe:
FCCmap fccmap = mesh.add_property_map<face_descriptor, faces_size_type>
("f:CC").first;
faces_size_type num = PMP::connected_components(mesh,fccmap);
std::vector<Mesh> meshes(num);
for(int i=0; i< num; ++i)
{
Filtered_graph ffg(mesh, i, fccmap);
CGAL::copy_face_graph(ffg, meshes[i]);
}