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
57 template <
typename _Traits>
59 NeighborGraphOneConnectedQuery<StaticKnnGraphBase<_Traits>>,
60 NeighborGraphRangeQuery<StaticKnnGraphBase<_Traits>>>
63 WRITE_NEIGHBOR_GRAPH_ALIASES
73 using Buffers =
typename Base::Buffers;
87 PONCA_MULTIARCH [[
nodiscard]]
inline int k(
int = 0)
const {
return Base::buffers().k; }
97 return Base::oneConnectedNeighbors(index);
104 return Base::oneConnectedNeighbors();
108 template <
typename _Traits>
112 WRITE_NEIGHBOR_GRAPH_ALIASES
116 using Buffers =
typename Base::Buffers;
127 template <
typename KdTreeTraits>
129 const int _k = Buffers::DefaultKInKnnGraph())
132 Base::m_bufs.points_size =
_kdtree.pointCount();
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");
140 CHECK_TRAITS_TYPENAME_COMPAT(
typename Traits::PointContainer,
typename KdTreeTraits::PointContainer)
141 CHECK_TRAITS_TYPENAME_COMPAT(
typename Traits::IndexContainer,
typename KdTreeTraits::IndexContainer)
143#undef CHECK_TRAITS_TYPENAME_COMPAT
154 Base::m_bufs.indices_size =
cloudSize * Base::m_bufs.k;
155 Base::m_bufs.indices.resize(Base::m_bufs.indices_size, -1);
157#pragma omp parallel for shared(_kdtree, cloudSize) default(none)
161 for (
auto n :
_kdtree.kNearestNeighbors(
typename KdTreeTraits::IndexType(
i),
162 typename KdTreeTraits::IndexType(Base::m_bufs.
k)))
164 Base::m_bufs.indices[
i * Base::m_bufs.k +
j] = n;
179 template <
typename DataPo
int>
Base class for neighbor graphs.
PointContainer points() const
Get the internal point container.
Aggregator class used to declare specialized structures using CRTP.
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...
Customizable base class for KnnGraph datastructure.
typename Traits::PointContainerConstRef PointContainerConstRef
Container for DataPoint used inside the KdTree
int beginId(int vId) const
Index of the beginning of the neighborhood range.
typename Traits::IndexContainerRef IndexContainerRef
Ref type to index container.
int endId(int vId) const
Index of the end of the neighborhood range.
int k(int=0) const
Number of neighbor per vertex for a given element (in the KnnGraph, all points have the same number o...
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.
Buffer class for StaticKnnGraphBase.
typename Traits::PointContainerConstRef PointContainerConstRef
Container for DataPoint used inside the KdTree
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.
Internal structure storing the buffers used by a neighbor graph.