Ponca  84886bac0b52a686e88046a375da13f12f2b87d2
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
22template <typename Traits,
23 template <typename, typename> typename IteratorType,
24 typename QueryType>
25class KdTreeKNearestQueryBase : public KdTreeQuery<Traits>, public QueryType
26{
27public:
28 using DataPoint = typename Traits::DataPoint;
29 using IndexType = typename Traits::IndexType;
30 using Scalar = typename DataPoint::Scalar;
31 using VectorType = typename DataPoint::VectorType;
33 using Iterator = IteratorType<typename Traits::IndexType, typename Traits::DataPoint>;
35
36 inline KdTreeKNearestQueryBase(const KdTreeBase<Traits>* kdtree, IndexType k, typename QueryType::InputType input) :
37 KdTreeQuery<Traits>(kdtree), QueryType(k, input) { }
38
40 inline Self& operator()(typename QueryType::InputType input, IndexType k)
41 {
42 return QueryType::template operator()<Self>(input, k);
43 }
45 inline Self& operator()(typename QueryType::InputType input)
46 {
47 return QueryType::template operator()<Self>(input);
48 }
49
51 inline Iterator begin(){
53 QueryType::reset();
54 this->search();
55 return Iterator(QueryType::m_queue.begin());
56 }
57
59 inline Iterator end(){
60 return Iterator(QueryType::m_queue.end());
61 }
62
63protected:
64 inline void search(){
65 KdTreeQuery<Traits>::searchInternal(QueryType::getInputPosition(QueryAccelType::m_kdtree->points()),
66 [](IndexType, IndexType){},
67 [this](){return QueryType::descentDistanceThreshold();},
68 [this](IndexType idx){return QueryType::skipIndexFunctor(idx);},
69 [this](IndexType idx, IndexType, Scalar d){QueryType::m_queue.push({idx, d}); return false;}
70 );
71 }
72};
79template <typename Traits>
88template <typename Traits>
91} // namespace ponca
[KdTreeSparse type definition]
Definition kdTree.h:104
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:22
void reset()
Init stack for a new search.
Definition kdTreeQuery.h:33
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:49
const KdTreeBase< Traits > * m_kdtree
[KdTreeQuery kdtree type]
Definition kdTreeQuery.h:39
Base Query class combining QueryInputIsIndex and QueryOutputIsKNearest.
Definition query.h:352
Base Query class combining QueryInputIsPosition and QueryOutputIsKNearest.
Definition query.h:355
This Source Code Form is subject to the terms of the Mozilla Public License, v.