From 12455fbd559d2bbb6140fe36a3b69df0e9648121 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 17 May 2024 10:19:49 +0200 Subject: [PATCH 1/5] add example using allow_move_functor --- .../Polygon_mesh_processing/CMakeLists.txt | 1 + .../isotropic_remeshing_with_allow_move.cpp | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt b/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt index 4bc63fcf8b3..10c328ae5e0 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt @@ -54,6 +54,7 @@ create_single_source_cgal_program("cc_compatible_orientations.cpp") create_single_source_cgal_program("hausdorff_distance_remeshing_example.cpp") create_single_source_cgal_program("hausdorff_bounded_error_distance_example.cpp") create_single_source_cgal_program("isotropic_remeshing_with_custom_sizing_example.cpp") +create_single_source_cgal_program("isotropic_remeshing_with_allow_move.cpp") create_single_source_cgal_program("triangle_mesh_autorefinement.cpp") create_single_source_cgal_program("soup_autorefinement.cpp") diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp new file mode 100644 index 00000000000..b89401f4370 --- /dev/null +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include + +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Surface_mesh Mesh; + +typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; +typedef boost::graph_traits::edge_descriptor edge_descriptor; + +namespace PMP = CGAL::Polygon_mesh_processing; + +struct Allow_no_surface_crossing +{ + using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; + using Point_3 = typename K::Point_3; + + CGAL::Side_of_triangle_mesh m_side_of_tmesh; + + Allow_no_surface_crossing(const Mesh& mesh) + : m_side_of_tmesh(mesh) + {} + + bool operator()(vertex_descriptor v, Point_3 src, Point_3 tgt) const + { + const CGAL::Bounded_side s_src = m_side_of_tmesh(src); + const CGAL::Bounded_side s_tgt = m_side_of_tmesh(tgt); + return (s_src == s_tgt); + } +}; + +int main(int argc, char* argv[]) +{ + const std::string filename = (argc > 1) ? std::string(argv[1]) : CGAL::data_file_path("meshes/pig.off"); + + Mesh mesh; + if(!PMP::IO::read_polygon_mesh(filename, mesh) || !CGAL::is_triangle_mesh(mesh)) + { + std::cerr << "Invalid input." << std::endl; + return EXIT_FAILURE; + } + + double target_edge_length = (argc > 2) ? std::stod(std::string(argv[2])) : 0.05; + unsigned int nb_iter = (argc > 3) ? std::stoi(std::string(argv[3])) : 1; + + if (PMP::does_self_intersect(mesh)) + std::cout << "Input mesh self-intersects" << std::endl; + else + std::cout << "Input mesh does not self-intersect" << std::endl; + + Allow_no_surface_crossing shall_move(mesh); + PMP::isotropic_remeshing(faces(mesh), target_edge_length, mesh, + CGAL::parameters::number_of_iterations(nb_iter) + .allow_move_functor(shall_move) + ); + + if (PMP::does_self_intersect(mesh)) + std::cout << "Output mesh self-intersects" << std::endl; + else + std::cout << "Output mesh does not self-intersect" << std::endl; + + std::cout << "Remeshing done." << std::endl; + CGAL::IO::write_polygon_mesh("out.off", mesh, CGAL::parameters::stream_precision(17)); + + return EXIT_SUCCESS; +} From de9eccf316abc87d610a9f9724be470a7cca486b Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 17 May 2024 15:41:29 +0200 Subject: [PATCH 2/5] functor is not unary! --- .../include/CGAL/Polygon_mesh_processing/remesh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh.h index 0a0fdfb4504..e7ef854319b 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh.h @@ -174,7 +174,7 @@ namespace Polygon_mesh_processing { * \cgalParamNBegin{allow_move_functor} * \cgalParamDescription{A function object used to determinate if a vertex move should * be allowed or not during the relaxation step.} -* \cgalParamType{Unary functor that provides `bool operator()(vertex_descriptor v, Point_3 src, Point_3 tgt)` +* \cgalParamType{Functor that provides `bool operator()(vertex_descriptor v, Point_3 src, Point_3 tgt)` * returning `true` * if the vertex `v` can be moved from `src` to `tgt`; * `%Point_3` being the value type of the vertex point map } From 8613b04e930e4945611707350bba1ab919262f02 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 4 Jun 2024 09:48:40 +0200 Subject: [PATCH 3/5] add to examples list --- Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt index 3aca69fb004..d257d82892d 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt @@ -48,5 +48,6 @@ \example Polygon_mesh_processing/remesh_almost_planar_patches.cpp \example Polygon_mesh_processing/sample_example.cpp \example Polygon_mesh_processing/soup_autorefinement.cpp +\example Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp */ */ From 8905201e2187e22bdc4a2a2833cc9766263ba2c7 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Mon, 1 Jul 2024 15:15:34 +0200 Subject: [PATCH 4/5] replace pig (not closed) by triceratops --- .../isotropic_remeshing_with_allow_move.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp index b89401f4370..1f74ab88f3e 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp @@ -1,4 +1,5 @@ #include + #include #include #include @@ -37,7 +38,7 @@ struct Allow_no_surface_crossing int main(int argc, char* argv[]) { - const std::string filename = (argc > 1) ? std::string(argv[1]) : CGAL::data_file_path("meshes/pig.off"); + const std::string filename = (argc > 1) ? std::string(argv[1]) : CGAL::data_file_path("meshes/triceratops.off"); Mesh mesh; if(!PMP::IO::read_polygon_mesh(filename, mesh) || !CGAL::is_triangle_mesh(mesh)) @@ -46,8 +47,9 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } - double target_edge_length = (argc > 2) ? std::stod(std::string(argv[2])) : 0.05; + double target_edge_length = (argc > 2) ? std::stod(std::string(argv[2])) : 0.3; unsigned int nb_iter = (argc > 3) ? std::stoi(std::string(argv[3])) : 1; + unsigned int nb_smoothing = (argc > 4) ? std::stoi(std::string(argv[4])) : 2; if (PMP::does_self_intersect(mesh)) std::cout << "Input mesh self-intersects" << std::endl; @@ -57,6 +59,7 @@ int main(int argc, char* argv[]) Allow_no_surface_crossing shall_move(mesh); PMP::isotropic_remeshing(faces(mesh), target_edge_length, mesh, CGAL::parameters::number_of_iterations(nb_iter) + .number_of_relaxation_steps(nb_smoothing) .allow_move_functor(shall_move) ); From e95ea7cde7d30ea6d6da40d66ff61336f5fa4a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 4 Jul 2024 18:36:55 +0200 Subject: [PATCH 5/5] unused variable --- .../isotropic_remeshing_with_allow_move.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp index 1f74ab88f3e..7ee9fa7bcf7 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_allow_move.cpp @@ -28,7 +28,7 @@ struct Allow_no_surface_crossing : m_side_of_tmesh(mesh) {} - bool operator()(vertex_descriptor v, Point_3 src, Point_3 tgt) const + bool operator()(vertex_descriptor, Point_3 src, Point_3 tgt) const { const CGAL::Bounded_side s_src = m_side_of_tmesh(src); const CGAL::Bounded_side s_tgt = m_side_of_tmesh(tgt);