Document adapter traits.

This commit is contained in:
Maxime Gimeno 2018-06-27 10:27:19 +02:00
parent 13bf29eca5
commit f3dd3ba1c0
6 changed files with 89 additions and 58 deletions

View File

@ -0,0 +1,42 @@
namespace CGAL {
/*!
* \ingroup PkgConvexHull3Traits
*
* The class `Extreme_points_traits_adapter_3` serves as a traits class for the function
* `extreme_points_3()`. It permits the use of this function for accessing vertices, indices,
* or anything that can be used as `key_type` for `PointPropertyMap`.
*
* \tparam Base_traits a model of `ConvexHullTraits_3` and `IsStronglyConvexTraits_3`
* \tparam PointPropertyMap a model of `ReadablePropertyMap` with `CGAL::Point_3`
* as value_type.
*
* \cgalModels `ConvexHullTraits_3`
* \cgalModels `IsStronglyConvexTraits_3`
*/
template<class Base_traits,class PointPropertyMap>
class Extreme_points_traits_adapter_3
{
public:
/*!
* Constructor for the adapter.
*
* It uses the functors from `Base_traits` with a call to `get()` for each argument.
*
* \param pmap the propertymap used for retrieving the data.
* \param base the base ConvexHullTraits_3 used for `extreme_points_3()`.
*/
Extreme_points_traits_adapter_3(const PointPropertyMap& pmap, Base_traits base=Base_traits());
/*!
*/
typedef boost::property_traits<PointPropertyMap>::key_type Point_3;
/*!
* \return the `CGAL::Point_3` associated with `k`
*/
boost::property_traits<PointPropertyMap>::reference
get_point(const typename boost::property_traits<PointPropertyMap>::key_type& k) const;
};
}//end CGAL

View File

@ -82,6 +82,8 @@ then the default traits class used is `Convex_hull_traits_3<R>`, and `R` otherwi
@param range the range of input points. @param range the range of input points.
@param out an output iterator where the extreme points will be put. @param out an output iterator where the extreme points will be put.
@param traits an instance of `Traits`. @param traits an instance of `Traits`.
\sa CGAL::Extreme_points_traits_adapter_3
*/ */
template <class InputRange, class OutputIterator, class Traits> template <class InputRange, class OutputIterator, class Traits>
OutputIterator OutputIterator

View File

@ -70,6 +70,7 @@ defining `CGAL_CH_CHECK_EXPENSIVE`.
## Traits Classes ## ## Traits Classes ##
- `CGAL::Convex_hull_traits_3<R>` - `CGAL::Convex_hull_traits_3<R>`
- `CGAL::Extreme_points_traits_adapter_3`
## Convex Hull Functions ## ## Convex Hull Functions ##

View File

