Ponca  82fc77e8c6294111c6f00670e92ec58a24e2ecf2
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{
15
23 template <typename Traits, template <typename, typename, typename> typename IteratorType, typename QueryType>
24 class KdTreeRangeQueryBase : public KdTreeQuery<Traits>, public QueryType
25 // public RangeIndexQuery<typename Traits::IndexType, typename Traits::DataPoint::Scalar>
26 {
27 public:
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<IndexType, DataPoint, KdTreeRangeQueryBase>;
35
36 protected:
37 friend Iterator;
38
39 public:
40 PONCA_MULTIARCH KdTreeRangeQueryBase(const StaticKdTreeBase<Traits>* kdtree, Scalar radius,
41 typename QueryType::InputType input)
42 : KdTreeQuery<Traits>(kdtree), QueryType(radius, input)
43 {
44 }
45
47 PONCA_MULTIARCH inline Self& operator()(typename QueryType::InputType input, Scalar radius)
48 {
49 return QueryType::template operator()<Self>(input, radius);
50 }
51
53 PONCA_MULTIARCH inline Self& operator()(typename QueryType::InputType input)
54 {
55 return QueryType::template operator()<Self>(input);
56 }
57
59 PONCA_MULTIARCH inline Iterator begin()
60 {
62 QueryType::reset();
63 Iterator it(this);
64 this->advance(it);
65 return it;
66 }
67
69 PONCA_MULTIARCH inline Iterator end() { return Iterator(this, QueryAccelType::m_kdtree->pointCount()); }
70
71 protected:
72 PONCA_MULTIARCH inline void advance(Iterator& it)
73 {
74 const auto& points = QueryAccelType::m_kdtree->points();
75 const auto& indices = QueryAccelType::m_kdtree->samples();
76 const auto& point = QueryType::template getInputPosition<VectorType>(points);
77
78 if (QueryAccelType::m_kdtree->pointCount() == 0 || QueryAccelType::m_kdtree->sampleCount() == 0)
79 {
80 it = end();
81 return;
82 }
83
84 auto descentDistanceThreshold = [this]() { return QueryType::descentDistanceThreshold(); };
85 auto skipFunctor = [this](IndexType idx) { return QueryType::skipIndexFunctor(idx); };
86 auto processNeighborFunctor = [&it](IndexType idx, IndexType i, Scalar) {
87 it.m_index = idx;
88 it.m_start = i + 1;
89 return true;
90 };
91
92 for (IndexType i = it.m_start; i < it.m_end; ++i)
93 {
94 IndexType idx = indices[i];
95 if (skipFunctor(idx))
96 continue;
97
98 Scalar d = (point - points[idx].pos()).squaredNorm();
99 if (d < descentDistanceThreshold())
100 {
101 if (processNeighborFunctor(idx, i, d))
102 return;
103 }
104 }
105
107 point,
108 [&it](IndexType start, IndexType end) {
109 it.m_start = start;
110 it.m_end = end;
111 },
112 descentDistanceThreshold, skipFunctor, processNeighborFunctor))
113 it.m_index = static_cast<IndexType>(QueryAccelType::m_kdtree->pointCount());
114 }
115 };
116
123 template <typename Traits>
133 template <typename Traits>
137} // namespace Ponca
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
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.
Customizable static base class for KdTree datastructure implementations.
Definition kdTree.h:138
IndexType pointCount() const
Get the number of points.
Definition kdTree.h:219
PointContainer & points()
Get the internal point container.
Definition kdTree.h:225
const IndexContainer & samples() const
Get the internal indice container.
Definition kdTree.h:234
Composes the Query object depending on an input type and output type.
Definition query.h:294
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11