diff --git a/Convex_hull_3/doc/Convex_hull_3/CGAL/Extreme_points_traits_adapter_3.h b/Convex_hull_3/doc/Convex_hull_3/CGAL/Extreme_points_traits_adapter_3.h new file mode 100644 index 00000000000..efea61694ed --- /dev/null +++ b/Convex_hull_3/doc/Convex_hull_3/CGAL/Extreme_points_traits_adapter_3.h @@ -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 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::key_type Point_3; + + /*! + * \return the `CGAL::Point_3` associated with `k` + */ + boost::property_traits::reference + get_point(const typename boost::property_traits::key_type& k) const; + +}; +}//end CGAL diff --git a/Convex_hull_3/doc/Convex_hull_3/CGAL/convex_hull_3.h b/Convex_hull_3/doc/Convex_hull_3/CGAL/convex_hull_3.h index 560150517ea..f89c03e27ad 100644 --- a/Convex_hull_3/doc/Convex_hull_3/CGAL/convex_hull_3.h +++ b/Convex_hull_3/doc/Convex_hull_3/CGAL/convex_hull_3.h @@ -82,6 +82,8 @@ then the default traits class used is `Convex_hull_traits_3`, and `R` otherwi @param range the range of input points. @param out an output iterator where the extreme points will be put. @param traits an instance of `Traits`. + +\sa CGAL::Extreme_points_traits_adapter_3 */ template OutputIterator diff --git a/Convex_hull_3/doc/Convex_hull_3/PackageDescription.txt b/Convex_hull_3/doc/Convex_hull_3/PackageDescription.txt index 4dbf102b99e..4836390c82f 100644 --- a/Convex_hull_3/doc/Convex_hull_3/PackageDescription.txt +++ b/Convex_hull_3/doc/Convex_hull_3/PackageDescription.txt @@ -70,6 +70,7 @@ defining `CGAL_CH_CHECK_EXPENSIVE`. ## Traits Classes ## - `CGAL::Convex_hull_traits_3` +- `CGAL::Extreme_points_traits_adapter_3` ## Convex Hull Functions ## diff --git a/Convex_hull_3/include/CGAL/Vertex_to_point_traits_adapter_3.h b/Convex_hull_3/include/CGAL/Extreme_points_traits_adapter_3.h similarity index 81% rename from Convex_hull_3/include/CGAL/Vertex_to_point_traits_adapter_3.h rename to Convex_hull_3/include/CGAL/Extreme_points_traits_adapter_3.h index 3e90c0f98b0..4cb222b0d10 100644 --- a/Convex_hull_3/include/CGAL/Vertex_to_point_traits_adapter_3.h +++ b/Convex_hull_3/include/CGAL/Extreme_points_traits_adapter_3.h @@ -19,8 +19,8 @@ // // Author(s) : Maxime Gimeno -#ifndef CGAL_VERTEX_TO_POINT_TRAITS_ADAPTER_3_H -#define CGAL_VERTEX_TO_POINT_TRAITS_ADAPTER_3_H +#ifndef CGAL_EXTREME_POINTS_TRAITS_ADAPTER_3_H +#define CGAL_EXTREME_POINTS_TRAITS_ADAPTER_3_H #include @@ -38,13 +38,13 @@ namespace CGAL { namespace Convex_hull_impl{ -template +template struct Forward_functor : public F { - VertexPointMap vpm_; + PointPropertyMap vpm_; - Forward_functor(const VertexPointMap& vpm, + Forward_functor(const PointPropertyMap& vpm, const F& f) : F(f), vpm_(vpm) {} @@ -77,27 +77,27 @@ struct Forward_functor } }; }//end Convex_hull_impl -template -class Vertex_to_point_traits_adapter +template +class Extreme_points_traits_adapter_3 :public Base_traits { - VertexPointMap vpm_; + PointPropertyMap vpm_; 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) {} - typedef typename boost::property_traits::key_type Vertex; + typedef typename boost::property_traits::key_type Vertex; typedef Vertex Point_3; - typedef Convex_hull_impl::Forward_functor Equal_3; - typedef Convex_hull_impl::Forward_functor Collinear_3; - typedef Convex_hull_impl::Forward_functor Coplanar_3; - typedef Convex_hull_impl::Forward_functor Less_distance_to_point_3; + typedef Convex_hull_impl::Forward_functor Equal_3; + typedef Convex_hull_impl::Forward_functor Collinear_3; + typedef Convex_hull_impl::Forward_functor Coplanar_3; + typedef Convex_hull_impl::Forward_functor Less_distance_to_point_3; class 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; public: typedef typename Base_traits::Plane_3 Plane_3; @@ -105,7 +105,7 @@ public: typedef bool result_type; Less_signed_distance_to_plane_3( - const VertexPointMap& map, + const PointPropertyMap& map, const typename Base_traits::Less_signed_distance_to_plane_3& 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 { - VertexPointMap vpm_; + PointPropertyMap vpm_; const typename Base_traits::Construct_plane_3& base; 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){} 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 { - VertexPointMap vpm_; + PointPropertyMap vpm_; const typename Base_traits::Has_on_positive_side_3& base; 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){} typedef typename Base_traits::Plane_3 Plane_3; @@ -166,24 +166,24 @@ public: template class Proj_traits_3:public Base_proj_traits { - VertexPointMap vpm_; + PointPropertyMap vpm_; typedef Base_proj_traits Btt; 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){} typedef Point_3 Point_2; - typedef Convex_hull_impl::Forward_functor Equal_2; - typedef Convex_hull_impl::Forward_functor Less_xy_2; - typedef Convex_hull_impl::Forward_functor Less_yx_2; - typedef Convex_hull_impl::Forward_functor Less_signed_distance_to_line_2; - typedef Convex_hull_impl::Forward_functor Left_turn_2; + typedef Convex_hull_impl::Forward_functor Equal_2; + typedef Convex_hull_impl::Forward_functor Less_xy_2; + typedef Convex_hull_impl::Forward_functor Less_yx_2; + typedef Convex_hull_impl::Forward_functor Less_signed_distance_to_line_2; + typedef Convex_hull_impl::Forward_functor Left_turn_2; class Less_rotate_ccw_2:public Btt::Less_rotate_ccw_2 { - VertexPointMap vpm_; + PointPropertyMap vpm_; const typename Btt::Less_rotate_ccw_2& base; 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){} public: bool operator()(Point_2 e, Point_2 p,Point_2 q) const @@ -203,10 +203,10 @@ public: class Orientation_2:public Btt::Orientation_2 { - VertexPointMap vpm_; + PointPropertyMap vpm_; const typename Btt::Orientation_2& base; 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){} 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 {return Traits_xz_3(vpm_, static_cast(this)->construct_traits_xz_3_object());} - typename boost::property_traits::reference - get_point(const typename boost::property_traits::key_type& k) const + typename boost::property_traits::reference + get_point(const typename boost::property_traits::key_type& k) const { return get(vpm_, k); } @@ -238,4 +238,4 @@ public: }//end CGAL -#endif // CGAL_VERTEX_TO_POINT_TRAITS_ADAPTER_3_H +#endif // CGAL_EXTREME_POINTS_TRAITS_ADAPTER_3_H diff --git a/Convex_hull_3/include/CGAL/convex_hull_3.h b/Convex_hull_3/include/CGAL/convex_hull_3.h index db34e478207..46331127bcd 100644 --- a/Convex_hull_3/include/CGAL/convex_hull_3.h +++ b/Convex_hull_3/include/CGAL/convex_hull_3.h @@ -68,7 +68,7 @@ namespace CGAL { // Forward declaration -template class Vertex_to_point_traits_adapter; +template class Extreme_points_traits_adapter_3; namespace internal{ namespace Convex_hull_3{ @@ -206,10 +206,10 @@ public: }; template -class Is_on_positive_side_of_plane_3< Vertex_to_point_traits_adapter, Is_CK> +class Is_on_positive_side_of_plane_3< Extreme_points_traits_adapter_3, Is_CK> : public Is_on_positive_side_of_plane_3< Base_traits > { - typedef Vertex_to_point_traits_adapter Traits; + typedef Extreme_points_traits_adapter_3 Traits; typedef Is_on_positive_side_of_plane_3< Base_traits > Base; typedef typename Traits::Point_3 Point_3; const Traits& m_traits; @@ -1033,28 +1033,11 @@ extreme_vertices(const InputRange& range, const Traits& traits) { - Vertex_to_point_traits_adapter traits_adapter(map, traits); + Extreme_points_traits_adapter_3 traits_adapter(map, traits); extreme_points_3(range, out,traits_adapter); return out; } -template -OutputIterator -extreme_vertices(const InputRange& range, - PointPropertyMap map, - OutputIterator out) -{ - typedef typename boost::property_traits::value_type Point_3; - typedef typename internal::Convex_hull_3::Default_traits_for_Chull_3::type Traits; - - Vertex_to_point_traits_adapter traits_adapter(map, Traits()); - extreme_points_3(range, out,traits_adapter); - return out; -} - - template void convex_hull_3(InputIterator first, InputIterator beyond, Polyhedron_3& polyhedron) diff --git a/Convex_hull_3/test/Convex_hull_3/test_extreme_points.cpp b/Convex_hull_3/test/Convex_hull_3/test_extreme_points.cpp index 9fd608ad397..cd7fc7f3d3b 100644 --- a/Convex_hull_3/test/Convex_hull_3/test_extreme_points.cpp +++ b/Convex_hull_3/test/Convex_hull_3/test_extreme_points.cpp @@ -1,8 +1,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -212,9 +212,12 @@ void test_extreme_vertices(const char* fname) std::cerr << fname << " is not a valid off file.\n"; exit(1); } + CGAL::Extreme_points_traits_adapter_3 + ,boost::property_map::type > + traits(get(CGAL::vertex_point, P)); std::vector::vertex_descriptor> verts; - CGAL::extreme_vertices(vertices(P), get(CGAL::vertex_point, P), std::back_inserter(verts) , - CGAL::Convex_hull_traits_3()); + CGAL::extreme_points_3(vertices(P), std::back_inserter(verts) , + traits); } int main()