Ponca  84886bac0b52a686e88046a375da13f12f2b87d2
Point Cloud Analysis library
Loading...
Searching...
No Matches
kdTreeRangeQueries.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/kdTreeRangeIterator.h"
12
13namespace Ponca {
14
22template <typename Traits,
23 template <typename,typename,typename> typename IteratorType,
24 typename QueryType>
25class KdTreeRangeQueryBase : public KdTreeQuery<Traits>, public QueryType
26 //public RangeIndexQuery<typename Traits::IndexType, typename Traits::DataPoint::Scalar>
27{
28public:
29 using DataPoint = typename Traits::DataPoint;
30 using IndexType = typename Traits::IndexType;
31 using Scalar = typename DataPoint::Scalar;
32 using VectorType = typename DataPoint::VectorType;
34 using Iterator = IteratorType<IndexType, DataPoint, KdTreeRangeQueryBase>;
36
37protected:
38 friend Iterator;
39
40public:
41 KdTreeRangeQueryBase(const KdTreeBase<Traits>* kdtree, Scalar radius, typename QueryType::InputType input) :
42 KdTreeQuery<Traits>(kdtree), QueryType(radius, input){}
43
45 inline Self& operator()(typename QueryType::InputType input, Scalar radius)
46 {
47 return QueryType::template operator()<Self>(input, radius);
48 }
49
51 inline Self& operator()(typename QueryType::InputType input)
52 {
53 return QueryType::template operator()<Self>(input);
54 }
55
57 inline Iterator begin(){
59 QueryType::reset();
60 Iterator it(this);
61 this->advance(it);
62 return it;
63 }
64
66 inline Iterator end(){
67 return Iterator(this, QueryAccelType::m_kdtree->pointCount());
68 }
69
70protected:
71 inline void advance(Iterator& it){
72 const auto& points = QueryAccelType::m_kdtree->points();
73 const auto& indices = QueryAccelType::m_kdtree->samples();
74 const auto& point = QueryType::getInputPosition(points);
75
76 if (points.empty() || indices.empty())
77 {
78 it = end();
79 return;
80 }
81
82 auto descentDistanceThreshold = [this](){return QueryType::descentDistanceThreshold();};
83 auto skipFunctor = [this](IndexType idx){return QueryType::skipIndexFunctor(idx);};
84 auto processNeighborFunctor = [&it](IndexType idx, IndexType i, Scalar)
85 {
86 it.m_index = idx;
87 it.m_start = i+1;
88 return true;
89 };
90
91 for(IndexType i=it.m_start; i<it.m_end; ++i)
92 {
93 IndexType idx = indices[i];
94 if(skipFunctor(idx)) continue;
95
96 Scalar d = (point - points[idx].pos()).squaredNorm();
97 if(d < descentDistanceThreshold())
98 {
99 if( processNeighborFunctor(idx, i, d) ) return;
100 }
101 }
102
104 [&it](IndexType start, IndexType end)
105 {
106 it.m_start = start;
107 it.m_end = end;
108 },
109 descentDistanceThreshold,
110 skipFunctor,
111 processNeighborFunctor))
112 it.m_index = static_cast<IndexType>(points.size());
113 }
114};
115
122template <typename Traits>
131template <typename Traits>
134} // namespace ponca
[KdTreeSparse type definition]
Definition kdTree.h:104
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
Input iterator to read the KdTreeRangeQueryBase object.
Extension of the Query class that allows to read the result of a range neighbors search on the KdTree...
Iterator begin()
Returns an iterator to the beginning of the Range Query.
Self & operator()(typename QueryType::InputType input, Scalar radius)
Call the range neighbors query with new input and radius parameters.
Self & operator()(typename QueryType::InputType input)
Call the range neighbors query with new input parameter.
Iterator end()
Returns an iterator to the end of the Range Query.
Base Query class combining QueryInputIsIndex and QueryOutputIsRange.
Definition query.h:354
Base Query class combining QueryInputIsPosition and QueryOutputIsRange.
Definition query.h:357
This Source Code Form is subject to the terms of the Mozilla Public License, v.