Ponca  f5b8b13495108d95baa74f687c24d962f21272fc
Point Cloud Analysis library
Loading...
Searching...
No Matches
knnGraphKNearestQuery.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 "../../query.h"
10#include "../Iterator/knnGraphRangeIterator.h"
11#include <vector>
12
13namespace Ponca {
14
15template <typename Traits>class KnnGraphBase; // Need forward declaration to avoid mutual inclusion
16
17
18#ifndef PARSED_WITH_DOXYGEN
19struct KnnGraphQueryOutputType : public QueryOutputBase{
20 using OutputParameter = typename QueryOutputBase::DummyOutputParameter;
21};
22#endif
23
31template <typename Traits>class KnnGraphKNearestQuery
32#ifdef PARSED_WITH_DOXYGEN
33: public KNearestIndexQuery<typename Traits::IndexType, typename Traits::DataPoint::Scalar>
34#else
35 // we skip output because we don't need it: k is static, and already stored in the index array
36: public Query<QueryInputIsIndex<typename Traits::IndexType>,KnnGraphQueryOutputType>
37#endif
38{
39public:
40 using Iterator = typename Traits::IndexContainer::const_iterator;
41#ifdef PARSED_WITH_DOXYGEN
43#else
45#endif
47
48public:
49 inline KnnGraphKNearestQuery(const KnnGraphBase<Traits>* graph, int index)
50 : QueryType(index), m_graph(graph){}
51
53 inline Self& operator()(int index) {
54 return QueryType::template operator()<Self>(index);
55 }
56
58 inline Iterator begin() const{
59 return m_graph->index_data().begin() + QueryType::input() * m_graph->k();
60 }
61
63 inline Iterator end() const{
64 return m_graph->index_data().begin() + (QueryType::input()+1) * m_graph->k();
65 }
66
67protected:
68 const KnnGraphBase<Traits>* m_graph {nullptr};
69};
70
71} // namespace Ponca
Customizable base class for KnnGraph datastructure.
Definition knnGraph.h:45
Extension of the Query class that allows to read the result of a k-nearest neighbors search on the Kn...
Self & operator()(int index)
Call the k-nearest neighbors query with new input parameter.
Iterator end() const
Returns an iterator to the end of the k-nearest neighbors query.
Iterator begin() const
Returns an iterator to the beginning of the k-nearest neighbors query.
const InputType & input() const
Read access to the input.
Definition query.h:102
Base Query class combining QueryInputIsIndex and QueryOutputIsKNearest.
Definition query.h:352
Composes the Query object depending on an input type and output type.
Definition query.h:316
This Source Code Form is subject to the terms of the Mozilla Public License, v.