@ -19,8 +19,8 @@
// //
// Author(s) : Maxime Gimeno // Author(s) : Maxime Gimeno
#ifndef CGAL_VERTEX_TO_POINT_TRAITS_ADAPTER_3_H #ifndef CGAL_EXTREME_POINTS_TRAITS_ADAPTER_3_H
#define CGAL_VERTEX_TO_POINT_TRAITS_ADAPTER_3_H #define CGAL_EXTREME_POINTS_TRAITS_ADAPTER_3_H
#include <CGAL/license/Convex_hull_3.h> #include <CGAL/license/Convex_hull_3.h>
@ -38,13 +38,13 @@
namespace CGAL { namespace CGAL {
namespace Convex_hull_impl{ namespace Convex_hull_impl{
template <class F, class VertexPointMap> template <class F, class PointPropertyMap>
struct Forward_functor struct Forward_functor
: public F : public F
{ {
VertexPointMap vpm_; PointPropertyMap vpm_;
Forward_functor(const VertexPointMap& vpm, Forward_functor(const PointPropertyMap& vpm,
const F& f) : F(f), vpm_(vpm) {} const F& f) : F(f), vpm_(vpm) {}
@ -77,27 +77,27 @@ struct Forward_functor
} }
}; };
}//end Convex_hull_impl }//end Convex_hull_impl
template<class Base_traits,class VertexPointMap> template<class Base_traits,class PointPropertyMap>
class Vertex_to_point_traits_adapter class Extreme_points_traits_adapter_3
:public Base_traits :public Base_traits
{ {
VertexPointMap vpm_; PointPropertyMap vpm_;
public: public:
Vertex_to_point_traits_adapter(const VertexPointMap& vpmap, Base_traits base=Base_traits()) Extreme_points_traits_adapter_3(const PointPropertyMap& vpmap, Base_traits base=Base_traits())
:Base_traits(base), vpm_(vpmap) :Base_traits(base), vpm_(vpmap)
{} {}
typedef typename boost::property_traits<VertexPointMap>::key_type Vertex; typedef typename boost::property_traits<PointPropertyMap>::key_type Vertex;
typedef Vertex Point_3; typedef Vertex Point_3;
typedef Convex_hull_impl::Forward_functor<typename Base_traits::Equal_3, VertexPointMap> Equal_3; typedef Convex_hull_impl::Forward_functor<typename Base_traits::Equal_3, PointPropertyMap> Equal_3;
typedef Convex_hull_impl::Forward_functor<typename Base_traits::Collinear_3, VertexPointMap> Collinear_3; typedef Convex_hull_impl::Forward_functor<typename Base_traits::Collinear_3, PointPropertyMap> Collinear_3;
typedef Convex_hull_impl::Forward_functor<typename Base_traits::Coplanar_3, VertexPointMap> Coplanar_3; typedef Convex_hull_impl::Forward_functor<typename Base_traits::Coplanar_3, PointPropertyMap> Coplanar_3;
typedef Convex_hull_impl::Forward_functor<typename Base_traits::Less_distance_to_point_3, VertexPointMap> Less_distance_to_point_3; typedef Convex_hull_impl::Forward_functor<typename Base_traits::Less_distance_to_point_3, PointPropertyMap> Less_distance_to_point_3;
class Less_signed_distance_to_plane_3 class Less_signed_distance_to_plane_3
:public Base_traits::Less_signed_distance_to_plane_3 :public Base_traits::Less_signed_distance_to_plane_3
{ {
VertexPointMap vpm_; PointPropertyMap vpm_;
const typename Base_traits::Less_signed_distance_to_plane_3& base; const typename Base_traits::Less_signed_distance_to_plane_3& base;
public: public:
typedef typename Base_traits::Plane_3 Plane_3; typedef typename Base_traits::Plane_3 Plane_3;
@ -105,7 +105,7 @@ public:
typedef bool result_type; typedef bool result_type;
Less_signed_distance_to_plane_3( Less_signed_distance_to_plane_3(
const VertexPointMap& map, const PointPropertyMap& map,
const typename Base_traits::Less_signed_distance_to_plane_3& base): const typename Base_traits::Less_signed_distance_to_plane_3& base):
Base_traits::Less_signed_distance_to_plane_3(base),vpm_(map), base(base){} Base_traits::Less_signed_distance_to_plane_3(base),vpm_(map), base(base){}
@ -129,10 +129,10 @@ public:
class Construct_plane_3:public Base_traits::Construct_plane_3 class Construct_plane_3:public Base_traits::Construct_plane_3
{ {
VertexPointMap vpm_; PointPropertyMap vpm_;
const typename Base_traits::Construct_plane_3& base; const typename Base_traits::Construct_plane_3& base;
public: public:
Construct_plane_3(const VertexPointMap& map, const typename Base_traits::Construct_plane_3& base): Construct_plane_3(const PointPropertyMap& map, const typename Base_traits::Construct_plane_3& base):
Base_traits::Construct_plane_3(base),vpm_(map), base(base){} Base_traits::Construct_plane_3(base),vpm_(map), base(base){}
typename Base_traits::Plane_3 operator()(const Point_3& p, const Point_3& q, const Point_3& r)const typename Base_traits::Plane_3 operator()(const Point_3& p, const Point_3& q, const Point_3& r)const
{ {
@ -144,10 +144,10 @@ public:
class Has_on_positive_side_3:public Base_traits::Has_on_positive_side_3 class Has_on_positive_side_3:public Base_traits::Has_on_positive_side_3
{ {
VertexPointMap vpm_; PointPropertyMap vpm_;
const typename Base_traits::Has_on_positive_side_3& base; const typename Base_traits::Has_on_positive_side_3& base;
public: public:
Has_on_positive_side_3(const VertexPointMap& map,const typename Base_traits::Has_on_positive_side_3& base): Has_on_positive_side_3(const PointPropertyMap& map,const typename Base_traits::Has_on_positive_side_3& base):
Base_traits::Has_on_positive_side_3(base),vpm_(map), base(base){} Base_traits::Has_on_positive_side_3(base),vpm_(map), base(base){}
typedef typename Base_traits::Plane_3 Plane_3; typedef typename Base_traits::Plane_3 Plane_3;
@ -166,24 +166,24 @@ public:
template<class Base_proj_traits> template<class Base_proj_traits>
class Proj_traits_3:public Base_proj_traits class Proj_traits_3:public Base_proj_traits
{ {
VertexPointMap vpm_; PointPropertyMap vpm_;
typedef Base_proj_traits Btt; typedef Base_proj_traits Btt;
public: public:
Proj_traits_3(const VertexPointMap& map,const Btt& base): Proj_traits_3(const PointPropertyMap& map,const Btt& base):
Base_proj_traits(base),vpm_(map){} Base_proj_traits(base),vpm_(map){}
typedef Point_3 Point_2; typedef Point_3 Point_2;
typedef Convex_hull_impl::Forward_functor<typename Btt::Equal_2, VertexPointMap> Equal_2; typedef Convex_hull_impl::Forward_functor<typename Btt::Equal_2, PointPropertyMap> Equal_2;
typedef Convex_hull_impl::Forward_functor<typename Btt::Less_xy_2, VertexPointMap> Less_xy_2; typedef Convex_hull_impl::Forward_functor<typename Btt::Less_xy_2, PointPropertyMap> Less_xy_2;
typedef Convex_hull_impl::Forward_functor<typename Btt::Less_yx_2, VertexPointMap> Less_yx_2; typedef Convex_hull_impl::Forward_functor<typename Btt::Less_yx_2, PointPropertyMap> Less_yx_2;
typedef Convex_hull_impl::Forward_functor<typename Btt::Less_signed_distance_to_line_2, VertexPointMap> Less_signed_distance_to_line_2; typedef Convex_hull_impl::Forward_functor<typename Btt::Less_signed_distance_to_line_2, PointPropertyMap> Less_signed_distance_to_line_2;
typedef Convex_hull_impl::Forward_functor<typename Btt::Left_turn_2, VertexPointMap> Left_turn_2; typedef Convex_hull_impl::Forward_functor<typename Btt::Left_turn_2, PointPropertyMap> Left_turn_2;
class Less_rotate_ccw_2:public Btt::Less_rotate_ccw_2 class Less_rotate_ccw_2:public Btt::Less_rotate_ccw_2
{ {
VertexPointMap vpm_; PointPropertyMap vpm_;
const typename Btt::Less_rotate_ccw_2& base; const typename Btt::Less_rotate_ccw_2& base;
public: public:
Less_rotate_ccw_2(const VertexPointMap& map,const typename Btt::Less_rotate_ccw_2& base): Less_rotate_ccw_2(const PointPropertyMap& map,const typename Btt::Less_rotate_ccw_2& base):
Btt::Less_rotate_ccw_2(base),vpm_(map), base(base){} Btt::Less_rotate_ccw_2(base),vpm_(map), base(base){}
public: public:
bool operator()(Point_2 e, Point_2 p,Point_2 q) const bool operator()(Point_2 e, Point_2 p,Point_2 q) const
@ -203,10 +203,10 @@ public:
class Orientation_2:public Btt::Orientation_2 class Orientation_2:public Btt::Orientation_2
{ {
VertexPointMap vpm_; PointPropertyMap vpm_;
const typename Btt::Orientation_2& base; const typename Btt::Orientation_2& base;
public: public:
Orientation_2(const VertexPointMap& map,const typename Btt::Orientation_2& base): Orientation_2(const PointPropertyMap& map,const typename Btt::Orientation_2& base):
Btt::Orientation_2(base),vpm_(map), base(base){} Btt::Orientation_2(base),vpm_(map), base(base){}
typename CGAL::Orientation operator()(Point_2 e,Point_2 p, Point_2 q) const typename CGAL::Orientation operator()(Point_2 e,Point_2 p, Point_2 q) const
@ -228,8 +228,8 @@ public:
Traits_xz_3 construct_traits_xz_3_object()const Traits_xz_3 construct_traits_xz_3_object()const
{return Traits_xz_3(vpm_, static_cast<const Base_traits*>(this)->construct_traits_xz_3_object());} {return Traits_xz_3(vpm_, static_cast<const Base_traits*>(this)->construct_traits_xz_3_object());}
typename boost::property_traits<VertexPointMap>::reference typename boost::property_traits<PointPropertyMap>::reference
get_point(const typename boost::property_traits<VertexPointMap>::key_type& k) const get_point(const typename boost::property_traits<PointPropertyMap>::key_type& k) const
{ {
return get(vpm_, k); return get(vpm_, k);
} }
@ -238,4 +238,4 @@ public:
}//end CGAL }//end CGAL
#endif // CGAL_VERTEX_TO_POINT_TRAITS_ADAPTER_3_H #endif // CGAL_EXTREME_POINTS_TRAITS_ADAPTER_3_H

View File

@ -68,7 +68,7 @@
namespace CGAL { namespace CGAL {
// Forward declaration // Forward declaration
template<class Base_traits,class VertexPointMap> class Vertex_to_point_traits_adapter; template<class Base_traits,class VertexPointMap> class Extreme_points_traits_adapter_3;
namespace internal{ namespace Convex_hull_3{ namespace internal{ namespace Convex_hull_3{
@ -206,10 +206,10 @@ public:
}; };
template <class Base_traits, class VPM, class Is_CK> template <class Base_traits, class VPM, class Is_CK>
class Is_on_positive_side_of_plane_3< Vertex_to_point_traits_adapter<Base_traits, VPM>, Is_CK> class Is_on_positive_side_of_plane_3< Extreme_points_traits_adapter_3<Base_traits, VPM>, Is_CK>
: public Is_on_positive_side_of_plane_3< Base_traits > : public Is_on_positive_side_of_plane_3< Base_traits >
{ {
typedef Vertex_to_point_traits_adapter<Base_traits, VPM> Traits; typedef Extreme_points_traits_adapter_3<Base_traits, VPM> Traits;
typedef Is_on_positive_side_of_plane_3< Base_traits > Base; typedef Is_on_positive_side_of_plane_3< Base_traits > Base;
typedef typename Traits::Point_3 Point_3; typedef typename Traits::Point_3 Point_3;
const Traits& m_traits; const Traits& m_traits;
@ -1033,28 +1033,11 @@ extreme_vertices(const InputRange& range,
const Traits& traits) const Traits& traits)
{ {
Vertex_to_point_traits_adapter<Traits, PointPropertyMap> traits_adapter(map, traits); Extreme_points_traits_adapter_3<Traits, PointPropertyMap> traits_adapter(map, traits);
extreme_points_3(range, out,traits_adapter); extreme_points_3(range, out,traits_adapter);
return out; return out;
} }
template <class InputRange,
class PointPropertyMap,
class OutputIterator>
OutputIterator
extreme_vertices(const InputRange& range,
PointPropertyMap map,
OutputIterator out)
{
typedef typename boost::property_traits<PointPropertyMap>::value_type Point_3;
typedef typename internal::Convex_hull_3::Default_traits_for_Chull_3<Point_3>::type Traits;
Vertex_to_point_traits_adapter<Traits, PointPropertyMap> traits_adapter(map, Traits());
extreme_points_3(range, out,traits_adapter);
return out;
}
template <class InputIterator, class Polyhedron_3> template <class InputIterator, class Polyhedron_3>
void convex_hull_3(InputIterator first, InputIterator beyond, void convex_hull_3(InputIterator first, InputIterator beyond,
Polyhedron_3& polyhedron) Polyhedron_3& polyhedron)

View File

@ -1,8 +1,8 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h> #include <CGAL/Surface_mesh.h>
#include <CGAL/convex_hull_3.h> #include <CGAL/convex_hull_3.h>
#include <CGAL/Vertex_to_point_traits_adapter_3.h>
#include <CGAL/Convex_hull_traits_3.h> #include <CGAL/Convex_hull_traits_3.h>
#include <CGAL/Extreme_points_traits_adapter_3.h>
#include <CGAL/Exact_rational.h> #include <CGAL/Exact_rational.h>
#include <CGAL/Cartesian.h> #include <CGAL/Cartesian.h>
#include <CGAL/Polyhedron_3.h> #include <CGAL/Polyhedron_3.h>
@ -212,9 +212,12 @@ void test_extreme_vertices(const char* fname)
std::cerr << fname << " is not a valid off file.\n"; std::cerr << fname << " is not a valid off file.\n";
exit(1); exit(1);
} }
CGAL::Extreme_points_traits_adapter_3<CGAL::Convex_hull_traits_3<K, Polyhedron_3, CGAL::Tag_true>
,boost::property_map<Polyhedron_3, CGAL::vertex_point_t>::type >
traits(get(CGAL::vertex_point, P));
std::vector<boost::graph_traits<Polyhedron_3>::vertex_descriptor> verts; std::vector<boost::graph_traits<Polyhedron_3>::vertex_descriptor> verts;
CGAL::extreme_vertices(vertices(P), get(CGAL::vertex_point, P), std::back_inserter(verts) , CGAL::extreme_points_3(vertices(P), std::back_inserter(verts) ,
CGAL::Convex_hull_traits_3<K, Polyhedron_3, CGAL::Tag_true>()); traits);
} }
int main() int main()