*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
This commit is contained in:
Sébastien Loriot 2011-05-24 16:36:48 +00:00
parent 98ddbf9c7e
commit 397d3c079a
10 changed files with 145 additions and 27 deletions

2
.gitattributes vendored
View File

@ -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/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_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_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.cpp -text
Spatial_sorting/examples/Spatial_sorting/hilbert_policies.cpp -text Spatial_sorting/examples/Spatial_sorting/hilbert_policies.cpp -text
Spatial_sorting/examples/Spatial_sorting/small_example_delaunay_2.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/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_2.h -text
Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_3.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_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_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 Straight_skeleton_2/demo/Straight_skeleton_2/data/complex_2.poly -text svneol=unset#application/octet-stream

View File

@ -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, \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. 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 The following example shows that, on particular input, spatial sort
runs much faster than a bad order or than Hilbert sort (below results 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} \ccIncludeExampleCode{Spatial_sorting/small_example_delaunay_2.cpp}
Next example describes how a traits class different than CGAL Kernel can be %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. %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} \subsection{Sorting Arbitrary Types}
\label{sec:sort_any_type} \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. 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} \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}

View File

@ -60,7 +60,8 @@ object types must exist.
\ccParDims \ccParDims
\ccHasModels \ccHasModels
Any \cgal{} $d$ dimensional kernel. Any \cgal{} $d$ dimensional kernel.\\
\ccc{CGAL::Spatial_sort_traits_adapter_d<Base_traits,PointPropertyMap>}.
\ccParDims \ccParDims
\end{ccRefConcept} \end{ccRefConcept}

View File

@ -0,0 +1,36 @@
\begin{ccRefClass}{Spatial_sort_traits_adapter_d<Base_traits,PointPropertyMap>}
\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<PointPropertyMap>::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}

View File

@ -24,6 +24,7 @@
\ccHeading{Traits classes} \ccHeading{Traits classes}
\ccRefIdfierPage{CGAL::Spatial_sort_traits_adapter_2<Base_traits,PointPropertyMap>} \\ \ccRefIdfierPage{CGAL::Spatial_sort_traits_adapter_2<Base_traits,PointPropertyMap>} \\
\ccRefIdfierPage{CGAL::Spatial_sort_traits_adapter_3<Base_traits,PointPropertyMap>} \\ \ccRefIdfierPage{CGAL::Spatial_sort_traits_adapter_3<Base_traits,PointPropertyMap>} \\
\ccRefIdfierPage{CGAL::Spatial_sort_traits_adapter_d<Base_traits,PointPropertyMap>} \\
\ccHeading{Concepts} \ccHeading{Concepts}

View File

@ -19,5 +19,6 @@
\input{Spatial_sorting_ref/Hilbert_policy_tags.tex} \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_2.tex}
\input{Spatial_sorting_ref/Spatial_sort_traits_adapter_3.tex} \input{Spatial_sorting_ref/Spatial_sort_traits_adapter_3.tex}
\input{Spatial_sorting_ref/Spatial_sort_traits_adapter_d.tex}
%% EOF %% EOF

View File

