Reputation: 596
I would like to ask if it is possible to optimize Surface mesh creation of CGAL in my code? In the following loops I am just adding vertices and faces from a flat array of double representing vertices and int array of face ids.
Do I need somehow to reserve memory for faster conversion since number of vertices and faces is already known? And in my workflow it will never change.
CGAL::Surface_mesh<CGAL::Exact_predicates_inexact_constructions_kernel::Point_3> mesh1;
for ( size_t i = 0; i < n_coord_mesh1; i++ ) {
mesh1.add_vertex (CGAL::Epick::Point_3 (coord_mesh1[3 * i], coord_mesh1[3 * i + 1], coord_mesh1[3 * i + 2]));
}
for ( size_t i = 0; i < n_faces_mesh1; i++ ) {
mesh1.add_face (CGAL::SM_Vertex_index (faces_mesh1[3 * i + 0]), CGAL::SM_Vertex_index (faces_mesh1[3 * i + 1]), CGAL::SM_Vertex_index (faces_mesh1[3 * i + 2]));
}
Upvotes: 2
Views: 520
Reputation: 726
You can use Surface_mesh::reserve()
, as in the doc, here:
https://doc.cgal.org/latest/Surface_mesh/classCGAL_1_1Surface__mesh.html#a2172cdbebc27ecf4ca36ac050aad11b8
Upvotes: 2