From 457ee558015e64f171d924b6dd02546cb17db969 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 20 Aug 2024 12:09:15 +0100 Subject: [PATCH 01/32] Store selection in Status --- BGL/examples/BGL_OpenMesh/CMakeLists.txt | 3 ++ BGL/examples/BGL_OpenMesh/PolyMesh.cpp | 60 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 BGL/examples/BGL_OpenMesh/PolyMesh.cpp diff --git a/BGL/examples/BGL_OpenMesh/CMakeLists.txt b/BGL/examples/BGL_OpenMesh/CMakeLists.txt index d11ac1444c9c..6195bddbb6ea 100644 --- a/BGL/examples/BGL_OpenMesh/CMakeLists.txt +++ b/BGL/examples/BGL_OpenMesh/CMakeLists.txt @@ -12,6 +12,9 @@ if(OpenMesh_FOUND) include(UseOpenMesh) create_single_source_cgal_program("TriMesh.cpp") target_link_libraries(TriMesh PRIVATE ${OPENMESH_LIBRARIES}) + + create_single_source_cgal_program("PolyMesh.cpp") + target_link_libraries(PolyMesh PRIVATE ${OPENMESH_LIBRARIES}) else() message("NOTICE: This project requires OpenMesh and will not be compiled.") endif() diff --git a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp new file mode 100644 index 000000000000..03192e9a3684 --- /dev/null +++ b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp @@ -0,0 +1,60 @@ +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; + +typedef OpenMesh::PolyMesh_ArrayKernelT Mesh; + +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::face_descriptor face_descriptor; +typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; + +int main(int argc, char** argv ) +{ + Mesh mesh; + + std::vector V; + const std::string filename = (argc>1)?argv[1]:CGAL::data_file_path("meshes/in.off"); + const char* outname= (argc>2)?argv[2]:"out.om"; + CGAL::IO::read_polygon_mesh(filename, mesh); + + mesh.request_vertex_status(); + // typedef boost::property_map >::type EdgeLabelMap; + // EdgeLabelMap elm = get(CGAL::dynamic_edge_property_t(), mesh); + + int i = 0; + for(auto v : vertices(mesh)){ + mesh.status(v).set_selected((i%2) == 0); + ++i; + } + + + OpenMesh::IO::write_mesh(mesh, outname, OpenMesh::IO::Options::Status); + + Mesh mesh2; + OpenMesh::IO::Options options; + bool read = OpenMesh::IO::read_mesh(mesh2, outname, options); + std::cout << num_vertices(mesh2) << std::endl; + assert(read); + if(options.vertex_has_status()){ + for(auto v : vertices(mesh2)){ + std::cout << std::boolalpha << mesh2.status(v).selected() << std::endl; + } + }else{ + std::cout << "no status" << std::endl; + } + + return 0; +} From b2d5dc4bfca060c8c6f78cacd9832125eb5fcda8 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 20 Aug 2024 13:38:11 +0100 Subject: [PATCH 02/32] Fix options --- BGL/examples/BGL_OpenMesh/PolyMesh.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp index 03192e9a3684..db92203be346 100644 --- a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp @@ -25,14 +25,11 @@ int main(int argc, char** argv ) { Mesh mesh; - std::vector V; const std::string filename = (argc>1)?argv[1]:CGAL::data_file_path("meshes/in.off"); const char* outname= (argc>2)?argv[2]:"out.om"; CGAL::IO::read_polygon_mesh(filename, mesh); mesh.request_vertex_status(); - // typedef boost::property_map >::type EdgeLabelMap; - // EdgeLabelMap elm = get(CGAL::dynamic_edge_property_t(), mesh); int i = 0; for(auto v : vertices(mesh)){ @@ -44,7 +41,7 @@ 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 options = OpenMesh::IO::Options::Status; bool read = OpenMesh::IO::read_mesh(mesh2, outname, options); std::cout << num_vertices(mesh2) << std::endl; assert(read); @@ -53,7 +50,7 @@ int main(int argc, char** argv ) std::cout << std::boolalpha << mesh2.status(v).selected() << std::endl; } }else{ - std::cout << "no status" << std::endl; + std::cout << "no vertex status" << std::endl; } return 0; From 65b7c09c1f21bf35502b9293e14e5bc9805364f7 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 20 Aug 2024 15:15:37 +0100 Subject: [PATCH 03/32] Add a conversion operator --- STL_Extension/include/CGAL/hash_openmesh.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/STL_Extension/include/CGAL/hash_openmesh.h b/STL_Extension/include/CGAL/hash_openmesh.h index 700f58e87eb2..eb9c71d58f11 100644 --- a/STL_Extension/include/CGAL/hash_openmesh.h +++ b/STL_Extension/include/CGAL/hash_openmesh.h @@ -37,6 +37,10 @@ class OMesh_edge { } } + operator OpenMesh::EdgeHandle () const { + return OpenMesh::EdgeHandle(idx()); + } + bool operator<(const OMesh_edge& other) const { return this->idx() < other.idx(); From 0c8e489f46caf5dfdb45845df07b2b006417da73 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 20 Aug 2024 15:16:13 +0100 Subject: [PATCH 04/32] store/retrieve selection and features of an OM --- BGL/examples/BGL_OpenMesh/PolyMesh.cpp | 51 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp index db92203be346..aad1c35ff62d 100644 --- a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp @@ -9,17 +9,20 @@ #include #include #include - +#include #include #include typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef OpenMesh::PolyMesh_ArrayKernelT Mesh; - +typedef CGAL::Surface_mesh SM; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; typedef boost::graph_traits::face_descriptor face_descriptor; typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; +typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; +typedef boost::graph_traits::edge_descriptor sm_edge_descriptor; int main(int argc, char** argv ) { @@ -30,28 +33,68 @@ int main(int argc, char** argv ) CGAL::IO::read_polygon_mesh(filename, mesh); mesh.request_vertex_status(); + mesh.request_edge_status(); int i = 0; for(auto v : vertices(mesh)){ mesh.status(v).set_selected((i%2) == 0); ++i; - } + } + i = 0; + for(auto e : edges(mesh)){ + mesh.status(e).set_feature(i > 2); + ++i; + } 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); - std::cout << num_vertices(mesh2) << std::endl; 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; + } + + std::cout << "vertex selection values:\n"; + for(auto v : vertices(sm)){ + std::cout << std::boolalpha << get(sm_selected_pmap, v) << std::endl; + } + + std::cout << "edge feature values:\n"; + for(auto e : edges(sm)){ + std::cout << std::boolalpha << get(sm_feature_pmap, e) << std::endl; + } return 0; } From 2c4fc75e177e11f11f9aecafb4ff400ea41ae863 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 20 Aug 2024 15:41:21 +0100 Subject: [PATCH 05/32] 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 aad1c35ff62d..76c38181a083 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)){ From 0e25e333a1028716ccd164f125e87ce86e3aec16 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 20 Aug 2024 16:20:33 +0100 Subject: [PATCH 06/32] put code in header file --- BGL/examples/BGL_OpenMesh/PolyMesh.cpp | 75 ++++++-------------------- BGL/examples/BGL_OpenMesh/read_OM.h | 62 +++++++++++++++++++++ 2 files changed, 77 insertions(+), 60 deletions(-) create mode 100644 BGL/examples/BGL_OpenMesh/read_OM.h diff --git a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp index 76c38181a083..7b56e0d6c3d4 100644 --- a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp @@ -1,98 +1,53 @@ #include #include -#include +#include #include #include -#include #include -#include #include #include #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 +#include "read_OM.h" typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; -typedef OpenMesh::PolyMesh_ArrayKernelT Mesh; +typedef OpenMesh::PolyMesh_ArrayKernelT OMesh; typedef CGAL::Surface_mesh SM; -typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; + typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; -typedef boost::graph_traits::face_descriptor face_descriptor; -typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; -typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; typedef boost::graph_traits::edge_descriptor sm_edge_descriptor; int main(int argc, char** argv ) { - Mesh mesh; + OMesh omesh; const std::string filename = (argc>1)?argv[1]:CGAL::data_file_path("meshes/in.off"); const char* outname= (argc>2)?argv[2]:"out.om"; - CGAL::IO::read_polygon_mesh(filename, mesh); + CGAL::IO::read_polygon_mesh(filename, omesh); - mesh.request_vertex_status(); - mesh.request_edge_status(); + omesh.request_vertex_status(); + omesh.request_edge_status(); int i = 0; - for(auto v : vertices(mesh)){ - mesh.status(v).set_selected((i%2) == 0); + for(auto v : vertices(omesh)){ + omesh.status(v).set_selected((i%2) == 0); ++i; } i = 0; - for(auto e : edges(mesh)){ - mesh.status(e).set_feature(i > 2); + for(auto e : edges(omesh)){ + omesh.status(e).set_feature(i > 2); ++i; } - OpenMesh::IO::write_mesh(mesh, outname, OpenMesh::IO::Options::Status); + OpenMesh::IO::write_mesh(omesh, outname, OpenMesh::IO::Options::Status); SM sm; diff --git a/BGL/examples/BGL_OpenMesh/read_OM.h b/BGL/examples/BGL_OpenMesh/read_OM.h new file mode 100644 index 000000000000..0ce872c10d34 --- /dev/null +++ b/BGL/examples/BGL_OpenMesh/read_OM.h @@ -0,0 +1,62 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace CGAL { +namespace IO { + +template +bool read_OM(std::string fname, SM& sm, VSelectionPM vspm, EFeaturePM efpm) +{ + typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; + typedef boost::graph_traits::vertex_descriptor om_vertex_descriptor; + typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; + typedef boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; + typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; + + OMesh omesh; + OpenMesh::IO::Options options = OpenMesh::IO::Options::Status; + bool ok = OpenMesh::IO::read_mesh(omesh, 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(omesh, sm, CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap)); + + if(options.vertex_has_status()){ + for(auto v : vertices(omesh)){ + put(vspm, v2v[v], omesh.status(v).selected()); + } + }else{ + std::cout << "no vertex status" << std::endl; + } + + if(options.edge_has_status()){ + for(auto e : edges(omesh)){ + auto sme = edge(h2h[halfedge(e,omesh)], sm); + put(efpm, sme , omesh.status(e).feature()); + } + }else{ + std::cout << "no edge status" << std::endl; + } + return true; +} + +} // namespace IO +} // namespace CGAL + + From 5d4ba30a100040643c8ca0347b961d7b97934f6e Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 20 Aug 2024 16:26:33 +0100 Subject: [PATCH 07/32] Avoid need for conversion operator --- BGL/examples/BGL_OpenMesh/PolyMesh.cpp | 4 ++-- BGL/examples/BGL_OpenMesh/read_OM.h | 2 +- STL_Extension/include/CGAL/hash_openmesh.h | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp index 7b56e0d6c3d4..bfc2d51b1ecd 100644 --- a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp @@ -42,8 +42,8 @@ int main(int argc, char** argv ) } i = 0; - for(auto e : edges(omesh)){ - omesh.status(e).set_feature(i > 2); + for(auto eit = omesh.edges_begin(); eit != omesh.edges_end(); ++eit){ + omesh.status(*eit).set_feature(i > 2); ++i; } diff --git a/BGL/examples/BGL_OpenMesh/read_OM.h b/BGL/examples/BGL_OpenMesh/read_OM.h index 0ce872c10d34..6c350bad03f9 100644 --- a/BGL/examples/BGL_OpenMesh/read_OM.h +++ b/BGL/examples/BGL_OpenMesh/read_OM.h @@ -48,7 +48,7 @@ bool read_OM(std::string fname, SM& sm, VSelectionPM vspm, EFeaturePM efpm) if(options.edge_has_status()){ for(auto e : edges(omesh)){ auto sme = edge(h2h[halfedge(e,omesh)], sm); - put(efpm, sme , omesh.status(e).feature()); + put(efpm, sme , omesh.status(OpenMesh::EdgeHandle(e.idx())).feature()); } }else{ std::cout << "no edge status" << std::endl; diff --git a/STL_Extension/include/CGAL/hash_openmesh.h b/STL_Extension/include/CGAL/hash_openmesh.h index eb9c71d58f11..9b080636b4d8 100644 --- a/STL_Extension/include/CGAL/hash_openmesh.h +++ b/STL_Extension/include/CGAL/hash_openmesh.h @@ -37,10 +37,11 @@ class OMesh_edge { } } +/* operator OpenMesh::EdgeHandle () const { return OpenMesh::EdgeHandle(idx()); } - +*/ bool operator<(const OMesh_edge& other) const { return this->idx() < other.idx(); From 4832f06ae4465b7b079ac156cbe5f99b4b2765b4 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 22 Aug 2024 11:40:27 +0100 Subject: [PATCH 08/32] Add plugin to read OpenMesh .om files --- BGL/examples/BGL_OpenMesh/PolyMesh.cpp | 3 +- Lab/demo/Lab/Plugins/IO/CMakeLists.txt | 10 ++ Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp | 169 +++++++++++++++++++++++ Stream_support/include/CGAL/IO/OM.h | 62 +++++++++ 4 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp create mode 100644 Stream_support/include/CGAL/IO/OM.h diff --git a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp index bfc2d51b1ecd..280eee442158 100644 --- a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp @@ -6,13 +6,12 @@ #include #include #include +#include #include #include #include #include -#include "read_OM.h" - typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; diff --git a/Lab/demo/Lab/Plugins/IO/CMakeLists.txt b/Lab/demo/Lab/Plugins/IO/CMakeLists.txt index 6ed225c04908..8729366809fe 100644 --- a/Lab/demo/Lab/Plugins/IO/CMakeLists.txt +++ b/Lab/demo/Lab/Plugins/IO/CMakeLists.txt @@ -43,6 +43,16 @@ target_link_libraries(surf_io_plugin PUBLIC scene_surface_mesh_item) cgal_lab_plugin(lcc_io_plugin lcc_io_plugin KEYWORDS Viewer) target_link_libraries(lcc_io_plugin PUBLIC scene_lcc_item) +find_package(OpenMesh) +if(OpenMesh_FOUND) + include(UseOpenMesh) + cgal_lab_plugin(om_plugin OM_io_plugin KEYWORDS Viewer PMP) + target_link_libraries(om_plugin PUBLIC scene_surface_mesh_item scene_polygon_soup_item) + target_link_libraries(om_plugin PRIVATE ${OPENMESH_LIBRARIES}) +else() + message(STATUS "NOTICE: the OM IO plugin needs OpenMesh libraries and will not be compiled.") +endif() + find_package(VTK 9.0 QUIET COMPONENTS CommonCore IOCore IOLegacy IOXML FiltersCore FiltersSources) set_package_properties( VTK PROPERTIES diff --git a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp new file mode 100644 index 000000000000..6ca5110a96be --- /dev/null +++ b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp @@ -0,0 +1,169 @@ +#include "SMesh_type.h" +#include "Scene_surface_mesh_item.h" +#include "Scene_polygon_soup_item.h" +#include "Kernel_type.h" +#include "Scene.h" + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +using namespace CGAL::Three; +class CGAL_Lab_om_plugin : + public QObject, + public CGAL_Lab_io_plugin_interface +{ + Q_OBJECT + Q_INTERFACES(CGAL::Three::CGAL_Lab_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.CGALLab.IOPluginInterface/1.90" FILE "om_io_plugin.json") + +public: + QString nameFilters() const; + QString name() const { return "om_plugin"; } + bool canLoad(QFileInfo fileinfo) const; + QList load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true); + + bool canSave(const CGAL::Three::Scene_item*); + bool save(QFileInfo fileinfo,QList&); +}; + +QString CGAL_Lab_om_plugin::nameFilters() const { + return "om files (*.om)"; +} + +bool CGAL_Lab_om_plugin::canLoad(QFileInfo) const { + return true; +} + + + +QList +CGAL_Lab_om_plugin:: +load(QFileInfo fileinfo, bool& ok, bool add_to_scene){ + + // Open file + std::ifstream in(fileinfo.filePath().toUtf8(), std::ios::in | std::ios::binary); + if(!in) { + std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; + ok = false; + return QList(); + } + in.close(); + if(fileinfo.size() == 0) + { + CGAL::Three::Three::warning( tr("The file you are trying to load is empty.")); + Scene_surface_mesh_item* item = new Scene_surface_mesh_item(); + item->setName(fileinfo.completeBaseName()); + ok = true; + if(add_to_scene) + CGAL::Three::Three::scene()->addItem(item); + return QList()<::vertex_descriptor vertex_descriptor; + typedef boost::graph_traits::edge_descriptor edge_descriptor; + std::map sm_selected_map; + auto sm_selected_pmap = boost::make_assoc_property_map(sm_selected_map); + + std::map sm_feature_map; + auto sm_feature_pmap = boost::make_assoc_property_map(sm_feature_map); + + // Try building a surface_mesh + SMesh* SM = new SMesh(); + if (CGAL::IO::read_OM((const char*)fileinfo.filePath().toUtf8(), *SM, sm_selected_pmap, sm_feature_pmap)) + {/* + std::cout << "vertex selection values:\n"; + for(auto v : vertices(*SM)){ + std::cout << std::boolalpha << get(sm_selected_pmap, v) << std::endl; + } + + std::cout << "edge feature values:\n"; + for(auto e : edges(*SM)){ + std::cout << std::boolalpha << get(sm_feature_pmap, e) << std::endl; + } + */ + } + + if(!SM->is_valid() || SM->is_empty()){ + std::cerr << "Error: Invalid facegraph" << std::endl; + } + else{ + Scene_surface_mesh_item* item = new Scene_surface_mesh_item(SM); + item->setName(fileinfo.completeBaseName()); + ok = true; + if(add_to_scene) + CGAL::Three::Three::scene()->addItem(item); + return QList()<(); +} + +bool CGAL_Lab_om_plugin::canSave(const CGAL::Three::Scene_item* item) +{ + return qobject_cast(item); +} + +bool CGAL_Lab_om_plugin:: +save(QFileInfo fileinfo,QList& items) +{ +#if 0 + Scene_item* item = items.front(); + const Scene_surface_mesh_item* sm_item = + qobject_cast(item); + + if(!sm_item) + return false; + + QStringList list; + list << tr("Binary"); + list << tr("Ascii"); + bool ok = false; + QString choice + = QInputDialog::getItem(nullptr, tr("Save om file"), tr("Format"), list, 0, false, &ok); + + if (!ok) + return false; + + std::ofstream out(fileinfo.filePath().toUtf8(), std::ios::out | std::ios::binary); + if ( choice == tr("Binary") ) + CGAL::IO::set_mode(out, CGAL::IO::BINARY); + else + { + CGAL::IO::set_mode(out, CGAL::IO::ASCII); + out.precision (std::numeric_limits::digits10 + 2); + } + + if (sm_item) + { + CGAL::IO::write_om(out, *sm_item->face_graph()); + items.pop_front(); + return true; + } + #endif + return false; +} + +#include "om_io_plugin.moc" diff --git a/Stream_support/include/CGAL/IO/OM.h b/Stream_support/include/CGAL/IO/OM.h new file mode 100644 index 000000000000..6c350bad03f9 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OM.h @@ -0,0 +1,62 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace CGAL { +namespace IO { + +template +bool read_OM(std::string fname, SM& sm, VSelectionPM vspm, EFeaturePM efpm) +{ + typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; + typedef boost::graph_traits::vertex_descriptor om_vertex_descriptor; + typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; + typedef boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; + typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; + + OMesh omesh; + OpenMesh::IO::Options options = OpenMesh::IO::Options::Status; + bool ok = OpenMesh::IO::read_mesh(omesh, 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(omesh, sm, CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap)); + + if(options.vertex_has_status()){ + for(auto v : vertices(omesh)){ + put(vspm, v2v[v], omesh.status(v).selected()); + } + }else{ + std::cout << "no vertex status" << std::endl; + } + + if(options.edge_has_status()){ + for(auto e : edges(omesh)){ + auto sme = edge(h2h[halfedge(e,omesh)], sm); + put(efpm, sme , omesh.status(OpenMesh::EdgeHandle(e.idx())).feature()); + } + }else{ + std::cout << "no edge status" << std::endl; + } + return true; +} + +} // namespace IO +} // namespace CGAL + + From 496019ae4eb36ffac2065b36b46b904d5dae3251 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 22 Aug 2024 13:25:31 +0100 Subject: [PATCH 09/32] Add a selection item for edges marked in the om file --- Lab/demo/Lab/Plugins/IO/CMakeLists.txt | 2 +- Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp | 20 ++++++++++++++++---- Stream_support/include/CGAL/IO/OM.h | 15 +++++++++++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Lab/demo/Lab/Plugins/IO/CMakeLists.txt b/Lab/demo/Lab/Plugins/IO/CMakeLists.txt index 8729366809fe..2b1b56be430f 100644 --- a/Lab/demo/Lab/Plugins/IO/CMakeLists.txt +++ b/Lab/demo/Lab/Plugins/IO/CMakeLists.txt @@ -47,7 +47,7 @@ find_package(OpenMesh) if(OpenMesh_FOUND) include(UseOpenMesh) cgal_lab_plugin(om_plugin OM_io_plugin KEYWORDS Viewer PMP) - target_link_libraries(om_plugin PUBLIC scene_surface_mesh_item scene_polygon_soup_item) + target_link_libraries(om_plugin PUBLIC scene_surface_mesh_item scene_polygon_soup_item scene_selection_item) target_link_libraries(om_plugin PRIVATE ${OPENMESH_LIBRARIES}) else() message(STATUS "NOTICE: the OM IO plugin needs OpenMesh libraries and will not be compiled.") diff --git a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp index 6ca5110a96be..20cda20b526a 100644 --- a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp +++ b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp @@ -6,10 +6,10 @@ #include #include +#include "Scene_polyhedron_selection_item.h" #include #include -#include #include #include @@ -90,7 +90,8 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){ // Try building a surface_mesh SMesh* SM = new SMesh(); if (CGAL::IO::read_OM((const char*)fileinfo.filePath().toUtf8(), *SM, sm_selected_pmap, sm_feature_pmap)) - {/* + { + /* std::cout << "vertex selection values:\n"; for(auto v : vertices(*SM)){ std::cout << std::boolalpha << get(sm_selected_pmap, v) << std::endl; @@ -108,11 +109,22 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){ } else{ Scene_surface_mesh_item* item = new Scene_surface_mesh_item(SM); + + Scene_polyhedron_selection_item* selection_item = new Scene_polyhedron_selection_item(item, CGAL::Three::Three::mainWindow()); + bool selected = false; + for(auto e : edges(*SM)){ + if(get(sm_feature_pmap, e)){ + selection_item->selected_edges.insert(e); + selected = true; + } + } item->setName(fileinfo.completeBaseName()); ok = true; - if(add_to_scene) + if(add_to_scene){ CGAL::Three::Three::scene()->addItem(item); - return QList()<addItem(selection_item); + } + return QList()< #include @@ -59,4 +70,4 @@ bool read_OM(std::string fname, SM& sm, VSelectionPM vspm, EFeaturePM efpm) } // namespace IO } // namespace CGAL - +#endif // CGAL_IO_OM \ No newline at end of file From 302e2fe594a00cdc784eea1d49b53c4554ff34ec Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 22 Aug 2024 14:53:11 +0100 Subject: [PATCH 10/32] We are only interested in features --- Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp | 38 ++++++++++-------------- Stream_support/include/CGAL/IO/OM.h | 6 ++-- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp index 20cda20b526a..35ea205c98a6 100644 --- a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp +++ b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp @@ -81,41 +81,35 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){ { typedef boost::graph_traits::vertex_descriptor vertex_descriptor; typedef boost::graph_traits::edge_descriptor edge_descriptor; - std::map sm_selected_map; - auto sm_selected_pmap = boost::make_assoc_property_map(sm_selected_map); + std::map sm_vfeature_map; + auto sm_vfeature_pmap = boost::make_assoc_property_map(sm_vfeature_map); - std::map sm_feature_map; - auto sm_feature_pmap = boost::make_assoc_property_map(sm_feature_map); + std::map sm_efeature_map; + auto sm_efeature_pmap = boost::make_assoc_property_map(sm_efeature_map); // Try building a surface_mesh SMesh* SM = new SMesh(); - if (CGAL::IO::read_OM((const char*)fileinfo.filePath().toUtf8(), *SM, sm_selected_pmap, sm_feature_pmap)) - { - /* - std::cout << "vertex selection values:\n"; - for(auto v : vertices(*SM)){ - std::cout << std::boolalpha << get(sm_selected_pmap, v) << std::endl; - } + ok = CGAL::IO::read_OM((const char*)fileinfo.filePath().toUtf8(), *SM, sm_vfeature_pmap, sm_efeature_pmap); - std::cout << "edge feature values:\n"; - for(auto e : edges(*SM)){ - std::cout << std::boolalpha << get(sm_feature_pmap, e) << std::endl; - } - */ - } - - if(!SM->is_valid() || SM->is_empty()){ + if(!ok || !SM->is_valid() || SM->is_empty()){ std::cerr << "Error: Invalid facegraph" << std::endl; } else{ Scene_surface_mesh_item* item = new Scene_surface_mesh_item(SM); Scene_polyhedron_selection_item* selection_item = new Scene_polyhedron_selection_item(item, CGAL::Three::Three::mainWindow()); - bool selected = false; + bool eselected = false; + bool vselected = false; + for(auto v : vertices(*SM)){ + if(get(sm_vfeature_pmap, v)){ + selection_item->selected_vertices.insert(v); + vselected = true; + } + } for(auto e : edges(*SM)){ - if(get(sm_feature_pmap, e)){ + if(get(sm_efeature_pmap, e)){ selection_item->selected_edges.insert(e); - selected = true; + eselected = true; } } item->setName(fileinfo.completeBaseName()); diff --git a/Stream_support/include/CGAL/IO/OM.h b/Stream_support/include/CGAL/IO/OM.h index 4390be1ced0c..1ad9cc57d665 100644 --- a/Stream_support/include/CGAL/IO/OM.h +++ b/Stream_support/include/CGAL/IO/OM.h @@ -24,8 +24,8 @@ namespace CGAL { namespace IO { -template -bool read_OM(std::string fname, SM& sm, VSelectionPM vspm, EFeaturePM efpm) +template +bool read_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) { typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; typedef boost::graph_traits::vertex_descriptor om_vertex_descriptor; @@ -50,7 +50,7 @@ bool read_OM(std::string fname, SM& sm, VSelectionPM vspm, EFeaturePM efpm) if(options.vertex_has_status()){ for(auto v : vertices(omesh)){ - put(vspm, v2v[v], omesh.status(v).selected()); + put(vfpm, v2v[v], omesh.status(v).feature()); } }else{ std::cout << "no vertex status" << std::endl; From 07fac94de2b70ce93c3082def6b7ab80f3364dc9 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Thu, 5 Sep 2024 17:13:43 +0200 Subject: [PATCH 11/32] use CGAL::OpenMesh_support --- Lab/demo/Lab/Plugins/IO/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lab/demo/Lab/Plugins/IO/CMakeLists.txt b/Lab/demo/Lab/Plugins/IO/CMakeLists.txt index 2b1b56be430f..030eeac8322d 100644 --- a/Lab/demo/Lab/Plugins/IO/CMakeLists.txt +++ b/Lab/demo/Lab/Plugins/IO/CMakeLists.txt @@ -45,10 +45,10 @@ target_link_libraries(lcc_io_plugin PUBLIC scene_lcc_item) find_package(OpenMesh) if(OpenMesh_FOUND) - include(UseOpenMesh) + include(CGAL_OpenMesh_support) cgal_lab_plugin(om_plugin OM_io_plugin KEYWORDS Viewer PMP) target_link_libraries(om_plugin PUBLIC scene_surface_mesh_item scene_polygon_soup_item scene_selection_item) - target_link_libraries(om_plugin PRIVATE ${OPENMESH_LIBRARIES}) + target_link_libraries(om_plugin PRIVATE CGAL::OpenMesh_support) else() message(STATUS "NOTICE: the OM IO plugin needs OpenMesh libraries and will not be compiled.") endif() From 2145d262d33b394704e8edb2dc9ffbc47199fa79 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Thu, 5 Sep 2024 17:14:53 +0200 Subject: [PATCH 12/32] add write_OM() and use it in OM_io_plugin --- Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp | 76 ++++++++++++++++-------- Stream_support/include/CGAL/IO/OM.h | 44 ++++++++++++++ 2 files changed, 95 insertions(+), 25 deletions(-) diff --git a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp index 35ea205c98a6..fc4191f878e6 100644 --- a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp +++ b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp @@ -129,47 +129,73 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){ bool CGAL_Lab_om_plugin::canSave(const CGAL::Three::Scene_item* item) { - return qobject_cast(item); + return qobject_cast(item) + || qobject_cast(item); } bool CGAL_Lab_om_plugin:: -save(QFileInfo fileinfo,QList& items) +save(QFileInfo fileinfo, QList& items) { -#if 0 Scene_item* item = items.front(); - const Scene_surface_mesh_item* sm_item = - qobject_cast(item); - if(!sm_item) - return false; + Scene_surface_mesh_item* sm_item = nullptr; + Scene_polyhedron_selection_item* selection_item = nullptr; - QStringList list; - list << tr("Binary"); - list << tr("Ascii"); - bool ok = false; - QString choice - = QInputDialog::getItem(nullptr, tr("Save om file"), tr("Format"), list, 0, false, &ok); + for (Scene_item* item : items) + { + if (sm_item == nullptr) + { + sm_item = qobject_cast(item); + if (sm_item != nullptr) //surface_mesh_item found + continue; + } + if (selection_item == nullptr) + { + selection_item = qobject_cast(item); + } + } - if (!ok) + if (sm_item == nullptr && selection_item == nullptr) return false; - std::ofstream out(fileinfo.filePath().toUtf8(), std::ios::out | std::ios::binary); - if ( choice == tr("Binary") ) - CGAL::IO::set_mode(out, CGAL::IO::BINARY); + if (selection_item != nullptr) + { + if (sm_item == nullptr) + sm_item = selection_item->polyhedron_item(); + + if (sm_item != selection_item->polyhedron_item()) + { + std::cerr << "Warning! Selection is not associated to the surface_mesh. Ignoring selection." << std::endl; + selection_item = nullptr; + } + } + + bool res = false; + if (selection_item != nullptr) + { + res = CGAL::IO::write_OM((const char*)fileinfo.filePath().toUtf8() + , *sm_item->face_graph() + , selection_item->constrained_vertices_pmap() + , selection_item->constrained_edges_pmap()); + } else { - CGAL::IO::set_mode(out, CGAL::IO::ASCII); - out.precision (std::numeric_limits::digits10 + 2); + using edge_descriptor = typename boost::graph_traits::edge_descriptor; + using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; + + res = CGAL::IO::write_OM((const char*)fileinfo.filePath().toUtf8() + , *sm_item->face_graph() + , CGAL::Constant_property_map(false) + , CGAL::Constant_property_map(false)); } - if (sm_item) + if (res) { - CGAL::IO::write_om(out, *sm_item->face_graph()); - items.pop_front(); - return true; + items.removeAll(sm_item); + if (selection_item != nullptr) + items.removeAll(selection_item); } - #endif - return false; + return res; } #include "om_io_plugin.moc" diff --git a/Stream_support/include/CGAL/IO/OM.h b/Stream_support/include/CGAL/IO/OM.h index 1ad9cc57d665..4c46bbed599a 100644 --- a/Stream_support/include/CGAL/IO/OM.h +++ b/Stream_support/include/CGAL/IO/OM.h @@ -67,6 +67,50 @@ bool read_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) return true; } +template +bool write_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) +{ + typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; + typedef boost::graph_traits::vertex_descriptor om_vertex_descriptor; + typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; + typedef boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; + typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; + + std::map v2v; + auto v2vpmap = boost::make_assoc_property_map(v2v); + + std::map h2h; + auto h2hpmap = boost::make_assoc_property_map(h2h); + + OMesh omesh; + CGAL::copy_face_graph(sm, omesh, + CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap)); + + omesh.request_edge_status(); + omesh.request_vertex_status(); + + std::size_t nbe = 0; + std::size_t nbv = 0; + for (auto h : halfedges(sm)) + { + om_halfedge_descriptor omh = h2h.at(h); + const bool isfeature = get(efpm, edge(h, sm)); + if (isfeature) nbe++; + omesh.status(omesh.edge_handle(omh)).set_feature(isfeature); + } + for (auto v : vertices(sm)) + { + auto omv = v2v.at(v); + const bool isfeature = get(vfpm, v); + if (isfeature) nbv++; + omesh.status(omv).set_feature(isfeature); + } + + std::cout << nbv << " feature vertices" << std::endl; + std::cout << nbe << " feature edges" << std::endl; + return OpenMesh::IO::write_mesh(omesh, fname, OpenMesh::IO::Options::Status); +} + } // namespace IO } // namespace CGAL From dfecf519da1b5455327ab6fc65daa61d8554a341 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Thu, 5 Sep 2024 17:21:40 +0200 Subject: [PATCH 13/32] trailing whitespaces --- Stream_support/include/CGAL/IO/OM.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stream_support/include/CGAL/IO/OM.h b/Stream_support/include/CGAL/IO/OM.h index 4c46bbed599a..c715234066ea 100644 --- a/Stream_support/include/CGAL/IO/OM.h +++ b/Stream_support/include/CGAL/IO/OM.h @@ -88,7 +88,7 @@ bool write_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) omesh.request_edge_status(); omesh.request_vertex_status(); - + std::size_t nbe = 0; std::size_t nbv = 0; for (auto h : halfedges(sm)) From 705729e45eef38079dc0d5f1084c47efcebd7e70 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Sun, 8 Sep 2024 12:17:24 +0100 Subject: [PATCH 14/32] cleanup --- Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp | 12 ++++++------ STL_Extension/include/CGAL/hash_openmesh.h | 5 ----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp index fc4191f878e6..3c6b8dedf4d0 100644 --- a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp +++ b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp @@ -88,25 +88,25 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){ auto sm_efeature_pmap = boost::make_assoc_property_map(sm_efeature_map); // Try building a surface_mesh - SMesh* SM = new SMesh(); - ok = CGAL::IO::read_OM((const char*)fileinfo.filePath().toUtf8(), *SM, sm_vfeature_pmap, sm_efeature_pmap); + SMesh* sm = new SMesh(); + ok = CGAL::IO::read_OM((const char*)fileinfo.filePath().toUtf8(), *sm, sm_vfeature_pmap, sm_efeature_pmap); - if(!ok || !SM->is_valid() || SM->is_empty()){ + if(!ok || !sm->is_valid() || sm->is_empty()){ std::cerr << "Error: Invalid facegraph" << std::endl; } else{ - Scene_surface_mesh_item* item = new Scene_surface_mesh_item(SM); + Scene_surface_mesh_item* item = new Scene_surface_mesh_item(sm); Scene_polyhedron_selection_item* selection_item = new Scene_polyhedron_selection_item(item, CGAL::Three::Three::mainWindow()); bool eselected = false; bool vselected = false; - for(auto v : vertices(*SM)){ + for(auto v : vertices(*sm)){ if(get(sm_vfeature_pmap, v)){ selection_item->selected_vertices.insert(v); vselected = true; } } - for(auto e : edges(*SM)){ + for(auto e : edges(*sm)){ if(get(sm_efeature_pmap, e)){ selection_item->selected_edges.insert(e); eselected = true; diff --git a/STL_Extension/include/CGAL/hash_openmesh.h b/STL_Extension/include/CGAL/hash_openmesh.h index 9b080636b4d8..700f58e87eb2 100644 --- a/STL_Extension/include/CGAL/hash_openmesh.h +++ b/STL_Extension/include/CGAL/hash_openmesh.h @@ -37,11 +37,6 @@ class OMesh_edge { } } -/* - operator OpenMesh::EdgeHandle () const { - return OpenMesh::EdgeHandle(idx()); - } -*/ bool operator<(const OMesh_edge& other) const { return this->idx() < other.idx(); From 9f77e301f45af06f05ba8a69a8cb7e8c544334ab Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Sun, 8 Sep 2024 12:19:58 +0100 Subject: [PATCH 15/32] STL_extension: Add conversion operator --- STL_Extension/include/CGAL/hash_openmesh.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/STL_Extension/include/CGAL/hash_openmesh.h b/STL_Extension/include/CGAL/hash_openmesh.h index 700f58e87eb2..eb9c71d58f11 100644 --- a/STL_Extension/include/CGAL/hash_openmesh.h +++ b/STL_Extension/include/CGAL/hash_openmesh.h @@ -37,6 +37,10 @@ class OMesh_edge { } } + operator OpenMesh::EdgeHandle () const { + return OpenMesh::EdgeHandle(idx()); + } + bool operator<(const OMesh_edge& other) const { return this->idx() < other.idx(); From 4aae544a1b2134ac73db301031eacf10cd660913 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Sun, 8 Sep 2024 12:40:25 +0100 Subject: [PATCH 16/32] cleanup --- STL_Extension/include/CGAL/hash_openmesh.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/STL_Extension/include/CGAL/hash_openmesh.h b/STL_Extension/include/CGAL/hash_openmesh.h index eb9c71d58f11..700f58e87eb2 100644 --- a/STL_Extension/include/CGAL/hash_openmesh.h +++ b/STL_Extension/include/CGAL/hash_openmesh.h @@ -37,10 +37,6 @@ class OMesh_edge { } } - operator OpenMesh::EdgeHandle () const { - return OpenMesh::EdgeHandle(idx()); - } - bool operator<(const OMesh_edge& other) const { return this->idx() < other.idx(); From 2eb80332ba02f2fa09831e7349c9a82955582183 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 10 Sep 2024 11:07:39 +0200 Subject: [PATCH 17/32] create selection item only when OM file contains feature vertices or edges --- Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp index 3c6b8dedf4d0..040cc1ced7f7 100644 --- a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp +++ b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp @@ -114,11 +114,18 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){ } item->setName(fileinfo.completeBaseName()); ok = true; - if(add_to_scene){ + if(add_to_scene) + { CGAL::Three::Three::scene()->addItem(item); - CGAL::Three::Three::scene()->addItem(selection_item); + if(!selection_item->isEmpty()) + CGAL::Three::Three::scene()->addItem(selection_item); } - return QList()< res; + res << item; + if(!selection_item->isEmpty()) + res << selection_item; + return res; } } catch(...){} From 6696b2a51f63055b870809a138f1b1c6f8b1cb9c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 17 Sep 2024 08:02:32 +0100 Subject: [PATCH 18/32] de X --- BGL/examples/BGL_OpenMesh/PolyMesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp index 280eee442158..3dde7d168456 100644 --- a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include From 206eb3c19812166fd09bad293b60bcaa1905704b Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 17 Sep 2024 08:52:14 +0100 Subject: [PATCH 19/32] Only compile OM.h when using OpenMesh --- Stream_support/include/CGAL/IO/OM.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Stream_support/include/CGAL/IO/OM.h b/Stream_support/include/CGAL/IO/OM.h index c715234066ea..2976c97c086d 100644 --- a/Stream_support/include/CGAL/IO/OM.h +++ b/Stream_support/include/CGAL/IO/OM.h @@ -11,6 +11,8 @@ #ifndef CGAL_IO_OM_H #define CGAL_IO_OM_H +#if defined(CGAL_USE_OPENMESH) || defined(DOXYGEN_RUNNING) + #include #include @@ -114,4 +116,5 @@ bool write_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) } // namespace IO } // namespace CGAL +#endif // CGAL_USE_OPENMESH || DOXYGEN_RUNNING #endif // CGAL_IO_OM \ No newline at end of file From 7faabe4b6273f8e1a0d5ac56df29a91d2a18051a Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 20 Sep 2024 07:54:34 +0100 Subject: [PATCH 20/32] Add #include of copy_face_graph --- Stream_support/include/CGAL/IO/OM.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Stream_support/include/CGAL/IO/OM.h b/Stream_support/include/CGAL/IO/OM.h index 2976c97c086d..ba648f9ab0c8 100644 --- a/Stream_support/include/CGAL/IO/OM.h +++ b/Stream_support/include/CGAL/IO/OM.h @@ -16,6 +16,7 @@ #include #include +#include #include #include #include From 5f2afe2e368b9c4531d9873595665e102a3936a0 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Thu, 26 Sep 2024 11:58:20 +0200 Subject: [PATCH 21/32] fix typedefs (code review) Co-authored-by: Sebastien Loriot --- Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp | 4 ++-- Stream_support/include/CGAL/IO/OM.h | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp index 040cc1ced7f7..9ea1aea33d73 100644 --- a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp +++ b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp @@ -187,8 +187,8 @@ save(QFileInfo fileinfo, QList& items) } else { - using edge_descriptor = typename boost::graph_traits::edge_descriptor; - using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; + using edge_descriptor = boost::graph_traits::edge_descriptor; + using vertex_descriptor = boost::graph_traits::vertex_descriptor; res = CGAL::IO::write_OM((const char*)fileinfo.filePath().toUtf8() , *sm_item->face_graph() diff --git a/Stream_support/include/CGAL/IO/OM.h b/Stream_support/include/CGAL/IO/OM.h index ba648f9ab0c8..d13ef30fdb0c 100644 --- a/Stream_support/include/CGAL/IO/OM.h +++ b/Stream_support/include/CGAL/IO/OM.h @@ -31,10 +31,10 @@ template bool read_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) { typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; - typedef boost::graph_traits::vertex_descriptor om_vertex_descriptor; - typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; - typedef boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; - typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; + typedef typename boost::graph_traits::vertex_descriptor om_vertex_descriptor; + typedef typename boost::graph_traits::vertex_descriptor sm_vertex_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; OMesh omesh; OpenMesh::IO::Options options = OpenMesh::IO::Options::Status; @@ -74,10 +74,10 @@ template bool write_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) { typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; - typedef boost::graph_traits::vertex_descriptor om_vertex_descriptor; - typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; - typedef boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; - typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; + typedef typename boost::graph_traits::vertex_descriptor om_vertex_descriptor; + typedef typename boost::graph_traits::vertex_descriptor sm_vertex_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; std::map v2v; auto v2vpmap = boost::make_assoc_property_map(v2v); From 54db08518a6b97e87c58fa9738f3a0d65b91c8d3 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Thu, 26 Sep 2024 11:58:52 +0200 Subject: [PATCH 22/32] add EOL Co-authored-by: Sebastien Loriot --- Stream_support/include/CGAL/IO/OM.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stream_support/include/CGAL/IO/OM.h b/Stream_support/include/CGAL/IO/OM.h index d13ef30fdb0c..0953a90516a8 100644 --- a/Stream_support/include/CGAL/IO/OM.h +++ b/Stream_support/include/CGAL/IO/OM.h @@ -118,4 +118,4 @@ bool write_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) } // namespace CGAL #endif // CGAL_USE_OPENMESH || DOXYGEN_RUNNING -#endif // CGAL_IO_OM \ No newline at end of file +#endif // CGAL_IO_OM From 5d77b6b19e76a3effaa48b5a3cd1f9a223576348 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Thu, 26 Sep 2024 12:11:11 +0200 Subject: [PATCH 23/32] remove debug code --- Stream_support/include/CGAL/IO/OM.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Stream_support/include/CGAL/IO/OM.h b/Stream_support/include/CGAL/IO/OM.h index 0953a90516a8..dfa8e8bdb4b3 100644 --- a/Stream_support/include/CGAL/IO/OM.h +++ b/Stream_support/include/CGAL/IO/OM.h @@ -55,8 +55,6 @@ bool read_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) for(auto v : vertices(omesh)){ put(vfpm, v2v[v], omesh.status(v).feature()); } - }else{ - std::cout << "no vertex status" << std::endl; } if(options.edge_has_status()){ @@ -64,8 +62,6 @@ bool read_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) auto sme = edge(h2h[halfedge(e,omesh)], sm); put(efpm, sme , omesh.status(OpenMesh::EdgeHandle(e.idx())).feature()); } - }else{ - std::cout << "no edge status" << std::endl; } return true; } @@ -92,25 +88,19 @@ bool write_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) omesh.request_edge_status(); omesh.request_vertex_status(); - std::size_t nbe = 0; - std::size_t nbv = 0; for (auto h : halfedges(sm)) { om_halfedge_descriptor omh = h2h.at(h); const bool isfeature = get(efpm, edge(h, sm)); - if (isfeature) nbe++; omesh.status(omesh.edge_handle(omh)).set_feature(isfeature); } for (auto v : vertices(sm)) { auto omv = v2v.at(v); const bool isfeature = get(vfpm, v); - if (isfeature) nbv++; omesh.status(omv).set_feature(isfeature); } - std::cout << nbv << " feature vertices" << std::endl; - std::cout << nbe << " feature edges" << std::endl; return OpenMesh::IO::write_mesh(omesh, fname, OpenMesh::IO::Options::Status); } From f30fffd5c360e50630019e809c864d17890c5561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 8 Oct 2024 11:07:22 +0200 Subject: [PATCH 24/32] fix warnings and incorrect filename --- Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp index 9ea1aea33d73..e02b89c5fd9b 100644 --- a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp +++ b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp @@ -98,18 +98,14 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){ Scene_surface_mesh_item* item = new Scene_surface_mesh_item(sm); Scene_polyhedron_selection_item* selection_item = new Scene_polyhedron_selection_item(item, CGAL::Three::Three::mainWindow()); - bool eselected = false; - bool vselected = false; for(auto v : vertices(*sm)){ if(get(sm_vfeature_pmap, v)){ selection_item->selected_vertices.insert(v); - vselected = true; } } for(auto e : edges(*sm)){ if(get(sm_efeature_pmap, e)){ selection_item->selected_edges.insert(e); - eselected = true; } } item->setName(fileinfo.completeBaseName()); @@ -143,8 +139,6 @@ bool CGAL_Lab_om_plugin::canSave(const CGAL::Three::Scene_item* item) bool CGAL_Lab_om_plugin:: save(QFileInfo fileinfo, QList& items) { - Scene_item* item = items.front(); - Scene_surface_mesh_item* sm_item = nullptr; Scene_polyhedron_selection_item* selection_item = nullptr; @@ -205,4 +199,4 @@ save(QFileInfo fileinfo, QList& items) return res; } -#include "om_io_plugin.moc" +#include "OM_io_plugin.moc" From b7b48b107c35c1e96ec1bae814dbfef9d7fe8daf Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 8 Oct 2024 11:44:17 +0200 Subject: [PATCH 25/32] add QUIET Co-authored-by: Sebastien Loriot --- Lab/demo/Lab/Plugins/IO/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab/demo/Lab/Plugins/IO/CMakeLists.txt b/Lab/demo/Lab/Plugins/IO/CMakeLists.txt index 6486ebbedd07..9288df09127b 100644 --- a/Lab/demo/Lab/Plugins/IO/CMakeLists.txt +++ b/Lab/demo/Lab/Plugins/IO/CMakeLists.txt @@ -47,7 +47,7 @@ target_link_libraries(surf_io_plugin PUBLIC scene_surface_mesh_item) cgal_lab_plugin(lcc_io_plugin lcc_io_plugin KEYWORDS Viewer) target_link_libraries(lcc_io_plugin PUBLIC scene_lcc_item) -find_package(OpenMesh) +find_package(OpenMesh QUIET) if(OpenMesh_FOUND) include(CGAL_OpenMesh_support) cgal_lab_plugin(om_plugin OM_io_plugin KEYWORDS Viewer PMP) From cddb3d5c562bb999dfe31f65f1ecd1d0b35f477b Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Wed, 23 Oct 2024 11:58:02 +0200 Subject: [PATCH 26/32] move OM.h IO header to BGL package adapt demo and examples BGL example TriMesh.cpp does not compile --- BGL/examples/BGL_OpenMesh/PolyMesh.cpp | 3 - BGL/examples/BGL_OpenMesh/TriMesh.cpp | 9 +- BGL/include/CGAL/IO/polygon_mesh_io.h | 6 + BGL/include/CGAL/boost/graph/IO/OM.h | 150 +++++++++++++++++++++++ Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp | 20 ++- Stream_support/include/CGAL/IO/OM.h | 111 ----------------- 6 files changed, 170 insertions(+), 129 deletions(-) create mode 100644 BGL/include/CGAL/boost/graph/IO/OM.h delete mode 100644 Stream_support/include/CGAL/IO/OM.h diff --git a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp index 3dde7d168456..96d6feb252bb 100644 --- a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp @@ -1,16 +1,13 @@ #include -#include #include #include #include #include -#include #include #include #include -#include typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; diff --git a/BGL/examples/BGL_OpenMesh/TriMesh.cpp b/BGL/examples/BGL_OpenMesh/TriMesh.cpp index e474020cc67e..f84a19762a85 100644 --- a/BGL/examples/BGL_OpenMesh/TriMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/TriMesh.cpp @@ -1,17 +1,18 @@ #include -#include #include #include +#include + #include -#include #include + +#include #include -#include #include -#include + typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; diff --git a/BGL/include/CGAL/IO/polygon_mesh_io.h b/BGL/include/CGAL/IO/polygon_mesh_io.h index 21f61087ab6b..60a1e5520c5d 100644 --- a/BGL/include/CGAL/IO/polygon_mesh_io.h +++ b/BGL/include/CGAL/IO/polygon_mesh_io.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,7 @@ bool read_polygon_mesh(std::istream& is, * Supported file formats are the following: * - \ref IOStreamOFF (`.off`) * - \ref IOStreamOBJ (`.obj`) + * - \ref IOStreamOM (`.om`) * - \ref IOStreamSTL (`.stl`) * - \ref IOStreamPLY (`.ply`) * - \ref IOStreamGocad (`.ts`) @@ -138,6 +140,10 @@ bool read_polygon_mesh(const std::string& fname, return read_OBJ(fname, g, np); else if(ext == "off") return read_OFF(fname, g, np); +#ifdef CGAL_USE_OPENMESH + else if(ext == "om") + return read_OM(fname, g, np); +#endif else if(ext == "ply") return read_PLY(fname, g, np); else if(ext == "stl") diff --git a/BGL/include/CGAL/boost/graph/IO/OM.h b/BGL/include/CGAL/boost/graph/IO/OM.h new file mode 100644 index 000000000000..c9a9f1f3ef32 --- /dev/null +++ b/BGL/include/CGAL/boost/graph/IO/OM.h @@ -0,0 +1,150 @@ +// Copyright (c) 2024 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_BGL_IO_OM_H +#define CGAL_BGL_IO_OM_H + +#if defined(CGAL_USE_OPENMESH) || defined(DOXYGEN_RUNNING) + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace CGAL { +namespace IO { + +template +bool read_OM(const std::string& fname, Graph& g, VFeaturePM vfpm, EFeaturePM efpm) +{ + typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; + typedef typename boost::graph_traits::vertex_descriptor om_vertex_descriptor; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + + OMesh omesh; + OpenMesh::IO::Options options = OpenMesh::IO::Options::Status; + bool ok = OpenMesh::IO::read_mesh(omesh, 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(omesh, g, + CGAL::parameters::vertex_to_vertex_map(v2vpmap) + .halfedge_to_halfedge_map(h2hpmap)); + if(options.vertex_has_status()){ + for(auto v : vertices(omesh)){ + put(vfpm, v2v[v], omesh.status(v).feature()); + } + } + + if(options.edge_has_status()){ + for(auto e : edges(omesh)){ + auto sme = edge(h2h[halfedge(e,omesh)], g); + put(efpm, sme , omesh.status(OpenMesh::EdgeHandle(e.idx())).feature()); + } + } + return true; +} + +template +bool read_OM(const std::string& fname, + Graph& g, + const CGAL_NP_CLASS& np = parameters::default_values()) +{ + using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; + using edge_descriptor = typename boost::graph_traits::edge_descriptor; + + using CGAL::parameters::get_parameter; + using CGAL::parameters::choose_parameter; + auto vfpm = choose_parameter(get_parameter(np, internal_np::vertex_is_constrained), + CGAL::Constant_property_map(false)); + auto efpm = choose_parameter(get_parameter(np, internal_np::edge_is_constrained), + CGAL::Constant_property_map(false)); + return read_OM(fname, g, vfpm, efpm); +} + +template +bool write_OM(std::string fname, Graph& g, VFeaturePM vfpm, EFeaturePM efpm) +{ + typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; + typedef typename boost::graph_traits::vertex_descriptor om_vertex_descriptor; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + + std::map v2v; + auto v2vpmap = boost::make_assoc_property_map(v2v); + + std::map h2h; + auto h2hpmap = boost::make_assoc_property_map(h2h); + + OMesh omesh; + CGAL::copy_face_graph(g, omesh, + CGAL::parameters::vertex_to_vertex_map(v2vpmap) + .halfedge_to_halfedge_map(h2hpmap)); + omesh.request_edge_status(); + omesh.request_vertex_status(); + + for (auto h : halfedges(g)) + { + om_halfedge_descriptor omh = h2h.at(h); + const bool isfeature = get(efpm, edge(h, g)); + omesh.status(omesh.edge_handle(omh)).set_feature(isfeature); + } + for (auto v : vertices(g)) + { + auto omv = v2v.at(v); + const bool isfeature = get(vfpm, v); + omesh.status(omv).set_feature(isfeature); + } + + return OpenMesh::IO::write_mesh(omesh, fname, OpenMesh::IO::Options::Status); +} + +template +bool write_OM(const std::string& fname, + Graph& g, + const CGAL_NP_CLASS& np = parameters::default_values()) +{ + using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; + using edge_descriptor = typename boost::graph_traits::edge_descriptor; + + using CGAL::parameters::get_parameter; + using CGAL::parameters::choose_parameter; + auto vfpm = choose_parameter(get_parameter(np, internal_np::vertex_is_constrained), + CGAL::Constant_property_map(false)); + auto efpm = choose_parameter(get_parameter(np, internal_np::edge_is_constrained), + CGAL::Constant_property_map(false)); + return write_OM(fname, g, vfpm, efpm); +} + + +} // namespace IO +} // namespace CGAL + +#endif // CGAL_USE_OPENMESH || DOXYGEN_RUNNING +#endif // CGAL_IO_OM diff --git a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp index e02b89c5fd9b..286fdd5bc01d 100644 --- a/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp +++ b/Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp @@ -8,7 +8,7 @@ #include #include "Scene_polyhedron_selection_item.h" -#include +#include #include #include @@ -89,7 +89,10 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){ // Try building a surface_mesh SMesh* sm = new SMesh(); - ok = CGAL::IO::read_OM((const char*)fileinfo.filePath().toUtf8(), *sm, sm_vfeature_pmap, sm_efeature_pmap); + ok = CGAL::IO::read_OM((const char*)fileinfo.filePath().toUtf8(), + *sm, + CGAL::parameters::vertex_is_constrained_map(sm_vfeature_pmap) + .edge_is_constrained_map(sm_efeature_pmap)); if(!ok || !sm->is_valid() || sm->is_empty()){ std::cerr << "Error: Invalid facegraph" << std::endl; @@ -175,19 +178,14 @@ save(QFileInfo fileinfo, QList& items) if (selection_item != nullptr) { res = CGAL::IO::write_OM((const char*)fileinfo.filePath().toUtf8() - , *sm_item->face_graph() - , selection_item->constrained_vertices_pmap() - , selection_item->constrained_edges_pmap()); + , *sm_item->face_graph() + , CGAL::parameters::vertex_is_constrained_map(selection_item->constrained_vertices_pmap()) + .edge_is_constrained_map(selection_item->constrained_edges_pmap())); } else { - using edge_descriptor = boost::graph_traits::edge_descriptor; - using vertex_descriptor = boost::graph_traits::vertex_descriptor; - res = CGAL::IO::write_OM((const char*)fileinfo.filePath().toUtf8() - , *sm_item->face_graph() - , CGAL::Constant_property_map(false) - , CGAL::Constant_property_map(false)); + , *sm_item->face_graph()); } if (res) diff --git a/Stream_support/include/CGAL/IO/OM.h b/Stream_support/include/CGAL/IO/OM.h deleted file mode 100644 index dfa8e8bdb4b3..000000000000 --- a/Stream_support/include/CGAL/IO/OM.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2024 GeometryFactory -// -// This file is part of CGAL (www.cgal.org); -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author(s) : Andreas Fabri - -#ifndef CGAL_IO_OM_H -#define CGAL_IO_OM_H - -#if defined(CGAL_USE_OPENMESH) || defined(DOXYGEN_RUNNING) - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace CGAL { -namespace IO { - -template -bool read_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) -{ - typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; - typedef typename boost::graph_traits::vertex_descriptor om_vertex_descriptor; - typedef typename boost::graph_traits::vertex_descriptor sm_vertex_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; - - OMesh omesh; - OpenMesh::IO::Options options = OpenMesh::IO::Options::Status; - bool ok = OpenMesh::IO::read_mesh(omesh, 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(omesh, sm, CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap)); - - if(options.vertex_has_status()){ - for(auto v : vertices(omesh)){ - put(vfpm, v2v[v], omesh.status(v).feature()); - } - } - - if(options.edge_has_status()){ - for(auto e : edges(omesh)){ - auto sme = edge(h2h[halfedge(e,omesh)], sm); - put(efpm, sme , omesh.status(OpenMesh::EdgeHandle(e.idx())).feature()); - } - } - return true; -} - -template -bool write_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm) -{ - typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; - typedef typename boost::graph_traits::vertex_descriptor om_vertex_descriptor; - typedef typename boost::graph_traits::vertex_descriptor sm_vertex_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; - - std::map v2v; - auto v2vpmap = boost::make_assoc_property_map(v2v); - - std::map h2h; - auto h2hpmap = boost::make_assoc_property_map(h2h); - - OMesh omesh; - CGAL::copy_face_graph(sm, omesh, - CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap)); - - omesh.request_edge_status(); - omesh.request_vertex_status(); - - for (auto h : halfedges(sm)) - { - om_halfedge_descriptor omh = h2h.at(h); - const bool isfeature = get(efpm, edge(h, sm)); - omesh.status(omesh.edge_handle(omh)).set_feature(isfeature); - } - for (auto v : vertices(sm)) - { - auto omv = v2v.at(v); - const bool isfeature = get(vfpm, v); - omesh.status(omv).set_feature(isfeature); - } - - return OpenMesh::IO::write_mesh(omesh, fname, OpenMesh::IO::Options::Status); -} - -} // namespace IO -} // namespace CGAL - -#endif // CGAL_USE_OPENMESH || DOXYGEN_RUNNING -#endif // CGAL_IO_OM From 9764dd1dcebe4e6f4557cb3626f1e311ce444267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 23 Oct 2024 12:15:13 +0200 Subject: [PATCH 27/32] remove extra include --- BGL/include/CGAL/boost/graph/graph_traits_OpenMesh.h | 2 -- .../CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_OpenMesh.h b/BGL/include/CGAL/boost/graph/graph_traits_OpenMesh.h index 79f1199e24d9..36a872737b13 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_OpenMesh.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_OpenMesh.h @@ -9,7 +9,6 @@ // // Author(s) : Andreas Fabri, Philipp Moeller -// include this to avoid a VC15 warning #include #include @@ -21,7 +20,6 @@ #include #include #include -#include #include #include diff --git a/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h b/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h index 5127f692a24e..dc7098520a6b 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h @@ -11,11 +11,16 @@ #ifndef CGAL_BOOST_GRAPH_GRAPH_TRAITS_POLYMESH_ARRAYKERNELT_H #define CGAL_BOOST_GRAPH_GRAPH_TRAITS_POLYMESH_ARRAYKERNELT_H +#ifdef OPEN_MESH_CLASS + #error OPEN_MESH_CLASS is already defined +#endif + // https://www.graphics.rwth-aachen.de/media/openmesh_static/Documentations/OpenMesh-Doc-Latest/a02182.html #include #include #include + #define OPEN_MESH_CLASS OpenMesh::PolyMesh_ArrayKernelT #include From 69bf76e106bff774d7fde514d46ef41657a5f5ed Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Wed, 23 Oct 2024 12:32:26 +0200 Subject: [PATCH 28/32] remove obselete header --- BGL/examples/BGL_OpenMesh/read_OM.h | 62 ----------------------------- 1 file changed, 62 deletions(-) delete mode 100644 BGL/examples/BGL_OpenMesh/read_OM.h diff --git a/BGL/examples/BGL_OpenMesh/read_OM.h b/BGL/examples/BGL_OpenMesh/read_OM.h deleted file mode 100644 index 6c350bad03f9..000000000000 --- a/BGL/examples/BGL_OpenMesh/read_OM.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace CGAL { -namespace IO { - -template -bool read_OM(std::string fname, SM& sm, VSelectionPM vspm, EFeaturePM efpm) -{ - typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; - typedef boost::graph_traits::vertex_descriptor om_vertex_descriptor; - typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; - typedef boost::graph_traits::halfedge_descriptor om_halfedge_descriptor; - typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; - - OMesh omesh; - OpenMesh::IO::Options options = OpenMesh::IO::Options::Status; - bool ok = OpenMesh::IO::read_mesh(omesh, 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(omesh, sm, CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap)); - - if(options.vertex_has_status()){ - for(auto v : vertices(omesh)){ - put(vspm, v2v[v], omesh.status(v).selected()); - } - }else{ - std::cout << "no vertex status" << std::endl; - } - - if(options.edge_has_status()){ - for(auto e : edges(omesh)){ - auto sme = edge(h2h[halfedge(e,omesh)], sm); - put(efpm, sme , omesh.status(OpenMesh::EdgeHandle(e.idx())).feature()); - } - }else{ - std::cout << "no edge status" << std::endl; - } - return true; -} - -} // namespace IO -} // namespace CGAL - - From 51b98e9cc24bf9a468032be743c4be98043e0071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 24 Oct 2024 16:54:15 +0200 Subject: [PATCH 29/32] add doc --- BGL/doc/BGL/PackageDescription.txt | 4 + BGL/examples/BGL_OpenMesh/PolyMesh.cpp | 45 ++++-- BGL/include/CGAL/boost/graph/IO/OM.h | 139 ++++++++++++++---- BGL/include/CGAL/boost/graph/io.h | 1 + .../File_formats/Supported_file_formats.txt | 24 +++ 5 files changed, 174 insertions(+), 39 deletions(-) diff --git a/BGL/doc/BGL/PackageDescription.txt b/BGL/doc/BGL/PackageDescription.txt index 883c1b3ad465..e058589c3bf4 100644 --- a/BGL/doc/BGL/PackageDescription.txt +++ b/BGL/doc/BGL/PackageDescription.txt @@ -482,6 +482,10 @@ the requirement for traversal of all faces in a graph. /// I/O Functions for the \ref IOStreamOBJ /// \ingroup PkgBGLIOFct +/// \defgroup PkgBGLIoFuncsOM OM I/O Functions +/// I/O Functions for the \ref IOStreamOM +/// \ingroup PkgBGLIOFct + /// \defgroup PkgBGLIoFuncsOFF OFF I/O Functions /// I/O Functions for the \ref IOStreamOFF /// \ingroup PkgBGLIOFct diff --git a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp index 96d6feb252bb..f5a644bba7bd 100644 --- a/BGL/examples/BGL_OpenMesh/PolyMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/PolyMesh.cpp @@ -24,25 +24,32 @@ int main(int argc, char** argv ) { OMesh omesh; - const std::string filename = (argc>1)?argv[1]:CGAL::data_file_path("meshes/in.off"); - const char* outname= (argc>2)?argv[2]:"out.om"; - CGAL::IO::read_polygon_mesh(filename, omesh); + const std::string filename = (argc>1)?argv[1]:CGAL::data_file_path("meshes/cube-meshed.off"); + + if (!CGAL::IO::read_polygon_mesh(filename, omesh)) + { + std::cerr << "Cannot read " << filename << "\n"; + return 1; + } omesh.request_vertex_status(); omesh.request_edge_status(); int i = 0; - for(auto v : vertices(omesh)){ - omesh.status(v).set_selected((i%2) == 0); - ++i; + for(auto v : vertices(omesh)) + { + omesh.status(v).set_feature((i%2) == 0); + ++i; } i = 0; - for(auto eit = omesh.edges_begin(); eit != omesh.edges_end(); ++eit){ - omesh.status(*eit).set_feature(i > 2); - ++i; + for(auto eit = omesh.edges_begin(); eit != omesh.edges_end(); ++eit) + { + omesh.status(*eit).set_feature((i%2) == 0); + ++i; } + const char* outname= (argc>2)?argv[2]:"out.om"; OpenMesh::IO::write_mesh(omesh, outname, OpenMesh::IO::Options::Status); SM sm; @@ -53,16 +60,26 @@ int main(int argc, char** argv ) std::map sm_feature_map; auto sm_feature_pmap = boost::make_assoc_property_map(sm_feature_map); - CGAL::IO::read_OM(outname, sm, sm_selected_pmap, sm_feature_pmap); + CGAL::IO::read_OM(outname, sm, CGAL::parameters::vertex_is_constrained_map(sm_selected_pmap) + .edge_is_constrained_map(sm_feature_pmap)); - std::cout << "vertex selection values:\n"; + + int nbv=0, nbfv=0; for(auto v : vertices(sm)){ - std::cout << std::boolalpha << get(sm_selected_pmap, v) << std::endl; + ++nbv; + if (get(sm_selected_pmap, v)) ++nbfv; } + std::cout << nbfv << " feature vertices out of " << nbv << "\n"; - std::cout << "edge feature values:\n"; + int nbe=0, nbfe=0; for(auto e : edges(sm)){ - std::cout << std::boolalpha << get(sm_feature_pmap, e) << std::endl; + ++nbe; + if (get(sm_feature_pmap, e)) ++nbfe; } + std::cout << nbfe << " feature edges out of " << nbe << "\n"; + + assert(nbv>1 || nbfv!=0); + assert(nbe>1 || nbfe!=0); + return 0; } diff --git a/BGL/include/CGAL/boost/graph/IO/OM.h b/BGL/include/CGAL/boost/graph/IO/OM.h index c9a9f1f3ef32..aae313b34421 100644 --- a/BGL/include/CGAL/boost/graph/IO/OM.h +++ b/BGL/include/CGAL/boost/graph/IO/OM.h @@ -30,8 +30,9 @@ namespace CGAL { namespace IO { -template -bool read_OM(const std::string& fname, Graph& g, VFeaturePM vfpm, EFeaturePM efpm) +namespace internal { +template +bool read_OM(const std::string& fname, Graph& g, VPM vpm, VFeaturePM vfpm, EFeaturePM efpm) { typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; typedef typename boost::graph_traits::vertex_descriptor om_vertex_descriptor; @@ -54,7 +55,8 @@ bool read_OM(const std::string& fname, Graph& g, VFeaturePM vfpm, EFeaturePM efp CGAL::copy_face_graph(omesh, g, CGAL::parameters::vertex_to_vertex_map(v2vpmap) - .halfedge_to_halfedge_map(h2hpmap)); + .halfedge_to_halfedge_map(h2hpmap), + CGAL::parameters::vertex_point_map(vpm)); if(options.vertex_has_status()){ for(auto v : vertices(omesh)){ put(vfpm, v2v[v], omesh.status(v).feature()); @@ -70,25 +72,8 @@ bool read_OM(const std::string& fname, Graph& g, VFeaturePM vfpm, EFeaturePM efp return true; } -template -bool read_OM(const std::string& fname, - Graph& g, - const CGAL_NP_CLASS& np = parameters::default_values()) -{ - using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; - using edge_descriptor = typename boost::graph_traits::edge_descriptor; - - using CGAL::parameters::get_parameter; - using CGAL::parameters::choose_parameter; - auto vfpm = choose_parameter(get_parameter(np, internal_np::vertex_is_constrained), - CGAL::Constant_property_map(false)); - auto efpm = choose_parameter(get_parameter(np, internal_np::edge_is_constrained), - CGAL::Constant_property_map(false)); - return read_OM(fname, g, vfpm, efpm); -} - -template -bool write_OM(std::string fname, Graph& g, VFeaturePM vfpm, EFeaturePM efpm) +template +bool write_OM(std::string fname, Graph& g, VPM vpm, VFeaturePM vfpm, EFeaturePM efpm) { typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; typedef typename boost::graph_traits::vertex_descriptor om_vertex_descriptor; @@ -104,8 +89,9 @@ bool write_OM(std::string fname, Graph& g, VFeaturePM vfpm, EFeaturePM efpm) OMesh omesh; CGAL::copy_face_graph(g, omesh, - CGAL::parameters::vertex_to_vertex_map(v2vpmap) - .halfedge_to_halfedge_map(h2hpmap)); + CGAL::parameters::vertex_point_map(vpm) + .vertex_to_vertex_map(v2vpmap) + .halfedge_to_halfedge_map(h2hpmap)); omesh.request_edge_status(); omesh.request_vertex_status(); @@ -124,7 +110,108 @@ bool write_OM(std::string fname, Graph& g, VFeaturePM vfpm, EFeaturePM efpm) return OpenMesh::IO::write_mesh(omesh, fname, OpenMesh::IO::Options::Status); } +} // end of internal namespace + +/*! + \ingroup PkgBGLIoFuncsOM + + \brief reads the graph `g` from the file `fname`, using the \ref IOStreamOM. + + The data is expected to represent a 2-manifold (possibly with borders). + + \attention The graph `g` is not cleared, and the data from the file are appended. + + \note This function is only available if OpenMesh is available (`CGAL_USE_OPENMESH` is defined or CMake target is linked with `CGAL::OpenMesh_support`). + + \tparam Graph a model of `MutableFaceGraph` + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" + + \param fname the name of the input file + \param g the graph to be built from the input data + \param np optional \ref bgl_namedparameters "Named Parameters" described below + + \cgalNamedParamsBegin + \cgalParamNBegin{vertex_point_map} + \cgalParamDescription{a property map associating points to the vertices of `g`} + \cgalParamType{a class model of `WritablePropertyMap` with `boost::graph_traits::%vertex_descriptor` + as key type and `%Point_3` as value type} + \cgalParamDefault{`boost::get(CGAL::vertex_point, g)`} + \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` + must be available in `Graph`.} + \cgalParamNEnd + \cgalParamNBegin{edge_is_constrained_map} + \cgalParamDescription{a property map containing the feature-or-not status of each edge of `g` to be filled by the reader} + \cgalParamType{a class model of `WritablePropertyMap` with `boost::graph_traits::%edge_descriptor` + as key type and `bool` as value type.} + \cgalParamDefault{a default property map where no edge is marked as feature} + \cgalParamNEnd + \cgalParamNBegin{vertex_is_constrained_map} + \cgalParamDescription{a property map containing the feature-or-not status of each vertex of `g` to be filled by the reader} + \cgalParamType{a class model of `WritablePropertyMap` with `boost::graph_traits::%vertex_descriptor` + as key type and `bool` as value type.} + \cgalParamDefault{a default property map where no vertex is marked as feature} + \cgalParamNEnd + \cgalNamedParamsEnd + + \returns `true` if reading was successful and the resulting mesh is valid, `false` otherwise. +*/ +template +bool read_OM(const std::string& fname, + Graph& g, + const CGAL_NP_CLASS& np = parameters::default_values()) +{ + using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; + using edge_descriptor = typename boost::graph_traits::edge_descriptor; + + using CGAL::parameters::get_parameter; + using CGAL::parameters::choose_parameter; + using Default_vfmap = Static_boolean_property_map; + using Default_efmap = Static_boolean_property_map; + auto vfpm = choose_parameter(get_parameter(np, internal_np::vertex_is_constrained)); + auto efpm = choose_parameter(get_parameter(np, internal_np::edge_is_constrained)); + auto vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), + get_property_map(vertex_point, g)); + return internal::read_OM(fname, g, vpm, vfpm, efpm); +} + +/*! +\ingroup PkgBGLIoFuncsOM + + \brief writes the graph `g` into a file named `fname`, using the \ref IOStreamOM. + + \note This function is only available if OpenMesh is available (`CGAL_USE_OPENMESH` is defined or CMake target is linked with `CGAL::OpenMesh_support`). + + \tparam Graph a model of `FaceListGraph` and `HalfedgeListGraph` + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" + + \param fname the output file + \param g the graph to be written + \param np optional \ref bgl_namedparameters "Named Parameters" described below + + \cgalNamedParamsBegin + \cgalParamNBegin{vertex_point_map} + \cgalParamDescription{a property map associating points to the vertices of `g`} + \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` + as key type and `%Point_3` as value type} + \cgalParamDefault{`boost::get(CGAL::vertex_point, g)`} + \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` + must be available in `Graph`.} + \cgalParamNEnd + \cgalParamNBegin{edge_is_constrained_map} + \cgalParamDescription{a property map containing the feature-or-not status of each edge of `g`} + \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%edge_descriptor` + as key type and `bool` as value type.} + \cgalParamNEnd + \cgalParamNBegin{vertex_is_constrained_map} + \cgalParamDescription{a property map containing the feature-or-not status of each vertex of `g`} + \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` + as key type and `bool` as value type.} + \cgalParamNEnd + \cgalNamedParamsEnd + + \returns `true` if writing was successful, `false` otherwise. +*/ template bool write_OM(const std::string& fname, Graph& g, @@ -139,7 +226,9 @@ bool write_OM(const std::string& fname, CGAL::Constant_property_map(false)); auto efpm = choose_parameter(get_parameter(np, internal_np::edge_is_constrained), CGAL::Constant_property_map(false)); - return write_OM(fname, g, vfpm, efpm); + auto vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), + get_property_map(vertex_point, g)); + return internal::write_OM(fname, g, vpm, vfpm, efpm); } diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index ad6b83dd31a1..c99b00c6e895 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt index 5badcf76a9c8..8f9a99e0877c 100644 --- a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -9,6 +9,7 @@ each specific format. - \ref IOStreamOFF - \ref IOStreamOBJ +- \ref IOStreamOM - \ref IOStreamSTL - \ref IOStreamPLY - \ref IOStreamXYZ @@ -141,6 +142,29 @@ If the data of a polygon mesh cannot be read in a `FaceGraph` due to bad orienta manifoldness issues, consider using \link PMP_IO_grp `CGAL::Polygon_mesh_processing::IO::read_polygon_mesh()` \endlink, which offers combinatorial repairing while reading bad inputs. +\section IOStreamOM OpenMesh (OM) File format +The OpenMesh proprietary format, using the file extension `.om`, can be used to represent collections of planar polygons with possibly shared vertices. +Additionally, it allows to store and restore custom properties along with the standard properties. + +More information are provided here. + + + + + + + + + + + + + + + + + +
OpenMesh Format (OM)
InputPolygon MeshAny model of `MutableFaceGraph`\link PkgBGLIoFuncsOM CGAL::IO::read_OM(const std::string&, Graph&)\endlink
OutputPolygon MeshAny model of `FaceGraph`\link PkgBGLIoFuncsOM CGAL::IO::write_OM(const std::string&, const Graph&)\endlink
\section IOStreamSTL STereoLithography (STL) File Format From c8936698ac245762cb7fcfdc7b52492ae0dfbf50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 8 Nov 2024 16:22:47 +0100 Subject: [PATCH 30/32] apply @MaelRL review --- BGL/include/CGAL/boost/graph/IO/OM.h | 2 +- Stream_support/doc/Stream_support/IOstream.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/BGL/include/CGAL/boost/graph/IO/OM.h b/BGL/include/CGAL/boost/graph/IO/OM.h index aae313b34421..5f982ffde489 100644 --- a/BGL/include/CGAL/boost/graph/IO/OM.h +++ b/BGL/include/CGAL/boost/graph/IO/OM.h @@ -214,7 +214,7 @@ bool read_OM(const std::string& fname, */ template bool write_OM(const std::string& fname, - Graph& g, + const Graph& g, const CGAL_NP_CLASS& np = parameters::default_values()) { using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index fb4d9fe8afae..f75adf3e2a9e 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -421,6 +421,7 @@ The table above only lists the functions that work with any polygon mesh. \ref IOStreamOBJ "OBJ" \ref IOStreamGocad "GOCAD" \ref IOStreamWRL "WRL" + \ref IOStreamOM "OpenMesh (OM)" Input @@ -430,6 +431,7 @@ The table above only lists the functions that work with any polygon mesh. `CGAL::IO::read_VTP()` `CGAL::IO::read_OBJ()` `CGAL::IO::read_GOCAD()` + `CGAL::IO::read_OM()`
-
@@ -441,6 +443,7 @@ The table above only lists the functions that work with any polygon mesh. `CGAL::IO::write_OBJ()` `CGAL::IO::write_GOCAD()` `CGAL::IO::write_WRL()` + `CGAL::IO::write_OM()` From 13fcef62e01146380164f1542ee093c0efed3c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 8 Nov 2024 16:26:01 +0100 Subject: [PATCH 31/32] missing const --- BGL/include/CGAL/boost/graph/IO/OM.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGL/include/CGAL/boost/graph/IO/OM.h b/BGL/include/CGAL/boost/graph/IO/OM.h index 5f982ffde489..89ab25bda0fd 100644 --- a/BGL/include/CGAL/boost/graph/IO/OM.h +++ b/BGL/include/CGAL/boost/graph/IO/OM.h @@ -227,7 +227,7 @@ bool write_OM(const std::string& fname, auto efpm = choose_parameter(get_parameter(np, internal_np::edge_is_constrained), CGAL::Constant_property_map(false)); auto vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), - get_property_map(vertex_point, g)); + get_const_property_map(vertex_point, g)); return internal::write_OM(fname, g, vpm, vfpm, efpm); } From 82e2e7a267d695ecd0b4194497722d2013ea96e2 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 12 Nov 2024 14:46:31 +0100 Subject: [PATCH 32/32] add missing const --- BGL/include/CGAL/boost/graph/IO/OM.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGL/include/CGAL/boost/graph/IO/OM.h b/BGL/include/CGAL/boost/graph/IO/OM.h index 89ab25bda0fd..9d393022a030 100644 --- a/BGL/include/CGAL/boost/graph/IO/OM.h +++ b/BGL/include/CGAL/boost/graph/IO/OM.h @@ -73,7 +73,7 @@ bool read_OM(const std::string& fname, Graph& g, VPM vpm, VFeaturePM vfpm, EFeat } template -bool write_OM(std::string fname, Graph& g, VPM vpm, VFeaturePM vfpm, EFeaturePM efpm) +bool write_OM(std::string fname, const Graph& g, VPM vpm, VFeaturePM vfpm, EFeaturePM efpm) { typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh; typedef typename boost::graph_traits::vertex_descriptor om_vertex_descriptor;