From f95a9558b27476bf542f38033c1a35292cb88a4b Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 27 Mar 2017 11:58:30 -0400 Subject: [PATCH] Update cmap to use index in attributes/darts for property maps. --- .../graph/graph_traits_Linear_cell_complex.h | 62 ++++++-- .../graph/properties_Linear_cell_complex.h | 141 ++++++++++++------ .../BGL/graph_concept_Linear_cell_complex.cpp | 95 +++--------- .../include/CGAL/Cell_attribute.h | 41 +++++ .../include/CGAL/Combinatorial_map.h | 80 +++++++--- Combinatorial_map/include/CGAL/Dart.h | 24 +++ .../Combinatorial_map_internal_functors.h | 12 ++ 7 files changed, 307 insertions(+), 148 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Linear_cell_complex.h b/BGL/include/CGAL/boost/graph/graph_traits_Linear_cell_complex.h index 358bf9edb81..e9847cf8d71 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Linear_cell_complex.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Linear_cell_complex.h @@ -67,6 +67,8 @@ template typename CMap::Dart_handle next(typename CMap::Dart_handle dh, const CMap& cmap) { return const_cast(cmap).template beta<1>(dh); } +namespace internal { + template struct EdgeHandle : Dart_handle { @@ -86,7 +88,8 @@ struct EdgeHandle : Dart_handle bool operator==(const EdgeHandle& h) const { return first_halfedge()==h.first_halfedge() || - first_halfedge()==h.second_halfedge(); + (h.first_halfedge()!=NULL && + first_halfedge()==h.second_halfedge()); } bool operator!=(const EdgeHandle& other) const @@ -95,12 +98,51 @@ struct EdgeHandle : Dart_handle friend bool operator<(const EdgeHandle& a, const EdgeHandle& b) { return a.first_halfedge()id() / 2; } + friend bool operator>(const EdgeHandle& a, const EdgeHandle& b) + { return bb); } + + friend bool operator>=(const EdgeHandle& a, const EdgeHandle& b) + { return !(aid()/2; } + + friend std::size_t hash_value(const EdgeHandle& i) + { + if (i.first_halfedge()==NULL) return 0; + return hash_value(i.first_halfedge() + struct Hash_functor< EdgeHandle > + { + std::size_t + operator()(const EdgeHandle& edge) + { return hash_value(edge); } + }; +} //end of namespace handle + +/*template +struct Construct_edge { + typedef EdgeHandle result_type; + result_type operator()(const EdgeHandle& he) const + { return HDS_edge(he); } +}; + +template +struct Construct_edge_opposite { + typedef EdgeHandle result_type; + result_type operator()(const EdgeHandle& he) const + { return HDS_edge(he->opposite()); } +};*/ + template class CMap_dart_handle_edge_iterator { @@ -150,6 +192,8 @@ private: Iterator nt; }; +} // internal + template struct CMap_Base_graph_traits { @@ -162,7 +206,7 @@ public : // Expose types required by the boost::Graph concept. typedef typename CMap::template Attribute_handle<0>::type vertex_descriptor; - typedef EdgeHandle edge_descriptor; + typedef internal::EdgeHandle edge_descriptor; typedef typename CMap::template Attribute_handle<2>::type face_descriptor; typedef typename CMap::Dart_handle halfedge_descriptor; @@ -174,7 +218,7 @@ public : typedef Prevent_deref::type::iterator> face_iterator; typedef Prevent_deref halfedge_iterator; - typedef CMap_dart_handle_edge_iterator edge_iterator; + typedef internal::CMap_dart_handle_edge_iterator edge_iterator; typedef typename CMap::size_type degree_size_type; typedef typename CMap::size_type halfedges_size_type; @@ -344,7 +388,7 @@ edge(typename boost::graph_traits::vertex_descriptor u, { std::pair::halfedge_descriptor, bool> res=halfedge(u,v,cm); - return std::make_pair(EdgeHandle(res.first), + return std::make_pair(internal::EdgeHandle(res.first), res.second); } @@ -484,7 +528,7 @@ CGAL_LCC_TEMPLATE_ARGS typename boost::graph_traits::edge_descriptor edge(typename boost::graph_traits::halfedge_descriptor h, const CGAL_LCC_TYPE&/* cm*/) -{ return EdgeHandle +{ return internal::EdgeHandle ::halfedge_descriptor>(h); } CGAL_LCC_TEMPLATE_ARGS diff --git a/BGL/include/CGAL/boost/graph/properties_Linear_cell_complex.h b/BGL/include/CGAL/boost/graph/properties_Linear_cell_complex.h index 09eb63e689c..1fba0d38d37 100644 --- a/BGL/include/CGAL/boost/graph/properties_Linear_cell_complex.h +++ b/BGL/include/CGAL/boost/graph/properties_Linear_cell_complex.h @@ -217,6 +217,30 @@ protected: const LCC & m_lcc; }; */ +template +struct Wrap_squared_lcc + : boost::put_get_helper< double, Wrap_squared_lcc > +{ + typedef typename boost::graph_traits::edge_descriptor Handle; + typedef FT value_type; + typedef FT reference; + typedef Handle key_type; + typedef boost::readable_property_map_tag category; + + Wrap_squared_lcc(const LCC& alcc): m_lcc(alcc) + {} + + template + FT operator[](const E& e) const + { + return approximate_sqrt(CGAL::squared_distance + (m_lcc.point(e.first_halfedge()), + m_lcc.point(e.second_halfedge()))); + } +private: + const LCC& m_lcc; +}; + // the tag we dispatch on from property_map template @@ -268,7 +292,7 @@ void put(PropertyTag p, CGAL_LCC_TYPE& g, const Key& key, const Value& value) typedef internal::ACCESSOR##_accessor< \ CGAL_LCC_TYPE, \ typename boost::graph_traits \ - ::ENTITY##_descriptor> type; \ + ::ENTITY##_descriptor > type; \ typedef type const_type; \ }; \ }; \ @@ -304,7 +328,7 @@ struct LCC_property_map typedef typename Traits_::FT FT; typedef typename boost::graph_traits::edge_descriptor edge_descriptor; - typedef internal::Wrap_squared type; + typedef Wrap_squared_lcc type; typedef type const_type; }; }; @@ -334,7 +358,9 @@ struct LCC_property_map template struct bind_ { - typedef internal::Polyhedron_edge_index_map_external type; + // typedef internal::Polyhedron_edge_index_map_external type; + typedef internal::Edge_index_accessor< + typename boost::graph_traits::edge_descriptor> type; typedef type const_type; }; }; @@ -345,7 +371,9 @@ struct LCC_property_map template struct bind_ { - typedef internal::Polyhedron_index_map_external type; + //typedef internal::Polyhedron_index_map_external< + typedef internal::Index_accessor::halfedge_descriptor> type; typedef type const_type; }; }; @@ -357,7 +385,9 @@ struct LCC_property_map template struct bind_ { - typedef internal::Polyhedron_index_map_external type; + //typedef internal::Polyhedron_index_map_external< + typedef internal::Index_accessor::vertex_descriptor> type; typedef type const_type; }; }; @@ -368,7 +398,9 @@ struct LCC_property_map template struct bind_ { - typedef internal::Polyhedron_index_map_external type; + //typedef internal::Polyhedron_index_map_external< + typedef internal::Index_accessor::face_descriptor> type; typedef type const_type; }; }; @@ -378,38 +410,42 @@ struct LCC_property_map namespace CGAL{ template -typename boost::property_map::const_type -get(boost::edge_external_index_t, CGAL_LCC_TYPE const& cmap) -{ - return typename boost::property_map:: - const_type(const_cast(cmap)); -} - -template -typename boost::property_map::const_type +typename boost::property_map::const_type get(boost::halfedge_external_index_t, CGAL_LCC_TYPE const& cmap) { - CGAL_LCC_TYPE& ncmap=const_cast(cmap); + return typename boost::property_map::const_type(); + /* CGAL_LCC_TYPE& ncmap=const_cast(cmap); return typename boost::property_map:: - const_type(halfedges(ncmap).begin(), halfedges(ncmap).end(), num_halfedges(ncmap)); + const_type(halfedges(ncmap).begin(), halfedges(ncmap).end(), num_halfedges(ncmap)); */ } template -typename boost::property_map::const_type +typename boost::property_map::const_type get(boost::vertex_external_index_t, CGAL_LCC_TYPE const& cmap) { - CGAL_LCC_TYPE& ncmap=const_cast(cmap); + return typename boost::property_map::const_type(); + /* CGAL_LCC_TYPE& ncmap=const_cast(cmap); return typename boost::property_map:: - const_type(vertices(ncmap).begin(), vertices(ncmap).end(), num_vertices(ncmap)); + const_type(vertices(ncmap).begin(), vertices(ncmap).end(), num_vertices(ncmap)); */ } template -typename boost::property_map::const_type +typename boost::property_map::const_type +get(boost::edge_external_index_t, CGAL_LCC_TYPE const& cmap) +{ + return typename boost::property_map::const_type(); + /*return typename boost::property_map:: + const_type(const_cast(cmap));*/ +} + +template +typename boost::property_map::const_type get(boost::face_external_index_t, CGAL_LCC_TYPE const& cmap) { - CGAL_LCC_TYPE& ncmap=const_cast(cmap); + return typename boost::property_map::const_type(); + /*CGAL_LCC_TYPE& ncmap=const_cast(cmap); return typename boost::property_map:: - const_type(faces(ncmap).begin(), faces(ncmap).end(), num_faces(ncmap)); + const_type(faces(ncmap).begin(), faces(ncmap).end(), num_faces(ncmap));*/ } /* @@ -454,47 +490,60 @@ get(boost::vertex_point_t, CGAL_LCC_TYPE const& cmap) return typename boost::property_map:: const_type(const_cast(cmap)); } +*/ template typename boost::property_map::const_type get(boost::edge_weight_t, CGAL_LCC_TYPE const& cmap) { - return typename boost::property_map:: + return typename boost::property_map:: const_type(const_cast(cmap)); } -*/ // the same blurb for non-const template -typename boost::property_map::type +typename boost::property_map::type +get(boost::halfedge_external_index_t, CGAL_LCC_TYPE& cmap) +{ + return typename boost::property_map::type(); +/* return typename boost::property_map:: + type(halfedges(cmap).begin(), halfedges(cmap).end(), num_halfedges(cmap));*/ +} + +template +typename boost::property_map::type +get(boost::vertex_external_index_t, CGAL_LCC_TYPE& cmap) +{ + return typename boost::property_map::type(); +/* return typename boost::property_map:: + type(vertices(cmap).begin(), vertices(cmap).end(), num_vertices(cmap));*/ +} + +template +typename boost::property_map::type get(boost::edge_external_index_t, CGAL_LCC_TYPE& cmap) { - return typename boost::property_map:: - type(const_cast(cmap)); + return typename boost::property_map::type(cmap); + /*return typename boost::property_map:: + type(const_cast(cmap));*/ } -template -typename boost::property_map::type -get(boost::halfedge_external_index_t, CGAL_LCC_TYPE& cmap) -{ - return typename boost::property_map:: - type(halfedges(cmap).begin(), halfedges(cmap).end(), num_halfedges(cmap)); -} template -typename boost::property_map::type -get(boost::vertex_external_index_t, CGAL_LCC_TYPE& cmap) -{ - return typename boost::property_map:: - type(vertices(cmap).begin(), vertices(cmap).end(), num_vertices(cmap)); -} - -template -typename boost::property_map::type +typename boost::property_map::type get(boost::face_external_index_t, CGAL_LCC_TYPE& cmap) { - return typename boost::property_map:: - type(faces(cmap).begin(), faces(cmap).end(), num_faces(cmap)); + return typename boost::property_map::type(); + /*return typename boost::property_map:: + type(faces(cmap).begin(), faces(cmap).end(), num_faces(cmap));*/ +} + +template +typename boost::property_map::type +get(boost::edge_weight_t, CGAL_LCC_TYPE & cmap) +{ + return typename boost::property_map:: + type(cmap); } } // namespace CGAL diff --git a/BGL/test/BGL/graph_concept_Linear_cell_complex.cpp b/BGL/test/BGL/graph_concept_Linear_cell_complex.cpp index 1e6fdfce147..7d9a1382755 100644 --- a/BGL/test/BGL/graph_concept_Linear_cell_complex.cpp +++ b/BGL/test/BGL/graph_concept_Linear_cell_complex.cpp @@ -33,40 +33,40 @@ void concept_check_polyhedron() { boost::function_requires< boost::GraphConcept >(); boost::function_requires< boost::VertexListGraphConcept >(); boost::function_requires< boost::EdgeListGraphConcept >(); - boost::function_requires< boost::AdjacencyMatrixConcept >(); - boost::function_requires< boost::MutableGraphConcept >(); - boost::function_requires< CGAL::FaceListGraphConcept >(); - boost::function_requires< CGAL::HalfedgeGraphConcept >(); boost::function_requires< boost::IncidenceGraphConcept >(); - boost::function_requires< CGAL::HalfedgeListGraphConcept >(); + boost::function_requires< boost::AdjacencyMatrixConcept >(); boost::function_requires< boost::BidirectionalGraphConcept >(); - boost::function_requires< CGAL::MutableHalfedgeGraphConcept >(); - - // TODO Perhaps to remove ? + boost::function_requires< CGAL::HalfedgeGraphConcept >(); + boost::function_requires< CGAL::HalfedgeListGraphConcept >(); boost::function_requires< CGAL::FaceGraphConcept >(); + boost::function_requires< CGAL::FaceListGraphConcept >(); + boost::function_requires< CGAL::MutableHalfedgeGraphConcept >(); boost::function_requires< CGAL::MutableFaceGraphConcept >(); + boost::function_requires< boost::MutableGraphConcept >(); + boost::function_requires< boost::concepts::PropertyGraph< LCC, halfedge_descriptor, boost::halfedge_index_t> >(); - boost::function_requires< boost::concepts::ReadablePropertyGraph< - LCC, halfedge_descriptor, boost::halfedge_external_index_t> >(); - boost::function_requires< boost::PropertyGraphConcept< - LCC, vertex_descriptor, boost::vertex_point_t> >(); boost::function_requires< boost::concepts::ReadablePropertyGraph< LCC, edge_descriptor, boost::edge_index_t> >(); - boost::function_requires< boost::concepts::ReadablePropertyGraph< - LCC, edge_descriptor, boost::edge_external_index_t> >(); - boost::function_requires< boost::concepts::PropertyGraph< - LCC, face_descriptor, boost::face_index_t> >(); - boost::function_requires< boost::concepts::ReadablePropertyGraph< - LCC, face_descriptor, boost::face_external_index_t> >(); boost::function_requires< boost::concepts::ReadablePropertyGraph< LCC, edge_descriptor, boost::edge_weight_t> >(); + boost::function_requires< boost::PropertyGraphConcept< + LCC, vertex_descriptor, boost::vertex_point_t> >(); boost::function_requires< boost::concepts::PropertyGraph< LCC, vertex_descriptor, boost::vertex_index_t> >(); + boost::function_requires< boost::concepts::PropertyGraph< + LCC, face_descriptor, boost::face_index_t> >(); + + boost::function_requires< boost::concepts::ReadablePropertyGraph< + LCC, halfedge_descriptor, boost::halfedge_external_index_t> >(); boost::function_requires< boost::concepts::ReadablePropertyGraph< LCC, vertex_descriptor, boost::vertex_external_index_t> >(); - + boost::function_requires< boost::concepts::ReadablePropertyGraph< + LCC, edge_descriptor, boost::edge_external_index_t> >(); + boost::function_requires< boost::concepts::ReadablePropertyGraph< + LCC, face_descriptor, boost::face_external_index_t> >(); + // null boost::graph_traits::null_vertex(); boost::graph_traits::null_face(); @@ -122,63 +122,8 @@ void runtime_check_halfedgegraph() assert(num_faces(p) == 4); } -int -main() +int main() { - LCC lcc; - typedef typename boost::graph_traits::halfedge_iterator iter; - iter it; - - - /* CGAL::Halfedge_around_target_iterator it; - - vd myvd; - - typedef typename boost::graph_traits::in_edge_iterator iter; - iter myiter; - */ - // std::pair p; // = in_edges(myvd, lcc);*/ - - /* - const LCC& lcc2 = lcc; - - iter_type a1(lcc); - const iter_type a2(a1); - iter_type a3(a2); - // a1=a2; - - - CGAL::CMap_one_dart_per_cell_iterator toto1(lcc); - const CGAL::CMap_one_dart_per_cell_iterator toto2(lcc); - - toto1=toto2; - - - - //iter_type it(lcc); - - std::pair::edge_iterator, typename boost::graph_traits::edge_iterator> it=std::make_pair - (iter_type(lcc), - iter_type(lcc)), it2=std::make_pair - (iter_type(lcc), - iter_type(lcc)); - - it=it2; - - iter_type t1(lcc); - - std::pair p=edges(lcc); - std::pair p2=std::make_pair(t1, t1);*/ - //p=std::make_pair(t1, t1); //p2; - - - //iter_type(lcc), iter_type(lcc)); - //toto(lcc); - - // std::pair p; - // p = std::make_pair(0,0); - - concept_check_polyhedron(); runtime_check_halfedgegraph(); std::cerr << "done\n"; diff --git a/Combinatorial_map/include/CGAL/Cell_attribute.h b/Combinatorial_map/include/CGAL/Cell_attribute.h index 5d7b048a6fa..fb557dec046 100644 --- a/Combinatorial_map/include/CGAL/Cell_attribute.h +++ b/Combinatorial_map/include/CGAL/Cell_attribute.h @@ -40,6 +40,13 @@ namespace CGAL { template class GMap_linear_cell_complex_storage_1; + namespace internal { + + template + struct Init_id; + + } // end namespace internal + /** @file Cell_attribute.h * Definition of cell attribute, with or without info. */ @@ -98,6 +105,9 @@ namespace CGAL { template friend class Concurrent_compact_container; + template + friend struct internal::Init_id; + public: typedef Tag_false Supports_cell_dart; @@ -136,6 +146,14 @@ namespace CGAL { bool operator!=(const Cell_attribute_without_info& other) const { return !operator==(other); } + // Required to have "internal" property maps. + // TODO better (use id only when we want to use bgl ?) + // (or have an id directly in compact container ?) + std::size_t& id() + { return m_id; } + const std::size_t& id() const + { return m_id; } + protected: /// Contructor without parameter. Cell_attribute_without_info(): mrefcounting(0) @@ -158,6 +176,9 @@ namespace CGAL { mrefcounting-=4; // 4 because the two lowest bits are reserved for cc } + void set_id(std::size_t id) + { m_id=id; } + public: /// Get the reference counting. std::size_t get_nb_refs() const @@ -175,6 +196,9 @@ namespace CGAL { std::size_t mrefcounting; void *vp; }; + + /// id of the dart // TODO better + std::size_t m_id; }; /** Definition of cell attribute. @@ -204,6 +228,9 @@ namespace CGAL { template friend class Concurrent_compact_container; + template + friend class internal::Init_id; + public: typedef Tag_true Supports_cell_dart; @@ -243,6 +270,14 @@ namespace CGAL { bool operator!=(const Cell_attribute_without_info& other) const { return !operator==(other); } + // Required to have "internal" property maps. + // TODO better (use id only when we want to use bgl ?) + // (or have an id directly in compact container ?) + std::size_t& id() + { return m_id; } + const std::size_t& id() const + { return m_id; } + protected: /// Contructor without parameter. Cell_attribute_without_info() : mdart(Refs::null_handle), @@ -267,6 +302,9 @@ namespace CGAL { --mrefcounting; } + void set_id(std::size_t id) + { m_id=id; } + public: /// Get the reference counting. std::size_t get_nb_refs() const @@ -283,6 +321,9 @@ namespace CGAL { /// Reference counting: the number of darts linked to this cell. std::size_t mrefcounting; + + /// id of the dart // TODO better + std::size_t m_id; }; /// Cell associated with an attribute, with or without info depending diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 6fffb0e6557..59ebaff7793 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -698,6 +698,8 @@ namespace CGAL { Helper::template Foreach_enabled_attributes >::run(*this, adart); + + internal::Init_id::run(mdarts, adart); } // Initialize a given dart: all beta to null_dart_handle and all // attributes to null, marks are given. @@ -1494,6 +1496,8 @@ namespace CGAL { // Reinitialize the ref counting of the new attribute. This is normally // not required except if create_attribute is used as "copy contructor". this->template init_attribute_ref_counting(res); + internal::Init_id::type>::run + (this->template attributes(), res); return res; } #else @@ -1503,8 +1507,12 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "create_attribute but i-attributes are disabled"); - return CGAL::cpp11::get::value> - (mattribute_containers).emplace(); + typename Attribute_handle::type res= + CGAL::cpp11::get::value> + (mattribute_containers).emplace(); + internal::Init_id::type>::run + (this->template attributes(), res); + return res; } template typename Attribute_handle::type @@ -1515,7 +1523,11 @@ namespace CGAL { typename Attribute_handle::type res= CGAL::cpp11::get::value> (mattribute_containers).emplace(t1); + // Reinitialize the ref counting of the new attribute. This is normally + // not required except if create_attribute is used as "copy contructor". this->template init_attribute_ref_counting(res); + internal::Init_id::type>::run + (this->template attributes(), res); return res; } template @@ -1524,8 +1536,12 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "create_attribute but i-attributes are disabled"); - return CGAL::cpp11::get::value> - (mattribute_containers).emplace(t1, t2); + typename Attribute_handle::type res= + CGAL::cpp11::get::value> + (mattribute_containers).emplace(t1, t2); + internal::Init_id::type>::run + (this->template attributes(), res); + return res; } template typename Attribute_handle::type @@ -1533,8 +1549,12 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "create_attribute but i-attributes are disabled"); - return CGAL::cpp11::get::value> - (mattribute_containers).emplace(t1, t2, t3); + typename Attribute_handle::type res= + CGAL::cpp11::get::value> + (mattribute_containers).emplace(t1, t2, t3); + internal::Init_id::type>::run + (this->template attributes(), res); + return res; } template typename Attribute_handle::type @@ -1542,8 +1562,12 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "create_attribute but i-attributes are disabled"); - return CGAL::cpp11::get::value> - (mattribute_containers).emplace(t1, t2, t3, t4); + typename Attribute_handle::type res= + CGAL::cpp11::get::value> + (mattribute_containers).emplace(t1, t2, t3, t4); + internal::Init_id::type>::run + (this->template attributes(), res); + return res; } template @@ -1553,8 +1577,12 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "create_attribute but i-attributes are disabled"); - return CGAL::cpp11::get::value> - (mattribute_containers).emplace(t1, t2, t3, t4, t5); + typename Attribute_handle::type res= + CGAL::cpp11::get::value> + (mattribute_containers).emplace(t1, t2, t3, t4, t5); + internal::Init_id::type>::run + (this->template attributes(), res); + return res; } template @@ -1564,8 +1592,12 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "create_attribute but i-attributes are disabled"); - return CGAL::cpp11::get::value> - (mattribute_containers).emplace(t1, t2, t3, t4, t5, t6); + typename Attribute_handle::type res= + CGAL::cpp11::get::value> + (mattribute_containers).emplace(t1, t2, t3, t4, t5, t6); + internal::Init_id::type>::run + (this->template attributes(), res); + return res; } template @@ -1575,8 +1607,12 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "create_attribute but i-attributes are disabled"); - return CGAL::cpp11::get::value> - (mattribute_containers).emplace(t1, t2, t3, t4, t5, t6, t7); + typename Attribute_handle::type res= + CGAL::cpp11::get::value> + (mattribute_containers).emplace(t1, t2, t3, t4, t5, t6, t7); + internal::Init_id::type>::run + (this->template attributes(), res); + return res; } template @@ -1586,8 +1622,12 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "create_attribute but i-attributes are disabled"); - return CGAL::cpp11::get::value> - (mattribute_containers).emplace(t1, t2, t3, t4, t5, t6, t7, t8); + typename Attribute_handle::type res= + CGAL::cpp11::get::value> + (mattribute_containers).emplace(t1, t2, t3, t4, t5, t6, t7, t8); + internal::Init_id::type>::run + (this->template attributes(), res); + return res; } template @@ -1598,8 +1638,12 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "create_attribute but i-attributes are disabled"); - return CGAL::cpp11::get::value> - (mattribute_containers).emplace(t1, t2, t3, t4, t5, t6, t7, t8, t9); + typename Attribute_handle::type res= + CGAL::cpp11::get::value> + (mattribute_containers).emplace(t1, t2, t3, t4, t5, t6, t7, t8, t9); + internal::Init_id::type>::run + (this->template attributes(), res); + return res; } #endif diff --git a/Combinatorial_map/include/CGAL/Dart.h b/Combinatorial_map/include/CGAL/Dart.h index 3d0cea84f4b..c9acbe3e623 100644 --- a/Combinatorial_map/include/CGAL/Dart.h +++ b/Combinatorial_map/include/CGAL/Dart.h @@ -44,6 +44,13 @@ namespace CGAL { template class GMap_linear_cell_complex_storage_1; + namespace internal { + + template + struct Init_id; + + } // end namespace internal + /** @file Dart.h * Definition of nD dart. */ @@ -77,6 +84,9 @@ namespace CGAL { template friend class Concurrent_compact_container; + template + friend struct internal::Init_id; + typedef Dart_without_info Self; typedef typename Refs::Dart_handle Dart_handle; typedef typename Refs::size_type size_type; @@ -109,6 +119,14 @@ namespace CGAL { return mf[i]; } + // Required to have "internal" property maps. + // TODO better (use id only when we want to use bgl ?) + // (or have an id directly in compact container ?) + std::size_t& id() + { return m_id; } + const std::size_t& id() const + { return m_id; } + protected: /** Default constructor: no real initialisation, * because this is done in the combinatorial map class. @@ -184,6 +202,9 @@ namespace CGAL { (mattribute_handles); } + void set_id(std::size_t id) + { m_id=id; } + protected: /// Neighboors for each dimension +1 (from 0 to dimension). Dart_handle mf[dimension+1]; @@ -193,6 +214,9 @@ namespace CGAL { /// Attributes enabled typename Helper::Attribute_handles mattribute_handles; + + /// id of the dart // TODO better + std::size_t m_id; }; #if defined(CGAL_CMAP_DART_DEPRECATED) && !defined(CGAL_NO_DEPRECATED_CODE) diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h index f47ef0bbe34..a2a3036156e 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -90,6 +90,9 @@ * * internal::Cleanup_useless_attributes to erase all attributes having * no more associated dart + * + * internal::Init_id initialize the id of an new element created in a compact + * container, when the underlying type defines id (TODO Move in Compact container ?) */ namespace CGAL @@ -1034,6 +1037,15 @@ struct Beta_functor_static }; #endif //CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES // **************************************************************************** +template +struct Init_id +{ + static void run(Container& c, typename Container::iterator e) + { + e->set_id(c.index(e)); + } +}; +// **************************************************************************** } // namespace internal } // namespace CGAL