From bf0e52cf6e73cd5fb89b17b57d162cff9cf383da Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 24 Sep 2019 16:36:57 +0200 Subject: [PATCH] Incorporate the initialization of the map to the helpers. --- .../CGAL/boost/graph/named_params_helper.h | 103 ++++++++++++++---- .../connected_components.h | 12 +- 2 files changed, 82 insertions(+), 33 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/named_params_helper.h b/BGL/include/CGAL/boost/graph/named_params_helper.h index 1a1639f0209..37f8a1f0b78 100644 --- a/BGL/include/CGAL/boost/graph/named_params_helper.h +++ b/BGL/include/CGAL/boost/graph/named_params_helper.h @@ -115,49 +115,106 @@ namespace CGAL { namespace internal_np { + template + struct MapInitializer{ + void operator()(PMap, const Graph& ) + {} + }; + + template + struct MapInitializer{ + void operator()( PMap, const Graph& ) + { + //do nothing. + } + }; + + template< class PMap, class Graph> + struct MapInitializer< + typename boost::graph_traits::vertex_descriptor, + PMap, Graph, + CGAL::Tag_true>{ + void operator()(PMap map, const Graph& g) + { + CGAL::helpers::init_vertex_indices(g, map); + } + }; + + template< class PMap, class Graph> + struct MapInitializer< + typename boost::graph_traits::halfedge_descriptor, + PMap, Graph, + CGAL::Tag_true>{ + void operator()(PMap map, const Graph& g) + { + CGAL::helpers::init_halfedge_indices(g, map); + } + }; + + template< class PMap, class Graph> + struct MapInitializer< + typename boost::graph_traits::face_descriptor, + PMap, Graph, + CGAL::Tag_true>{ + void operator()(PMap map,const Graph& g) + { + CGAL::helpers::init_face_indices(g, map); + } + }; template - bool is_pmap_writable(PMapCategory) - { - return false; - } + struct Is_pmap_writable{ + typedef CGAL::Tag_false result; + }; + template<> - bool is_pmap_writable(boost::read_write_property_map_tag) - { - return true; - } + struct Is_pmap_writable{ + typedef CGAL::Tag_true result; + }; + template<> - bool is_pmap_writable(boost::writable_property_map_tag) - { - return true; - } + struct Is_pmap_writable{ + typedef CGAL::Tag_true result; + }; //overloads used to select a default map: // use the one passed in the named parameters (user must have initialized it) template MapFromNP - get_map(MapFromNP m, Default_tag, Dynamic_tag, const Mesh&, bool& need_init) + get_map(MapFromNP m, Default_tag, Dynamic_tag, const Mesh&) { - need_init = false; return m; } // use the one internal to the mesh (user must have initialized it) template typename boost::property_map::const_type - get_map(CGAL::internal_np::Param_not_found, Default_tag t, Dynamic_tag , const Mesh& m, bool& need_init) + get_map(CGAL::internal_np::Param_not_found, Default_tag t, Dynamic_tag , const Mesh& m) { - need_init = is_pmap_writable(typename boost::property_traits::const_type>::category()); - return get(t,m); + typename boost::property_map::const_type map = get(t, m); + MapInitializer< + typename boost::property_traits::const_type>::key_type, + typename boost::property_map::const_type, + Mesh, + typename Is_pmap_writable< + typename boost::property_traits + + ::const_type>::category>::result> + ()(map, m); + return map; } // create a dynamic property and initialize it template typename boost::property_map::const_type - get_map(CGAL::internal_np::Param_not_found, Dynamic_tag t, Dynamic_tag , const Mesh& m, bool& need_init) + get_map(CGAL::internal_np::Param_not_found, Dynamic_tag t, Dynamic_tag , const Mesh& m) { - - need_init = true; - return get(t,m); + typename boost::property_map::const_type map = get(t,m); + MapInitializer< + typename boost::property_traits::const_type>::key_type, + typename boost::property_map::const_type, + Mesh, + CGAL::Tag_true>()(map, m); + return map; } }//end of internal_np @@ -197,13 +254,13 @@ namespace CGAL { : dtag(dtag), m(m), np(np), p(p) {} - PropertyMapType property_map(bool& need_init) + PropertyMapType property_map() { return internal_np::get_map( parameters::get_parameter(np, p), Final_tag(), dtag, - m, need_init); + m); } }; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h index 72c9c708dc0..d80320ce963 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h @@ -240,11 +240,7 @@ connected_components(const PolygonMesh& pmesh, CGAL::dynamic_face_property_t(), pmesh, np, internal_np::face_index); - bool need_init; - typename MapGetter::PropertyMapType fimap = get_map.property_map(need_init); - if(need_init) - CGAL::helpers::init_face_indices(pmesh, fimap); - + typename MapGetter::PropertyMapType fimap = get_map.property_map(); return boost::connected_components(finite_dual, fcm, boost::vertex_index_map(fimap) @@ -327,11 +323,7 @@ std::size_t keep_largest_connected_components(PolygonMesh& pmesh, CGAL::dynamic_face_property_t(), pmesh, np, internal_np::face_index); - bool need_init; - FaceIndexMap fimap = get_map.property_map(need_init); - if(need_init) - CGAL::helpers::init_face_indices(pmesh, fimap); - + FaceIndexMap fimap = get_map.property_map(); // FaceSizeMap typedef typename internal_np::Lookup_named_param_def