change the Id in the base class + update pmaps to handle also pairs

This commit is contained in:
Sébastien Loriot 2018-10-09 14:04:59 +02:00
parent aa10bcc5b0
commit eb8e5e5b35
3 changed files with 107 additions and 152 deletions

View File

@ -30,52 +30,9 @@
#include <CGAL/AABB_primitive.h> #include <CGAL/AABB_primitive.h>
#include <CGAL/boost/graph/property_maps.h> #include <CGAL/boost/graph/property_maps.h>
#include <CGAL/Default.h> #include <CGAL/Default.h>
#include <boost/mpl/if.hpp>
namespace CGAL { 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 FaceGraph,
class OneFaceGraphPerTree>
class Primitive_wrapper;
template<class FaceGraph>
class Primitive_wrapper<FaceGraph, Tag_true>
{
public:
typedef typename boost::graph_traits<FaceGraph>::face_descriptor Id;
Primitive_wrapper(const FaceGraph*)
{}
template<class T>
Id from_id(const T& id)const
{
return Id(id);
}
};
template<class FaceGraph>
class Primitive_wrapper<FaceGraph, Tag_false>
{
public:
typedef std::pair<typename boost::graph_traits<FaceGraph>::face_descriptor,
FaceGraph> Id;
Primitive_wrapper(const FaceGraph* graph)
:this_graph(graph)
{}
template<class T>
Id from_id(const T& id)const
{
return std::make_pair(id, *this_graph);
}
private:
const FaceGraph* this_graph;
};
}//end internal
/*! /*!
* \ingroup PkgAABB_tree * \ingroup PkgAABB_tree
@ -109,7 +66,9 @@ template < class FaceGraph,
class CacheDatum=Tag_false > class CacheDatum=Tag_false >
class AABB_face_graph_triangle_primitive class AABB_face_graph_triangle_primitive
#ifndef DOXYGEN_RUNNING #ifndef DOXYGEN_RUNNING
: public AABB_primitive<typename boost::graph_traits<FaceGraph>::face_descriptor, : public AABB_primitive<typename boost::mpl::if_<OneFaceGraphPerTree,
typename boost::graph_traits<FaceGraph>::face_descriptor,
std::pair<typename boost::graph_traits<FaceGraph>::face_descriptor, const FaceGraph*> >::type,
Triangle_from_face_descriptor_map< Triangle_from_face_descriptor_map<
FaceGraph, FaceGraph,
typename Default::Get<VertexPointPMap, typename Default::Get<VertexPointPMap,
@ -121,12 +80,13 @@ class AABB_face_graph_triangle_primitive
typename boost::property_map< FaceGraph, typename boost::property_map< FaceGraph,
vertex_point_t>::type >::type>, vertex_point_t>::type >::type>,
OneFaceGraphPerTree, OneFaceGraphPerTree,
CacheDatum >, CacheDatum >
public internal_primitive_id::Primitive_wrapper<FaceGraph, OneFaceGraphPerTree>
#endif #endif
{ {
typedef typename Default::Get<VertexPointPMap, typename boost::property_map< FaceGraph, vertex_point_t>::type >::type VertexPointPMap_; typedef typename Default::Get<VertexPointPMap, typename boost::property_map< FaceGraph, vertex_point_t>::type >::type VertexPointPMap_;
typedef typename boost::graph_traits<FaceGraph>::face_descriptor Id_; typedef typename boost::graph_traits<FaceGraph>::face_descriptor FD;
typedef typename boost::mpl::if_<OneFaceGraphPerTree, FD, std::pair<FD, const FaceGraph*> >::type Id_;
typedef Triangle_from_face_descriptor_map<FaceGraph,VertexPointPMap_> Triangle_property_map; typedef Triangle_from_face_descriptor_map<FaceGraph,VertexPointPMap_> Triangle_property_map;
typedef One_point_from_face_descriptor_map<FaceGraph,VertexPointPMap_> Point_property_map; typedef One_point_from_face_descriptor_map<FaceGraph,VertexPointPMap_> Point_property_map;
@ -136,10 +96,16 @@ class AABB_face_graph_triangle_primitive
OneFaceGraphPerTree, OneFaceGraphPerTree,
CacheDatum > Base; CacheDatum > Base;
typedef internal_primitive_id::Primitive_wrapper<FaceGraph, OneFaceGraphPerTree> Base_2; FD make_id(FD fd, const FaceGraph&, Tag_true)
{
return fd;
}
std::pair<FD, const FaceGraph*> make_id(FD fd, const FaceGraph& fg, Tag_false)
{
return std::make_pair(fd, &fg);
}
public:
typedef typename Base_2::Id Id;
public: public:
#ifdef DOXYGEN_RUNNING #ifdef DOXYGEN_RUNNING
/// \name Types /// \name Types
@ -154,10 +120,10 @@ public:
typedef Kernel_traits<Point>::Kernel::Triangle_3 Datum; typedef Kernel_traits<Point>::Kernel::Triangle_3 Datum;
/*! /*!
Id type: Id type:
- boost::graph_traits<FaceGraph>::face_descriptor Id if OneFaceGraphPerTree is `CGAL::Tag_true` - `boost::graph_traits<FaceGraph>::face_descriptor` if `OneFaceGraphPerTree` is `CGAL::Tag_true`
- std::pair<boost::graph_traits<FaceGraph>::face_descriptor, FaceGraph> Id if OneFaceGraphPerTree is `CGAL::Tag_false` - `std::pair<boost::graph_traits<FaceGraph>::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`. 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 ); static unspecified_type construct_shared_data( FaceGraph& graph );
#else
typedef typename Base::Id Id;
#endif #endif
Id id() const { typedef typename boost::graph_traits<FaceGraph>::face_descriptor face_descriptor;
return Base_2::from_id(Base::id());
}
// constructors // constructors
/*! /*!
\tparam Iterator an input iterator with `Id` as value type. \tparam Iterator an input iterator with `Id` as value type.
@ -178,10 +145,9 @@ public:
*/ */
template <class Iterator> template <class Iterator>
AABB_face_graph_triangle_primitive(Iterator it, const FaceGraph& graph, VertexPointPMap_ vppm) 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<FaceGraph*>(&graph),vppm), Triangle_property_map(const_cast<FaceGraph*>(&graph),vppm),
Point_property_map(const_cast<FaceGraph*>(&graph),vppm) ), Point_property_map(const_cast<FaceGraph*>(&graph),vppm) )
Base_2(&graph)
{} {}
/*! /*!
@ -189,30 +155,24 @@ public:
If `VertexPointPMap` is the default of the class, an additional constructor If `VertexPointPMap` is the default of the class, an additional constructor
is available with `vppm` set to `get(vertex_point, graph)`. is available with `vppm` set to `get(vertex_point, graph)`.
*/ */
AABB_face_graph_triangle_primitive( AABB_face_graph_triangle_primitive(face_descriptor fd, const FaceGraph& graph, VertexPointPMap_ vppm)
typename boost::graph_traits<FaceGraph>::face_descriptor id, const FaceGraph& graph, : Base( Id_(make_id(fd, graph, OneFaceGraphPerTree())),
VertexPointPMap_ vppm)
: Base( Id_(id),
Triangle_property_map(const_cast<FaceGraph*>(&graph),vppm), Triangle_property_map(const_cast<FaceGraph*>(&graph),vppm),
Point_property_map(const_cast<FaceGraph*>(&graph),vppm) ), Point_property_map(const_cast<FaceGraph*>(&graph),vppm) )
Base_2(&graph)
{} {}
#ifndef DOXYGEN_RUNNING #ifndef DOXYGEN_RUNNING
template <class Iterator> template <class Iterator>
AABB_face_graph_triangle_primitive(Iterator it, const FaceGraph& graph) 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<FaceGraph*>(&graph)), Triangle_property_map(const_cast<FaceGraph*>(&graph)),
Point_property_map(const_cast<FaceGraph*>(&graph)) ), Point_property_map(const_cast<FaceGraph*>(&graph)) )
Base_2(&graph)
{} {}
AABB_face_graph_triangle_primitive( AABB_face_graph_triangle_primitive(face_descriptor fd, const FaceGraph& graph)
typename boost::graph_traits<FaceGraph>::face_descriptor id, const FaceGraph& graph) : Base( Id_(make_id(fd, graph, OneFaceGraphPerTree())),
: Base( Id_(id),
Triangle_property_map(const_cast<FaceGraph*>(&graph)), Triangle_property_map(const_cast<FaceGraph*>(&graph)),
Point_property_map(const_cast<FaceGraph*>(&graph)) ), Point_property_map(const_cast<FaceGraph*>(&graph)) )
Base_2(&graph)
{} {}
#endif #endif

