diff --git a/Shape_detection/doc/Shape_detection/PackageDescription.txt b/Shape_detection/doc/Shape_detection/PackageDescription.txt index 330385b73f7..78ea0359c2d 100644 --- a/Shape_detection/doc/Shape_detection/PackageDescription.txt +++ b/Shape_detection/doc/Shape_detection/PackageDescription.txt @@ -60,7 +60,7 @@ Classified Reference Manual for the Region Growing shape detection component. - `RegionType` # Algorithm # -- `CGAL::Shape_detection::Region_growing<%NeighborQuery, %RegionType>` +- `CGAL::Shape_detection::Region_growing<%NeighborQuery, %RegionType, RegionMap>` # Point Set # ## Neighbord Query Classes ## 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 386331341cd..61ae8c2a246 100644 --- a/Shape_detection/include/CGAL/Polygon_mesh_processing/region_growing.h +++ b/Shape_detection/include/CGAL/Polygon_mesh_processing/region_growing.h @@ -106,7 +106,7 @@ region_growing_of_planes_on_faces(const PolygonMesh& mesh, using Neighbor_query = RG_PM::One_ring_neighbor_query; using Region_type = RG_PM::Least_squares_plane_fit_region; using Sorting = RG_PM::Least_squares_plane_fit_sorting; - using Region_growing = CGAL::Shape_detection::Region_growing; + using Region_growing = CGAL::Shape_detection::Region_growing; Neighbor_query neighbor_query(mesh); Region_type region_type(mesh, np); @@ -115,12 +115,9 @@ region_growing_of_planes_on_faces(const PolygonMesh& mesh, std::vector regions; Region_growing region_growing( - faces(mesh), sorting.ordered(), neighbor_query, region_type); + faces(mesh), sorting.ordered(), neighbor_query, region_type, region_map); region_growing.detect(CGAL::Emptyset_iterator()); - for (face_descriptor f : faces(mesh)) - put(region_map, f, get(region_growing.region_map(), f)); - return region_growing.number_of_regions_detected(); } diff --git a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing.h b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing.h index a9dd3d89e29..27163d57105 100644 --- a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing.h +++ b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Region_growing.h @@ -48,10 +48,14 @@ namespace Shape_detection { \tparam RegionType a model of `RegionType` + + \tparam RegionMap a model of `ReadWritePropertyMap` whose key type is `Item` + and value type is `std::size_t`. */ template< typename NeighborQuery, - typename RegionType > + typename RegionType, + typename RegionMap = typename RegionType::Region_index_map> class Region_growing { public: @@ -69,7 +73,7 @@ namespace Shape_detection { using Primitive_and_region = std::pair; /// Item to region property map. - using Region_map = typename Region_type::Region_index_map; + using Region_map = RegionMap; private: using Running_queue = std::queue; @@ -90,7 +94,7 @@ namespace Shape_detection { either `CGAL::Dereference_property_map` or `CGAL::Identity_property_map`. \param input_range - a range of input items for region growing + a range of input items for region growing. `input_range` must not be empty. \param neighbor_query an instance of `NeighborQuery` that is used internally to @@ -102,15 +106,15 @@ namespace Shape_detection { \param item_map an instance of the property map to retrieve items from input values - - \pre `input_range.size() > 0` */ template Region_growing( const InputRange& input_range, NeighborQuery& neighbor_query, RegionType& region_type, - ItemMap item_map = ItemMap()) : + ItemMap item_map = ItemMap(), + std::enable_if_t::value>* = 0 + ) : m_neighbor_query(neighbor_query), m_region_type(region_type), m_region_map(region_type.region_index_map()), @@ -130,6 +134,34 @@ namespace Shape_detection { clear(input_range, item_map_); } + /// \copydoc Region_growing() + /// \param rm external property map that will be filled when calling `detect()` + template + Region_growing( + const InputRange& input_range, + NeighborQuery& neighbor_query, + RegionType& region_type, + Region_map rm, + ItemMap item_map = ItemMap()) : + m_neighbor_query(neighbor_query), + m_region_type(region_type), + m_region_map(rm), + m_visited(m_visited_map) + { + CGAL_precondition(input_range.size() > 0); + m_seed_range.resize(input_range.size()); + + using Item_helper = internal::Item_map_helper; + using Item_map = typename Item_helper::type; + Item_map item_map_ = Item_helper::get(item_map); + + std::size_t idx = 0; + for (auto it = input_range.begin(); it != input_range.end(); it++) + m_seed_range[idx++] = get(item_map_, it); + + clear(input_range, item_map_); + } + /*! \brief initializes the region growing algorithm. @@ -208,8 +240,8 @@ namespace Shape_detection { \return past-the-end position in the output sequence */ - template - PrimitiveAndRegionOutputIterator detect(PrimitiveAndRegionOutputIterator region_out) { + template + PrimitiveAndRegionOutputIterator detect(PrimitiveAndRegionOutputIterator region_out = PrimitiveAndRegionOutputIterator()) { // clear(); TODO: this is not valid to comment this clear() m_visited_map.clear(); // tmp replacement for the line above