@ -12,18 +12,18 @@ typedef std::vector< Point_with_info > Data_vector;
//property map and get as friend //property map and get as friend
// to be allowed to use private member // to be allowed to use private member
class Vect_ppmap{ class Vect_ppmap{
const Data_vector& points const Data_vector& points;
public: public:
//classical typedefs //classical typedefs
typedef Data_vector::size_t key_type; typedef Data_vector::size_type key_type;
typedef Point_d value_type; typedef Point_d value_type;
typedef const Point_d& reference; typedef const value_type& reference;
typedef boost::readable_property_map_tag category; typedef boost::readable_property_map_tag category;
Vect_ppmap(const Data_vector& points_):points(points_){} Vect_ppmap(const Data_vector& points_):points(points_){}
friend reference get(const Vect_ppmap& vmap,key_type i) const{ friend reference get(const Vect_ppmap& vmap, key_type i) {
return vmap.points[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 ,coords+4) , 1));
points.push_back(std::make_pair(Point_d(4,coords+4,coords+8) , 2)); points.push_back(std::make_pair(Point_d(4,coords+4,coords+8) , 2));
std::vector<std::ptrdiff_t> indices; std::vector<Vect_ppmap::key_type> indices;
indices.reserve(points.size()); indices.reserve(points.size());
std::copy(boost::counting_iterator<std::ptrdiff_t>(0), std::copy(boost::counting_iterator<Vect_ppmap::key_type>(0),
boost::counting_iterator<std::ptrdiff_t>(points.size()), boost::counting_iterator<Vect_ppmap::key_type>(points.size()),
std::back_inserter(indices)); std::back_inserter(indices));
CGAL::spatial_sort( indices.begin(),indices.end(),Search_traits_d(Vect_ppmap(points)) ); CGAL::spatial_sort( indices.begin(),indices.end(),Search_traits_d(Vect_ppmap(points)) );
std::vector<Vect_ppmap::key_type>::iterator it=indices.begin();
for (Data_vector::iterator it=points.begin();it!=points.end();++it) for (;it!=indices.end();++it)
std::cout << it->second << " "; std::cout << points[*it].second << " ";
std::cout << "\n"; std::cout << "\n";
std::cout << "done" << std::endl; std::cout << "done" << std::endl;

View File

@ -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 <boost/call_traits.hpp>
#include <boost/property_map/property_map.hpp>
namespace CGAL{
using ::get;
template<class Base_traits,class PointPropertyMap>
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<PointPropertyMap>::key_type Point_d;
typedef typename boost::call_traits<Point_d>::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<const typename Base_traits::Less_coordinate_d*>(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<const typename Base_traits::Compute_coordinate_d*>(this)->operator()(get(ppmap_,p),i);
}
};
Less_coordinate_d less_coordinate_d_object () const {return Less_coordinate_d(ppmap_,static_cast<const Gt*>(this)->less_coordinate_d_object() );}
Compute_coordinate_d compute_coordinate_d_object () const {return Compute_coordinate_d(ppmap_,static_cast<const Gt*>(this)->compute_coordinate_d_object() );}
const PointPropertyMap& point_property_map() const {return ppmap_;}
};
} //namespace CGAL
#endif //CGAL_SPATIAL_SORT_TRAITS_ADAPTER_D_H

View File

@ -41,7 +41,7 @@ namespace internal {
template <class RandomAccessIterator, class Policy, class Kernel> template <class RandomAccessIterator, class Policy, class Kernel>
void hilbert_sort (RandomAccessIterator begin, void hilbert_sort (RandomAccessIterator begin,
RandomAccessIterator end, RandomAccessIterator end,
Policy policy, Policy /*policy*/,
const Kernel &k, typename Kernel::Point_2 *) const Kernel &k, typename Kernel::Point_2 *)
{ {
boost::rand48 random; boost::rand48 random;

View File

@ -40,7 +40,7 @@ namespace internal {
void spatial_sort ( void spatial_sort (
RandomAccessIterator begin, RandomAccessIterator end, RandomAccessIterator begin, RandomAccessIterator end,
const Kernel &k, const Kernel &k,
Policy policy, Policy /*policy*/,
typename Kernel::Point_2 *, typename Kernel::Point_2 *,
std::ptrdiff_t threshold_hilbert, std::ptrdiff_t threshold_hilbert,
std::ptrdiff_t threshold_multiscale, std::ptrdiff_t threshold_multiscale,
@ -63,7 +63,7 @@ namespace internal {
void spatial_sort ( void spatial_sort (
RandomAccessIterator begin, RandomAccessIterator end, RandomAccessIterator begin, RandomAccessIterator end,
const Kernel &k, const Kernel &k,
Policy policy, Policy /*policy*/,
typename Kernel::Point_3 *, typename Kernel::Point_3 *,
std::ptrdiff_t threshold_hilbert, std::ptrdiff_t threshold_hilbert,
std::ptrdiff_t threshold_multiscale, std::ptrdiff_t threshold_multiscale,
@ -86,7 +86,7 @@ namespace internal {
void spatial_sort ( void spatial_sort (
RandomAccessIterator begin, RandomAccessIterator end, RandomAccessIterator begin, RandomAccessIterator end,
const Kernel &k, const Kernel &k,
Policy policy, Policy /*policy*/,
typename Kernel::Point_d *, typename Kernel::Point_d *,
std::ptrdiff_t threshold_hilbert, std::ptrdiff_t threshold_hilbert,
std::ptrdiff_t threshold_multiscale, std::ptrdiff_t threshold_multiscale,