diff --git a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing_on_polygon_mesh/Least_squares_plane_fit_region.h b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing_on_polygon_mesh/Least_squares_plane_fit_region.h index 9a7f8111fa7..5d6ae21f8c7 100644 --- a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing_on_polygon_mesh/Least_squares_plane_fit_region.h +++ b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing_on_polygon_mesh/Least_squares_plane_fit_region.h @@ -66,7 +66,16 @@ namespace Polygon_mesh { using Face_graph = PolygonMesh; using Face_range = FaceRange; using Vertex_to_point_map = VertexToPointMap; - using Face_to_region_map = internal::Item_to_region_index_map; + + using Face_to_index_map = internal::Item_to_index_property_map; + using Face_to_region_index_map = internal::Item_to_region_index_map; + + struct Face_to_region_map : public Face_to_region_index_map { + template + Face_to_region_map(const Face_range& face_range, const Regions& regions) : + Face_to_region_index_map(face_range, Face_to_index_map(face_range), regions) + { } + }; /// \endcond /// Number type. diff --git a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing_on_polygon_mesh/Polyline_graph.h b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing_on_polygon_mesh/Polyline_graph.h index 9acf46d960b..72963983a79 100644 --- a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing_on_polygon_mesh/Polyline_graph.h +++ b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing_on_polygon_mesh/Polyline_graph.h @@ -69,7 +69,7 @@ namespace Polygon_mesh { std::size_t index = std::size_t(-1); std::set sneighbors; std::set tneighbors; - std::pair regions; + std::pair regions; }; public: @@ -179,7 +179,7 @@ namespace Polygon_mesh { void build_graph() { clear(); - int r1 = -1, r2 = -1; + long r1 = -1, r2 = -1; std::vector pedge_map( m_edge_range.size(), std::size_t(-1)); for (const auto& edge : m_edge_range) { @@ -301,7 +301,7 @@ namespace Polygon_mesh { \pre `query_index < segment_range().size()` */ - const std::pair& edge_regions( + const std::pair& edge_regions( const std::size_t query_index) const { CGAL_precondition(query_index < segment_range().size()); @@ -334,7 +334,7 @@ namespace Polygon_mesh { std::vector m_pedges; template - std::pair get_regions(const EdgeType& edge) const { + std::pair get_regions(const EdgeType& edge) const { const auto hedge1 = halfedge(edge, m_face_graph); const auto hedge2 = opposite(hedge1, m_face_graph); @@ -346,17 +346,17 @@ namespace Polygon_mesh { const std::size_t fi2 = get(m_face_to_index_map, face2); CGAL_precondition(fi1 != fi2); - int r1 = -1, r2 = -1; + long r1 = -1, r2 = -1; if (fi1 != std::size_t(-1)) - r1 = get(m_face_to_region_map, fi1); + r1 = get(m_face_to_region_map, face1); if (fi2 != std::size_t(-1)) - r2 = get(m_face_to_region_map, fi2); + r2 = get(m_face_to_region_map, face2); return std::make_pair(r1, r2); } template void add_graph_edge( - const EdgeType& edge, const int region1, const int region2, + const EdgeType& edge, const long region1, const long region2, std::vector& pedge_map) { PEdge pedge; diff --git a/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/property_map.h b/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/property_map.h index cb9f8f572ce..1d06f8b6c73 100644 --- a/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/property_map.h +++ b/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/property_map.h @@ -42,17 +42,14 @@ namespace internal { class Item_property_map { public: - using Item_range = ItemRange; - using Property_map = PropertyMap; - - using value_type = typename Property_map::value_type; - using reference = const value_type&; using key_type = std::size_t; + using value_type = typename PropertyMap::value_type; + using reference = const value_type&; using category = boost::lvalue_property_map_tag; Item_property_map( - const Item_range& item_range, - const Property_map& property_map) : + const ItemRange& item_range, + const PropertyMap& property_map) : m_item_range(item_range), m_property_map(property_map) { } @@ -69,26 +66,20 @@ namespace internal { } private: - const Item_range& m_item_range; - const Property_map& m_property_map; + const ItemRange& m_item_range; + const PropertyMap& m_property_map; }; template class Item_to_index_property_map { public: - using Item_range = ItemRange; - - using Iterator = typename Item_range::const_iterator; - using Item = typename Iterator::value_type; - + using key_type = typename ItemRange::const_iterator::value_type; using value_type = std::size_t; - using key_type = Item; + using reference = value_type; using category = boost::readable_property_map_tag; - using Item_map = std::map; - - Item_to_index_property_map(const Item_range& item_range) : + Item_to_index_property_map(const ItemRange& item_range) : m_item_range(item_range) { value_type i = 0; @@ -112,8 +103,8 @@ namespace internal { } private: - const Item_range& m_item_range; - Item_map m_item_map; + const ItemRange& m_item_range; + std::map m_item_map; }; class Seed_property_map { @@ -121,6 +112,7 @@ namespace internal { public: using key_type = std::size_t; using value_type = std::size_t; + using reference = value_type; using category = boost::readable_property_map_tag; Seed_property_map( @@ -141,41 +133,52 @@ namespace internal { const std::vector& m_seeds; }; + template class Item_to_region_index_map { public: - using key_type = std::size_t; - using value_type = int; + using key_type = typename ItemToIndexMap::key_type; + using value_type = long; using reference = value_type; using category = boost::readable_property_map_tag; - Item_to_region_index_map() { } + Item_to_region_index_map() : + m_item_to_index_map(nullptr) + { } - template + template Item_to_region_index_map( const ItemRange& items, - const std::vector< std::vector >& regions) : + const ItemToIndexMap& item_to_index_map, + const RegionRange& regions) : + m_item_to_index_map(std::make_shared(item_to_index_map)), m_indices(items.size(), -1) { - for (std::size_t i = 0; i < regions.size(); ++i) { - for (const std::size_t index : regions[i]) { + long region_index = 0; + for (const auto& region : regions) { + for (const auto index : region) { CGAL_precondition(index < m_indices.size()); - m_indices[index] = static_cast(i); + m_indices[index] = region_index; } + ++region_index; } + CGAL_precondition(region_index == static_cast(regions.size())); } inline friend value_type get( const Item_to_region_index_map& item_to_region_index_map, - const key_type key) { + const key_type& key) { const auto& indices = item_to_region_index_map.m_indices; - CGAL_precondition(key < indices.size()); - return indices[key]; + const auto& item_to_index_map = item_to_region_index_map.m_item_to_index_map; + const std::size_t item_index = get(*item_to_index_map, key); + CGAL_precondition(item_index < indices.size()); + return indices[item_index]; } private: - std::vector m_indices; + const std::shared_ptr m_item_to_index_map; + std::vector m_indices; }; } // namespace internal diff --git a/Shape_detection/todo.md b/Shape_detection/todo.md index 4a28799d53b..baea6ec34ed 100644 --- a/Shape_detection/todo.md +++ b/Shape_detection/todo.md @@ -1,4 +1,3 @@ -- make a better version of the Polyline_graph where I return a filtered set of original edges instead of PEdge - update the polyhedron demo - ---- submission ---- - add new tests: polyline (2D, 3D), polyline with sorting (2D, 3D), free functions, randomness, strict tests on the data from PMP, tests similar to the basic_example, check polylines with equal points