From 2c4fc75e177e11f11f9aecafb4ff400ea41ae863 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 20 Aug 2024 15:41:21 +0100 Subject: [PATCH] Add CGAL::IO::read_OM() --- BGL/examples/BGL_OpenMesh/PolyMesh.cpp | 77 ++++++++++++++++---------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp index aad1c35ff62..76c38181a08 100644 --- a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp @@ -13,6 +13,51 @@ #include #include +namespace CGAL { +namespace IO { + +template +bool read_OM(std::string fname, SM& sm, VSelectionPM vspm, EFeaturePM efpm) +{ + typedef OpenMesh::PolyMesh_ArrayKernelT<> Mesh; + Mesh mesh; + OpenMesh::IO::Options options = OpenMesh::IO::Options::Status; + bool ok = OpenMesh::IO::read_mesh(mesh, fname, options); + if(! ok){ + return false; + } + + std::map v2v; + auto v2vpmap = boost::make_assoc_property_map(v2v); + + std::map h2h; + auto h2hpmap = boost::make_assoc_property_map(h2h); + + CGAL::copy_face_graph(mesh, sm, CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap)); + + if(options.vertex_has_status()){ + for(auto v : vertices(mesh)){ + put(vspm, v2v[v], mesh.status(v).selected()); + } + }else{ + std::cout << "no vertex status" << std::endl; + } + + if(options.edge_has_status()){ + for(auto e : edges(mesh)){ + auto sme = edge(h2h[halfedge(e,mesh)], sm); + put(efpm, sme , mesh.status(e).feature()); + } + }else{ + std::cout << "no edge status" << std::endl; + } + return true; +} + +} // namespace IO +} // namespace CGAL + + typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef OpenMesh::PolyMesh_ArrayKernelT Mesh; @@ -49,43 +94,15 @@ int main(int argc, char** argv ) OpenMesh::IO::write_mesh(mesh, outname, OpenMesh::IO::Options::Status); - Mesh mesh2; - OpenMesh::IO::Options options = OpenMesh::IO::Options::Status; - bool read = OpenMesh::IO::read_mesh(mesh2, outname, options); - assert(read); - SM sm; - std::map v2v; - auto v2vpmap = boost::make_assoc_property_map(v2v); - - std::map h2h; - auto h2hpmap = boost::make_assoc_property_map(h2h); - - CGAL::copy_face_graph(mesh, sm, CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap)); std::map sm_selected_map; auto sm_selected_pmap = boost::make_assoc_property_map(sm_selected_map); - if(options.vertex_has_status()){ - for(auto v : vertices(mesh2)){ - put(sm_selected_pmap, v2v[v], mesh2.status(v).selected()); - std::cout << std::boolalpha << mesh2.status(v).selected() << std::endl; - } - }else{ - std::cout << "no vertex status" << std::endl; - } - std::map sm_feature_map; auto sm_feature_pmap = boost::make_assoc_property_map(sm_feature_map); - if(options.edge_has_status()){ - for(auto e : edges(mesh2)){ - auto sme = edge(h2h[halfedge(e,mesh2)], sm); - put(sm_feature_pmap, sme , mesh2.status(e).feature()); - std::cout << std::boolalpha << mesh2.status(e).feature() << std::endl; - } - }else{ - std::cout << "no edge status" << std::endl; - } + + CGAL::IO::read_OM(outname, sm, sm_selected_pmap, sm_feature_pmap); std::cout << "vertex selection values:\n"; for(auto v : vertices(sm)){