diff --git a/BGL/include/CGAL/boost/graph/Dual.h b/BGL/include/CGAL/boost/graph/Dual.h index f71c7d543a1..bf30a828883 100644 --- a/BGL/include/CGAL/boost/graph/Dual.h +++ b/BGL/include/CGAL/boost/graph/Dual.h @@ -104,8 +104,8 @@ public: typedef typename GTP::halfedge_iterator halfedge_iterator; typedef typename GTP::edge_iterator edge_iterator; - typedef CGAL::Halfedge_around_face_iterator in_edge_iterator; - typedef CGAL::Opposite_edge_around_face_iterator out_edge_iterator; + typedef CGAL::Edge_around_face_iterator out_edge_iterator; + typedef CGAL::Opposite_edge_around_face_iterator in_edge_iterator; static vertex_descriptor null_vertex() { return vertex_descriptor(); } static face_descriptor null_face() { return face_descriptor(); } @@ -335,7 +335,7 @@ source(typename boost::graph_traits >::halfedge_descriptor h, const Dual

& dual) { const typename Dual

::Primal& primal = dual.primal(); - return face(opposite(h,primal),primal); + return face(h,primal); } template @@ -344,7 +344,7 @@ target(typename boost::graph_traits >::halfedge_descriptor h, const Dual

& dual) { const typename Dual

::Primal& primal = dual.primal(); - return face(h,primal); + return face(opposite(h,primal),primal); } @@ -354,7 +354,7 @@ source(typename boost::graph_traits >::edge_descriptor h, const Dual

& dual) { const typename Dual

::Primal& primal = dual.primal(); - return face(opposite(halfedge(h,primal),primal),primal); + return face(halfedge(h,primal),primal); } template @@ -363,7 +363,7 @@ target(typename boost::graph_traits >::edge_descriptor h, const Dual

& dual) { const typename Dual

::Primal& primal = dual.primal(); - return face(halfedge(h,primal),primal); + return face(opposite(halfedge(h,primal),primal),primal); } template @@ -371,7 +371,8 @@ typename boost::graph_traits >::halfedge_descriptor halfedge(typename boost::graph_traits >::vertex_descriptor v, const Dual

& dual) { - return halfedge(v, dual.primal()); + const typename Dual

::Primal& primal = dual.primal(); + return opposite(halfedge(v, primal),primal); } template @@ -428,7 +429,7 @@ next(typename boost::graph_traits >::halfedge_descriptor h, const Dual

& dual) { const typename Dual

::Primal& primal = dual.primal(); - return opposite(prev(h,primal),primal); + return prev(opposite(h,primal),primal); } template @@ -437,7 +438,7 @@ prev(typename boost::graph_traits >::halfedge_descriptor h, const Dual

& dual) { const typename Dual

::Primal& primal = dual.primal(); - return next(opposite(h,primal),primal); + return opposite(next(h,primal),primal); } template @@ -446,16 +447,16 @@ out_edges(typename boost::graph_traits >::vertex_descriptor v, const Dual

& dual) { const typename Dual

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

& dual) { const typename Dual

::Primal& primal = dual.primal(); - return halfedges_around_face(halfedge(v,primal),primal); + return opposite_edges_around_face(halfedge(v,primal),primal); } template diff --git a/BGL/include/CGAL/boost/graph/iterator.h b/BGL/include/CGAL/boost/graph/iterator.h index 0b66e61cb0e..af093961c97 100644 --- a/BGL/include/CGAL/boost/graph/iterator.h +++ b/BGL/include/CGAL/boost/graph/iterator.h @@ -1128,6 +1128,40 @@ opposite_edges_around_face(typename boost::graph_traits::halfedge_descrip return make_range(I(h,g), I(h,g,1)); } +template +class Edge_around_face_iterator +#ifndef DOXYGEN_RUNNING + : public boost::iterator_adaptor< + Edge_around_face_iterator // Derived + , Halfedge_around_face_iterator // Base + , typename boost::graph_traits::edge_descriptor // Value + , std::bidirectional_iterator_tag // CategoryOrTraversal + , typename boost::graph_traits::edge_descriptor // Reference + > +#endif +{ + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + internal::Edge fct; +public: + + Edge_around_face_iterator() + {} + + Edge_around_face_iterator(halfedge_descriptor h, const Graph& g, int n = 0) + : Edge_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::edge_descriptor dereference() const { return fct(*this->base_reference()); } +}; + +template +Iterator_range > +edges_around_face(typename boost::graph_traits::halfedge_descriptor h, const Graph& g) +{ + typedef Edge_around_face_iterator I; + return make_range(I(h,g), I(h,g,1)); +} diff --git a/BGL/test/BGL/CMakeLists.txt b/BGL/test/BGL/CMakeLists.txt index 8ccadec9216..52154710778 100644 --- a/BGL/test/BGL/CMakeLists.txt +++ b/BGL/test/BGL/CMakeLists.txt @@ -65,6 +65,8 @@ create_single_source_cgal_program( "test_circulator.cpp" ) create_single_source_cgal_program( "test_Gwdwg.cpp" ) +create_single_source_cgal_program( "test_bgl_dual.cpp" ) + create_single_source_cgal_program( "graph_concept_Polyhedron_3.cpp" ) create_single_source_cgal_program( "graph_concept_Dual.cpp" ) diff --git a/BGL/test/BGL/data/primal.off b/BGL/test/BGL/data/primal.off new file mode 100644 index 00000000000..d91d1201df6 --- /dev/null +++ b/BGL/test/BGL/data/primal.off @@ -0,0 +1,15 @@ +OFF +4 4 0 + +0 0 0 +1 0 0 +0 1 0 +0 0 1 + +3 0 1 2 +3 2 1 3 +3 1 0 3 +3 0 2 3 + + + diff --git a/BGL/test/BGL/test_bgl_dual.cpp b/BGL/test/BGL/test_bgl_dual.cpp new file mode 100644 index 00000000000..1456eec0cc7 --- /dev/null +++ b/BGL/test/BGL/test_bgl_dual.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +#include +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; +typedef CGAL::Surface_mesh Mesh; +typedef CGAL::Dual Dual; +typedef boost::graph_traits::face_descriptor face_descriptor; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; +typedef boost::graph_traits::out_edge_iterator out_edge_iterator; +typedef boost::graph_traits::in_edge_iterator in_edge_iterator; + +int main() +{ + std::ifstream in("data/primal.off"); + Mesh primal; + in >> primal; + + Dual dual(primal); + face_descriptor fd = *faces(dual).first; + halfedge_descriptor hd = halfedge(fd,dual); + assert(face(hd,dual) == fd); + halfedge_descriptor nhd = next(hd,dual); + assert(hd != nhd); + assert(hd == prev(nhd,dual)); + assert(face(nhd,dual) == fd); + BOOST_FOREACH(halfedge_descriptor lhd, halfedges_around_face(hd,dual)){ + assert(face(lhd,dual) == fd); + } + + vertex_descriptor vd = *vertices(dual).first; + + assert(target(halfedge(vd,dual),dual) == vd); + BOOST_FOREACH(halfedge_descriptor lhd, halfedges_around_target(halfedge(vd,dual),dual)){ + assert(target(lhd,dual) == vd); + } + + { + out_edge_iterator b,e; + boost::tie(b,e) = out_edges(vd,dual); + std::cerr << vd << " " << source(*b,dual) << std::endl; + } + + { + in_edge_iterator b,e; + boost::tie(b,e) = in_edges(vd,dual); + std::cerr << vd << " " << source(*b,dual) << std::endl; + } + std::cerr << "done"<< std::endl; + return 0; +}