23 #ifndef KD_TREE_SEARCH_H_ 24 #define KD_TREE_SEARCH_H_ 26 #include <CGAL/Orthogonal_k_neighbor_search.h> 27 #include <CGAL/Orthogonal_incremental_neighbor_search.h> 28 #include <CGAL/Search_traits.h> 29 #include <CGAL/Search_traits_adapter.h> 30 #include <CGAL/Fuzzy_sphere.h> 31 #include <CGAL/property_map.h> 33 #include <boost/property_map/property_map.hpp> 34 #include <boost/iterator/counting_iterator.hpp> 40 namespace spatial_searching {
68 template <
typename Search_traits,
typename Po
int_range>
70 typedef boost::iterator_property_map<
71 typename Point_range::const_iterator,
72 CGAL::Identity_property_map<std::ptrdiff_t> > Point_property_map;
78 typedef typename Traits::FT
FT;
80 typedef typename Point_range::value_type
Point;
82 typedef CGAL::Search_traits<
84 typename Traits::Cartesian_const_iterator_d,
85 typename Traits::Construct_cartesian_const_iterator_d> Traits_base;
87 typedef CGAL::Search_traits_adapter<
91 typedef CGAL::Distance_adapter<
94 CGAL::Euclidean_distance<Traits_base> > Orthogonal_distance;
96 typedef CGAL::Orthogonal_k_neighbor_search<STraits> K_neighbor_search;
97 typedef typename K_neighbor_search::Tree Tree;
98 typedef typename K_neighbor_search::Distance Distance;
104 typedef CGAL::Orthogonal_incremental_neighbor_search<
105 STraits, Distance, CGAL::Sliding_midpoint<STraits>, Tree>
106 Incremental_neighbor_search;
112 typedef CGAL::Fuzzy_sphere<STraits> Fuzzy_sphere;
118 m_tree(boost::counting_iterator<std::ptrdiff_t>(0),
119 boost::counting_iterator<std::ptrdiff_t>(points.size()),
120 typename Tree::Splitter(),
121 STraits(std::begin(points))) {
131 template <
typename Po
int_indices_range>
133 Point_range
const& points,
134 Point_indices_range
const& only_these_points)
137 only_these_points.begin(), only_these_points.end(),
138 typename Tree::Splitter(),
139 STraits(std::begin(points))) {
150 Point_range
const& points,
151 std::size_t begin_idx, std::size_t past_the_end_idx)
154 boost::counting_iterator<std::ptrdiff_t>(begin_idx),
155 boost::counting_iterator<std::ptrdiff_t>(past_the_end_idx),
156 typename Tree::Splitter(),
157 STraits(std::begin(points))) {
164 void insert(std::ptrdiff_t point_idx) {
165 m_tree.insert(point_idx);
178 FT eps =
FT(0))
const {
182 K_neighbor_search search(
188 Orthogonal_distance(std::begin(m_points)), sorted);
204 Incremental_neighbor_search search(
209 Orthogonal_distance(std::begin(m_points)) );
224 FT eps =
FT(0))
const {
228 K_neighbor_search search(
234 Orthogonal_distance(std::begin(m_points)), sorted);
250 Incremental_neighbor_search search(
255 Orthogonal_distance(std::begin(m_points)) );
266 template <
typename OutputIterator>
270 FT eps =
FT(0))
const {
271 m_tree.search(it, Fuzzy_sphere(p, radius, eps, m_tree.traits()));
274 int tree_depth()
const {
275 return m_tree.root()->depth();
279 Point_range
const& m_points;
286 #endif // KD_TREE_SEARCH_H_ Spatial tree data structure to perform (approximate) nearest and furthest neighbor search...
Definition: Kd_tree_search.h:69
Kd_tree_search(Point_range const &points, std::size_t begin_idx, std::size_t past_the_end_idx)
Constructor.
Definition: Kd_tree_search.h:149
Kd_tree_search(Point_range const &points, Point_indices_range const &only_these_points)
Constructor.
Definition: Kd_tree_search.h:132
Incremental_neighbor_search INS_range
The range returned by an incremental nearest or furthest neighbor search. Its value type is std::pair...
Definition: Kd_tree_search.h:110
K_neighbor_search KNS_range
The range returned by a k-nearest or k-furthest neighbor search. Its value type is std::pair<std::siz...
Definition: Kd_tree_search.h:102
INS_range incremental_furthest_neighbors(Point const &p, FT eps=FT(0)) const
Search incrementally for the furthest neighbors from a query point.
Definition: Kd_tree_search.h:246
KNS_range k_nearest_neighbors(Point const &p, unsigned int k, bool sorted=true, FT eps=FT(0)) const
Search for the k-nearest neighbors from a query point.
Definition: Kd_tree_search.h:174
Kd_tree_search(Point_range const &points)
Constructor.
Definition: Kd_tree_search.h:116
Definition: SimplicialComplexForAlpha.h:26
INS_range incremental_nearest_neighbors(Point const &p, FT eps=FT(0)) const
Search incrementally for the nearest neighbors from a query point.
Definition: Kd_tree_search.h:200
KNS_range k_furthest_neighbors(Point const &p, unsigned int k, bool sorted=true, FT eps=FT(0)) const
Search for the k-furthest points from a query point.
Definition: Kd_tree_search.h:220
Traits::FT FT
Number type used for distances.
Definition: Kd_tree_search.h:78
void all_near_neighbors(Point const &p, FT radius, OutputIterator it, FT eps=FT(0)) const
Search for all the neighbors in a ball.
Definition: Kd_tree_search.h:267
Point_range::value_type Point
The point type.
Definition: Kd_tree_search.h:80
Search_traits Traits
The Traits.
Definition: Kd_tree_search.h:76