From 7d0969d15f3b1547b6bb0dd96ccef23acfa5c76c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 14 Aug 2024 15:47:16 +0200 Subject: [PATCH] use dynamic property maps --- .../Least_squares_plane_fit_region.h | 23 +++++++++++-------- .../Region_growing/internal/utils.h | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Polygon_mesh/Least_squares_plane_fit_region.h b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Polygon_mesh/Least_squares_plane_fit_region.h index 0ab7463a08e..2c8801ea5e6 100644 --- a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Polygon_mesh/Least_squares_plane_fit_region.h +++ b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Polygon_mesh/Least_squares_plane_fit_region.h @@ -93,9 +93,6 @@ namespace Polygon_mesh { using Scalar_product_3 = typename GeomTraits::Compute_scalar_product_3; using Cross_product_3 = typename GeomTraits::Construct_cross_product_vector_3; - std::unordered_map > m_face_normals; - std::unordered_map, internal::hash_item > m_face_triangulations; - public: /// \name Initialization /// @{ @@ -163,7 +160,10 @@ namespace Polygon_mesh { m_squared_length_3(m_traits.compute_squared_length_3_object()), m_squared_distance_3(m_traits.compute_squared_distance_3_object()), m_scalar_product_3(m_traits.compute_scalar_product_3_object()), - m_cross_product_3(m_traits.construct_cross_product_vector_3_object()) { + m_cross_product_3(m_traits.construct_cross_product_vector_3_object()), + m_face_normals( get(CGAL::dynamic_face_property_t(), pmesh) ), + m_face_triangulations( get(CGAL::dynamic_face_property_t>(), pmesh) ) + { #ifdef CGAL_SD_RG_USE_PMP auto get_face_normal = [this](Item face, const PolygonMesh& pmesh) @@ -194,7 +194,7 @@ namespace Polygon_mesh { #endif for (const Item &i : faces(pmesh)) { - m_face_normals[i] = get_face_normal(i, pmesh); + put(m_face_normals, i, get_face_normal(i, pmesh)); std::vector pts; auto h = halfedge(i, pmesh); auto s = h; @@ -204,7 +204,9 @@ namespace Polygon_mesh { h = next(h, pmesh); } while (h != s); - internal::triangulate_face(pts, m_face_triangulations[i]); + std::vector face_triangulation; + internal::triangulate_face(pts, face_triangulation); + put(m_face_triangulations, i, face_triangulation); } CGAL_precondition(faces(m_face_graph).size() > 0); @@ -283,7 +285,7 @@ namespace Polygon_mesh { const FT squared_distance_threshold = m_distance_threshold * m_distance_threshold; - const Vector_3 face_normal = m_face_normals.at(query); + const Vector_3 face_normal = get(m_face_normals, query); const FT cos_value = m_scalar_product_3(face_normal, m_normal_of_best_fit); const FT squared_cos_value = cos_value * cos_value; @@ -333,7 +335,7 @@ namespace Polygon_mesh { // The best fit plane will be a plane through this face centroid with // its normal being the face's normal. const Point_3 face_centroid = get_face_centroid(face); - const Vector_3 face_normal = m_face_normals.at(face); + const Vector_3 face_normal = get(m_face_normals, face); if (face_normal == CGAL::NULL_VECTOR) return false; CGAL_precondition(face_normal != CGAL::NULL_VECTOR); @@ -374,7 +376,7 @@ namespace Polygon_mesh { // Approach: each face gets one vote to keep or flip the current plane normal. long votes_to_keep_normal = 0; for (const auto &face : region) { - const Vector_3 face_normal = m_face_normals.at(face); + const Vector_3 face_normal = get(m_face_normals, face); const bool agrees = m_scalar_product_3(face_normal, unoriented_normal_of_best_fit) > FT(0); votes_to_keep_normal += (agrees ? 1 : -1); @@ -406,6 +408,9 @@ namespace Polygon_mesh { const Scalar_product_3 m_scalar_product_3; const Cross_product_3 m_cross_product_3; + typename boost::property_map >::const_type m_face_normals; + typename boost::property_map> >::const_type m_face_triangulations; + Plane_3 m_plane_of_best_fit; Vector_3 m_normal_of_best_fit; diff --git a/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/utils.h b/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/utils.h index 8a0d8690893..09f87c109a8 100644 --- a/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/utils.h +++ b/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/utils.h @@ -442,7 +442,7 @@ namespace internal { const IConverter iconverter = IConverter(); for (const typename Region::value_type face : region) { - const std::vector& tris = face_to_triangles_map.at(face); + const std::vector& tris = get(face_to_triangles_map, face); // Degenerate polygons are omitted. if (tris.empty())