View File

@ -35,54 +35,11 @@
#include <CGAL/is_iterator.h> #include <CGAL/is_iterator.h>
#include <boost/type_traits/is_convertible.hpp> #include <boost/type_traits/is_convertible.hpp>
#include <boost/utility/enable_if.hpp> #include <boost/utility/enable_if.hpp>
#include <boost/mpl/if.hpp>
#include <CGAL/Default.h> #include <CGAL/Default.h>
namespace CGAL { 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 Graph,
class OneGraphPerTree>
class EPrimitive_wrapper;
template<class Graph>
class EPrimitive_wrapper<Graph, Tag_true>
{
public:
typedef typename boost::graph_traits<Graph>::edge_descriptor Id;
EPrimitive_wrapper(const Graph*)
{}
template<class T>
Id from_id(const T& id)const
{
return Id(id);
}
};
template<class Graph>
class EPrimitive_wrapper<Graph, Tag_false>
{
public:
typedef std::pair<typename boost::graph_traits<Graph>::edge_descriptor,
Graph> Id;
EPrimitive_wrapper(const Graph* graph)
:this_graph(graph)
{}
template<class T>
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 CacheDatum = Tag_false >
class AABB_halfedge_graph_segment_primitive class AABB_halfedge_graph_segment_primitive
#ifndef DOXYGEN_RUNNING #ifndef DOXYGEN_RUNNING
: public AABB_primitive< typename boost::graph_traits<HalfedgeGraph>::edge_descriptor, : public AABB_primitive< typename boost::mpl::if_<OneHalfedgeGraphPerTree,
typename boost::graph_traits<HalfedgeGraph>::edge_descriptor,
std::pair<typename boost::graph_traits<HalfedgeGraph>::edge_descriptor, const HalfedgeGraph*> >::type,
Segment_from_edge_descriptor_map< Segment_from_edge_descriptor_map<
HalfedgeGraph, HalfedgeGraph,
typename Default::Get<VertexPointPMap, typename Default::Get<VertexPointPMap,
@ -134,13 +93,13 @@ class AABB_halfedge_graph_segment_primitive
typename boost::property_map< HalfedgeGraph, typename boost::property_map< HalfedgeGraph,
vertex_point_t>::type >::type >, vertex_point_t>::type >::type >,
OneHalfedgeGraphPerTree, OneHalfedgeGraphPerTree,
CacheDatum >, CacheDatum >
public internal_primitive_id::EPrimitive_wrapper<HalfedgeGraph, OneHalfedgeGraphPerTree>
#endif #endif
{ {
typedef typename Default::Get<VertexPointPMap,typename boost::property_map< HalfedgeGraph,vertex_point_t>::type >::type VertexPointPMap_; typedef typename Default::Get<VertexPointPMap,typename boost::property_map< HalfedgeGraph,vertex_point_t>::type >::type VertexPointPMap_;
typedef typename boost::graph_traits<HalfedgeGraph>::edge_descriptor ED;
typedef typename boost::mpl::if_<OneHalfedgeGraphPerTree, ED, std::pair<ED, const HalfedgeGraph*> >::type Id_;
typedef typename boost::graph_traits<HalfedgeGraph>::edge_descriptor Id_;
typedef Segment_from_edge_descriptor_map<HalfedgeGraph,VertexPointPMap_> Segment_property_map; typedef Segment_from_edge_descriptor_map<HalfedgeGraph,VertexPointPMap_> Segment_property_map;
typedef Source_point_from_edge_descriptor_map<HalfedgeGraph,VertexPointPMap_> Point_property_map; typedef Source_point_from_edge_descriptor_map<HalfedgeGraph,VertexPointPMap_> Point_property_map;
@ -150,12 +109,18 @@ class AABB_halfedge_graph_segment_primitive
OneHalfedgeGraphPerTree, OneHalfedgeGraphPerTree,
CacheDatum > Base; CacheDatum > Base;
typedef internal_primitive_id::EPrimitive_wrapper<HalfedgeGraph, OneHalfedgeGraphPerTree> Base_2; ED make_id(ED ed, const HalfedgeGraph&, Tag_true)
{
return ed;
}
std::pair<ED, const HalfedgeGraph*> make_id(ED ed, const HalfedgeGraph& fg, Tag_false)
{
return std::make_pair(ed, &fg);
}
public: public:
typedef typename Base_2::Id Id;
public:
#ifdef DOXYGEN_RUNNING #ifdef DOXYGEN_RUNNING
/// \name Types /// \name Types
/// @{ /// @{
@ -169,20 +134,20 @@ public:
typedef Kernel_traits<Point>::Kernel::Segment_3 Datum; typedef Kernel_traits<Point>::Kernel::Segment_3 Datum;
/*! /*!
Id type: Id type:
- boost::graph_traits<HalfegdeGraph>::edge_descriptor Id if OneHalfegdeGraphPerTree is `CGAL::Tag_true` - `boost::graph_traits<HalfedgeGraph>::edge_descriptor if `OneHalfedgeGraphPerTree` is `Tag_true`
- std::pair<boost::graph_traits<HalfegdeGraph>::edge_descriptor, HalfegdeGraph> Id if OneHalfegdeGraphPerTree is `CGAL::Tag_false` - `std::pair<boost::graph_traits<HalfedgeGraph>::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 ); static unspecified_type construct_shared_data( HalfedgeGraph& graph );
#else
typedef typename Base::Id Id;
#endif #endif
Id id() const { typedef typename boost::graph_traits<HalfedgeGraph>::edge_descriptor edge_descriptor;
return Base_2::from_id(Base::id());
}
/*! /*!
Constructs a primitive. Constructs a primitive.
@ -194,10 +159,9 @@ public:
*/ */
template <class Iterator> template <class Iterator>
AABB_halfedge_graph_segment_primitive(Iterator it, const HalfedgeGraph& graph, VertexPointPMap_ vppm) 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<HalfedgeGraph*>(&graph), vppm), Segment_property_map(const_cast<HalfedgeGraph*>(&graph), vppm),
Point_property_map(const_cast<HalfedgeGraph*>(&graph), vppm) ), Point_property_map(const_cast<HalfedgeGraph*>(&graph), vppm) )
Base_2(&graph)
{} {}
/*! /*!
@ -205,30 +169,23 @@ public:
If `VertexPointPMap` is the default of the class, an additional constructor If `VertexPointPMap` is the default of the class, an additional constructor
is available with `vppm` set to `boost::get(vertex_point, graph)`. is available with `vppm` set to `boost::get(vertex_point, graph)`.
*/ */
AABB_halfedge_graph_segment_primitive( AABB_halfedge_graph_segment_primitive(edge_descriptor ed, const HalfedgeGraph& graph, VertexPointPMap_ vppm)
typename boost::graph_traits<HalfedgeGraph>::edge_descriptor id, const HalfedgeGraph& graph, VertexPointPMap_ vppm) : Base( Id_(make_id(ed, graph, OneHalfedgeGraphPerTree())),
: Base( Id_(id),
Segment_property_map(const_cast<HalfedgeGraph*>(&graph), vppm), Segment_property_map(const_cast<HalfedgeGraph*>(&graph), vppm),
Point_property_map(const_cast<HalfedgeGraph*>(&graph), vppm) ), Point_property_map(const_cast<HalfedgeGraph*>(&graph), vppm) )
Base_2(&graph)
{} {}
#ifndef DOXYGEN_RUNNING #ifndef DOXYGEN_RUNNING
template <class Iterator> template <class Iterator>
AABB_halfedge_graph_segment_primitive(Iterator it, const HalfedgeGraph& graph) 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<HalfedgeGraph*>(&graph)), Segment_property_map(const_cast<HalfedgeGraph*>(&graph)),
Point_property_map(const_cast<HalfedgeGraph*>(&graph)) ), Point_property_map(const_cast<HalfedgeGraph*>(&graph)) ){}
Base_2(&graph)
{}
AABB_halfedge_graph_segment_primitive( AABB_halfedge_graph_segment_primitive(edge_descriptor ed, const HalfedgeGraph& graph)
typename boost::graph_traits<HalfedgeGraph>::edge_descriptor id, const HalfedgeGraph& graph) : Base( Id_(make_id(ed, graph, OneHalfedgeGraphPerTree())),
: Base( Id_(id),
Segment_property_map(const_cast<HalfedgeGraph*>(&graph)), Segment_property_map(const_cast<HalfedgeGraph*>(&graph)),
Point_property_map(const_cast<HalfedgeGraph*>(&graph)) ), Point_property_map(const_cast<HalfedgeGraph*>(&graph)) ){}
Base_2(&graph)
{}
#endif #endif
/// \internal /// \internal

