Skip to content

Instantly share code, notes, and snippets.

@petrasvestartas
Last active February 7, 2021 21:27
Show Gist options
  • Save petrasvestartas/606b9e2809c907922eee35791745180e to your computer and use it in GitHub Desktop.
Save petrasvestartas/606b9e2809c907922eee35791745180e to your computer and use it in GitHub Desktop.
std::vector< Mesh > meshList;
std::vector<Mesh::Property_map<Mesh::Face_index, int>> meshList_id;
Mesh out;
Mesh::Property_map<Mesh::Face_index, int> out_id = out.add_property_map<Mesh::Face_index, int> ("f:id", -1).first;
int numOfValidMeshes = 0;
for ( size_t i = 0; i < n_mesh; i++ ) {
CGAL::Surface_mesh<CGAL::Exact_predicates_inexact_constructions_kernel::Point_3> tempMesh;
for ( int j = n_coord_meshArray[i]; j < n_coord_meshArray[i + 1]; j++ ) {
tempMesh.add_vertex (CGAL::Epick::Point_3 (coord_mesh[3 * j + 0], coord_mesh[3 * j + 1], coord_mesh[3 * j + 2]));
}
for ( int j = n_faces_meshArray[i]; j < n_faces_meshArray[i + 1]; j++ ) {
tempMesh.add_face (CGAL::SM_Vertex_index (faces_mesh[3 * j + 0]), CGAL::SM_Vertex_index (faces_mesh[3 * j + 1]), CGAL::SM_Vertex_index (faces_mesh[3 * j + 2]));
}
if ( tempMesh.is_valid (false) ) {
meshList.push_back (tempMesh);
numOfValidMeshes++;
}
}
/////////////////////////////////////////////////////////////////
//Add Visitor
/////////////////////////////////////////////////////////////////
Visitor visitor;
for ( int i = 0; i < meshList.size (); i++ ) {
Mesh::Property_map<Mesh::Face_index, int> mesh_id = meshList[i].add_property_map<Mesh::Face_index, int> ("f:id", -1).first;
for ( Mesh::Face_index f : faces (meshList[i]) )
mesh_id[f] = (i+1);
meshList_id.push_back (mesh_id);
visitor.properties[&meshList[i]] = meshList_id[i];// mesh_id;
}
visitor.properties[&out] = out_id;
//////////////////////////////////////////////////////////////////
//// Perform CGAL Boolean
//////////////////////////////////////////////////////////////////
CGAL::Surface_mesh<CGAL::Exact_predicates_inexact_constructions_kernel::Point_3> mesh0 = meshList[0];
CGAL::Surface_mesh<CGAL::Exact_predicates_inexact_constructions_kernel::Point_3> mesh1 = meshList[1];
bool valid_union = CGAL::Polygon_mesh_processing::corefine_and_compute_union (mesh0, mesh1, out, CGAL::Polygon_mesh_processing::parameters::visitor (visitor));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment