diff --git a/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h b/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h index 20fa60d52f6..0d0a5b2ef26 100644 --- a/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h +++ b/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h @@ -30,52 +30,9 @@ #include #include #include +#include namespace CGAL { -namespace internal_primitive_id{ -//helper base class for creating the right Id: just a face_descriptor if OneFaceGraphPerTree -// is true,else : a pair with the corresponding graph. -template -class Primitive_wrapper; - -template -class Primitive_wrapper -{ - public: - typedef typename boost::graph_traits::face_descriptor Id; - - Primitive_wrapper(const FaceGraph*) - {} - - template - Id from_id(const T& id)const - { - return Id(id); - } -}; - -template -class Primitive_wrapper -{ -public: - typedef std::pair::face_descriptor, - FaceGraph> Id; - - Primitive_wrapper(const FaceGraph* graph) - :this_graph(graph) - {} - - template - Id from_id(const T& id)const - { - return std::make_pair(id, *this_graph); - } - -private: - const FaceGraph* this_graph; -}; -}//end internal /*! * \ingroup PkgAABB_tree @@ -109,7 +66,9 @@ template < class FaceGraph, class CacheDatum=Tag_false > class AABB_face_graph_triangle_primitive #ifndef DOXYGEN_RUNNING - : public AABB_primitive::face_descriptor, + : public AABB_primitive::face_descriptor, + std::pair::face_descriptor, const FaceGraph*> >::type, Triangle_from_face_descriptor_map< FaceGraph, typename Default::Get::type >::type>, OneFaceGraphPerTree, - CacheDatum >, - public internal_primitive_id::Primitive_wrapper + CacheDatum > #endif { typedef typename Default::Get::type >::type VertexPointPMap_; - typedef typename boost::graph_traits::face_descriptor Id_; + typedef typename boost::graph_traits::face_descriptor FD; + typedef typename boost::mpl::if_ >::type Id_; + typedef Triangle_from_face_descriptor_map Triangle_property_map; typedef One_point_from_face_descriptor_map Point_property_map; @@ -135,11 +95,17 @@ class AABB_face_graph_triangle_primitive Point_property_map, OneFaceGraphPerTree, CacheDatum > Base; + + FD make_id(FD fd, const FaceGraph&, Tag_true) + { + return fd; + } + + std::pair make_id(FD fd, const FaceGraph& fg, Tag_false) + { + return std::make_pair(fd, &fg); + } - typedef internal_primitive_id::Primitive_wrapper Base_2; - -public: - typedef typename Base_2::Id Id; public: #ifdef DOXYGEN_RUNNING /// \name Types @@ -154,10 +120,10 @@ public: typedef Kernel_traits::Kernel::Triangle_3 Datum; /*! Id type: - - boost::graph_traits::face_descriptor Id if OneFaceGraphPerTree is `CGAL::Tag_true` - - std::pair::face_descriptor, FaceGraph> Id if OneFaceGraphPerTree is `CGAL::Tag_false` + - `boost::graph_traits::face_descriptor` if `OneFaceGraphPerTree` is `CGAL::Tag_true` + - `std::pair::face_descriptor, FaceGraph>` if `OneFaceGraphPerTree` is `CGAL::Tag_false` */ - Unspecified_type Id; + unspecified_type Id; /// @} @@ -165,10 +131,11 @@ public: If `OneFaceGraphPerTree` is CGAL::Tag_true, constructs a `Shared_data` object from a reference to the polyhedon `graph`. */ static unspecified_type construct_shared_data( FaceGraph& graph ); + #else + typedef typename Base::Id Id; #endif - Id id() const { - return Base_2::from_id(Base::id()); - } + typedef typename boost::graph_traits::face_descriptor face_descriptor; + // constructors /*! \tparam Iterator an input iterator with `Id` as value type. @@ -178,10 +145,9 @@ public: */ template AABB_face_graph_triangle_primitive(Iterator it, const FaceGraph& graph, VertexPointPMap_ vppm) - : Base( it, + : Base( Id_(make_id(*it, graph, OneFaceGraphPerTree())), Triangle_property_map(const_cast(&graph),vppm), - Point_property_map(const_cast(&graph),vppm) ), - Base_2(&graph) + Point_property_map(const_cast(&graph),vppm) ) {} /*! @@ -189,30 +155,24 @@ public: If `VertexPointPMap` is the default of the class, an additional constructor is available with `vppm` set to `get(vertex_point, graph)`. */ - AABB_face_graph_triangle_primitive( - typename boost::graph_traits::face_descriptor id, const FaceGraph& graph, - VertexPointPMap_ vppm) - : Base( Id_(id), + AABB_face_graph_triangle_primitive(face_descriptor fd, const FaceGraph& graph, VertexPointPMap_ vppm) + : Base( Id_(make_id(fd, graph, OneFaceGraphPerTree())), Triangle_property_map(const_cast(&graph),vppm), - Point_property_map(const_cast(&graph),vppm) ), - Base_2(&graph) + Point_property_map(const_cast(&graph),vppm) ) {} #ifndef DOXYGEN_RUNNING template AABB_face_graph_triangle_primitive(Iterator it, const FaceGraph& graph) - : Base( Id_(*it), + : Base( Id_(make_id(*it, graph, OneFaceGraphPerTree())), Triangle_property_map(const_cast(&graph)), - Point_property_map(const_cast(&graph)) ), - Base_2(&graph) + Point_property_map(const_cast(&graph)) ) {} - AABB_face_graph_triangle_primitive( - typename boost::graph_traits::face_descriptor id, const FaceGraph& graph) - : Base( Id_(id), + AABB_face_graph_triangle_primitive(face_descriptor fd, const FaceGraph& graph) + : Base( Id_(make_id(fd, graph, OneFaceGraphPerTree())), Triangle_property_map(const_cast(&graph)), - Point_property_map(const_cast(&graph)) ), - Base_2(&graph) + Point_property_map(const_cast(&graph)) ) {} #endif diff --git a/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h b/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h index 7783b330b34..ed497c3f579 100644 --- a/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h +++ b/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h @@ -35,54 +35,11 @@ #include #include #include +#include #include namespace CGAL { -namespace internal_primitive_id{ -//helper base class for creating the right Id: just a face_descriptor if OneFaceGraphPerTree -// is true,else : a pair with the corresponding graph. -template -class EPrimitive_wrapper; - -template -class EPrimitive_wrapper -{ - public: - typedef typename boost::graph_traits::edge_descriptor Id; - - EPrimitive_wrapper(const Graph*) - {} - - template - Id from_id(const T& id)const - { - return Id(id); - } -}; - -template -class EPrimitive_wrapper -{ -public: - typedef std::pair::edge_descriptor, - Graph> Id; - - EPrimitive_wrapper(const Graph* graph) - :this_graph(graph) - {} - - template - Id from_id(const T& id)const - { - return std::make_pair(id, *this_graph); - } - -private: - const Graph* this_graph; -}; -}//end internal /*! @@ -122,7 +79,9 @@ template < class HalfedgeGraph, class CacheDatum = Tag_false > class AABB_halfedge_graph_segment_primitive #ifndef DOXYGEN_RUNNING - : public AABB_primitive< typename boost::graph_traits::edge_descriptor, + : public AABB_primitive< typename boost::mpl::if_::edge_descriptor, + std::pair::edge_descriptor, const HalfedgeGraph*> >::type, Segment_from_edge_descriptor_map< HalfedgeGraph, typename Default::Get::type >::type >, OneHalfedgeGraphPerTree, - CacheDatum >, - public internal_primitive_id::EPrimitive_wrapper + CacheDatum > #endif { typedef typename Default::Get::type >::type VertexPointPMap_; + typedef typename boost::graph_traits::edge_descriptor ED; + typedef typename boost::mpl::if_ >::type Id_; - typedef typename boost::graph_traits::edge_descriptor Id_; typedef Segment_from_edge_descriptor_map Segment_property_map; typedef Source_point_from_edge_descriptor_map Point_property_map; @@ -149,13 +108,19 @@ class AABB_halfedge_graph_segment_primitive Point_property_map, OneHalfedgeGraphPerTree, CacheDatum > Base; - - typedef internal_primitive_id::EPrimitive_wrapper Base_2; + + ED make_id(ED ed, const HalfedgeGraph&, Tag_true) + { + return ed; + } + + std::pair make_id(ED ed, const HalfedgeGraph& fg, Tag_false) + { + return std::make_pair(ed, &fg); + } public: - typedef typename Base_2::Id Id; -public: #ifdef DOXYGEN_RUNNING /// \name Types /// @{ @@ -169,20 +134,20 @@ public: typedef Kernel_traits::Kernel::Segment_3 Datum; /*! Id type: - - boost::graph_traits::edge_descriptor Id if OneHalfegdeGraphPerTree is `CGAL::Tag_true` - - std::pair::edge_descriptor, HalfegdeGraph> Id if OneHalfegdeGraphPerTree is `CGAL::Tag_false` + - `boost::graph_traits::edge_descriptor if `OneHalfedgeGraphPerTree` is `Tag_true` + - `std::pair::edge_descriptor`, HalfedgeGraph>` if `OneHalfedgeGraphPerTree` is `Tag_false` */ - Unspecified_type Id; + unspecified_type Id; /// @} /*! - If `OneHalfedgeGraphPerTreeGraphPerTree` is CGAL::Tag_true, constructs a `Shared_data` object from a reference to the halfedge graph. + If `OneHalfedgeGraphPerTree` is CGAL::Tag_true, constructs a `Shared_data` object from a reference to the halfedge graph. */ static unspecified_type construct_shared_data( HalfedgeGraph& graph ); +#else + typedef typename Base::Id Id; #endif - Id id() const { - return Base_2::from_id(Base::id()); - } + typedef typename boost::graph_traits::edge_descriptor edge_descriptor; /*! Constructs a primitive. @@ -194,10 +159,9 @@ public: */ template AABB_halfedge_graph_segment_primitive(Iterator it, const HalfedgeGraph& graph, VertexPointPMap_ vppm) - : Base( Id_(*it), + : Base( Id_(make_id(*it, graph, OneHalfedgeGraphPerTree())), Segment_property_map(const_cast(&graph), vppm), - Point_property_map(const_cast(&graph), vppm) ), - Base_2(&graph) + Point_property_map(const_cast(&graph), vppm) ) {} /*! @@ -205,30 +169,23 @@ public: If `VertexPointPMap` is the default of the class, an additional constructor is available with `vppm` set to `boost::get(vertex_point, graph)`. */ - AABB_halfedge_graph_segment_primitive( - typename boost::graph_traits::edge_descriptor id, const HalfedgeGraph& graph, VertexPointPMap_ vppm) - : Base( Id_(id), + AABB_halfedge_graph_segment_primitive(edge_descriptor ed, const HalfedgeGraph& graph, VertexPointPMap_ vppm) + : Base( Id_(make_id(ed, graph, OneHalfedgeGraphPerTree())), Segment_property_map(const_cast(&graph), vppm), - Point_property_map(const_cast(&graph), vppm) ), - Base_2(&graph) + Point_property_map(const_cast(&graph), vppm) ) {} #ifndef DOXYGEN_RUNNING template AABB_halfedge_graph_segment_primitive(Iterator it, const HalfedgeGraph& graph) - : Base( Id_(*it), + : Base( Id_(make_id(*it, graph, OneHalfedgeGraphPerTree())), Segment_property_map(const_cast(&graph)), - Point_property_map(const_cast(&graph)) ), - Base_2(&graph) - {} + Point_property_map(const_cast(&graph)) ){} - AABB_halfedge_graph_segment_primitive( - typename boost::graph_traits::edge_descriptor id, const HalfedgeGraph& graph) - : Base( Id_(id), + AABB_halfedge_graph_segment_primitive(edge_descriptor ed, const HalfedgeGraph& graph) + : Base( Id_(make_id(ed, graph, OneHalfedgeGraphPerTree())), Segment_property_map(const_cast(&graph)), - Point_property_map(const_cast(&graph)) ), - Base_2(&graph) - {} + Point_property_map(const_cast(&graph)) ){} #endif /// \internal diff --git a/BGL/include/CGAL/boost/graph/property_maps.h b/BGL/include/CGAL/boost/graph/property_maps.h index 28f11307193..fb6c8b486da 100644 --- a/BGL/include/CGAL/boost/graph/property_maps.h +++ b/BGL/include/CGAL/boost/graph/property_maps.h @@ -73,6 +73,19 @@ struct Triangle_from_face_descriptor_map{ get(pmap.m_vpm, target(next(halfedge(f,tm),tm),tm)), get(pmap.m_vpm, source(halfedge(f,tm),tm)) ); } + + inline friend + reference + get(const Triangle_from_face_descriptor_map& pmap, + const std::pair& f) + { + typename boost::remove_const::type & tm = *(pmap.m_tm); + CGAL_precondition(halfedge(f.first,tm) == next(next(next(halfedge(f.first,tm),tm),tm),tm)); + + return value_type( get(pmap.m_vpm, target(halfedge(f.first,tm),tm)), + get(pmap.m_vpm, target(next(halfedge(f.first,tm),tm),tm)), + get(pmap.m_vpm, source(halfedge(f.first,tm),tm)) ); + } }; template < class PolygonMesh, @@ -114,6 +127,15 @@ struct Segment_from_edge_descriptor_map{ return value_type(get(pmap.m_vpm, source(h, *pmap.m_pm) ), get(pmap.m_vpm, target(h, *pmap.m_pm) ) ); } + + inline friend + reference + get(const Segment_from_edge_descriptor_map& pmap, + const std::pair& h) + { + return value_type(get(pmap.m_vpm, source(h.first, *pmap.m_pm) ), + get(pmap.m_vpm, target(h.first, *pmap.m_pm) ) ); + } }; //property map to access a point from a face_descriptor @@ -151,6 +173,14 @@ struct One_point_from_face_descriptor_map{ { return get(m.m_vpm, target(halfedge(f, *m.m_pm), *m.m_pm)); } + + inline friend + reference + get(const One_point_from_face_descriptor_map& m, + const std::pair& f) + { + return get(m.m_vpm, target(halfedge(f.first, *m.m_pm), *m.m_pm)); + } }; //property map to access a point from an edge @@ -187,6 +217,14 @@ struct Source_point_from_edge_descriptor_map{ { return get(pmap.m_vpm, source(h, *pmap.m_pm) ); } + + inline friend + reference + get(const Source_point_from_edge_descriptor_map& pmap, + const std::pair& h) + { + return get(pmap.m_vpm, source(h.first, *pmap.m_pm) ); + } }; } //namespace CGAL