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.point_count();
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)
97 for(
auto n : kdtree.k_nearest_neighbors(
typename KdTreeTraits::IndexType(i),
98 typename KdTreeTraits::IndexType(m_k)))
100 m_indices[i * m_k + j] = n;
112 inline RangeIndexQuery range_neighbors(
int index,
Scalar r)
const{
113 return RangeIndexQuery(
this, r, index);
119 inline int k()
const {
return m_k; }
121 inline int size()
const {
return m_indices.size()/m_k; }
130 inline const IndexContainer& index_data()
const {
return m_indices; };
[KdTreeSparse type definition]
Customizable base class for KnnGraph datastructure.
int size() const
Number of vertices in the neighborhood graph.
typename Traits::PointContainer PointContainer
Container for DataPoint used inside the KdTree.
typename Traits::DataPoint DataPoint
DataPoint given by user via Traits.
KnnGraphBase(const KdTreeBase< KdTreeTraits > &kdtree, int k=6)
Build a KnnGraph from a KdTreeDense.
typename DataPoint::Scalar Scalar
Scalar given by user via DataPoint.
int k() const
Number of neighbor per vertex.
typename Traits::IndexContainer IndexContainer
Container for indices used inside the KdTree.
typename DataPoint::VectorType VectorType
VectorType given by user via DataPoint.
Base Query class combining QueryInputIsIndex and QueryOutputIsKNearest.
This Source Code Form is subject to the terms of the Mozilla Public License, v.