View File

@ -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, target(next(halfedge(f,tm),tm),tm)),
get(pmap.m_vpm, source(halfedge(f,tm),tm)) ); get(pmap.m_vpm, source(halfedge(f,tm),tm)) );
} }
inline friend
reference
get(const Triangle_from_face_descriptor_map<TriangleMesh,VertexPointMap>& pmap,
const std::pair<key_type, const TriangleMesh*>& f)
{
typename boost::remove_const<TriangleMesh>::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, 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) ), return value_type(get(pmap.m_vpm, source(h, *pmap.m_pm) ),
get(pmap.m_vpm, target(h, *pmap.m_pm) ) ); get(pmap.m_vpm, target(h, *pmap.m_pm) ) );
} }
inline friend
reference
get(const Segment_from_edge_descriptor_map<PolygonMesh,VertexPointMap>& pmap,
const std::pair<key_type, const PolygonMesh*>& 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 //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)); 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<PolygonMesh,VertexPointMap>& m,
const std::pair<key_type, const PolygonMesh*>& 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 //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) ); return get(pmap.m_vpm, source(h, *pmap.m_pm) );
} }
inline friend
reference
get(const Source_point_from_edge_descriptor_map<PolygonMesh,VertexPointMap>& pmap,
const std::pair<key_type, const PolygonMesh*>& h)
{
return get(pmap.m_vpm, source(h.first, *pmap.m_pm) );
}
}; };
} //namespace CGAL } //namespace CGAL