From 36e309e677b72a4a640aa7536d04c64c537d7dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 20 Mar 2023 21:28:11 +0100 Subject: [PATCH] add example for almost coplanar remeshing --- .../doc/Polygon_mesh_processing/examples.txt | 3 +- .../Polygon_mesh_processing/CMakeLists.txt | 4 +- .../remesh_almost_planar_patches.cpp | 66 +++++++++++++++++++ ..._patches.cpp => remesh_planar_patches.cpp} | 0 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 Polygon_mesh_processing/examples/Polygon_mesh_processing/remesh_almost_planar_patches.cpp rename Polygon_mesh_processing/examples/Polygon_mesh_processing/{decimation_planar_patches.cpp => remesh_planar_patches.cpp} (100%) diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt index 6f4199d0ee3..146e1261ff4 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt @@ -41,5 +41,6 @@ \example Polygon_mesh_processing/triangulate_faces_split_visitor_example.cpp \example Polygon_mesh_processing/hausdorff_bounded_error_distance_example.cpp \example Polygon_mesh_processing/cc_compatible_orientations.cpp -\example Polygon_mesh_processing/decimation_planar_patches.cpp +\example Polygon_mesh_processing/remesh_planar_patches.cpp +\example Polygon_mesh_processing/remesh_almost_planar_patches.cpp */ diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt b/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt index 8299ee82419..c755ecf63e8 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt @@ -19,7 +19,7 @@ create_single_source_cgal_program("point_inside_example.cpp") create_single_source_cgal_program("triangulate_faces_example.cpp") create_single_source_cgal_program("triangulate_faces_split_visitor_example.cpp") create_single_source_cgal_program("connected_components_example.cpp") -create_single_source_cgal_program("decimation_planar_patches.cpp") +create_single_source_cgal_program("remesh_planar_patches.cpp") create_single_source_cgal_program( "face_filtered_graph_example.cpp") create_single_source_cgal_program("orient_polygon_soup_example.cpp") create_single_source_cgal_program("triangulate_polyline_example.cpp") @@ -71,6 +71,8 @@ if(TARGET CGAL::Eigen3_support) target_link_libraries(mesh_smoothing_example PUBLIC CGAL::Eigen3_support) create_single_source_cgal_program("delaunay_remeshing_example.cpp") target_link_libraries(delaunay_remeshing_example PUBLIC CGAL::Eigen3_support) + create_single_source_cgal_program("remesh_almost_planar_patches.cpp") + target_link_libraries(remesh_almost_planar_patches PUBLIC CGAL::Eigen3_support) else() message(STATUS "NOTICE: Examples that use Eigen will not be compiled.") endif() diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/remesh_almost_planar_patches.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/remesh_almost_planar_patches.cpp new file mode 100644 index 00000000000..e3924c3e095 --- /dev/null +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/remesh_almost_planar_patches.cpp @@ -0,0 +1,66 @@ +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include + + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef Kernel::Point_3 Point_3; +typedef CGAL::Surface_mesh Surface_mesh; + +namespace PMP = CGAL::Polygon_mesh_processing; + +int main() +{ + Surface_mesh sm; + CGAL::IO::read_polygon_mesh(CGAL::data_file_path("meshes/fandisk.off"), sm); + + //apply a perturbation to input vertices so that points are no longer coplanar + PMP::random_perturbation(sm, 0.001); + + // declare vectors to store mesh properties + std::vector region_ids(num_faces(sm)); + std::vector corner_id_map(num_vertices(sm), -1); // corner status of vertices + std::vector ecm(num_edges(sm), false); // mark edges at the boundary of regions + boost::vector_property_map normal_map; // normal of the supporting planes of the regions detected + + // detect planar regions in the mesh + std::size_t nb_regions = + PMP::region_growing_of_planes_on_faces(sm, + CGAL::make_random_access_property_map(region_ids), + CGAL::parameters::cosine_of_maximum_angle(0.98). + region_primitive_map(normal_map). + maximum_distance(0.011)); + + // detect corner vertices on the boundary of planar regions + std::size_t nb_corners = + PMP::detect_corners_of_regions(sm, + CGAL::make_random_access_property_map(region_ids), + nb_regions, + CGAL::make_random_access_property_map(corner_id_map), + CGAL::parameters::cosine_of_maximum_angle(0.98). + maximum_distance(0.011). + edge_is_constrained_map(CGAL::make_random_access_property_map(ecm))); + + // run the remeshing algorithm using filled properties + Surface_mesh out; + PMP::remesh_almost_planar_patches(sm, + out, + nb_regions, nb_corners, + CGAL::make_random_access_property_map(region_ids), + CGAL::make_random_access_property_map(corner_id_map), + CGAL::make_random_access_property_map(ecm), + CGAL::parameters::patch_normal_map(normal_map)); + + CGAL::IO::write_polygon_mesh("fandisk_remeshed.off", out); + + return 0; +} diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/decimation_planar_patches.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/remesh_planar_patches.cpp similarity index 100% rename from Polygon_mesh_processing/examples/Polygon_mesh_processing/decimation_planar_patches.cpp rename to Polygon_mesh_processing/examples/Polygon_mesh_processing/remesh_planar_patches.cpp