From 44509967259d3bdf80d3f1e658acf72f13466c29 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 8 Apr 2019 16:13:12 +0200 Subject: [PATCH] Add example to the User Manual --- .../CGAL/Convex_hull_traits_adapter_2.h | 62 +++++++++++++++++++ .../Convex_hull_2/CGAL/convex_hull_traits_2.h | 3 +- .../Concepts/ConvexHullTraits_2.h | 1 + .../doc/Convex_hull_2/Convex_hull_2.txt | 15 +++++ .../doc/Convex_hull_2/PackageDescription.txt | 1 + Convex_hull_2/doc/Convex_hull_2/examples.txt | 1 + .../Convex_hull_2/convex_hull_indices.cpp | 24 +++---- 7 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 Convex_hull_2/doc/Convex_hull_2/CGAL/Convex_hull_traits_adapter_2.h diff --git a/Convex_hull_2/doc/Convex_hull_2/CGAL/Convex_hull_traits_adapter_2.h b/Convex_hull_2/doc/Convex_hull_2/CGAL/Convex_hull_traits_adapter_2.h new file mode 100644 index 00000000000..a81344198cc --- /dev/null +++ b/Convex_hull_2/doc/Convex_hull_2/CGAL/Convex_hull_traits_adapter_2.h @@ -0,0 +1,62 @@ +namespace CGAL { + +/*! +\ingroup PkgConvexHull2Traits + +The class `Convex_hull_traits_adapter_2` serves as a traits class for all the two-dimensional +convex hull and extreme point calculation function. This class corresponds +to the default traits class for these functions. + +Given a property map associating a key to a point, the class `Convex_hull_traits_adapter_2` enables +to compute the sequence of keys for which the associted points are the convex hull points , +the predicates being computed on the associated points. +In other words, the traits provides to a convex hull algorithm a point type which is a key, +while the actual point type is `Base_traits::Point_2`. + +\cgalModels `ConvexHullTraits_2` + +\sa `CGAL::Convex_hull_constructive_traits_2` +\sa `CGAL::Projection_traits_xy_3` +\sa `CGAL::Projection_traits_yz_3` +\sa `CGAL::Projection_traits_xz_3` + +*/ +template< typename Base_traits, typename PointPropertyMap > +class Convex_hull_traits_adapter_2 { +public: + +/// \name Types +/// @{ + +/*! + +*/ +typedef boost::property_traits::key_type Point_2; + +/// @} + +/// \name Creation +/// @{ + +/*! +*/ +Convex_hull_traits_2(Base_traits base=Base_traits()); + +/*! +*/ +Convex_hull_traits_2(const PointPropertyMap& ppmap, Base_traits base=Base_traits()); +/// @} + +/// \name Operations +/// @{ + +/*! +Returns a const reference to the point property map. +*/ +const PointPropertyMap& point_property_map() const; + + +/// @} + +}; /* end Convex_hull_traits_2 */ +} /* end namespace CGAL */ diff --git a/Convex_hull_2/doc/Convex_hull_2/CGAL/convex_hull_traits_2.h b/Convex_hull_2/doc/Convex_hull_2/CGAL/convex_hull_traits_2.h index 83483c391df..524accb0f17 100644 --- a/Convex_hull_2/doc/Convex_hull_2/CGAL/convex_hull_traits_2.h +++ b/Convex_hull_2/doc/Convex_hull_2/CGAL/convex_hull_traits_2.h @@ -9,7 +9,8 @@ to the default traits class for these functions. \cgalModels `ConvexHullTraits_2` -\sa `CGAL::Convex_hull_constructive_traits_2` +\sa `CGAL::Convex_hull_constructive_traits_2` +\sa `CGAL::Convex_hull_traits_adapter_2` \sa `CGAL::Projection_traits_xy_3` \sa `CGAL::Projection_traits_yz_3` \sa `CGAL::Projection_traits_xz_3` diff --git a/Convex_hull_2/doc/Convex_hull_2/Concepts/ConvexHullTraits_2.h b/Convex_hull_2/doc/Convex_hull_2/Concepts/ConvexHullTraits_2.h index 4a2fb65e294..426f8f3f265 100644 --- a/Convex_hull_2/doc/Convex_hull_2/Concepts/ConvexHullTraits_2.h +++ b/Convex_hull_2/doc/Convex_hull_2/Concepts/ConvexHullTraits_2.h @@ -11,6 +11,7 @@ is specified with each function. \cgalHasModel `CGAL::Convex_hull_constructive_traits_2` \cgalHasModel `CGAL::Convex_hull_traits_2` +\cgalHasModel `CGAL::Convex_hull_traits_adapter_2` \cgalHasModel `CGAL::Projection_traits_xy_3` \cgalHasModel `CGAL::Projection_traits_yz_3 ` \cgalHasModel `CGAL::Projection_traits_xz_3` diff --git a/Convex_hull_2/doc/Convex_hull_2/Convex_hull_2.txt b/Convex_hull_2/doc/Convex_hull_2/Convex_hull_2.txt index 428794ea844..ae6264b8514 100644 --- a/Convex_hull_2/doc/Convex_hull_2/Convex_hull_2.txt +++ b/Convex_hull_2/doc/Convex_hull_2/Convex_hull_2.txt @@ -79,6 +79,21 @@ functions such as `ch_bykat()`. \cgalExample{Convex_hull_2/ch_from_cin_to_cout.cpp} + +\section Convex_hull_2ExampleIndex Example using a Property Map + +In the following example we have as input a vector of points, +and we retrieve the indices of of the points which are on the convex hull. +The convex hull function takes as fourth argument a traits class +that must be model of the concept `ConvexHullTraits_2`. It provides +predicates such as orientation tests. +The class `Convex_hull_traits_adapter_2` in combination with a +`Pointer_property_map`, is a model. The indices `i` are then "points", +and the adapter performs the predicates on `points[i]`. + +\cgalExample{Convex_hull_2/convex_hull_indices_2.cpp} + + \section Convex_hull_2Extreme Extreme Points and Hull Subsequences In addition to the functions for producing convex hulls, there are a diff --git a/Convex_hull_2/doc/Convex_hull_2/PackageDescription.txt b/Convex_hull_2/doc/Convex_hull_2/PackageDescription.txt index 259bf022018..094ed2fd3a0 100644 --- a/Convex_hull_2/doc/Convex_hull_2/PackageDescription.txt +++ b/Convex_hull_2/doc/Convex_hull_2/PackageDescription.txt @@ -69,6 +69,7 @@ defining `CGAL_CH_CHECK_EXPENSIVE`. - `CGAL::Convex_hull_constructive_traits_2` - `CGAL::Convex_hull_traits_2` +- `CGAL::Convex_hull_traits_adapter_2` \cgalCRPSection{Convex Hull Functions} diff --git a/Convex_hull_2/doc/Convex_hull_2/examples.txt b/Convex_hull_2/doc/Convex_hull_2/examples.txt index dd02318b5db..8439df4a923 100644 --- a/Convex_hull_2/doc/Convex_hull_2/examples.txt +++ b/Convex_hull_2/doc/Convex_hull_2/examples.txt @@ -1,5 +1,6 @@ /*! \example Convex_hull_2/array_convex_hull_2.cpp +\example Convex_hull_2/convex_hull_indices_2.cpp \example Convex_hull_2/ch_from_cin_to_cout.cpp \example Convex_hull_2/ch_graham_anderson.cpp \example Convex_hull_2/ch_timing.cpp diff --git a/Convex_hull_2/examples/Convex_hull_2/convex_hull_indices.cpp b/Convex_hull_2/examples/Convex_hull_2/convex_hull_indices.cpp index 9e03ce2f528..9fab2740109 100644 --- a/Convex_hull_2/examples/Convex_hull_2/convex_hull_indices.cpp +++ b/Convex_hull_2/examples/Convex_hull_2/convex_hull_indices.cpp @@ -3,6 +3,7 @@ #include #include #include +#include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef K::Point_2 Point_2; @@ -11,22 +12,17 @@ typedef CGAL::Convex_hull_traits_adapter_2 points; - - points.push_back(Point_2(10,0)); - points.push_back(Point_2(0,10)); - points.push_back(Point_2(1,1)); - points.push_back(Point_2(3,4)); - points.push_back(Point_2(0,0)); - points.push_back(Point_2(10,10)); - points.push_back(Point_2(2,6)); + std::vector points = { Point_2(10,0), + Point_2(10,0), + Point_2(0,10), + Point_2(1,1), + Point_2(3,4), + Point_2(0,0), + Point_2(10,10), + Point_2(2,6) }; std::vector indices(points.size()), out; - - for(int i=0; i < indices.size();i++){ - indices[i] = i; - } - + std::iota(indices.begin(), indices.end(),0); CGAL::convex_hull_2(indices.begin(), indices.end(), std::back_inserter(out), Convex_hull_traits_2(CGAL::make_property_map(points)));