#include #include #include #include #if defined(CGAL_USE_OPENMESH) #include #include #include #endif #include #include #include #include #include typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Polyhedron_3 Source; typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; typedef boost::graph_traits::face_descriptor sm_face_descriptor; typedef CGAL::Exact_predicates_exact_constructions_kernel Other_kernel; typedef Other_kernel::Point_3 Point; int main(int argc, char* argv[]) { Source S; std::ifstream in((argc>1)?argv[1]:CGAL::data_file_path("meshes/cube_poly.off")); in >> S; assert( CGAL::is_valid_polygon_mesh(S) ); // Note that the vertex_point property of the Source and Target1 // come from different kernels. typedef CGAL::Surface_mesh Target1; Target1 T1; CGAL::copy_face_graph(S, T1); assert( CGAL::is_valid_polygon_mesh(T1) ); assert( vertices(S).size()==vertices(T1).size() ); assert( halfedges(S).size()==halfedges(T1).size() ); assert( faces(S).size()==faces(T1).size() ); #if defined(CGAL_USE_OPENMESH) typedef OpenMesh::PolyMesh_ArrayKernelT Target2; Target2 T2; { typedef boost::graph_traits::vertex_descriptor tm_vertex_descriptor; typedef boost::graph_traits::halfedge_descriptor tm_halfedge_descriptor; typedef boost::graph_traits::face_descriptor tm_face_descriptor; // Use an unordered_map to keep track of elements. std::unordered_map v2v; std::unordered_map h2h; std::unordered_map f2f; CGAL::copy_face_graph(S, T2, CGAL::parameters::vertex_to_vertex_output_iterator(std::inserter(v2v, v2v.end())) .halfedge_to_halfedge_output_iterator(std::inserter(h2h, h2h.end())) .face_to_face_output_iterator(std::inserter(f2f, f2f.end()))); assert( CGAL::is_valid_polygon_mesh(T2) ); assert( v2v.size()==vertices(T2).size() ); assert( h2h.size()==halfedges(T2).size() ); assert( f2f.size()==faces(T2).size() ); assert( vertices(S).size()==vertices(T2).size() ); assert( halfedges(S).size()==halfedges(T2).size() ); assert( faces(S).size()==faces(T2).size() ); } #endif S.clear(); { typedef boost::graph_traits::vertex_descriptor source_vertex_descriptor; typedef boost::graph_traits::halfedge_descriptor source_halfedge_descriptor; typedef boost::graph_traits::face_descriptor source_face_descriptor; typedef boost::graph_traits::vertex_descriptor tm_vertex_descriptor; typedef boost::graph_traits::halfedge_descriptor tm_halfedge_descriptor; typedef boost::graph_traits::face_descriptor tm_face_descriptor; std::unordered_map v2v; std::unordered_map h2h; std::unordered_map f2f; CGAL::copy_face_graph(T1, S, CGAL::parameters::vertex_to_vertex_map(boost::make_assoc_property_map(v2v)) .halfedge_to_halfedge_output_iterator(std::inserter(h2h, h2h.end())) .face_to_face_map(boost::make_assoc_property_map(f2f))); assert( CGAL::is_valid_polygon_mesh(S) ); assert( vertices(S).size()==vertices(T1).size() ); assert( halfedges(S).size()==halfedges(T1).size() ); assert( faces(S).size()==faces(T1).size() ); } return 0; }