Robotics Library  0.7.0
KdtreeBoundingBoxNearestNeighbors.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef RL_MATH_KDTREEBOUNDINGBOXNEARESTNEIGHBORS_H
28 #define RL_MATH_KDTREEBOUNDINGBOXNEARESTNEIGHBORS_H
29 
30 #include <algorithm>
31 #include <array>
32 #include <deque>
33 #include <fstream>
34 #include <iterator>
35 #include <memory>
36 #include <numeric>
37 #include <type_traits>
38 #include <utility>
39 #include <vector>
40 #include <boost/optional.hpp>
41 
42 namespace rl
43 {
44  namespace math
45  {
55  template<typename MetricT>
57  {
58  private:
59  struct Node;
60 
61  public:
62  typedef const typename MetricT::Value& const_reference;
63 
64  typedef ::std::ptrdiff_t difference_type;
65 
66  typedef typename MetricT::Value& reference;
67 
68  typedef ::std::size_t size_type;
69 
70  typedef typename MetricT::Value value_type;
71 
72  typedef typename MetricT::Distance Distance;
73 
74  typedef MetricT Metric;
75 
76  typedef typename MetricT::Size Size;
77 
78  typedef typename MetricT::Value Value;
79 
80  typedef ::std::pair<Distance, Value> Neighbor;
81 
83  boundingBox(),
84  checks(),
85  metric(metric),
86  nodeDataMax(10),
87  root(),
88  values(0)
89  {
90  }
91 
93  boundingBox(),
94  checks(),
95  metric(::std::move(metric)),
96  nodeDataMax(10),
97  root(),
98  values(0)
99  {
100  }
101 
102  template<typename InputIterator>
103  KdtreeBoundingBoxNearestNeighbors(InputIterator first, InputIterator last, const Metric& metric) :
104  boundingBox(),
105  checks(),
106  metric(metric),
107  nodeDataMax(10),
108  root(),
109  values(0)
110  {
111  this->insert(first, last);
112  }
113 
114  template<typename InputIterator>
115  KdtreeBoundingBoxNearestNeighbors(InputIterator first, InputIterator last, Metric&& metric = Metric()) :
116  boundingBox(),
117  checks(),
118  metric(::std::move(metric)),
119  nodeDataMax(10),
120  root(),
121  values(0)
122  {
123  this->insert(first, last);
124  }
125 
127  {
128  }
129 
130  void clear()
131  {
132  this->boundingBox.clear();
133  this->root.children[0].reset(nullptr);
134  this->root.children[1].reset(nullptr);
135  this->root.data.clear();
136  this->values = 0;
137  }
138 
139  ::std::vector<Value> data() const
140  {
141  ::std::vector<Value> data;
142  data.reserve(this->values);
143  this->data(this->root, data);
144  return data;
145  }
146 
147  bool empty() const
148  {
149  return this->root.data.empty() && nullptr == this->root.children[0] && nullptr == this->root.children[1];
150  }
151 
152  ::boost::optional< ::std::size_t> getChecks() const
153  {
154  return this->checks;
155  }
156 
157  ::std::size_t getNodeDataMax() const
158  {
159  return this->nodeDataMax;
160  }
161 
162  template<typename InputIterator>
163  void insert(InputIterator first, InputIterator last)
164  {
165  using ::std::size;
166 
167  if (this->empty())
168  {
169  typename ::std::iterator_traits<InputIterator>::difference_type distance = ::std::distance(first, last);
170 
171  if (distance > 1)
172  {
173  this->boundingBox.resize(size(*first));
174  this->computeBoundingBox(first, last, this->boundingBox);
175  this->divide(this->root, this->boundingBox, first, last);
176  }
177  else
178  {
179  this->root.data.insert(this->root.data.end(), first, last);
180  }
181 
182  this->values += distance;
183  }
184  else
185  {
186  for (InputIterator i = first; i != last; ++i)
187  {
188  this->push(*i);
189  }
190  }
191  }
192 
193  ::std::vector<Neighbor> nearest(const Value& query, const ::std::size_t& k, const bool& sorted = true) const
194  {
195  return this->search(query, &k, nullptr, sorted);
196  }
197 
198  void push(const Value& value)
199  {
200  using ::std::begin;
201  using ::std::size;
202 
203  if (this->boundingBox.empty())
204  {
205  this->boundingBox.resize(size(value));
206 
207  for (::std::size_t i = 0; i < this->boundingBox.size(); ++i)
208  {
209  Distance tmp = *(begin(value) + i);
210  this->boundingBox[i].low = tmp;
211  this->boundingBox[i].high = tmp;
212  }
213  }
214  else
215  {
216  for (::std::size_t i = 0; i < this->boundingBox.size(); ++i)
217  {
218  Distance tmp = *(begin(value) + i);
219  this->boundingBox[i].low = ::std::min(tmp, this->boundingBox[i].low);
220  this->boundingBox[i].high = ::std::max(tmp, this->boundingBox[i].high);
221  }
222  }
223 
224  this->push(this->root, value);
225 
226  ++this->values;
227  }
228 
229  ::std::vector<Neighbor> radius(const Value& query, const Distance& radius, const bool& sorted = true) const
230  {
231  return this->search(query, nullptr, &radius, sorted);
232  }
233 
234  void setChecks(const ::boost::optional< ::std::size_t>& checks)
235  {
236  this->checks = checks;
237  }
238 
239  void setNodeDataMax(const ::std::size_t& nodeDataMax)
240  {
241  this->nodeDataMax = nodeDataMax;
242  }
243 
244  ::std::size_t size() const
245  {
246  return this->values;
247  }
248 
250  {
252  swap(this->mean, other.mean);
253  swap(this->metric, other.metric);
254  swap(this->samples, other.samples);
255  swap(this->root, other.root);
256  swap(this->values, other.values);
257  swap(this->var, other.var);
258  }
259 
261  {
262  lhs.swap(rhs);
263  }
264 
265  protected:
266 
267  private:
268  struct Interval;
269 
270  typedef ::std::vector<Interval> BoundingBox;
271 
272  struct Branch
273  {
274  Branch(Distance& dist, ::std::vector<Distance>& sidedist, const Node* node) :
275  dist(dist),
276  node(node),
278  {
279  }
280 
282 
283  const Node* node;
284 
285  ::std::vector<Distance> sidedist;
286  };
287 
289  {
290  bool operator()(const Branch& lhs, const Branch& rhs) const
291  {
292  return lhs.dist > rhs.dist;
293  }
294  };
295 
296  struct Cut
297  {
298  bool operator()(const Value& other) const
299  {
300  using ::std::begin;
301  return *(begin(other) + this->index) < this->value;
302  }
303 
304  Size index;
305 
307  };
308 
310  {
312  index(index)
313  {
314  }
315 
316  bool operator()(const Value& lhs, const Value& rhs) const
317  {
318  using ::std::begin;
319  return *(begin(lhs) + this->index) < *(begin(rhs) + this->index);
320  }
321 
322  Size index;
323  };
324 
325  struct Interval
326  {
328 
330  };
331 
333  {
334  bool operator()(const Neighbor& lhs, const Neighbor& rhs) const
335  {
336  return lhs.first < rhs.first;
337  }
338  };
339 
340  struct Node
341  {
342  Node() :
343  children(),
344  data(),
345  index(),
346  interval()
347  {
348  }
349 
351  {
352  }
353 
354  void swap(Node& other)
355  {
357  swap(this->children, other.children);
358  swap(this->data, other.data);
359  swap(this->index, other.index);
360  swap(this->interval, other.interval);
361  }
362 
363  friend void swap(Node& lhs, Node& rhs)
364  {
365  lhs.swap(rhs);
366  }
367 
368  ::std::array< ::std::unique_ptr<Node>, 2> children;
369 
370  ::std::vector<Value> data;
371 
373 
375  };
376 
377  template<typename InputIterator>
378  void computeBoundingBox(InputIterator first, InputIterator last, BoundingBox& boundingBox)
379  {
380  using ::std::begin;
381 
382  for (::std::size_t i = 0; i < boundingBox.size(); ++i)
383  {
384  Distance value = *(begin(*first) + i);
385  boundingBox[i].low = value;
386  boundingBox[i].high = value;
387  }
388 
389  for (InputIterator i = first + 1; i != last; ++i)
390  {
391  auto start = begin(*i);
392 
393  for (::std::size_t j = 0; j < boundingBox.size(); ++j)
394  {
395  Distance value = *(start + j);
396  boundingBox[j].low = ::std::min(value, boundingBox[j].low);
397  boundingBox[j].high = ::std::max(value, boundingBox[j].high);
398  }
399  }
400  }
401 
402  void data(const Node& node, ::std::vector<Value>& data) const
403  {
404  data.insert(data.end(), node.data.begin(), node.data.end());
405 
406  for (::std::size_t i = 0; i < node.children.size(); ++i)
407  {
408  this->data(*node.children[i], data);
409  }
410  }
411 
412  template<typename InputIterator>
413  void divide(Node& node, BoundingBox& boundingBox, InputIterator first, InputIterator last)
414  {
415  Cut cut = this->select(first, last, boundingBox);
416  node.index = cut.index;
417  InputIterator split = ::std::partition(first, last, cut);
418 
419  ::std::array<BoundingBox, 2> boundingBoxes = { boundingBox, boundingBox };
420 
421  for (::std::size_t i = 0; i < 2; ++i)
422  {
423  InputIterator begin = 0 == i ? first : split;
424  InputIterator end = 0 == i ? split : last;
425 
426  switch (i)
427  {
428  case 0:
429  boundingBoxes[i][cut.index].high = cut.value;
430  break;
431  case 1:
432  boundingBoxes[i][cut.index].low = cut.value;
433  break;
434  default:
435  break;
436  }
437 
438 #if __cplusplus > 201103L || _MSC_VER >= 1800
439  node.children[i] = ::std::make_unique<Node>();
440 #else
441  node.children[i].reset(new Node());
442 #endif
443 
444  if (::std::distance(begin, end) > this->nodeDataMax)
445  {
446  this->divide(*node.children[i], boundingBoxes[i], begin, end);
447  }
448  else
449  {
450  node.children[i]->data.insert(node.children[i]->data.end(), begin, end);
451  this->computeBoundingBox(begin, end, boundingBoxes[i]);
452  }
453  }
454 
455  node.interval.low = boundingBoxes[0][cut.index].high;
456  node.interval.high = boundingBoxes[1][cut.index].low;
457 
458  for (::std::size_t i = 0; i < boundingBox.size(); ++i)
459  {
460  boundingBox[i].low = ::std::min(boundingBoxes[0][i].low, boundingBoxes[1][i].low);
461  boundingBox[i].high = ::std::max(boundingBoxes[0][i].high, boundingBoxes[1][i].high);
462  }
463  }
464 
465  void push(Node& node, const Value& value)
466  {
467  using ::std::begin;
468  using ::std::size;
469 
470  if (nullptr == node.children[0] && nullptr == node.children[1])
471  {
472  node.data.push_back(value);
473 
474  if (node.data.size() > this->nodeDataMax)
475  {
476  BoundingBox boundingBox(size(value));
477  this->computeBoundingBox(node.data.begin(), node.data.end(), boundingBox);
478  this->divide(node, boundingBox, node.data.begin(), node.data.end());
479  node.data.clear();
480  node.data.shrink_to_fit();
481  }
482  }
483  else
484  {
485  Distance tmp = *(begin(value) + node.index);
486  Distance diff0 = tmp - node.interval.low;
487  Distance diff1 = tmp - node.interval.high;
488  Distance diff = diff0 + diff1;
489 
490  if (diff < 0)
491  {
492  this->push(*node.children[0], value);
493  node.interval.low = ::std::max(node.interval.low, tmp);
494  }
495  else
496  {
497  this->push(*node.children[1], value);
498  node.interval.high = ::std::min(node.interval.high, tmp);
499  }
500  }
501  }
502 
503  ::std::vector<Neighbor> search(const Value& query, const ::std::size_t* k, const Distance* radius, const bool& sorted) const
504  {
505  using ::std::begin;
506  using ::std::size;
507 
508  ::std::vector<Neighbor> neighbors;
509 
510  if (this->empty())
511  {
512  return neighbors;
513  }
514 
515  neighbors.reserve(nullptr != k ? *k : this->values);
516 
517  ::std::size_t checks = 0;
518 
519  Distance mindist = Distance();
520  ::std::vector<Distance> sidedist(size(query), Distance());
521 
522  for (::std::size_t i = 0; i < sidedist.size(); ++i)
523  {
524  Distance value = *(begin(query) + i);
525 
526  if (value < this->boundingBox[i].low)
527  {
528  sidedist[i] = this->metric(value, this->boundingBox[i].low, i);
529  mindist += sidedist[i];
530  }
531 
532  if (value > this->boundingBox[i].high)
533  {
534  sidedist[i] = this->metric(value, this->boundingBox[i].high, i);
535  mindist += sidedist[i];
536  }
537  }
538 
539  ::std::vector<Branch> branches;
540 
541  this->search(this->root, query, k, radius, branches, neighbors, checks, mindist, sidedist);
542 
543  while (!branches.empty() && (!this->checks || checks < this->checks))
544  {
545  Branch branch = branches.front();
546  ::std::pop_heap(branches.begin(), branches.end(), BranchCompare());
547  branches.pop_back();
548  this->search(*branch.node, query, k, radius, branches, neighbors, checks, branch.dist, branch.sidedist);
549  }
550 
551  if (sorted)
552  {
553  ::std::sort_heap(neighbors.begin(), neighbors.end(), NeighborCompare());
554  }
555 
556  if (nullptr == k)
557  {
558  neighbors.shrink_to_fit();
559  }
560 
561  return neighbors;
562  }
563 
564  void search(const Node& node, const Value& query, const ::std::size_t* k, const Distance* radius, ::std::vector<Branch>& branches, ::std::vector<Neighbor>& neighbors, ::std::size_t& checks, const Distance& mindist, const ::std::vector<Distance>& sidedist) const
565  {
566  using ::std::begin;
567 
568  if (nullptr == node.children[0] && nullptr == node.children[1])
569  {
570  for (::std::size_t i = 0; i < node.data.size(); ++i)
571  {
572  Distance distance = this->metric(query, node.data[i]);
573 
574  if (nullptr == k || neighbors.size() < *k || distance < neighbors.front().first)
575  {
576  if (nullptr == radius || distance < *radius)
577  {
578  if (nullptr != k && *k == neighbors.size())
579  {
580  ::std::pop_heap(neighbors.begin(), neighbors.end(), NeighborCompare());
581  neighbors.pop_back();
582  }
583 
584 #if (defined(_MSC_VER) && _MSC_VER < 1800) || (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 8)
585  neighbors.push_back(::std::make_pair(distance, node.data[i]));
586 #else
587  neighbors.emplace_back(::std::piecewise_construct, ::std::forward_as_tuple(distance), ::std::forward_as_tuple(node.data[i]));
588 #endif
589  ::std::push_heap(neighbors.begin(), neighbors.end(), NeighborCompare());
590  }
591  }
592 
593  if (this->checks && ++checks > this->checks)
594  {
595  return;
596  }
597  }
598  }
599  else
600  {
601  Distance value = *(begin(query) + node.index);
602  Distance diff0 = value - node.interval.low;
603  Distance diff1 = value - node.interval.high;
604  Distance diff = diff0 + diff1;
605 
606  ::std::size_t best = diff < 0 ? 0 : 1;
607  ::std::size_t worst = diff < 0 ? 1 : 0;
608 
609  this->search(*node.children[best], query, k, radius, branches, neighbors, checks, mindist, sidedist);
610 
611  Distance cutdist = this->metric(value, diff < 0 ? node.interval.high : node.interval.low, node.index);
612  Distance newdist = mindist - sidedist[node.index] + cutdist;
613 
614  if (nullptr == k || neighbors.size() < *k || newdist <= neighbors.front().first)
615  {
616  ::std::vector<Distance> newsidedist(sidedist);
617  newsidedist[node.index] = cutdist;
618 
619  if (!this->checks)
620  {
621  this->search(*node.children[worst], query, k, radius, branches, neighbors, checks, newdist, newsidedist);
622  }
623  else
624  {
625 #if defined(_MSC_VER) && _MSC_VER < 1800
626  branches.push_back(Branch(newdist, newsidedist, node.children[worst].get()));
627 #else
628  branches.emplace_back(newdist, newsidedist, node.children[worst].get());
629 #endif
630  ::std::push_heap(branches.begin(), branches.end(), BranchCompare());
631  }
632  }
633  }
634  }
635 
636  template<typename InputIterator>
637  Cut select(InputIterator first, InputIterator last, BoundingBox& boundingBox)
638  {
639  using ::std::begin;
640 
641  Cut cut;
642  cut.index = 0;
643  cut.value = (boundingBox[0].high + boundingBox[0].low) / 2;
644 
645  Distance maxSpan = boundingBox[0].high - boundingBox[0].low;
646 
647  for (::std::size_t i = 1; i < boundingBox.size(); ++i)
648  {
649  Distance span = boundingBox[i].high - boundingBox[i].low;
650 
651  if (span > maxSpan)
652  {
653  maxSpan = span;
654  cut.index = i;
655  cut.value = (boundingBox[i].high + boundingBox[i].low) / 2;
656  }
657  }
658 
659  ::std::pair<InputIterator, InputIterator> minmax = ::std::minmax_element(first, last, IndexCompare(cut.index));
660  Distance min = *(begin(*minmax.first) + cut.index);
661  Distance max = *(begin(*minmax.second) + cut.index);
662 
663  cut.value = (max + min) / 2;
664  maxSpan = max - min;
665 
666  Size index = cut.index;
667 
668  for (::std::size_t i = 0; i < boundingBox.size(); ++i)
669  {
670  if (index != i)
671  {
672  Distance span = boundingBox[i].high - boundingBox[i].low;
673 
674  if (span > maxSpan)
675  {
676  minmax = ::std::minmax_element(first, last, IndexCompare(i));
677  min = *(begin(*minmax.first) + i);
678  max = *(begin(*minmax.second) + i);
679  span = max - min;
680 
681  if (span > maxSpan)
682  {
683  maxSpan = span;
684  cut.index = i;
685  cut.value = (max + min) / 2;
686  }
687  }
688  }
689  }
690 
691  return cut;
692  }
693 
695 
696  ::boost::optional< ::std::size_t> checks;
697 
699 
700  ::std::size_t nodeDataMax;
701 
702  Node root;
703 
704  ::std::size_t values;
705  };
706  }
707 }
708 
709 #endif // RL_MATH_KDTREEBOUNDINGBOXNEARESTNEIGHBORS_H
rl::math::KdtreeBoundingBoxNearestNeighbors::Branch::dist
Distance dist
Definition: KdtreeBoundingBoxNearestNeighbors.h:281
rl::math::KdtreeBoundingBoxNearestNeighbors::search
::std::vector< Neighbor > search(const Value &query, const ::std::size_t *k, const Distance *radius, const bool &sorted) const
Definition: KdtreeBoundingBoxNearestNeighbors.h:503
rl::math::KdtreeBoundingBoxNearestNeighbors::data
::std::vector< Value > data() const
Definition: KdtreeBoundingBoxNearestNeighbors.h:139
rl::math::KdtreeBoundingBoxNearestNeighbors::reference
MetricT::Value & reference
Definition: KdtreeBoundingBoxNearestNeighbors.h:66
rl::math::KdtreeBoundingBoxNearestNeighbors::divide
void divide(Node &node, BoundingBox &boundingBox, InputIterator first, InputIterator last)
Definition: KdtreeBoundingBoxNearestNeighbors.h:413
rl::math::KdtreeBoundingBoxNearestNeighbors::getChecks
::boost::optional< ::std::size_t > getChecks() const
Definition: KdtreeBoundingBoxNearestNeighbors.h:152
rl::math::KdtreeBoundingBoxNearestNeighbors::Node::children
::std::array< ::std::unique_ptr< Node >, 2 > children
Definition: KdtreeBoundingBoxNearestNeighbors.h:368
rl::math::KdtreeBoundingBoxNearestNeighbors::KdtreeBoundingBoxNearestNeighbors
KdtreeBoundingBoxNearestNeighbors(Metric &&metric=Metric())
Definition: KdtreeBoundingBoxNearestNeighbors.h:92
rl::math::KdtreeBoundingBoxNearestNeighbors::data
void data(const Node &node, ::std::vector< Value > &data) const
Definition: KdtreeBoundingBoxNearestNeighbors.h:402
rl::math::KdtreeBoundingBoxNearestNeighbors::size
::std::size_t size() const
Definition: KdtreeBoundingBoxNearestNeighbors.h:244
rl::math::KdtreeBoundingBoxNearestNeighbors::Node::swap
friend void swap(Node &lhs, Node &rhs)
Definition: KdtreeBoundingBoxNearestNeighbors.h:363
rl::math::KdtreeBoundingBoxNearestNeighbors::Node::interval
Interval interval
Definition: KdtreeBoundingBoxNearestNeighbors.h:374
rl::math::KdtreeBoundingBoxNearestNeighbors::push
void push(Node &node, const Value &value)
Definition: KdtreeBoundingBoxNearestNeighbors.h:465
rl::math::KdtreeBoundingBoxNearestNeighbors::swap
friend void swap(KdtreeBoundingBoxNearestNeighbors &lhs, KdtreeBoundingBoxNearestNeighbors &rhs)
Definition: KdtreeBoundingBoxNearestNeighbors.h:260
rl::math::KdtreeBoundingBoxNearestNeighbors::push
void push(const Value &value)
Definition: KdtreeBoundingBoxNearestNeighbors.h:198
rl::math::KdtreeBoundingBoxNearestNeighbors::clear
void clear()
Definition: KdtreeBoundingBoxNearestNeighbors.h:130
rl::math::KdtreeBoundingBoxNearestNeighbors::size_type
::std::size_t size_type
Definition: KdtreeBoundingBoxNearestNeighbors.h:68
rl::math::KdtreeBoundingBoxNearestNeighbors::Node::swap
void swap(Node &other)
Definition: KdtreeBoundingBoxNearestNeighbors.h:354
rl::math::KdtreeBoundingBoxNearestNeighbors::IndexCompare
Definition: KdtreeBoundingBoxNearestNeighbors.h:310
rl::math::KdtreeBoundingBoxNearestNeighbors::values
::std::size_t values
Definition: KdtreeBoundingBoxNearestNeighbors.h:704
rl::math::KdtreeBoundingBoxNearestNeighbors
k-d tree.
Definition: KdtreeBoundingBoxNearestNeighbors.h:57
rl::math::KdtreeBoundingBoxNearestNeighbors::Size
MetricT::Size Size
Definition: KdtreeBoundingBoxNearestNeighbors.h:76
rl::math::KdtreeBoundingBoxNearestNeighbors::~KdtreeBoundingBoxNearestNeighbors
~KdtreeBoundingBoxNearestNeighbors()
Definition: KdtreeBoundingBoxNearestNeighbors.h:126
rl::math::KdtreeBoundingBoxNearestNeighbors::Node::~Node
~Node()
Definition: KdtreeBoundingBoxNearestNeighbors.h:350
rl::math::KdtreeBoundingBoxNearestNeighbors::Branch::node
const Node * node
Definition: KdtreeBoundingBoxNearestNeighbors.h:283
rl::math::KdtreeBoundingBoxNearestNeighbors::Branch::Branch
Branch(Distance &dist, ::std::vector< Distance > &sidedist, const Node *node)
Definition: KdtreeBoundingBoxNearestNeighbors.h:274
rl::math::KdtreeBoundingBoxNearestNeighbors::Value
MetricT::Value Value
Definition: KdtreeBoundingBoxNearestNeighbors.h:78
rl::math::KdtreeBoundingBoxNearestNeighbors::Node::data
::std::vector< Value > data
Definition: KdtreeBoundingBoxNearestNeighbors.h:370
rl::math::KdtreeBoundingBoxNearestNeighbors::root
Node root
Definition: KdtreeBoundingBoxNearestNeighbors.h:702
rl::math::KdtreeBoundingBoxNearestNeighbors::metric
Metric metric
Definition: KdtreeBoundingBoxNearestNeighbors.h:698
rl::math::KdtreeBoundingBoxNearestNeighbors::getNodeDataMax
::std::size_t getNodeDataMax() const
Definition: KdtreeBoundingBoxNearestNeighbors.h:157
rl::math::KdtreeBoundingBoxNearestNeighbors::NeighborCompare::operator()
bool operator()(const Neighbor &lhs, const Neighbor &rhs) const
Definition: KdtreeBoundingBoxNearestNeighbors.h:334
rl::math::KdtreeBoundingBoxNearestNeighbors::KdtreeBoundingBoxNearestNeighbors
KdtreeBoundingBoxNearestNeighbors(InputIterator first, InputIterator last, Metric &&metric=Metric())
Definition: KdtreeBoundingBoxNearestNeighbors.h:115
rl::math::KdtreeBoundingBoxNearestNeighbors::IndexCompare::index
Size index
Definition: KdtreeBoundingBoxNearestNeighbors.h:322
rl::math::KdtreeBoundingBoxNearestNeighbors::Neighbor
::std::pair< Distance, Value > Neighbor
Definition: KdtreeBoundingBoxNearestNeighbors.h:80
rl::math::KdtreeBoundingBoxNearestNeighbors::NeighborCompare
Definition: KdtreeBoundingBoxNearestNeighbors.h:333
rl::math::KdtreeBoundingBoxNearestNeighbors::Cut
Definition: KdtreeBoundingBoxNearestNeighbors.h:297
rl::math::KdtreeBoundingBoxNearestNeighbors::IndexCompare::operator()
bool operator()(const Value &lhs, const Value &rhs) const
Definition: KdtreeBoundingBoxNearestNeighbors.h:316
rl::math::KdtreeBoundingBoxNearestNeighbors::setChecks
void setChecks(const ::boost::optional< ::std::size_t > &checks)
Definition: KdtreeBoundingBoxNearestNeighbors.h:234
rl::math::KdtreeBoundingBoxNearestNeighbors::nearest
::std::vector< Neighbor > nearest(const Value &query, const ::std::size_t &k, const bool &sorted=true) const
Definition: KdtreeBoundingBoxNearestNeighbors.h:193
std::swap
void swap(::rl::util::rtai::thread &x, ::rl::util::rtai::thread &y)
Definition: thread.h:492
rl::math::KdtreeBoundingBoxNearestNeighbors::Node::Node
Node()
Definition: KdtreeBoundingBoxNearestNeighbors.h:342
rl::math::KdtreeBoundingBoxNearestNeighbors::Distance
MetricT::Distance Distance
Definition: KdtreeBoundingBoxNearestNeighbors.h:72
rl::math::KdtreeBoundingBoxNearestNeighbors::BoundingBox
::std::vector< Interval > BoundingBox
Definition: KdtreeBoundingBoxNearestNeighbors.h:268
rl::math::KdtreeBoundingBoxNearestNeighbors::Cut::operator()
bool operator()(const Value &other) const
Definition: KdtreeBoundingBoxNearestNeighbors.h:298
rl::math::KdtreeBoundingBoxNearestNeighbors::swap
void swap(KdtreeBoundingBoxNearestNeighbors &other)
Definition: KdtreeBoundingBoxNearestNeighbors.h:249
rl::math::KdtreeBoundingBoxNearestNeighbors::empty
bool empty() const
Definition: KdtreeBoundingBoxNearestNeighbors.h:147
rl::math::KdtreeBoundingBoxNearestNeighbors::Branch::sidedist
::std::vector< Distance > sidedist
Definition: KdtreeBoundingBoxNearestNeighbors.h:285
rl::math::KdtreeBoundingBoxNearestNeighbors::KdtreeBoundingBoxNearestNeighbors
KdtreeBoundingBoxNearestNeighbors(InputIterator first, InputIterator last, const Metric &metric)
Definition: KdtreeBoundingBoxNearestNeighbors.h:103
rl::math::KdtreeBoundingBoxNearestNeighbors::BranchCompare::operator()
bool operator()(const Branch &lhs, const Branch &rhs) const
Definition: KdtreeBoundingBoxNearestNeighbors.h:290
rl::math::KdtreeBoundingBoxNearestNeighbors::checks
::boost::optional< ::std::size_t > checks
Definition: KdtreeBoundingBoxNearestNeighbors.h:696
rl::math::KdtreeBoundingBoxNearestNeighbors::Node
Definition: KdtreeBoundingBoxNearestNeighbors.h:341
rl::math::KdtreeBoundingBoxNearestNeighbors::Interval::low
Distance low
Definition: KdtreeBoundingBoxNearestNeighbors.h:329
rl::math::KdtreeBoundingBoxNearestNeighbors::select
Cut select(InputIterator first, InputIterator last, BoundingBox &boundingBox)
Definition: KdtreeBoundingBoxNearestNeighbors.h:637
rl::plan::Metric
Definition: Metric.h:40
rl::math::KdtreeBoundingBoxNearestNeighbors::BranchCompare
Definition: KdtreeBoundingBoxNearestNeighbors.h:289
rl::math::KdtreeBoundingBoxNearestNeighbors::Branch
Definition: KdtreeBoundingBoxNearestNeighbors.h:273
rl::math::KdtreeBoundingBoxNearestNeighbors::Interval
Definition: KdtreeBoundingBoxNearestNeighbors.h:326
rl::math::KdtreeBoundingBoxNearestNeighbors::const_reference
const MetricT::Value & const_reference
Definition: KdtreeBoundingBoxNearestNeighbors.h:59
rl::math::KdtreeBoundingBoxNearestNeighbors::IndexCompare::IndexCompare
IndexCompare(const Size &index)
Definition: KdtreeBoundingBoxNearestNeighbors.h:311
std
Definition: thread.h:482
rl::math::KdtreeBoundingBoxNearestNeighbors::nodeDataMax
::std::size_t nodeDataMax
Definition: KdtreeBoundingBoxNearestNeighbors.h:700
rl::math::KdtreeBoundingBoxNearestNeighbors::Cut::index
Size index
Definition: KdtreeBoundingBoxNearestNeighbors.h:304
rl::math::KdtreeBoundingBoxNearestNeighbors::search
void search(const Node &node, const Value &query, const ::std::size_t *k, const Distance *radius, ::std::vector< Branch > &branches, ::std::vector< Neighbor > &neighbors, ::std::size_t &checks, const Distance &mindist, const ::std::vector< Distance > &sidedist) const
Definition: KdtreeBoundingBoxNearestNeighbors.h:564
distance
Scalar distance(const Transform< Scalar, Dim, Mode, Options > &other, const Scalar &weight=1) const
Definition: TransformAddons.h:33
rl::math::KdtreeBoundingBoxNearestNeighbors::value_type
MetricT::Value value_type
Definition: KdtreeBoundingBoxNearestNeighbors.h:70
rl::math::KdtreeBoundingBoxNearestNeighbors::Metric
MetricT Metric
Definition: KdtreeBoundingBoxNearestNeighbors.h:74
rl::math::KdtreeBoundingBoxNearestNeighbors::difference_type
::std::ptrdiff_t difference_type
Definition: KdtreeBoundingBoxNearestNeighbors.h:64
rl::math::KdtreeBoundingBoxNearestNeighbors::radius
::std::vector< Neighbor > radius(const Value &query, const Distance &radius, const bool &sorted=true) const
Definition: KdtreeBoundingBoxNearestNeighbors.h:229
rl::math::KdtreeBoundingBoxNearestNeighbors::boundingBox
BoundingBox boundingBox
Definition: KdtreeBoundingBoxNearestNeighbors.h:694
rl::math::KdtreeBoundingBoxNearestNeighbors::Node::index
Size index
Definition: KdtreeBoundingBoxNearestNeighbors.h:372
rl::math::KdtreeBoundingBoxNearestNeighbors::Cut::value
Distance value
Definition: KdtreeBoundingBoxNearestNeighbors.h:306
rl::math::KdtreeBoundingBoxNearestNeighbors::setNodeDataMax
void setNodeDataMax(const ::std::size_t &nodeDataMax)
Definition: KdtreeBoundingBoxNearestNeighbors.h:239
rl::math::KdtreeBoundingBoxNearestNeighbors::computeBoundingBox
void computeBoundingBox(InputIterator first, InputIterator last, BoundingBox &boundingBox)
Definition: KdtreeBoundingBoxNearestNeighbors.h:378
rl::math::KdtreeBoundingBoxNearestNeighbors::Interval::high
Distance high
Definition: KdtreeBoundingBoxNearestNeighbors.h:327
rl::math::KdtreeBoundingBoxNearestNeighbors::KdtreeBoundingBoxNearestNeighbors
KdtreeBoundingBoxNearestNeighbors(const Metric &metric)
Definition: KdtreeBoundingBoxNearestNeighbors.h:82
rl::math::KdtreeBoundingBoxNearestNeighbors::insert
void insert(InputIterator first, InputIterator last)
Definition: KdtreeBoundingBoxNearestNeighbors.h:163
rl
Robotics Library.
Definition: AnalogInput.cpp:30