Ponca  e26a0e88a45818354616c1a7180bcd203aecad3c
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
15template <typename Traits,
16 template <typename,typename,typename> typename IteratorType,
17 typename QueryType>
18class KdTreeRangeQueryBase : public KdTreeQuery<Traits>, public QueryType
19 //public RangeIndexQuery<typename Traits::IndexType, typename Traits::DataPoint::Scalar>
20{
21public:
22 using DataPoint = typename Traits::DataPoint;
23 using IndexType = typename Traits::IndexType;
24 using Scalar = typename DataPoint::Scalar;
25 using VectorType = typename DataPoint::VectorType;
27 using Iterator = IteratorType<IndexType, DataPoint, KdTreeRangeQueryBase>;
28
29protected:
30 friend Iterator;
31
32public:
33 KdTreeRangeQueryBase(const KdTreeBase<Traits>* kdtree, Scalar radius, typename QueryType::InputType input) :
34 KdTreeQuery<Traits>(kdtree), QueryType(radius, input){}
35
36public:
37 inline Iterator begin(){
39 QueryType::reset();
40 Iterator it(this);
41 this->advance(it);
42 return it;
43 }
44 inline Iterator end(){
45 return Iterator(this, QueryAccelType::m_kdtree->point_count());
46 }
47
48protected:
49 inline void advance(Iterator& it){
50 const auto& points = QueryAccelType::m_kdtree->points();
51 const auto& indices = QueryAccelType::m_kdtree->samples();
52 const auto& point = QueryType::getInputPosition(points);
53
54 if (points.empty() || indices.empty())
55 {
56 it = end();
57 return;
58 }
59
60 auto descentDistanceThreshold = [this](){return QueryType::descentDistanceThreshold();};
61 auto skipFunctor = [this](IndexType idx){return QueryType::skipIndexFunctor(idx);};
62 auto processNeighborFunctor = [&it](IndexType idx, IndexType i, Scalar)
63 {
64 it.m_index = idx;
65 it.m_start = i+1;
66 return true;
67 };
68
69 for(IndexType i=it.m_start; i<it.m_end; ++i)
70 {
71 IndexType idx = indices[i];
72 if(skipFunctor(idx)) continue;
73
74 Scalar d = (point - points[idx].pos()).squaredNorm();
75 if(d < descentDistanceThreshold())
76 {
77 if( processNeighborFunctor(idx, i, d) ) return;
78 }
79 }
80
82 [&it](IndexType start, IndexType end)
83 {
84 it.m_start = start;
85 it.m_end = end;
86 },
87 descentDistanceThreshold,
88 skipFunctor,
89 processNeighborFunctor))
90 it.m_index = static_cast<IndexType>(points.size());
91 }
92};
93
94template <typename Traits>
97template <typename Traits>
100} // namespace ponca
[KdTreeSparse type definition]
Definition: kdTree.h:104
void reset()
Init stack for a new search.
Definition: kdTreeQuery.h:28
const KdTreeBase< Traits > * m_kdtree
[KdTreeQuery kdtree type]
Definition: kdTreeQuery.h:34
Base Query class combining QueryInputIsIndex and QueryOutputIsRange.
Definition: query.h:205
Base Query class combining QueryInputIsPosition and QueryOutputIsRange.
Definition: query.h:208
This Source Code Form is subject to the terms of the Mozilla Public License, v.