From e3478fed9857fcffe1618f71c5b0019ef89a10e0 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 24 Apr 2025 17:39:24 +0200 Subject: [PATCH] add an example polygon soup with face patch map --- .../CMakeLists.txt | 4 +- ...elaunay_triangulation_3_from_soup_fmap.cpp | 63 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_from_soup_fmap.cpp diff --git a/Constrained_triangulation_3/examples/Constrained_triangulation_3/CMakeLists.txt b/Constrained_triangulation_3/examples/Constrained_triangulation_3/CMakeLists.txt index 6407c040b81..4623aa28260 100644 --- a/Constrained_triangulation_3/examples/Constrained_triangulation_3/CMakeLists.txt +++ b/Constrained_triangulation_3/examples/Constrained_triangulation_3/CMakeLists.txt @@ -6,12 +6,14 @@ find_package(CGAL REQUIRED COMPONENTS Qt6) create_single_source_cgal_program(conforming_constrained_Delaunay_triangulation_3.cpp) create_single_source_cgal_program(conforming_constrained_Delaunay_triangulation_3_fpmap.cpp) create_single_source_cgal_program(conforming_constrained_Delaunay_triangulation_3_from_soup.cpp) +create_single_source_cgal_program(conforming_constrained_Delaunay_triangulation_3_from_soup_fmap.cpp) create_single_source_cgal_program(remesh_constrained_Delaunay_triangulation_3.cpp) if(CGAL_Qt6_FOUND) target_link_libraries(conforming_constrained_Delaunay_triangulation_3 PUBLIC CGAL::CGAL_Basic_viewer) target_link_libraries(conforming_constrained_Delaunay_triangulation_3_from_soup PUBLIC CGAL::CGAL_Basic_viewer) + target_link_libraries(conforming_constrained_Delaunay_triangulation_3_from_soup_fmap PUBLIC CGAL::CGAL_Basic_viewer) target_link_libraries(remesh_constrained_Delaunay_triangulation_3 PUBLIC CGAL::CGAL_Basic_viewer) else() - message(STATUS "NOTICE: The example 'conforming_constrained_Delaunay_triangulation_3' requires Qt6, and will not be compiled.") + message(STATUS "NOTICE: The example 'conforming_constrained_Delaunay_triangulation_3' cannot draw the result without Qt6.") endif() diff --git a/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_from_soup_fmap.cpp b/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_from_soup_fmap.cpp new file mode 100644 index 00000000000..a09c2a90fc9 --- /dev/null +++ b/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_from_soup_fmap.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include + +#include +#include + +using K = CGAL::Exact_predicates_inexact_constructions_kernel; +using Point = K::Point_3; +using Surface_mesh = CGAL::Surface_mesh; +using face_descriptor = Surface_mesh::Face_index; + +namespace PMP = CGAL::Polygon_mesh_processing; + +int main(int argc, char* argv[]) +{ + CGAL::Surface_mesh mesh; + std::vector points; + std::vector> polygons; + + auto filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/cubes_one_patch_id_per_cc.off"); + std::ifstream in(filename); + if(!in || !(in >> mesh)) { + std::cerr << "Error: cannot read file " << filename << std::endl; + return EXIT_FAILURE; + } + + auto fpmap = mesh.add_property_map("f:cc_id").first; + + std::cout << "Read " << mesh.number_of_vertices() << " vertices and " + << mesh.number_of_faces() << " polygons" << std::endl; + + PMP::connected_components(mesh, fpmap); + + std::cout << "Number of connected components: " + << fpmap[*std::max_element(mesh.faces_begin(), mesh.faces_end(), + [&](face_descriptor f1, face_descriptor f2) { + return fpmap[f1] < fpmap[f2]; + })] + 1 + << std::endl; + PMP::polygon_mesh_to_polygon_soup(mesh, points, polygons); + + auto polygon_to_patch_id = [&](std::size_t i) { + return fpmap[*std::next(mesh.faces_begin(), i)]; + }; + + auto soup_fpmap = boost::make_function_property_map(polygon_to_patch_id); + + auto ccdt = CGAL::make_conforming_constrained_Delaunay_triangulation_3( + points, polygons, CGAL::parameters::face_patch_map(soup_fpmap)); + + std::cout << "Number of vertices in the CDT: " + << ccdt.triangulation().number_of_vertices() << '\n' + << "Number of constrained facets in the CDT: " + << ccdt.number_of_constrained_facets() << '\n'; + + CGAL::draw(ccdt.triangulation()); + + return EXIT_SUCCESS; +}