From eb4d2953d5f774ecacaeeaa1b065aa27c6021842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 23 Jul 2021 12:14:32 +0200 Subject: [PATCH 1/8] Fix index maps for non-const Face_filtered_graph --- .../CGAL/boost/graph/Face_filtered_graph.h | 135 ++++++++++++------ 1 file changed, 88 insertions(+), 47 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/Face_filtered_graph.h b/BGL/include/CGAL/boost/graph/Face_filtered_graph.h index c7a8182d68d..982adf381bc 100644 --- a/BGL/include/CGAL/boost/graph/Face_filtered_graph.h +++ b/BGL/include/CGAL/boost/graph/Face_filtered_graph.h @@ -1206,40 +1206,6 @@ CGAL_FFG_DYNAMIC_PMAP_SPEC(dynamic_face_property_t) #undef CGAL_FFG_DYNAMIC_PMAP_SPEC -//specializations for indices -template -typename boost::property_map, CGAL::face_index_t >::type -get(CGAL::face_index_t, const Face_filtered_graph& w) -{ - return w.get_face_index_map(); -} - - -template -typename boost::property_map, boost::vertex_index_t >::type -get(boost::vertex_index_t, const Face_filtered_graph& w) -{ - return w.get_vertex_index_map(); -} - - -template -typename boost::property_map, CGAL::halfedge_index_t >::type -get(CGAL::halfedge_index_t, const Face_filtered_graph& w) -{ - return w.get_halfedge_index_map(); -} - - template struct property_map, CGAL::face_index_t> { - typedef typename CGAL::Face_filtered_graph::FIM FIM; + typedef CGAL::Face_filtered_graph FFG; + typedef typename FFG::FIM FIM; + + typedef typename boost::property_traits::value_type Face_index; + typedef typename CGAL::dynamic_face_property_t Face_index_dtag; + typedef typename boost::property_map::type type; + typedef typename CGAL::Property_map_binder::value_type>::type> type; - typedef type const_type; + typename boost::property_traits::value_type>::type> const_type; }; template struct property_map, boost::vertex_index_t> { - typedef typename CGAL::Face_filtered_graph::VIM VIM; + typedef CGAL::Face_filtered_graph FFG; + typedef typename FFG::VIM VIM; + + typedef typename boost::property_traits::value_type Vertex_index; + typedef typename CGAL::dynamic_vertex_property_t Vertex_index_dtag; + typedef typename boost::property_map::type type; + typedef typename CGAL::Property_map_binder::value_type>::type> type; - typedef type const_type; + typename boost::property_traits::value_type>::type> const_type; }; -template +template struct property_map, CGAL::halfedge_index_t> { - typedef typename CGAL::Face_filtered_graph::HIM HIM; + typedef CGAL::Face_filtered_graph FFG; + typedef typename FFG::HIM HIM; + + typedef typename boost::property_traits::value_type Halfedge_index; + typedef typename CGAL::dynamic_halfedge_property_t Halfedge_index_dtag; + typedef typename boost::property_map::type type; + typedef typename CGAL::Property_map_binder::value_type>::type> type; - typedef type const_type; + typename boost::property_traits::value_type>::type> const_type; }; } // namespace boost +namespace CGAL { + +//specializations for indices +template +typename boost::property_map, CGAL::face_index_t >::const_type +get(CGAL::face_index_t, const Face_filtered_graph& w) +{ + return w.get_face_index_map(); +} + +template +typename boost::property_map, boost::vertex_index_t >::const_type +get(boost::vertex_index_t, const Face_filtered_graph& w) +{ + return w.get_vertex_index_map(); +} + +template +typename boost::property_map, CGAL::halfedge_index_t >::const_type +get(CGAL::halfedge_index_t, const Face_filtered_graph& w) +{ + return w.get_halfedge_index_map(); +} + +// non-const (dynamic pmap) +template +typename boost::property_map, CGAL::face_index_t >::type +get(CGAL::face_index_t, Face_filtered_graph& w) +{ + typedef CGAL::Face_filtered_graph FFG; + typedef typename boost::property_map::type result_type; + typedef typename boost::property_traits::value_type Index; + typedef typename CGAL::dynamic_face_property_t Index_dtag; + + return get(Index_dtag(), w.graph()); +} + +template +typename boost::property_map, boost::vertex_index_t >::type +get(boost::vertex_index_t, Face_filtered_graph& w) +{ + typedef CGAL::Face_filtered_graph FFG; + typedef typename boost::property_map::type result_type; + typedef typename boost::property_traits::value_type Index; + typedef typename CGAL::dynamic_vertex_property_t Index_dtag; + + return get(Index_dtag(), w.graph()); +} + +template +typename boost::property_map, CGAL::halfedge_index_t >::type +get(CGAL::halfedge_index_t, Face_filtered_graph& w) +{ + typedef CGAL::Face_filtered_graph FFG; + typedef typename boost::property_map::type result_type; + typedef typename boost::property_traits::value_type Index; + typedef typename CGAL::dynamic_halfedge_property_t Index_dtag; + + return get(Index_dtag(), w.graph()); +} + +} // namespace CGAL + #endif // CGAL_BOOST_GRAPH_FACE_FILTERED_GRAPH_H From 4d471cf1399aa9e7e92d771dc458678b228c713f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 23 Jul 2021 12:15:42 +0200 Subject: [PATCH 2/8] Enhance tests for Face_filtered_graph --- BGL/test/BGL/test_Face_filtered_graph.cpp | 152 +++++++++++++--------- 1 file changed, 87 insertions(+), 65 deletions(-) diff --git a/BGL/test/BGL/test_Face_filtered_graph.cpp b/BGL/test/BGL/test_Face_filtered_graph.cpp index 0a579fe96cc..10e3086476d 100644 --- a/BGL/test/BGL/test_Face_filtered_graph.cpp +++ b/BGL/test/BGL/test_Face_filtered_graph.cpp @@ -1,15 +1,23 @@ -#include -#include #include +#include +#include +#include +#include #include "test_Prefix.h" + #include #include #include -#include + #include +#include +#include +#include typedef boost::unordered_set id_map; +namespace PMP = CGAL::Polygon_mesh_processing; + template void test_halfedge_around_vertex_iterator(const Graph& g) { @@ -17,8 +25,7 @@ void test_halfedge_around_vertex_iterator(const Graph& g) typedef CGAL::Face_filtered_graph Adapter; CGAL_GRAPH_TRAITS_MEMBERS(Adapter); boost::unordered_map map(num_faces(g)); - CGAL::Polygon_mesh_processing::connected_components(g, boost::make_assoc_property_map(map), CGAL::Polygon_mesh_processing::parameters::all_default()); - + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); Adapter fg(g, 0, boost::make_assoc_property_map(map)); typename boost::graph_traits::vertex_iterator vit, vend; @@ -45,8 +52,9 @@ void test_halfedge_around_face_iterator(const Graph& g) typedef CGAL::Face_filtered_graph Adapter; CGAL_GRAPH_TRAITS_MEMBERS(Adapter); std::map map; - CGAL::Polygon_mesh_processing::connected_components(g, boost::make_assoc_property_map(map), CGAL::Polygon_mesh_processing::parameters::all_default()); + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); Adapter fg(g, 0, boost::make_assoc_property_map(map)); + face_iterator fit, fend; for(boost::tie(fit, fend) = faces(fg); fit != fend; ++fit) { halfedge_around_face_iterator hafit, hafend; @@ -65,7 +73,7 @@ void test_edge_iterators(const Graph& g) typedef CGAL::Face_filtered_graph Adapter; CGAL_GRAPH_TRAITS_MEMBERS(Adapter); std::map map; - CGAL::Polygon_mesh_processing::connected_components(g, boost::make_assoc_property_map(map), CGAL::Polygon_mesh_processing::parameters::all_default()); + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); Adapter fg(g, 0, boost::make_assoc_property_map(map)); // do we iterate as many as that? @@ -91,7 +99,7 @@ void test_vertex_iterators(Graph& g) typedef CGAL::Face_filtered_graph Adapter; CGAL_GRAPH_TRAITS_MEMBERS(Adapter); std::map map; - CGAL::Polygon_mesh_processing::connected_components(g, boost::make_assoc_property_map(map), CGAL::Polygon_mesh_processing::parameters::all_default()); + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); Adapter fg(g, 0, boost::make_assoc_property_map(map)); vertex_iterator vb, ve; std::size_t count = 0; @@ -121,7 +129,7 @@ void test_out_edges(const Graph& g) typedef CGAL::Face_filtered_graph Adapter; CGAL_GRAPH_TRAITS_MEMBERS(Adapter); std::map map; - CGAL::Polygon_mesh_processing::connected_components(g, boost::make_assoc_property_map(map), CGAL::Polygon_mesh_processing::parameters::all_default()); + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); Adapter fg(g, 0, boost::make_assoc_property_map(map)); vertex_iterator vb, ve; @@ -150,7 +158,7 @@ void test_in_edges(const Graph& g) typedef CGAL::Face_filtered_graph Adapter; CGAL_GRAPH_TRAITS_MEMBERS(Adapter); std::map map; - CGAL::Polygon_mesh_processing::connected_components(g, boost::make_assoc_property_map(map), CGAL::Polygon_mesh_processing::parameters::all_default()); + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); Adapter fg(g, 0, boost::make_assoc_property_map(map)); vertex_iterator vb, ve; @@ -177,7 +185,7 @@ void test_in_out_edges(const Graph& g) typedef CGAL::Face_filtered_graph Adapter; CGAL_GRAPH_TRAITS_MEMBERS(Adapter); std::map map; - CGAL::Polygon_mesh_processing::connected_components(g, boost::make_assoc_property_map(map), CGAL::Polygon_mesh_processing::parameters::all_default()); + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); Adapter fg(g, 0, boost::make_assoc_property_map(map)); // check that the sets of in out edges are the same @@ -219,7 +227,7 @@ void test_edge_find(const Graph& g) typedef CGAL::Face_filtered_graph Adapter; CGAL_GRAPH_TRAITS_MEMBERS(Adapter); std::map map; - CGAL::Polygon_mesh_processing::connected_components(g, boost::make_assoc_property_map(map), CGAL::Polygon_mesh_processing::parameters::all_default()); + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); Adapter fg(g, 0, boost::make_assoc_property_map(map)); typedef std::pair ret; @@ -243,7 +251,7 @@ void test_faces(const Graph& g) typedef CGAL::Face_filtered_graph Adapter; CGAL_GRAPH_TRAITS_MEMBERS(Adapter); std::map map; - CGAL::Polygon_mesh_processing::connected_components(g, boost::make_assoc_property_map(map), CGAL::Polygon_mesh_processing::parameters::all_default()); + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); Adapter fg(g, 0, boost::make_assoc_property_map(map)); unsigned int count = 0; @@ -262,6 +270,45 @@ void test_faces(const Graph& g) assert(count == num_faces(fg)); } +template +void test_index_property_maps(const Graph& g) +{ + typedef CGAL::Face_filtered_graph Adapter; + CGAL_GRAPH_TRAITS_MEMBERS(Adapter); + + typedef typename boost::graph_traits::face_descriptor g_face_descriptor; + std::map map; + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); + Adapter fg(g, 0, boost::make_assoc_property_map(map)); + + // Non const + typedef typename CGAL::GetInitializedVertexIndexMap::type VIMap; + VIMap vim = CGAL::get_initialized_vertex_index_map(fg); + assert(CGAL::BGL::internal::is_index_map_valid(vim, num_vertices(fg), vertices(fg))); + + typedef typename CGAL::GetInitializedHalfedgeIndexMap::type HIMap; + HIMap him = CGAL::get_initialized_halfedge_index_map(fg); + assert(CGAL::BGL::internal::is_index_map_valid(him, num_halfedges(fg), halfedges(fg))); + + typedef typename CGAL::GetInitializedFaceIndexMap::type FIMap; + FIMap fim = CGAL::get_initialized_face_index_map(fg); + assert(CGAL::BGL::internal::is_index_map_valid(fim, num_faces(fg), faces(fg))); + + // Const + const Adapter cfg(g, 0, boost::make_assoc_property_map(map)); + typedef typename CGAL::GetInitializedVertexIndexMap::const_type CVIMap; + CVIMap cvim = CGAL::get_initialized_vertex_index_map(cfg); + assert(CGAL::BGL::internal::is_index_map_valid(cvim, num_vertices(cfg), vertices(cfg))); + + typedef typename CGAL::GetInitializedHalfedgeIndexMap::const_type CHIMap; + CHIMap chim = CGAL::get_initialized_halfedge_index_map(cfg); + assert(CGAL::BGL::internal::is_index_map_valid(chim, num_halfedges(cfg), halfedges(cfg))); + + typedef typename CGAL::GetInitializedFaceIndexMap::const_type CFIMap; + CFIMap cfim = CGAL::get_initialized_face_index_map(cfg); + assert(CGAL::BGL::internal::is_index_map_valid(cfim, num_faces(cfg), faces(cfg))); +} + template void test_read(const Graph& g) { @@ -270,7 +317,7 @@ void test_read(const Graph& g) CGAL_GRAPH_TRAITS_MEMBERS(Adapter); std::map map; - CGAL::Polygon_mesh_processing::connected_components(g, boost::make_assoc_property_map(map), CGAL::Polygon_mesh_processing::parameters::all_default()); + PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); Adapter fg(g, 0, boost::make_assoc_property_map(map)); assert(fg.is_selection_valid()); assert(CGAL::is_valid_polygon_mesh(fg)); @@ -292,6 +339,7 @@ test_graph_range(const std::vector& graphs) test_edge_iterators(p); test_halfedge_around_face_iterator(p); test_halfedge_around_vertex_iterator(p); + test_index_property_maps(p); } } @@ -356,7 +404,6 @@ struct Constraint : public boost::put_get_helper void test_mesh(Adapter fga) { - CGAL_GRAPH_TRAITS_MEMBERS(Adapter); //check that there is the right number of simplices in fga CGAL_assertion(CGAL::is_valid_polygon_mesh(fga)); @@ -365,31 +412,23 @@ void test_mesh(Adapter fga) CGAL_assertion(num_halfedges(fga) == 10); CGAL_assertion(num_vertices(fga) == 4); halfedge_descriptor h = halfedge(*faces(fga).first, fga); - CGAL_assertion_code( vertex_descriptor v = source(h, fga) ); + CGAL_assertion_code( vertex_descriptor v = source(h, fga)); //check that next() works inside the patch - CGAL_assertion( - next(next(next(h, fga), fga), fga) == h - ); + CGAL_assertion(next(next(next(h, fga), fga), fga) == h); //check that next() works on bordure of the patch h = opposite(h, fga); - CGAL_assertion( - next(next(next(next(h, fga), fga), fga), fga) == h - ); + CGAL_assertion(next(next(next(next(h, fga), fga), fga), fga) == h); //check that prev() works inside the patch h = halfedge(*faces(fga).first, fga); - CGAL_assertion( - prev(prev(prev(h, fga), fga), fga) == h - ); + CGAL_assertion(prev(prev(prev(h, fga), fga), fga) == h); //check that prev() works on bordure of the patch h = opposite(h, fga); - CGAL_assertion( - prev(prev(prev(prev(h, fga), fga), fga), fga) == h - ); + CGAL_assertion(prev(prev(prev(prev(h, fga), fga), fga), fga) == h); //check degree CGAL_assertion(degree(v, fga) == 3); //check in_edges and out_edges - CGAL_assertion(std::distance(in_edges(v, fga).first ,in_edges(v, fga).second) == 3 ); - CGAL_assertion(std::distance(out_edges(v, fga).first ,out_edges(v, fga).second) == 3 ); + CGAL_assertion(std::distance(in_edges(v, fga).first ,in_edges(v, fga).second) == 3); + CGAL_assertion(std::distance(out_edges(v, fga).first ,out_edges(v, fga).second) == 3); Mesh copy; CGAL::copy_face_graph(fga, copy); @@ -454,7 +493,7 @@ int main() { test_graph_range(poly_data()); -#if defined(CGAL_USE_SURFACE_MESH) +#ifdef CGAL_USE_SURFACE_MESH test_graph_range(sm_data()); #endif @@ -464,64 +503,47 @@ int main() test_invalid_selections(); - //Make a tetrahedron and test the adapter for a patch that only contains 2 faces + // Make a tetrahedron and test the adapter for a patch that only contains 2 faces typedef CGAL::Face_filtered_graph SM_Adapter; typedef SM::Property_map::face_descriptor , std::size_t> SM_FCCMap; auto sm = std::make_unique(); - CGAL::make_tetrahedron( - Point_3(1,1,1), - Point_3(0,0,0), - Point_3(0,0,1), - Point_3(1,0,1), - *sm); - SM_FCCMap fccmap = - sm->add_property_map::face_descriptor, std::size_t>("f:CC").first; - SM::Property_map::vertex_descriptor, SM::Point> positions = - sm->points(); - CGAL::Polygon_mesh_processing::connected_components(*sm, fccmap, CGAL::Polygon_mesh_processing::parameters:: - edge_is_constrained_map(Constraint::vertex_descriptor, - SM::Point> >(*sm, positions))); + CGAL::make_tetrahedron(Point_3(1,1,1), Point_3(0,0,0), Point_3(0,0,1), Point_3(1,0,1), *sm); + + SM_FCCMap fccmap = sm->add_property_map::face_descriptor, std::size_t>("f:CC").first; + SM::Property_map::vertex_descriptor, SM::Point> positions = sm->points(); + CGAL::Polygon_mesh_processing::connected_components( + *sm, fccmap, CGAL::parameters::edge_is_constrained_map(Constraint::vertex_descriptor, + SM::Point> >(*sm, positions))); + boost::unordered_set pids; pids.insert(0); pids.insert(2); SM_Adapter sm_adapter(*sm, pids, fccmap); test_mesh(sm_adapter); - - - typedef boost::graph_traits PolyTraits; typedef boost::property_map::const_type VPMap; typedef PolyTraits::face_descriptor poly_face_descriptor; - typedef boost::associative_property_map< std::map > FCMap; + typedef boost::associative_property_map > FCMap; typedef boost::property_map::const_type FIMap; typedef boost::property_map::const_type VIMap; typedef boost::property_map::const_type HIMap; typedef CGAL::Face_filtered_graph Poly_Adapter; - auto poly = std::make_unique(); - CGAL::make_tetrahedron( - Point_3(1,1,1), - Point_3(0,0,0), - Point_3(0,0,1), - Point_3(1,0,1), - *poly); + auto poly = std::make_unique(); + CGAL::make_tetrahedron(Point_3(1,1,1), Point_3(0,0,0), Point_3(0,0,1), Point_3(1,0,1), *poly); FIMap poly_fimap = get(CGAL::face_external_index, *poly); VIMap poly_vimap = get(CGAL::vertex_external_index, *poly); HIMap poly_himap = get(CGAL::halfedge_external_index, *poly); - std::map fc_map; + std::map fc_map; FCMap poly_fccmap(fc_map); VPMap vpmap = get(boost::vertex_point, *poly); - CGAL::Polygon_mesh_processing::connected_components(*poly, poly_fccmap, - CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(Constraint(*poly, vpmap)) - .face_index_map(poly_fimap)); - Poly_Adapter poly_adapter(*poly, - pids, - poly_fccmap, + PMP::connected_components(*poly, poly_fccmap, + CGAL::parameters::edge_is_constrained_map(Constraint(*poly, vpmap)) + .face_index_map(poly_fimap)); + Poly_Adapter poly_adapter(*poly, pids, poly_fccmap, CGAL::parameters::face_index_map(poly_fimap) .vertex_index_map(poly_vimap) .halfedge_index_map(poly_himap)); From a221d9f1a77fd990d22e4c845d154417167c08fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 23 Jul 2021 14:26:20 +0200 Subject: [PATCH 3/8] Using boost:: rather than CGAL:: for FFG's index pmap properties --- .../CGAL/boost/graph/Face_filtered_graph.h | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/Face_filtered_graph.h b/BGL/include/CGAL/boost/graph/Face_filtered_graph.h index 982adf381bc..5bdc06c873b 100644 --- a/BGL/include/CGAL/boost/graph/Face_filtered_graph.h +++ b/BGL/include/CGAL/boost/graph/Face_filtered_graph.h @@ -1273,14 +1273,14 @@ CGAL_FILTERED_FACE_GRAPH_DYNAMIC_PMAP_SPECIALIZATION(dynamic_face_property_t) //specializations for indices template -struct property_map, CGAL::face_index_t> +struct property_map, boost::face_index_t> { typedef CGAL::Face_filtered_graph FFG; typedef typename FFG::FIM FIM; - typedef typename boost::property_traits::value_type Face_index; - typedef typename CGAL::dynamic_face_property_t Face_index_dtag; - typedef typename boost::property_map::type type; + typedef typename boost::property_traits::value_type Index; + typedef typename CGAL::dynamic_face_property_t Index_dtag; + typedef typename boost::property_map::type type; typedef typename CGAL::Property_map_binder, boost typedef CGAL::Face_filtered_graph FFG; typedef typename FFG::VIM VIM; - typedef typename boost::property_traits::value_type Vertex_index; - typedef typename CGAL::dynamic_vertex_property_t Vertex_index_dtag; - typedef typename boost::property_map::type type; + typedef typename boost::property_traits::value_type Index; + typedef typename CGAL::dynamic_vertex_property_t Index_dtag; + typedef typename boost::property_map::type type; typedef typename CGAL::Property_map_binder, boost }; template -struct property_map, CGAL::halfedge_index_t> +struct property_map, boost::halfedge_index_t> { typedef CGAL::Face_filtered_graph FFG; typedef typename FFG::HIM HIM; - typedef typename boost::property_traits::value_type Halfedge_index; - typedef typename CGAL::dynamic_halfedge_property_t Halfedge_index_dtag; - typedef typename boost::property_map::type type; + typedef typename boost::property_traits::value_type Index; + typedef typename CGAL::dynamic_halfedge_property_t Index_dtag; + typedef typename boost::property_map::type type; typedef typename CGAL::Property_map_binder -typename boost::property_map, CGAL::face_index_t >::const_type -get(CGAL::face_index_t, const Face_filtered_graph& w) +typename boost::property_map, boost::face_index_t >::const_type +get(boost::face_index_t, const Face_filtered_graph& w) { return w.get_face_index_map(); } @@ -1337,19 +1337,19 @@ get(boost::vertex_index_t, const Face_filtered_graph } template -typename boost::property_map, CGAL::halfedge_index_t >::const_type -get(CGAL::halfedge_index_t, const Face_filtered_graph& w) +typename boost::property_map, boost::halfedge_index_t >::const_type +get(boost::halfedge_index_t, const Face_filtered_graph& w) { return w.get_halfedge_index_map(); } // non-const (dynamic pmap) template -typename boost::property_map, CGAL::face_index_t >::type -get(CGAL::face_index_t, Face_filtered_graph& w) +typename boost::property_map, boost::face_index_t >::type +get(boost::face_index_t, Face_filtered_graph& w) { typedef CGAL::Face_filtered_graph FFG; - typedef typename boost::property_map::type result_type; + typedef typename boost::property_map::type result_type; typedef typename boost::property_traits::value_type Index; typedef typename CGAL::dynamic_face_property_t Index_dtag; @@ -1369,11 +1369,11 @@ get(boost::vertex_index_t, Face_filtered_graph& w) } template -typename boost::property_map, CGAL::halfedge_index_t >::type -get(CGAL::halfedge_index_t, Face_filtered_graph& w) +typename boost::property_map, boost::halfedge_index_t >::type +get(boost::halfedge_index_t, Face_filtered_graph& w) { typedef CGAL::Face_filtered_graph FFG; - typedef typename boost::property_map::type result_type; + typedef typename boost::property_map::type result_type; typedef typename boost::property_traits::value_type Index; typedef typename CGAL::dynamic_halfedge_property_t Index_dtag; From 5240e402dee00a2fca3f9f904511f15c2ed068a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 23 Jul 2021 14:26:40 +0200 Subject: [PATCH 4/8] Fix wrong PMap type --- Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp index 94741aac6a7..7facb373c1f 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp @@ -2453,8 +2453,7 @@ QString Scene_polyhedron_selection_item::computeStats(int type) // Extract the part n°0 of the partition into a new, independent mesh if(selected_facets.size() == 0) return QString("n/a"); - boost::vector_property_map::type> + boost::vector_property_map, boost::face_index_t>::type> fccmap(get(boost::face_index, *d->filtered_graph)); return QString::number(CGAL::Polygon_mesh_processing::connected_components(*d->filtered_graph, fccmap)); From e3b154407029ceba20ed7600e065b3c2a9fef1de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 26 Jul 2021 12:25:46 +0200 Subject: [PATCH 5/8] Revert to binder-pmaps for FFG's index maps (but fix them) --- .../CGAL/boost/graph/Face_filtered_graph.h | 164 ++++++++++-------- 1 file changed, 87 insertions(+), 77 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/Face_filtered_graph.h b/BGL/include/CGAL/boost/graph/Face_filtered_graph.h index 5bdc06c873b..7cdbbfc9747 100644 --- a/BGL/include/CGAL/boost/graph/Face_filtered_graph.h +++ b/BGL/include/CGAL/boost/graph/Face_filtered_graph.h @@ -393,21 +393,68 @@ struct Face_filtered_graph ///returns a reference to the underlying graph. Graph& graph(){ return _graph; } - ///change the set of selected faces using a patch id - template - void set_selected_faces(typename boost::property_traits::value_type face_patch_id, - FacePatchIndexMap face_patch_index_map) + // Handling of internal correspondency for index maps. + // The indices must be kept valid when the selection changes. + void initialize_face_indices() const + { + if(face_indices.empty()) + { + face_index_type index = 0; + face_indices.resize(num_faces(_graph)); + for(std::size_t i=selected_faces.find_first(); i + void set_selected_faces(typename boost::property_traits::value_type face_patch_id, + FacePatchIndexMap face_patch_index_map) + { selected_faces.resize(num_faces(_graph)); selected_vertices.resize(num_vertices(_graph)); selected_halfedges.resize(num_halfedges(_graph)); + selected_faces.reset(); selected_vertices.reset(); selected_halfedges.reset(); + for(face_descriptor fd : faces(_graph) ) { if(get(face_patch_index_map, fd) == face_patch_id) @@ -421,6 +468,8 @@ struct Face_filtered_graph } } } + + reset_indices(); } /// change the set of selected faces using a range of patch ids template @@ -433,16 +482,14 @@ struct Face_filtered_graph #endif ) { - face_indices.clear(); - vertex_indices.clear(); - halfedge_indices.clear(); - selected_faces.resize(num_faces(_graph)); selected_vertices.resize(num_vertices(_graph)); selected_halfedges.resize(num_halfedges(_graph)); + selected_faces.reset(); selected_vertices.reset(); selected_halfedges.reset(); + typedef typename boost::property_traits::value_type Patch_index; boost::unordered_set pids(boost::begin(selected_face_patch_indices), boost::end(selected_face_patch_indices)); @@ -460,21 +507,22 @@ struct Face_filtered_graph } } } + + reset_indices(); } + /// change the set of selected faces using a range of face descriptors template void set_selected_faces(const FaceRange& selection) { - face_indices.clear(); - vertex_indices.clear(); - halfedge_indices.clear(); - selected_faces.resize(num_faces(_graph)); selected_vertices.resize(num_vertices(_graph)); selected_halfedges.resize(num_halfedges(_graph)); + selected_faces.reset(); selected_vertices.reset(); selected_halfedges.reset(); + for(face_descriptor fd : selection) { selected_faces.set(get(fimap, fd)); @@ -485,6 +533,8 @@ struct Face_filtered_graph selected_vertices.set(get(vimap, target(hd, _graph))); } } + + reset_indices(); } struct Is_simplex_valid @@ -543,45 +593,27 @@ struct Face_filtered_graph Property_map_binder::value_type>::type> get_face_index_map() const { - if (face_indices.empty()) - { - face_index_type index = 0; - face_indices.resize(num_faces(_graph)); - for (std::size_t i=selected_faces.find_first(); i < selected_faces.npos; i = selected_faces.find_next(i)) - { - face_indices[i] = index++; - } - } - return bind_property_maps(fimap, make_property_map(face_indices) ); + is_imap_in_use.set(0); + initialize_face_indices(); + + return bind_property_maps(fimap, make_property_map(face_indices)); } Property_map_binder::value_type>::type> get_vertex_index_map() const { - if (vertex_indices.empty()) - { - vertex_index_type index = 0; - vertex_indices.resize(num_vertices(_graph)); - for (std::size_t i=selected_vertices.find_first(); i < selected_vertices.npos; i = selected_vertices.find_next(i)) - { - vertex_indices[i] = index++; - } - } + is_imap_in_use.set(1); + initialize_vertex_indices(); + return bind_property_maps(vimap, make_property_map(vertex_indices) ); } Property_map_binder::value_type >::type> get_halfedge_index_map() const { - if (halfedge_indices.empty()) - { - halfedge_index_type index = 0; - halfedge_indices.resize(num_halfedges(_graph)); - for (std::size_t i=selected_halfedges.find_first(); i < selected_halfedges.npos; i = selected_halfedges.find_next(i)) - { - halfedge_indices[i] = index++; - } - } + is_imap_in_use.set(2); + initialize_halfedge_indices(); + return bind_property_maps(himap, make_property_map(halfedge_indices) ); } @@ -649,9 +681,11 @@ private: boost::dynamic_bitset<> selected_faces; boost::dynamic_bitset<> selected_vertices; boost::dynamic_bitset<> selected_halfedges; + mutable std::vector face_indices; mutable std::vector vertex_indices; mutable std::vector halfedge_indices; + mutable std::bitset<3> is_imap_in_use; // one per descriptor type (face, vertex, halfedge) }; } // namespace CGAL @@ -1278,13 +1312,10 @@ struct property_map, boost typedef CGAL::Face_filtered_graph FFG; typedef typename FFG::FIM FIM; - typedef typename boost::property_traits::value_type Index; - typedef typename CGAL::dynamic_face_property_t Index_dtag; - typedef typename boost::property_map::type type; - typedef typename CGAL::Property_map_binder::value_type>::type> const_type; + typename boost::property_traits::value_type>::type> type; + typedef type const_type; }; template @@ -1293,13 +1324,10 @@ struct property_map, boost typedef CGAL::Face_filtered_graph FFG; typedef typename FFG::VIM VIM; - typedef typename boost::property_traits::value_type Index; - typedef typename CGAL::dynamic_vertex_property_t Index_dtag; - typedef typename boost::property_map::type type; - typedef typename CGAL::Property_map_binder::value_type>::type> const_type; + typename boost::property_traits::value_type>::type> type; + typedef type const_type; }; template @@ -1308,13 +1336,10 @@ struct property_map, boost typedef CGAL::Face_filtered_graph FFG; typedef typename FFG::HIM HIM; - typedef typename boost::property_traits::value_type Index; - typedef typename CGAL::dynamic_halfedge_property_t Index_dtag; - typedef typename boost::property_map::type type; - typedef typename CGAL::Property_map_binder::value_type>::type> const_type; + typename boost::property_traits::value_type>::type> type; + typedef type const_type; }; } // namespace boost @@ -1343,41 +1368,26 @@ get(boost::halfedge_index_t, const Face_filtered_graph -typename boost::property_map, boost::face_index_t >::type +typename boost::property_map, boost::face_index_t >::const_type get(boost::face_index_t, Face_filtered_graph& w) { - typedef CGAL::Face_filtered_graph FFG; - typedef typename boost::property_map::type result_type; - typedef typename boost::property_traits::value_type Index; - typedef typename CGAL::dynamic_face_property_t Index_dtag; - - return get(Index_dtag(), w.graph()); + return w.get_face_index_map(); } template -typename boost::property_map, boost::vertex_index_t >::type +typename boost::property_map, boost::vertex_index_t >::const_type get(boost::vertex_index_t, Face_filtered_graph& w) { - typedef CGAL::Face_filtered_graph FFG; - typedef typename boost::property_map::type result_type; - typedef typename boost::property_traits::value_type Index; - typedef typename CGAL::dynamic_vertex_property_t Index_dtag; - - return get(Index_dtag(), w.graph()); + return w.get_vertex_index_map(); } template -typename boost::property_map, boost::halfedge_index_t >::type +typename boost::property_map, boost::halfedge_index_t >::const_type get(boost::halfedge_index_t, Face_filtered_graph& w) { - typedef CGAL::Face_filtered_graph FFG; - typedef typename boost::property_map::type result_type; - typedef typename boost::property_traits::value_type Index; - typedef typename CGAL::dynamic_halfedge_property_t Index_dtag; - - return get(Index_dtag(), w.graph()); + return w.get_halfedge_index_map(); } } // namespace CGAL From 55e71b602a216b61ffbfb8d6a1097d56d68fb6ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 26 Jul 2021 12:27:03 +0200 Subject: [PATCH 6/8] Test binder-based index pmaps on selection -changing FFG --- BGL/test/BGL/test_Face_filtered_graph.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/BGL/test/BGL/test_Face_filtered_graph.cpp b/BGL/test/BGL/test_Face_filtered_graph.cpp index 10e3086476d..100f08eb278 100644 --- a/BGL/test/BGL/test_Face_filtered_graph.cpp +++ b/BGL/test/BGL/test_Face_filtered_graph.cpp @@ -279,7 +279,8 @@ void test_index_property_maps(const Graph& g) typedef typename boost::graph_traits::face_descriptor g_face_descriptor; std::map map; PMP::connected_components(g, boost::make_assoc_property_map(map), CGAL::parameters::all_default()); - Adapter fg(g, 0, boost::make_assoc_property_map(map)); + Adapter fg(g, -1, boost::make_assoc_property_map(map)); + assert(is_empty(fg)); // Non const typedef typename CGAL::GetInitializedVertexIndexMap::type VIMap; @@ -294,6 +295,13 @@ void test_index_property_maps(const Graph& g) FIMap fim = CGAL::get_initialized_face_index_map(fg); assert(CGAL::BGL::internal::is_index_map_valid(fim, num_faces(fg), faces(fg))); + fg.set_selected_faces(0, boost::make_assoc_property_map(map)); + assert(!is_empty(fg)); + + assert(CGAL::BGL::internal::is_index_map_valid(vim, num_vertices(fg), vertices(fg))); + assert(CGAL::BGL::internal::is_index_map_valid(him, num_halfedges(fg), halfedges(fg))); + assert(CGAL::BGL::internal::is_index_map_valid(fim, num_faces(fg), faces(fg))); + // Const const Adapter cfg(g, 0, boost::make_assoc_property_map(map)); typedef typename CGAL::GetInitializedVertexIndexMap::const_type CVIMap; From 09337e4c3b7dc290ea56723bd86a2393fc95e427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 26 Jul 2021 12:31:22 +0200 Subject: [PATCH 7/8] Add some missing STL includes --- BGL/include/CGAL/boost/graph/Face_filtered_graph.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BGL/include/CGAL/boost/graph/Face_filtered_graph.h b/BGL/include/CGAL/boost/graph/Face_filtered_graph.h index 7cdbbfc9747..58eb511d846 100644 --- a/BGL/include/CGAL/boost/graph/Face_filtered_graph.h +++ b/BGL/include/CGAL/boost/graph/Face_filtered_graph.h @@ -28,6 +28,10 @@ #include #include +#include +#include +#include + #ifdef DOXYGEN_RUNNING #define CGAL_BGL_NP_TEMPLATE_PARAMETERS NamedParameters #define CGAL_BGL_NP_CLASS NamedParameters From ec9c77b44d117685b6a591ae4d71469abefc5962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 26 Jul 2021 13:49:27 +0200 Subject: [PATCH 8/8] Use the non-const ::type typedef for consistency Internally, both ::type and ::const_type are the same --- BGL/include/CGAL/boost/graph/Face_filtered_graph.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/Face_filtered_graph.h b/BGL/include/CGAL/boost/graph/Face_filtered_graph.h index 58eb511d846..88dc8f55b92 100644 --- a/BGL/include/CGAL/boost/graph/Face_filtered_graph.h +++ b/BGL/include/CGAL/boost/graph/Face_filtered_graph.h @@ -1374,21 +1374,21 @@ get(boost::halfedge_index_t, const Face_filtered_graph -typename boost::property_map, boost::face_index_t >::const_type +typename boost::property_map, boost::face_index_t >::type get(boost::face_index_t, Face_filtered_graph& w) { return w.get_face_index_map(); } template -typename boost::property_map, boost::vertex_index_t >::const_type +typename boost::property_map, boost::vertex_index_t >::type get(boost::vertex_index_t, Face_filtered_graph& w) { return w.get_vertex_index_map(); } template -typename boost::property_map, boost::halfedge_index_t >::const_type +typename boost::property_map, boost::halfedge_index_t >::type get(boost::halfedge_index_t, Face_filtered_graph& w) { return w.get_halfedge_index_map();