From 33c868818f16fcbd642e9c3906cc4d31d8204581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 7 Mar 2023 17:55:28 +0100 Subject: [PATCH] fix property map for region primitives --- .../remesh_planar_patches.h | 46 ++++++++++++------- .../PMP/Remesh_planar_patches_plugin.cpp | 9 ++-- .../internal/parameters_interface.h | 3 +- .../Polygon_mesh_processing/region_growing.h | 41 ++++++++++++++--- 4 files changed, 71 insertions(+), 28 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h index d250da9f11e..3f40124c1ff 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h @@ -165,13 +165,14 @@ struct Face_index_tracker +template void init_face_normals(std::vector& face_normals, std::size_t nb_patches, - const NormalRange& normal_range) + PatchNormalMap patch_normal_map) { - face_normals.reserve(nb_patches); - face_normals.assign(normal_range.begin(), normal_range.end()); + face_normals.resize(nb_patches); + for (std::size_t i=0; i @@ -741,7 +742,18 @@ bool decimate_impl(const TriangleMesh& tm, { //TODO: shall we try to plug pseudo-cdt? #ifdef CGAL_DEBUG_DECIMATION - std::cout << " DEBUG: Failed to remesh a patch" << std::endl; + static int fail_case_id=0; + std::cout << " DEBUG: Failed to remesh a patch, case #" << fail_case_id << std::endl; + std::ofstream debug("failed_remesh_"+std::to_string(fail_case_id)+".polylines.txt"); + debug << std::setprecision(17); + for (auto c : csts) + debug << "2 " << corners[c.first] << " " << corners[c.second] << "\n"; + debug.close(); + std::cout << " normal used is " << face_normals[cc_id] << "\n"; + debug.open("normal"+std::to_string(fail_case_id)+".polylines.txt"); + debug << "2 " << corners[csts[0].first] << " " << corners[csts[0].first]+face_normals[cc_id] << "\n"; + debug.close(); + ++fail_case_id; #endif all_patches_successfully_remeshed = false; // make all vertices of the patch a corner @@ -1501,6 +1513,17 @@ void remesh_planar_patches(const TriangleMeshIn& tm_in, * \param np_in an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below: * * \cgalNamedParamsBegin + * \cgalParamNBegin{patch_normal_map} + * \cgalParamDescription{a property map providing for each patch the normal of the supporting plane of the patch (used to triangulate it)} + * \cgalParamType{a class model of `ReadPropertyMap` with the value type of `FacePatchMap` as key and + * `GeomTraits::Vector_3` as value type, `GeomTraits` being the type of the parameter `geom_traits`} + * \cgalParamDefault{If not provided, patch normals will be estimated using corners of the patches} + * \cgalParamNEnd + * \cgalParamNBegin{do_not_triangulate_faces} + * \cgalParamDescription{if `true`, faces of `out` will not be triangulated, but the one with more than one connected component of the boundary.} + * \cgalParamType{`bool`} + * \cgalParamDefault{false} + * \cgalParamNEnd * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm_in`} * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -1509,11 +1532,6 @@ void remesh_planar_patches(const TriangleMeshIn& tm_in, * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` * must be available in `TriangleMeshIn`.} * \cgalParamNEnd - * \cgalParamNBegin{do_not_triangulate_faces} - * \cgalParamDescription{if `true`, faces of `out` will not be triangulated, but the one with more than one connected component of the boundary.} - * \cgalParamType{`bool`} - * \cgalParamDefault{false} - * \cgalParamNEnd * \cgalParamNBegin{geom_traits} * \cgalParamDescription{an instance of a geometric traits class} * \cgalParamType{a class model of `Kernel`} @@ -1540,12 +1558,6 @@ void remesh_planar_patches(const TriangleMeshIn& tm_in, * as key type and `std::size_t` as value type} * \cgalParamDefault{None} * \cgalParamNEnd - * \cgalParamNBegin{normals_of_patches} - * \cgalParamDescription{the normals of the supporting planes of the patches (in the same order of `face_patch_map`) used to triangulate patches.} - * \cgalParamType{a model of `InputIterator` with `GeomTraits::Vector_3` as value type, - * `GeomTraits` being the type of the parameter `geom_traits`} - * \cgalParamDefault{normals will be estimated from three non-collinear corners on the boundary of each patch} - * \cgalParamNEnd * \cgalParamNBegin{vertex_corner_map} * \cgalParamDescription{a property map filled by this function and that will contain for each vertex its corner * an id in the range `[0, number of corners - 1]`} @@ -1599,7 +1611,7 @@ bool remesh_almost_planar_patches(const TriangleMeshIn& tm_in, bool do_not_triangulate_faces = choose_parameter(get_parameter(np_in, internal_np::do_not_triangulate_faces), false); std::vector< typename Traits::Vector_3 > face_normals; - Planar_segmentation::init_face_normals(face_normals, nb_patches, get_parameter(np_out, internal_np::normals_of_patches)); + Planar_segmentation::init_face_normals(face_normals, nb_patches, get_parameter(np_in, internal_np::patch_normal_map)); return Planar_segmentation::decimate_impl(tm_in, tm_out, std::make_pair(nb_corners, nb_patches), vertex_corner_map, ecm, face_patch_map, vpm_in, vpm_out, diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Remesh_planar_patches_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Remesh_planar_patches_plugin.cpp index a0934f83dde..4f85dabc702 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Remesh_planar_patches_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Remesh_planar_patches_plugin.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -198,12 +199,12 @@ public Q_SLOTS: Patch_id_pmap in_fpmap = get(CGAL::face_patch_id_t(), pmesh); std::vector corner_id_map(num_vertices(pmesh), -1); std::vector ecm(num_edges(pmesh), false); - std::vector normals; + boost::vector_property_map normal_map; std::size_t nb_regions = PMP::region_growing_of_planes_on_faces(pmesh, in_fpmap, - normals, CGAL::parameters::cosine_of_maximum_angle(cos_threshold). + region_primitive_map(normal_map). maximum_distance(ui.dist_dspinbox->value())); std::size_t nb_corners = PMP::detect_corners_of_regions(pmesh, @@ -227,7 +228,7 @@ public Q_SLOTS: CGAL::make_random_access_property_map(corner_id_map), CGAL::make_random_access_property_map(ecm), CGAL::parameters::do_not_triangulate_faces(do_not_triangulate_faces). - normals_of_patches(CGAL::make_random_access_property_map(normals)), + patch_normal_map(normal_map), CGAL::parameters::face_patch_map(out_fpmap)); @@ -253,7 +254,7 @@ public Q_SLOTS: CGAL::make_random_access_property_map(corner_id_map), CGAL::make_random_access_property_map(ecm), CGAL::parameters::do_not_triangulate_faces(do_not_triangulate_faces). - normals_of_patches(CGAL::make_random_access_property_map(normals)), + patch_normal_map(normal_map), CGAL::parameters::visitor([](Mesh& pmesh){pmesh.clear_without_removing_property_maps ();})); pmesh.remove_property_map(in_fpmap); poly_item->invalidateOpenGLBuffers(); diff --git a/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h b/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h index e501a496ea5..74574237665 100644 --- a/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h +++ b/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h @@ -148,7 +148,8 @@ CGAL_add_named_parameter(mesh_facet_distance_t, mesh_facet_distance, mesh_facet_ CGAL_add_named_parameter(mesh_facet_topology_t, mesh_facet_topology, mesh_facet_topology) CGAL_add_named_parameter(polyline_constraints_t, polyline_constraints, polyline_constraints) CGAL_add_named_parameter(vertex_corner_map_t, vertex_corner_map, vertex_corner_map) -CGAL_add_named_parameter(normals_of_patches_t, normals_of_patches, normals_of_patches) +CGAL_add_named_parameter(patch_normal_map_t, patch_normal_map, patch_normal_map) +CGAL_add_named_parameter(region_primitive_map_t, region_primitive_map, region_primitive_map) // List of named parameters that we use in the package 'Surface Mesh Simplification' CGAL_add_named_parameter(get_cost_policy_t, get_cost_policy, get_cost) diff --git a/Shape_detection/include/CGAL/Polygon_mesh_processing/region_growing.h b/Shape_detection/include/CGAL/Polygon_mesh_processing/region_growing.h index 1161ff90db5..ddf23b11089 100644 --- a/Shape_detection/include/CGAL/Polygon_mesh_processing/region_growing.h +++ b/Shape_detection/include/CGAL/Polygon_mesh_processing/region_growing.h @@ -25,6 +25,32 @@ namespace CGAL { namespace Polygon_mesh_processing { +namespace internal +{ + template + void fill_region_primitive_map(const std::vector&, internal_np::Param_not_found) {} + + template + void fill_plane_or_vector_map(const std::vector& normals, RegionMap region_map, typename GT::Vector_3) + { + for (std::size_t i = 0 ; i + void fill_plane_or_vector_map(const std::vector& normals, RegionMap region_map, typename GT::Plane_3) + { + for (std::size_t i = 0 ; i + void fill_region_primitive_map(const std::vector& normals, RegionMap region_map) + { + fill_plane_or_vector_map(normals, region_map, typename boost::property_traits::value_type()); + } +} + /*! \ingroup PkgPolygonMeshProcessingRef \brief applies a region growing algorithm to fit planes on faces of a mesh. @@ -81,6 +107,14 @@ namespace Polygon_mesh_processing { \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} \cgalParamNEnd + \cgalParamNBegin{region_primitive_map} + \cgalParamDescription{a property map filled by this function and that will contain for each region + the plane (or only its orthognonal vector) estimated that approximates it.} + \cgalParamType{a class model of `WritablePropertyMap` with the value type of `RegionMap` as key and + `GeomTraits::Plane_3` or `GeomTraits::Vector_3` as value type, + `GeomTraits` being the type of the parameter `geom_traits`} + \cgalParamDefault{None} + \cgalParamNEnd \cgalNamedParamsEnd */ template::type::Vector_3> & normals, const NamedParameters& np = parameters::default_values()) { namespace RG_PM = CGAL::Shape_detection::Polygon_mesh; @@ -118,11 +151,7 @@ region_growing_of_planes_on_faces(const PolygonMesh& mesh, std::vector > > tmp; region_growing.detect(std::back_inserter(tmp)); - normals.resize(region_growing.number_of_regions_detected()); - for (std::size_t i =0 ; i(tmp, parameters::get_parameter(np, internal_np::region_primitive_map)); return region_growing.number_of_regions_detected(); }