9#include "./knnGraphTraits.h"
11#include "Query/knnGraphKNearestQuery.h"
12#include "Query/knnGraphRangeQuery.h"
14#include "../KdTree/kdTree.h"
15#include "../../Common/Assert.h"
22 template <
typename Traits>
33 template <
typename DataPo
int>
47 template <
typename Traits>
52 using DataPoint = typename Traits::DataPoint; \
53 using Scalar = typename DataPoint::Scalar; \
54 using VectorType = typename DataPoint::VectorType; \
55 using IndexType = typename Traits::IndexType; \
56 using PointContainer = typename Traits::PointContainer; \
57 using IndexContainer = typename Traits::IndexContainer;
68 PONCA_MULTIARCH
inline const IndexType* getIndexPtr()
const {
return Traits::getIndexRawPtr(
m_bufs.
indices); }
78 size_t points_size{0};
79 size_t indices_size{0};
82 PONCA_MULTIARCH
inline Buffers() =
default;
85 PONCA_MULTIARCH
inline Buffers(
PointContainer _points,
typename Traits::IndexContainerRef _indices,
86 const size_t _points_size,
const size_t _indices_size,
const int _k)
87 :
points(_points),
indices(_indices), points_size(_points_size), indices_size(_indices_size), k(_k)
93 PONCA_MULTIARCH
inline StaticKnnGraphBase(
PointContainer _points,
const int _k) :
m_bufs(_points, _k) {}
171 return m_bufs.indices_size /
static_cast<size_t>(
m_bufs.k);
189 template <
typename Traits>
207 template <
typename KdTreeTraits>
211 Base::m_bufs.points_size =
_kdtree.pointCount();
212#define CHECK_TRAITS_TYPENAME_COMPAT(A, B) \
213 static_assert(std::is_same_v<A, B> || std::is_convertible_v<A, B> || std::is_convertible_v<B, A>, \
214 "KdTreeTraits::DataPoint is not equal to Traits::DataPoint");
216 static_assert(std::is_same_v<typename Traits::DataPoint, typename KdTreeTraits::DataPoint>,
217 "KdTreeTraits::DataPoint is not equal to Traits::DataPoint");
219 CHECK_TRAITS_TYPENAME_COMPAT(
typename Traits::PointContainer,
typename KdTreeTraits::PointContainer)
220 CHECK_TRAITS_TYPENAME_COMPAT(
typename Traits::IndexContainer,
typename KdTreeTraits::IndexContainer)
222#undef CHECK_TRAITS_TYPENAME_COMPAT
233 Base::m_bufs.indices_size =
cloudSize * Base::m_bufs.k;
234 Base::m_bufs.indices.resize(Base::m_bufs.indices_size, -1);
236#pragma omp parallel for shared(_kdtree, cloudSize) default(none)
240 for (
auto n :
_kdtree.kNearestNeighbors(
typename KdTreeTraits::IndexType(
i),
241 typename KdTreeTraits::IndexType(Base::m_bufs.
k)))
243 Base::m_bufs.indices[
i * Base::m_bufs.k +
j] = n;
Aggregator class used to declare specialized structures using CRTP.
KnnGraphBase(const KdTreeBase< KdTreeTraits > &_kdtree, const int _k=6)
Build a KnnGraph from a KdTreeDense.
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...
Customizable base class for KnnGraph datastructure.
StaticKnnGraphBase(Buffers &_bufs)
Constructor that allows the use of prebuilt KnnGraph containers.
typename Traits::IndexContainer IndexContainer
Container for indices used inside the KdTree
KNearestIndexQuery kNearestNeighborsIndexQuery() const
Convenience function that provides a k-nearest neighbors Query object.
IndexContainer samples() const
Get the internal index container.
typename DataPoint::Scalar Scalar
Scalar given by user via DataPoint
size_t size() const
Number of vertices in the neighborhood graph.
RangeIndexQuery rangeNeighborsIndexQuery() const
Convenience function that provides an empty range neighbors Query object.
IndexType sampleCount() const
Get the number of indices.
typename Traits::PointContainer PointContainer
Container for DataPoint used inside the KdTree
typename Traits::IndexType IndexType
Type used to index points into the PointContainer.
KNearestIndexQuery kNearestNeighbors(int index) const
Computes a Query object to iterate over the k-nearest neighbors of a point.
const Buffers & buffers() const
Get access to the internal buffer, for instance to prepare GPU binding.
RangeIndexQuery rangeNeighbors(int index, Scalar r) const
Computes a Query object to iterate over the neighbors that are inside a given radius.
Buffers m_bufs
Buffers used to store the KnnGraph.
PointContainer points() const
Get the internal point container.
IndexType pointCount() const
Get the number of points.
int k() const
Number of neighbor per vertex.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Internal structure storing all the buffers used by the KdTree.
PointContainer points
Buffer storing the input points (read only)
IndexContainer indices
Buffer storing the indices associating the input points to the nodes.