9#include "../../indexSquaredDistance.h"
10#include "../../../Common/Containers/stack.h"
13template <
typename Traits>
class KdTreeBase;
15template <
typename Traits>
19 using DataPoint =
typename Traits::DataPoint;
20 using IndexType =
typename Traits::IndexType;
21 using Scalar =
typename DataPoint::Scalar;
22 using VectorType =
typename DataPoint::VectorType;
39 template<
typename LeafPreparationFunctor,
40 typename DescentDistanceThresholdFunctor,
41 typename SkipIndexFunctor,
42 typename ProcessNeighborFunctor>
44 LeafPreparationFunctor prepareLeafTraversal,
45 DescentDistanceThresholdFunctor descentDistanceThreshold,
46 SkipIndexFunctor skipFunctor,
47 ProcessNeighborFunctor processNeighborFunctor
50 const auto& nodes =
m_kdtree->nodes();
51 const auto& points =
m_kdtree->points();
53 if (nodes.empty() || points.empty() ||
m_kdtree->sample_count() == 0)
59 const auto& node = nodes[qnode.index];
61 if(qnode.squared_distance < descentDistanceThreshold())
66 IndexType start = node.leaf_start();
67 IndexType end = node.leaf_start() + node.leaf_size();
68 prepareLeafTraversal(start, end);
69 for(IndexType i=start; i<end; ++i)
71 IndexType idx =
m_kdtree->pointFromSample(i);
72 if(skipFunctor(idx))
continue;
74 Scalar d = (point - points[idx].pos()).squaredNorm();
76 if(d < descentDistanceThreshold())
78 if( processNeighborFunctor( idx, i, d ))
return false;
85 Scalar newOff = point[node.inner_split_dim()] - node.inner_split_value();
89 m_stack.top().index = node.inner_first_child_id();
90 qnode.index = node.inner_first_child_id()+1;
94 m_stack.top().index = node.inner_first_child_id()+1;
95 qnode.index = node.inner_first_child_id();
97 m_stack.top().squared_distance = qnode.squared_distance;
98 qnode.squared_distance = newOff*newOff;
[KdTreeSparse type definition]
void reset()
Init stack for a new search.
Stack< IndexSquaredDistance< IndexType, Scalar >, 2 *Traits::MAX_DEPTH > m_stack
[KdTreeQuery kdtree type]
bool search_internal(const VectorType &point, LeafPreparationFunctor prepareLeafTraversal, DescentDistanceThresholdFunctor descentDistanceThreshold, SkipIndexFunctor skipFunctor, ProcessNeighborFunctor processNeighborFunctor)
const KdTreeBase< Traits > * m_kdtree
[KdTreeQuery kdtree type]
Stack with fixed-size storage.
This Source Code Form is subject to the terms of the Mozilla Public License, v.