From a41f54cc54b365a93685c3025153c11a2ee48ffa Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 12 Feb 2015 11:14:57 +0100 Subject: [PATCH] Add property map for Dual<> --- BGL/examples/BGL_surface_mesh/dual.cpp | 4 ++ BGL/include/CGAL/boost/graph/Dual.h | 68 ++++++++++++++++++++++--- BGL/include/CGAL/boost/graph/iterator.h | 38 ++++++++++++++ 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/BGL/examples/BGL_surface_mesh/dual.cpp b/BGL/examples/BGL_surface_mesh/dual.cpp index 88caf3e6a26..05afcf1777c 100644 --- a/BGL/examples/BGL_surface_mesh/dual.cpp +++ b/BGL/examples/BGL_surface_mesh/dual.cpp @@ -40,6 +40,10 @@ int main(int, char* argv[]) ccmap = sm.add_property_map("f:CC").first; int num = connected_components(dsm, ccmap); + BOOST_FOREACH(face_descriptor f , faces(sm)){ + std::cout << f << "in connected component " << ccmap[f] << std::endl; + } + #if 0 Mesh::Property_map predecessor; diff --git a/BGL/include/CGAL/boost/graph/Dual.h b/BGL/include/CGAL/boost/graph/Dual.h index a1b24a20ab6..09e470db32f 100644 --- a/BGL/include/CGAL/boost/graph/Dual.h +++ b/BGL/include/CGAL/boost/graph/Dual.h @@ -1,6 +1,9 @@ #ifndef CGAL_BGL_DUAL_H #define CGAL_BGL_DUAL_H +#include +#include + namespace CGAL { template @@ -30,9 +33,9 @@ template class graph_traits > { typedef boost::graph_traits GTP; - struct SM_graph_traversal_category : public virtual boost::bidirectional_graph_tag, - public virtual boost::vertex_list_graph_tag, - public virtual boost::edge_list_graph_tag + struct Dual_traversal_category : public virtual boost::bidirectional_graph_tag, + public virtual boost::vertex_list_graph_tag, + public virtual boost::edge_list_graph_tag {}; public: @@ -42,7 +45,7 @@ public: typedef typename GTP::edge_descriptor edge_descriptor; typedef typename GTP::directed_category directed_category; typedef boost::allow_parallel_edge_tag edge_parallel_category; - typedef SM_graph_traversal_category traversal_category; + typedef Dual_traversal_category traversal_category; typedef typename GTP::faces_size_type vertices_size_type; typedef typename GTP::vertices_size_type faces_size_type; @@ -55,8 +58,8 @@ public: typedef typename GTP::halfedge_iterator halfedge_iterator; typedef typename GTP::edge_iterator edge_iterator; - typedef CGAL::In_edge_iterator > in_edge_iterator; - typedef CGAL::Out_edge_iterator > out_edge_iterator; + typedef CGAL::Halfedge_around_face_iterator in_edge_iterator; + typedef CGAL::Opposite_halfedge_around_face_iterator out_edge_iterator; static vertex_descriptor null_vertex() { return vertex_descriptor(); } static face_descriptor null_face() { return face_descriptor(); } @@ -66,12 +69,28 @@ public: template struct graph_traits< const CGAL::Dual

> : public graph_traits< CGAL::Dual

> -{ }; +{}; + +template +struct property_map, boost::vertex_index_t> +{ + typedef typename property_map::type type; + typedef typename property_map::const_type const_type; +}; + } // namespace boost namespace CGAL { +template +typename boost::property_map::type +get(boost::vertex_index_t, const Dual

& dual) +{ + return get(CGAL::face_index, dual.primal()); +} + + template typename boost::graph_traits >::vertices_size_type num_vertices(const CGAL::Dual

& dual) @@ -188,6 +207,41 @@ prev(typename boost::graph_traits >::halfedge_descriptor h, return next(opposite(h,primal),primal); } +template +Iterator_range >::out_edge_iterator> +out_edges(typename boost::graph_traits >::vertex_descriptor v, + const Dual

& dual) +{ + typename const Dual

::Primal& primal = dual.primal(); + return opposite_halfedges_around_face(halfedge(v,primal),primal); +} + +template +Iterator_range >::out_edge_iterator> +in_edges(typename boost::graph_traits >::vertex_descriptor v, + const Dual

& dual) +{ + typename const Dual

::Primal& primal = dual.primal(); + return halfedges_around_face(halfedge(v,primal),primal); +} + +template +typename boost::graph_traits >::degree_size_type +out_degree(typename boost::graph_traits >::vertex_descriptor v, + const Dual

& dual) +{ + typename const Dual

::Primal& primal = dual.primal(); + return boost::distance(halfedges_around_face(halfedge(v,primal),primal)); +} + + template +typename boost::graph_traits >::degree_size_type +in_degree(typename boost::graph_traits >::vertex_descriptor v, + const Dual

& dual) +{ + return out_degree(v,dual); +} + } // namespace CGAL diff --git a/BGL/include/CGAL/boost/graph/iterator.h b/BGL/include/CGAL/boost/graph/iterator.h index c1cd3a46279..4db3cf661ab 100644 --- a/BGL/include/CGAL/boost/graph/iterator.h +++ b/BGL/include/CGAL/boost/graph/iterator.h @@ -1050,6 +1050,44 @@ private: }; +template +class Opposite_halfedge_around_face_iterator +#ifndef DOXYGEN_RUNNING + : public boost::iterator_adaptor< + Opposite_halfedge_around_face_iterator // Derived + , Halfedge_around_face_iterator // Base + , typename boost::graph_traits::halfedge_descriptor // Value + , std::bidirectional_iterator_tag // CategoryOrTraversal + , typename boost::graph_traits::halfedge_descriptor // Reference + > +#endif +{ + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + internal::OppositeHalfedge fct; +public: + + Opposite_halfedge_around_face_iterator() + {} + + Opposite_halfedge_around_face_iterator(halfedge_descriptor h, const Graph& g, int n = 0) + : Opposite_halfedge_around_face_iterator::iterator_adaptor_(Halfedge_around_face_iterator(h,g,(h==halfedge_descriptor())?1:n)), fct(g) + {} +private: + friend class boost::iterator_core_access; + typename boost::graph_traits::halfedge_descriptor dereference() const { return fct(*this->base_reference()); } +}; + +template +Iterator_range > +opposite_halfedges_around_face(typename boost::graph_traits::halfedge_descriptor h, const Graph& g) +{ + typedef Opposite_halfedge_around_face_iterator I; + return make_range(I(h,g), I(h,g,1)); +} + + + + /** * \ingroup PkgBGLIterators * A bidirectional circulator with value type `boost::graph_traits::%vertex_descriptor` over all vertices adjacent to the same vertex.