CGAL 6.1.1 - Spatial Sorting

Loading...
Searching...
No Matches
Spatial_sorting/sp_sort_using_property_map_d.cpp
#include <CGAL/Cartesian_d.h>
#include <CGAL/spatial_sort.h>
#include <CGAL/Spatial_sort_traits_adapter_d.h>
#include <CGAL/boost/iterator/counting_iterator.hpp>
#include <vector>
typedef CGAL::Cartesian_d<double> Kernel;
typedef Kernel::Point_d Point_d;
typedef std::pair<Point_d,int> Point_with_info;
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;
public:
//classical typedefs
typedef Data_vector::size_type key_type;
typedef Point_d value_type;
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) {
return vmap.points[i].first;
}
};
typedef CGAL::Spatial_sort_traits_adapter_d<Kernel,Vect_ppmap> Search_traits_d;
int main()
{
double coords[] ={ 1.0, 1.0, 1.0, 1.0,
2.0, 2.0, 2.0, 2.0 };
Data_vector points;
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<Vect_ppmap::key_type> indices;
indices.reserve(points.size());
std::copy(
boost::counting_iterator<Vect_ppmap::key_type>(0),
boost::counting_iterator<Vect_ppmap::key_type>(points.size()),
std::back_inserter(indices) );
std::cout << "Order using default policy (median)\n";
CGAL::spatial_sort(
indices.begin(),
indices.end(),
Search_traits_d(Vect_ppmap(points))
);
for (auto i : indices)
std::cout << points[i].second << " ";
std::cout << std::endl;
std::cout << "Order using middle policy\n";
CGAL::spatial_sort(
indices.begin(),
indices.end(),
Search_traits_d(Vect_ppmap(points)),
CGAL::Hilbert_sort_middle_policy()
);
for (auto i : indices)
std::cout << points[i].second << " ";
std::cout << std::endl;
std::cout << "done" << std::endl;
return 0;
}
CGAL::Spatial_sort_traits_adapter_d
Given a property map associating a key to a point, the class Spatial_sort_traits_adapter_d induces a ...
Definition: Spatial_sort_traits_adapter_d.h:20
CGAL::spatial_sort
void spatial_sort(InputPointIterator begin, InputPointIterator end, const Traits &traits=Default_traits, PolicyTag policy=Default_policy, std::ptrdiff_t threshold_hilbert=default, std::ptrdiff_t threshold_multiscale=default, double ratio=default)
The function spatial_sort() sorts an iterator range of points in a way that improves space locality.
Kernel
CGAL::Hilbert_policy
Hilbert_policy is a policy class which can be used to parameterize a strategy policy in order to spec...
Definition: Hilbert_policy_tags.h:56