Ponca  19ef58fd3760f23a8af99a5eeac4f934757e30d9
Point Cloud Analysis library
Loading...
Searching...
No Matches
kdTreeKNearestQueries.h
1/*
2 This Source Code Form is subject to the terms of the Mozilla Public
3 License, v. 2.0. If a copy of the MPL was not distributed with this
4 file, You can obtain one at http://mozilla.org/MPL/2.0/.
5*/
6
7#pragma once
8
9#include "kdTreeQuery.h"
10#include "../../query.h"
11#include "../Iterator/kdTreeKNearestIterator.h"
12
13namespace Ponca
14{
15
23 template <typename Traits, template <typename, typename> typename IteratorType, typename QueryType>
24 class KdTreeKNearestQueryBase : public KdTreeQuery<Traits>, public QueryType
25 {
26 public:
27 using DataPoint = typename Traits::DataPoint;
28 using IndexType = typename Traits::IndexType;
29 using Scalar = typename DataPoint::Scalar;
30 using VectorType = typename DataPoint::VectorType;
32 using Iterator = IteratorType<typename Traits::IndexType, typename Traits::DataPoint>;
34
35 PONCA_MULTIARCH inline KdTreeKNearestQueryBase(const StaticKdTreeBase<Traits>* kdtree, IndexType k,
36 typename QueryType::InputType input)
37 : KdTreeQuery<Traits>(kdtree), QueryType(k, input)
38 {
39 }
40
42 PONCA_MULTIARCH inline Self& operator()(typename QueryType::InputType input, IndexType k)
43 {
44 return QueryType::template operator()<Self>(input, k);
45 }
47 PONCA_MULTIARCH inline Self& operator()(typename QueryType::InputType input)
48 {
49 return QueryType::template operator()<Self>(input);
50 }
51
53 PONCA_MULTIARCH inline Iterator begin()
54 {
56 QueryType::reset();
57 this->search();
58 return Iterator(QueryType::m_queue.begin());
59 }
60
62 PONCA_MULTIARCH inline Iterator end() { return Iterator(QueryType::m_queue.end()); }
63
64 protected:
65 PONCA_MULTIARCH inline void search()
66 {
68 QueryType::template getInputPosition<VectorType>(QueryAccelType::m_kdtree->points()),
69 [](IndexType, IndexType) {}, [this]() { return QueryType::descentDistanceThreshold(); },
70 [this](IndexType idx) { return QueryType::skipIndexFunctor(idx); },
71 [this](IndexType idx, IndexType, Scalar d) {
72 QueryType::m_queue.push({idx, d});
73 return false;
74 });
75 }
76 };
83 template <typename Traits>
93 template <typename Traits>
97} // namespace Ponca
Input iterator to read the KdTreeKNearestQueryBase object.
Extension of the Query class that allows to read the result of a k-nearest neighbors search on the Kd...
Self & operator()(typename QueryType::InputType input, IndexType k)
Call the k-nearest neighbors query with new input and neighbor number parameters.
Self & operator()(typename QueryType::InputType input)
Call the k-nearest neighbors query with new input parameter.
Iterator end()
Returns an iterator to the end of the k-nearest neighbors query.
Iterator begin()
Returns an iterator to the beginning of the k-nearest neighbors query.
Query object that provides a method to search neighbors on the KdTree depending on a distance thresho...
Definition kdTreeQuery.h:24
const StaticKdTreeBase< Traits > * m_kdtree
[KdTreeQuery kdtree type]
Definition kdTreeQuery.h:45
void reset()
Init stack for a new search.
Definition kdTreeQuery.h:38
bool searchInternal(const VectorType &point, LeafPreparationFunctor prepareLeafTraversal, DescentDistanceThresholdFunctor descentDistanceThreshold, SkipIndexFunctor skipFunctor, ProcessNeighborFunctor processNeighborFunctor)
Search internally the neighbors of a point using the kdtree.
Definition kdTreeQuery.h:53
Customizable static base class for KdTree datastructure implementations.
Definition kdTree.h:138
Base Query class combining QueryInputIsIndex and QueryOutputIsKNearest.
Definition query.h:373
Base Query class combining QueryInputIsPosition and QueryOutputIsKNearest.
Definition query.h:376
This Source Code Form is subject to the terms of the Mozilla Public License, v.