9#include "./knnGraphTraits.h"
11#include "Query/knnGraphKNearestQuery.h"
12#include "Query/knnGraphRangeQuery.h"
14#include "../KdTree/kdTree.h"
20template <
typename Traits>
class KnnGraphBase;
30template <
typename DataPo
int>
48 using Scalar =
typename DataPoint::Scalar;
51 using IndexType =
typename Traits::IndexType;
70 template<
typename KdTreeTraits>
72 : m_k(std::min(
k,kdtree.sample_count()-1)),
73 m_kdTreePoints(kdtree.points())
75 static_assert( std::is_same<typename Traits::DataPoint, typename KdTreeTraits::DataPoint>::value,
76 "KdTreeTraits::DataPoint is not equal to Traits::DataPoint" );
77 static_assert( std::is_same<typename Traits::PointContainer, typename KdTreeTraits::PointContainer>::value,
78 "KdTreeTraits::PointContainer is not equal to Traits::PointContainer" );
79 static_assert( std::is_same<typename Traits::IndexContainer, typename KdTreeTraits::IndexContainer>::value,
80 "KdTreeTraits::IndexContainer is not equal to Traits::IndexContainer" );
85 const int cloudSize = kdtree.pointCount();
87 const int samplesSize = kdtree.sample_count();
88 eigen_assert(cloudSize == samplesSize);
91 m_indices.resize(cloudSize * m_k, -1);
93#pragma omp parallel for shared(kdtree, cloudSize) default(none)
94 for(
int i=0; i<cloudSize; ++i)
98 typename KdTreeTraits::IndexType(m_k)))
100 m_indices[i * m_k + j] = n;
167 [[nodiscard]]
inline int k()
const {
return m_k; }
169 [[nodiscard]]
inline size_t size()
const {
return m_indices.size()/
static_cast<size_t>(m_k); }
178 inline const IndexContainer& index_data()
const {
return m_indices; };
[KdTreeSparse type definition]
KdTreeKNearestPointQuery< Traits > kNearestNeighbors(const VectorType &point, IndexType k) const
Computes a Query object to iterate over the k-nearest neighbors of a point. The returned object can b...
Customizable base class for KnnGraph datastructure.
typename Traits::PointContainer PointContainer
Container for DataPoint used inside the KdTree.
KNearestIndexQuery kNearestNeighborsIndexQuery() const
Convenience function that provides a k-nearest neighbors Query object.
RangeIndexQuery rangeNeighbors(int index, Scalar r) const
Computes a Query object to iterate over the neighbors that are inside a given radius.
typename Traits::DataPoint DataPoint
DataPoint given by user via Traits.
KnnGraphBase(const KdTreeBase< KdTreeTraits > &kdtree, int k=6)
Build a KnnGraph from a KdTreeDense.
RangeIndexQuery rangeNeighborsIndexQuery() const
Convenience function that provides an empty range neighbors Query object.
typename DataPoint::Scalar Scalar
Scalar given by user via DataPoint.
int k() const
Number of neighbor per vertex.
size_t size() const
Number of vertices in the neighborhood graph.
typename Traits::IndexContainer IndexContainer
Container for indices used inside the KdTree.
typename DataPoint::VectorType VectorType
VectorType given by user via DataPoint.
KNearestIndexQuery kNearestNeighbors(int index) const
Computes a Query object to iterate over the k-nearest neighbors of a point.
Extension of the Query class that allows to read the result of a k-nearest neighbors search on the Kn...
Extension of the Query class that allows to read the result of a range neighbor search on the KnnGrap...
This Source Code Form is subject to the terms of the Mozilla Public License, v.