Ponca  84886bac0b52a686e88046a375da13f12f2b87d2
Point Cloud Analysis library
Loading...
Searching...
No Matches
kdTreeNearestQueries.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/kdTreeNearestIterator.h"
12
13namespace Ponca {
14
22template <typename Traits,
23 template <typename> typename IteratorType,
24 typename QueryType>
25class KdTreeNearestQueryBase : 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>;
34
35 KdTreeNearestQueryBase(const KdTreeBase<Traits>* kdtree, typename QueryType::InputType input) :
36 KdTreeQuery<Traits>(kdtree), QueryType(input){}
37
39 inline Iterator begin(){
41 QueryType::reset();
42 this->search();
43 return Iterator(QueryType::m_nearest);
44 }
45
47 inline Iterator end(){
48 return Iterator(QueryType::m_nearest + 1);
49 }
50
51protected:
52 inline void search(){
53 KdTreeQuery<Traits>::searchInternal(QueryType::getInputPosition(QueryAccelType::m_kdtree->points()),
54 [](IndexType, IndexType){},
55 [this](){return QueryType::descentDistanceThreshold();},
56 [this](IndexType idx){return QueryType::skipIndexFunctor(idx);},
57 [this](IndexType idx, IndexType, Scalar d)
58 {
59 QueryType::m_nearest = idx;
60 QueryType::m_squared_distance = d;
61 return false;
62 }
63 );
64 }
65};
72template <typename Traits>
75
82template <typename Traits>
85} // 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 nearest neighbor search on the KdTre...
Iterator end()
Returns an iterator to the end of the nearest neighbor query.
Iterator begin()
Returns an iterator to the beginning of the nearest neighbor 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 QueryOutputIsNearest.
Definition query.h:353
Base Query class combining QueryInputIsPosition and QueryOutputIsNearest.
Definition query.h:356
This Source Code Form is subject to the terms of the Mozilla Public License, v.