Reputation: 84599
I have a triangle CGAL mesh with the exact kernel (EK, EMesh3, EPoint3
) and I want to convert it to the same mesh with the inexact kernel (K, Mesh3, Point3
). My solution consists in taking each vertex and each face of the exact mesh and adding them one by one to an empty inexact mesh. Is there a more straightforward way?
Mesh3 Convert(EMesh3 emesh) {
const size_t nvertices = emesh.number_of_vertices();
const size_t nedges = emesh.number_of_edges();
const size_t nfaces = emesh.number_of_faces();
Mesh3 mesh;
mesh.reserve(nvertices, nedges, nfaces);
for(EMesh3::Vertex_index vd : emesh.vertices()) {
const EPoint3 vertex = emesh.point(vd);
const double x = CGAL::to_double<EK::FT>(vertex.x());
const double y = CGAL::to_double<EK::FT>(vertex.y());
const double z = CGAL::to_double<EK::FT>(vertex.z());
mesh.add_vertex(Point3(x, y ,z));
}
for(EMesh3::Face_index fd : emesh.faces()) {
std::vector<int> face;
for(EMesh3::Vertex_index vd : vertices_around_face(emesh.halfedge(fd), emesh)) {
face.push_back(vd);
}
mesh.add_face(
CGAL::SM_Vertex_index(face[0]),
CGAL::SM_Vertex_index(face[1]),
CGAL::SM_Vertex_index(face[2])
);
}
return mesh;
}
Upvotes: 1
Views: 203
Reputation: 6263
You can either create a new mesh like you did but with the function copy_face_graph()
or you can use the vertex_property_map()
parameter of PMP functions to have one mesh with different point map (exact and inexact).
Upvotes: 3