From 397d3c079a848c833d1cf11f6d070db0869d481c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 24 May 2011 16:36:48 +0000 Subject: [PATCH] *add Spatial_sort_traits_adapter_d and its documentation *update reference manual(comments sort_indice which is outdated) and reintroduced myPoint.cpp example *remove unused variable warning *remove const bool warning --- .gitattributes | 2 + .../Spatial_sorting/spatial_sorting.tex | 23 +++--- .../SpatialSortingTraits_d.tex | 3 +- .../Spatial_sort_traits_adapter_d.tex | 36 +++++++++ .../doc_tex/Spatial_sorting_ref/intro.tex | 1 + .../doc_tex/Spatial_sorting_ref/main.tex | 1 + .../sp_sort_using_property_map_d.cpp | 22 +++--- .../CGAL/Spatial_sort_traits_adapter_d.h | 76 +++++++++++++++++++ Spatial_sorting/include/CGAL/hilbert_sort.h | 2 +- Spatial_sorting/include/CGAL/spatial_sort.h | 6 +- 10 files changed, 145 insertions(+), 27 deletions(-) create mode 100644 Spatial_sorting/doc_tex/Spatial_sorting_ref/Spatial_sort_traits_adapter_d.tex create mode 100644 Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_d.h diff --git a/.gitattributes b/.gitattributes index 52f4dff2c89..ae00e7df0f4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3316,6 +3316,7 @@ Spatial_sorting/doc_tex/Spatial_sorting_ref/Hilbert_sort_d.tex -text Spatial_sorting/doc_tex/Spatial_sorting_ref/SpatialSortingTraits_d.tex -text Spatial_sorting/doc_tex/Spatial_sorting_ref/Spatial_sort_traits_adapter_2.tex -text Spatial_sorting/doc_tex/Spatial_sorting_ref/Spatial_sort_traits_adapter_3.tex -text +Spatial_sorting/doc_tex/Spatial_sorting_ref/Spatial_sort_traits_adapter_d.tex -text Spatial_sorting/examples/Spatial_sorting/hilbert.cpp -text Spatial_sorting/examples/Spatial_sorting/hilbert_policies.cpp -text Spatial_sorting/examples/Spatial_sorting/small_example_delaunay_2.cpp -text @@ -3333,6 +3334,7 @@ Spatial_sorting/include/CGAL/Hilbert_sort_middle_base.h -text Spatial_sorting/include/CGAL/Hilbert_sort_middle_d.h -text Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_2.h -text Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_3.h -text +Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_d.h -text Straight_skeleton_2/demo/Straight_skeleton_2/data/complex_0.poly -text svneol=unset#application/octet-stream Straight_skeleton_2/demo/Straight_skeleton_2/data/complex_1.poly -text svneol=unset#application/octet-stream Straight_skeleton_2/demo/Straight_skeleton_2/data/complex_2.poly -text svneol=unset#application/octet-stream diff --git a/Spatial_sorting/doc_tex/Spatial_sorting/spatial_sorting.tex b/Spatial_sorting/doc_tex/Spatial_sorting/spatial_sorting.tex index e002bcdc448..9470465bb6d 100644 --- a/Spatial_sorting/doc_tex/Spatial_sorting/spatial_sorting.tex +++ b/Spatial_sorting/doc_tex/Spatial_sorting/spatial_sorting.tex @@ -161,7 +161,7 @@ such an order provides enough randomness to combine the advantages of a random \cgal\ provides spatial sorting for points in 2D, 3D and higher dimensions, with the middle and the median policies for Hilbert sort in the buckets. -\subsection{Examples} +\subsection{Basic Example} The following example shows that, on particular input, spatial sort runs much faster than a bad order or than Hilbert sort (below results @@ -176,11 +176,19 @@ $ ./small_example_delaunay_2 \ccIncludeExampleCode{Spatial_sorting/small_example_delaunay_2.cpp} -Next example describes how a traits class different than CGAL Kernel can be -used to sort a container of handle on points instead of points directly. +%Next example describes how a traits class different than CGAL Kernel can be +%used to sort a container of handle on points instead of points directly. +%\ccIncludeExampleCode{Spatial_sorting/sort_indices.cpp} -\ccIncludeExampleCode{Spatial_sorting/sort_indices.cpp} +\subsection{Using your own Point Type} +If you want to sort points of your own point type, +you only have to provide functors that compare +the \ccc{x} and \ccc{y} coordinates of your points. Note that in case you simply want +to associate an extra information to your point you might consider the example of this section +\ref{sec:sort_any_type_2} +as an alternative. +\ccIncludeExampleCode{Spatial_sorting/myPoint.cpp} \subsection{Sorting Arbitrary Types} \label{sec:sort_any_type} @@ -206,12 +214,5 @@ In this example program, the sorted sequence of points is retrieved using the indices of the points in a vector of pairs of point and integer. \ccIncludeExampleCode{Spatial_sorting/sp_sort_using_property_map_d.cpp} -If you want to sort points of your own point type, -you only have to provide functors that compare -the \ccc{x} and \ccc{y} coordinates of your points. Note that in case you simply want -to associate an extra information to your point you might consider the example of this section -\ref{sec:sort_any_type_2} -as an alternative. -\ccIncludeExampleCode{Spatial_sorting/myPoint.cpp} diff --git a/Spatial_sorting/doc_tex/Spatial_sorting_ref/SpatialSortingTraits_d.tex b/Spatial_sorting/doc_tex/Spatial_sorting_ref/SpatialSortingTraits_d.tex index 06659646395..94b3863882e 100644 --- a/Spatial_sorting/doc_tex/Spatial_sorting_ref/SpatialSortingTraits_d.tex +++ b/Spatial_sorting/doc_tex/Spatial_sorting_ref/SpatialSortingTraits_d.tex @@ -60,7 +60,8 @@ object types must exist. \ccParDims \ccHasModels -Any \cgal{} $d$ dimensional kernel. +Any \cgal{} $d$ dimensional kernel.\\ +\ccc{CGAL::Spatial_sort_traits_adapter_d}. \ccParDims \end{ccRefConcept} diff --git a/Spatial_sorting/doc_tex/Spatial_sorting_ref/Spatial_sort_traits_adapter_d.tex b/Spatial_sorting/doc_tex/Spatial_sorting_ref/Spatial_sort_traits_adapter_d.tex new file mode 100644 index 00000000000..f69cff26075 --- /dev/null +++ b/Spatial_sorting/doc_tex/Spatial_sorting_ref/Spatial_sort_traits_adapter_d.tex @@ -0,0 +1,36 @@ +\begin{ccRefClass}{Spatial_sort_traits_adapter_d} + +\ccDefinition + +Given a property map associating a key to a point, the class \ccRefName\ induces a spatial +reorder of the keys instead of the points, the comparisons being done on the associated points. +In other words, the traits provides to a spatial sort algorithm a point type which is a key, +while the actual point type is \ccc{Base_traits::Point_d}. + +\ccRequirements \ccc{Base_traits} is a model for \ccc{SpatialSortingTraits_d}. +\ccc{PointPropertyMap} is a model of \ccAnchor{http://www.boost.org/doc/libs/release/libs/property_map/doc/ReadablePropertyMap.html}{boost::ReadablePropertyMap} +with \ccc{Base_traits::Point_d} as \ccc{value_type}. + + +\ccInheritsFrom +\ccc{Base_traits} + +\ccIsModel +\ccc{SpatialSortingTraits_d} + +\ccTypes +\ccTypedef{boost::property_traits::key_type Point_d;}{} + +\ccTagFullDeclarations +\ccCreationVariable{o} +\ccCreation +\ccConstructor{Spatial_sort_traits_adapter_d(Base_traits base=Base_traits());}{} +\ccConstructor{Spatial_sort_traits_adapter_d(const PointPropertyMap& ppmap,Base_traits base=Base_traits());}{} + +\ccOperations +\ccThree{void;;}{A}{} + +\ccMethod{const PointPropertyMap& point_property_map() const;}{Returns a const reference to the point property map.} + + +\end{ccRefClass} diff --git a/Spatial_sorting/doc_tex/Spatial_sorting_ref/intro.tex b/Spatial_sorting/doc_tex/Spatial_sorting_ref/intro.tex index 4ee265f1512..f06bd424fa3 100644 --- a/Spatial_sorting/doc_tex/Spatial_sorting_ref/intro.tex +++ b/Spatial_sorting/doc_tex/Spatial_sorting_ref/intro.tex @@ -24,6 +24,7 @@ \ccHeading{Traits classes} \ccRefIdfierPage{CGAL::Spatial_sort_traits_adapter_2} \\ \ccRefIdfierPage{CGAL::Spatial_sort_traits_adapter_3} \\ +\ccRefIdfierPage{CGAL::Spatial_sort_traits_adapter_d} \\ \ccHeading{Concepts} diff --git a/Spatial_sorting/doc_tex/Spatial_sorting_ref/main.tex b/Spatial_sorting/doc_tex/Spatial_sorting_ref/main.tex index 2412d151368..dc005400549 100644 --- a/Spatial_sorting/doc_tex/Spatial_sorting_ref/main.tex +++ b/Spatial_sorting/doc_tex/Spatial_sorting_ref/main.tex @@ -19,5 +19,6 @@ \input{Spatial_sorting_ref/Hilbert_policy_tags.tex} \input{Spatial_sorting_ref/Spatial_sort_traits_adapter_2.tex} \input{Spatial_sorting_ref/Spatial_sort_traits_adapter_3.tex} +\input{Spatial_sorting_ref/Spatial_sort_traits_adapter_d.tex} %% EOF diff --git a/Spatial_sorting/examples/Spatial_sorting/sp_sort_using_property_map_d.cpp b/Spatial_sorting/examples/Spatial_sorting/sp_sort_using_property_map_d.cpp index c2f8f8e239a..c13b829b713 100644 --- a/Spatial_sorting/examples/Spatial_sorting/sp_sort_using_property_map_d.cpp +++ b/Spatial_sorting/examples/Spatial_sorting/sp_sort_using_property_map_d.cpp @@ -12,18 +12,18 @@ typedef std::vector< Point_with_info > Data_vector; //property map and get as friend // to be allowed to use private member class Vect_ppmap{ - const Data_vector& points + const Data_vector& points; public: //classical typedefs - typedef Data_vector::size_t key_type; + typedef Data_vector::size_type key_type; typedef Point_d value_type; - typedef const Point_d& reference; + typedef const value_type& reference; typedef boost::readable_property_map_tag category; Vect_ppmap(const Data_vector& points_):points(points_){} - friend reference get(const Vect_ppmap& vmap,key_type i) const{ - return vmap.points[i]; + friend reference get(const Vect_ppmap& vmap, key_type i) { + return vmap.points[i].first; } }; @@ -38,17 +38,17 @@ int main() points.push_back(std::make_pair(Point_d(4,coords ,coords+4) , 1)); points.push_back(std::make_pair(Point_d(4,coords+4,coords+8) , 2)); - std::vector indices; + std::vector indices; indices.reserve(points.size()); - std::copy(boost::counting_iterator(0), - boost::counting_iterator(points.size()), + std::copy(boost::counting_iterator(0), + boost::counting_iterator(points.size()), std::back_inserter(indices)); CGAL::spatial_sort( indices.begin(),indices.end(),Search_traits_d(Vect_ppmap(points)) ); - - for (Data_vector::iterator it=points.begin();it!=points.end();++it) - std::cout << it->second << " "; + std::vector::iterator it=indices.begin(); + for (;it!=indices.end();++it) + std::cout << points[*it].second << " "; std::cout << "\n"; std::cout << "done" << std::endl; diff --git a/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_d.h b/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_d.h new file mode 100644 index 00000000000..5115f58f3d5 --- /dev/null +++ b/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_d.h @@ -0,0 +1,76 @@ +// Copyright (c) 2011 GeometryFactory (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Sebastien Loriot + + +#ifndef CGAL_SPATIAL_SORT_TRAITS_ADAPTER_D_H +#define CGAL_SPATIAL_SORT_TRAITS_ADAPTER_D_H + +#include +#include + +namespace CGAL{ + +using ::get; + +template +class Spatial_sort_traits_adapter_d:public Base_traits{ + PointPropertyMap ppmap_; +public: + Spatial_sort_traits_adapter_d(Base_traits base=Base_traits()):Base_traits(base){} + + Spatial_sort_traits_adapter_d(const PointPropertyMap& ppmap,Base_traits base=Base_traits()) + :Base_traits(base),ppmap_(ppmap){} + + typedef Base_traits Gt; + typedef typename boost::property_traits::key_type Point_d; + typedef typename boost::call_traits::param_type Arg_type; + + + + struct Less_coordinate_d: public Base_traits::Less_coordinate_d{ + Less_coordinate_d(const PointPropertyMap& ppmap,const typename Base_traits::Less_coordinate_d& base): + Base_traits::Less_coordinate_d(base),ppmap_(ppmap){} + const PointPropertyMap& ppmap_; + bool operator()(Arg_type p,Arg_type q,int i) const { + return static_cast(this)->operator()(get(ppmap_,p),get(ppmap_,q),i); + } + }; + + + struct Compute_coordinate_d: public Base_traits::Compute_coordinate_d{ + Compute_coordinate_d(const PointPropertyMap& ppmap,const typename Base_traits::Compute_coordinate_d& base): + Base_traits::Compute_coordinate_d(base),ppmap_(ppmap){} + const PointPropertyMap& ppmap_; + bool operator()(Arg_type p,int i) const { + return static_cast(this)->operator()(get(ppmap_,p),i); + } + }; + + + + Less_coordinate_d less_coordinate_d_object () const {return Less_coordinate_d(ppmap_,static_cast(this)->less_coordinate_d_object() );} + Compute_coordinate_d compute_coordinate_d_object () const {return Compute_coordinate_d(ppmap_,static_cast(this)->compute_coordinate_d_object() );} + + const PointPropertyMap& point_property_map() const {return ppmap_;} + +}; + +} //namespace CGAL + +#endif //CGAL_SPATIAL_SORT_TRAITS_ADAPTER_D_H diff --git a/Spatial_sorting/include/CGAL/hilbert_sort.h b/Spatial_sorting/include/CGAL/hilbert_sort.h index 2529325ca03..b79431b28d2 100644 --- a/Spatial_sorting/include/CGAL/hilbert_sort.h +++ b/Spatial_sorting/include/CGAL/hilbert_sort.h @@ -41,7 +41,7 @@ namespace internal { template void hilbert_sort (RandomAccessIterator begin, RandomAccessIterator end, - Policy policy, + Policy /*policy*/, const Kernel &k, typename Kernel::Point_2 *) { boost::rand48 random; diff --git a/Spatial_sorting/include/CGAL/spatial_sort.h b/Spatial_sorting/include/CGAL/spatial_sort.h index 1d561149fba..ec93d9e1eb8 100644 --- a/Spatial_sorting/include/CGAL/spatial_sort.h +++ b/Spatial_sorting/include/CGAL/spatial_sort.h @@ -40,7 +40,7 @@ namespace internal { void spatial_sort ( RandomAccessIterator begin, RandomAccessIterator end, const Kernel &k, - Policy policy, + Policy /*policy*/, typename Kernel::Point_2 *, std::ptrdiff_t threshold_hilbert, std::ptrdiff_t threshold_multiscale, @@ -63,7 +63,7 @@ namespace internal { void spatial_sort ( RandomAccessIterator begin, RandomAccessIterator end, const Kernel &k, - Policy policy, + Policy /*policy*/, typename Kernel::Point_3 *, std::ptrdiff_t threshold_hilbert, std::ptrdiff_t threshold_multiscale, @@ -86,7 +86,7 @@ namespace internal { void spatial_sort ( RandomAccessIterator begin, RandomAccessIterator end, const Kernel &k, - Policy policy, + Policy /*policy*/, typename Kernel::Point_d *, std::ptrdiff_t threshold_hilbert, std::ptrdiff_t threshold_multiscale,