9#include "abstractNeighborGraph.h"
10#include "Query/neighborGraphOneConnectedQuery.h"
11#include "Query/neighborGraphRangeQuery.h"
13#include "../KdTree/kdTree.h"
14#include "../../Common/Assert.h"
22 template <
typename _Traits>
25 WRITE_NEIGHBOR_GRAPH_ALIASES
36 : Base(_points),
k(_k)
40 const size_t _points_size,
const size_t _indices_size,
const int _k)
41 : Base(_points, _indices, _points_size, _indices_size),
k(_k)
57 template <
typename _Traits>
59 NeighborGraphOneConnectedQuery<StaticKnnGraphBase<_Traits>>,
60 NeighborGraphRangeQuery<StaticKnnGraphBase<_Traits>>>
63 WRITE_NEIGHBOR_GRAPH_ALIASES
73 using Buffers =
typename Base::Buffers;
75 PONCA_MULTIARCH
inline StaticKnnGraphBase<Traits>(Buffers& _bufs) : Base(_bufs) {}
79 : Base(Buffers(_points, _k))
87 PONCA_MULTIARCH [[nodiscard]]
inline int k(
int = 0)
const {
return Base::buffers().
k; }
89 PONCA_MULTIARCH [[nodiscard]]
inline int beginId(
int vId)
const {
return vId *
k(); }
91 PONCA_MULTIARCH [[nodiscard]]
inline int endId(
int vId)
const {
return (vId + 1) *
k(); }
95 PONCA_MULTIARCH [[nodiscard]]
inline typename Base::OneConnectedIndexQuery
kNearestNeighbors(
int index)
const
108 template <
typename _Traits>
112 WRITE_NEIGHBOR_GRAPH_ALIASES
115 using Base = StaticKnnGraphBase<Traits>;
116 using Buffers =
typename Base::Buffers;
127 template <
typename KdTreeTraits>
129 const int _k = Buffers::DefaultKInKnnGraph())
130 : Base(_kdtree.
points(), std::min(_k, _kdtree.sampleCount() - 1))
133#define CHECK_TRAITS_TYPENAME_COMPAT(A, B) \
134 static_assert(std::is_same_v<A, B> || std::is_convertible_v<A, B> || std::is_convertible_v<B, A>, \
135 "KdTreeTraits::DataPoint is not equal to Traits::DataPoint");
137 static_assert(std::is_same_v<typename Traits::DataPoint, typename KdTreeTraits::DataPoint>,
138 "KdTreeTraits::DataPoint is not equal to Traits::DataPoint");
143#undef CHECK_TRAITS_TYPENAME_COMPAT
151 PONCA_ASSERT(cloudSize == samplesSize);
157#pragma omp parallel for shared(_kdtree, cloudSize) default(none)
158 for (
int i = 0; i < cloudSize; ++i)
179 template <
typename DataPo
int>
Buffers m_bufs
Buffers used to store the KnnGraph.
AbstractNeighborGraph(const Buffers &_bufs)
OneConnectedIndexQuery oneConnectedNeighbors(int index=0) const
PointContainerConstRef points() const
const Buffers & buffers() const
Constructor that allows the use of prebuilt KdTree containers.
KnnGraphBase(const KdTreeBase< KdTreeTraits > &_kdtree, const int _k=Buffers::DefaultKInKnnGraph())
Build a KnnGraph from a KdTreeDense.
Extension of the Query class that allows to read the neighbors that are directly connected to the que...
Extension of the Query class that allows to read the result of a range neighbor search on the KnnGrap...
IndexType pointCount() const
Get the number of points.
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...
IndexType sampleCount() const
Get the number of indices.
Customizable base class for KnnGraph datastructure.
int beginId(int vId) const
Index of the beginning of the neighborhood range.
typename Traits::IndexContainerRef IndexContainerRef
int endId(int vId) const
Index of the end of the neighborhood range.
typename Traits::PointContainerConstRef PointContainerConstRef
_Traits Traits
Alias to the Traits type.
Base::OneConnectedIndexQuery kNearestNeighborsIndexQuery() const
Convenience function that provides an empty k-nearest neighbors Query object.
Base::OneConnectedIndexQuery kNearestNeighbors(int index) const
Convenience function that provides an empty k-nearest neighbors Query object.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
KnnGraphBase< NeighborGraphDefaultTraits< DataPoint > > KnnGraph
Public interface for the KnnGraph datastructure.
Buffer class for StaticKnnGraphBase.
static constexpr int DefaultKInKnnGraph()
Helper constexpr defining the default number of neighbors in Knn graphs.
const int k
Number of neighbors used to build the graph.
typename Traits::PointContainerConstRef PointContainerConstRef
Container for DataPoint used inside the KdTree.
NeighborGraphBufferBase()=default
Default constructor, might be deleted depending on the PointContainer type (e.g. const reference).
std::vector< IndexType > IndexContainer
Type used to store the index container in the AbstractNeighborGraph::Buffers.
std::vector< DataPoint > PointContainer
Type used to store the external Point container in AbstractNeighborGraph::Buffers.