9#include "./kdTreeTraits.h"
20#include <Eigen/Geometry>
22#include "../../Common/Assert.h"
24#include "Query/kdTreeNearestQueries.h"
25#include "Query/kdTreeKNearestQueries.h"
26#include "Query/kdTreeRangeQueries.h"
30 template <
typename Traits>
32 template <
typename Traits>
33 class KdTreeDenseBase;
34 template <
typename Traits>
35 class KdTreeSparseBase;
49#ifdef PARSED_WITH_DOXYGEN
51 template <
typename DataPo
int>
57 template <
typename DataPo
int>
70#ifdef PARSED_WITH_DOXYGEN
72 template <
typename DataPo
int>
78 template <
typename DataPo
int>
90#ifdef PARSED_WITH_DOXYGEN
92 template <
typename DataPo
int>
98 template <
typename DataPo
int>
110#ifdef PARSED_WITH_DOXYGEN
112 template <
typename DataPo
int>
118 template <
typename DataPo
int>
136 template <
typename _Traits>
140#define WRITE_TRAITS \
141 using Traits = _Traits; \
142 using DataPoint = typename Traits::DataPoint; \
143 using IndexType = typename Traits::IndexType; \
144 using LeafSizeType = typename Traits::LeafSizeType; \
145 using PointContainer = typename Traits::PointContainer; \
146 using IndexContainer = typename Traits::IndexContainer; \
147 using NodeIndexType = typename Traits::NodeIndexType; \
148 using NodeType = typename Traits::NodeType; \
149 using NodeContainer = typename Traits::NodeContainer; \
150 using Scalar = typename DataPoint::Scalar; \
151 using VectorType = typename DataPoint::VectorType; \
152 using AabbType = typename NodeType::AabbType;
162 size_t points_size{0};
163 size_t nodes_size{0};
164 size_t indices_size{0};
166 PONCA_MULTIARCH
inline Buffers() =
default;
169 const size_t _points_size,
const size_t _nodes_size,
170 const size_t _indices_size)
171 :
points(_points),
nodes(_nodes),
indices(_indices), points_size(_points_size), nodes_size(_nodes_size),
172 indices_size(_indices_size)
185 static constexpr bool SUPPORTS_SUBSAMPLING =
false;
188 static_assert(std::is_signed_v<IndexType>,
"Index type must be signed");
189 static_assert(
MAX_DEPTH > 0,
"Max depth must be strictly positive");
429 PONCA_MULTIARCH_HOST [[
nodiscard]]
inline bool valid()
const;
430 PONCA_MULTIARCH_HOST
inline void print(std::ostream&
os,
bool verbose =
false)
const;
455 template <
typename _Traits>
466 template <
typename Po
intUserContainer,
typename Po
intConverter>
472 template <
typename Input>
476 if constexpr (std::is_same_v<InputContainer, PointContainer> && std::is_copy_assignable_v<DataPoint>)
477 o = std::forward<Input>(
i);
480 i.cbegin(),
i.cend(), std::back_inserter(
o),
481 [](
const typename InputContainer::value_type&
p) ->
DataPoint { return DataPoint(p); });
488 template <
typename Po
intUserContainer>
503 template <
typename Po
intUserContainer,
typename IndexUserContainer,
typename Po
intConverter>
512 template <
typename Po
intUserContainer,
typename IndexUserContainer>
538 template <
typename Traits>
550 template <
typename Po
intUserContainer>
570 template <
typename Traits>
577 static constexpr bool SUPPORTS_SUBSAMPLING =
true;
584 template <
typename Po
intUserContainer>
587 this->
build(std::forward<PointUserContainer>(
points));
596 template <
typename Po
intUserContainer,
typename IndexUserContainer>
605#include "./kdTree.hpp"
608template <
typename Traits>
Aggregator class used to declare specialized structures using CRTP.
typename Traits::IndexType IndexType
Type used to index points into the PointContainer
void buildWithSampling(PointUserContainer &&points, IndexUserContainer &&sampling)
Generate a tree sampled from a custom contained type converted using a KdTreeBase::DefaultConverter.
typename Traits::NodeIndexType NodeIndexType
Type used to index nodes into the NodeContainer
void buildWithSampling(PointUserContainer &&points, IndexUserContainer &&sampling, PointConverter c)
Generate a tree sampled from a custom contained type converted using a Converter
void build(PointUserContainer &&points, PointConverter c)
Generate a tree from a custom contained type converted using the specified converter.
void build(PointUserContainer &&points)
Generate a tree from a custom contained type converted using DefaultConverter.
typename Traits::DataPoint DataPoint
DataPoint given by user via Traits
typename Traits::PointContainer PointContainer
Container for DataPoint used inside the KdTree.
Customizable base class for dense KdTree datastructure.
KdTreeDenseBase()=default
Default constructor creating an empty tree.
KdTreeDenseBase(PointUserContainer &&points)
Constructor generating a tree from a custom contained type converted using a Traits::ContainerConvert...
Customizable base class for KdTreeSparse datastructure.
KdTreeSparseBase(PointUserContainer &&points, IndexUserContainer sampling)
Constructor generating a tree sampled from a custom contained type converted using a Traits::Containe...
KdTreeSparseBase(PointUserContainer &&points)
Constructor generating a tree from a custom contained type converted using a Traits::ContainerConvert...
KdTreeSparseBase()=default
Default constructor creating an empty tree.
Customizable static base class for KdTree datastructure implementations.
KdTreeNearestIndexQuery< Traits > nearestNeighborQuery() const
Convenience function that provides an empty nearest neighbor Query object.
LeafSizeType m_min_cell_size
Minimal number of points per leaf.
typename Traits::NodeContainer NodeContainer
Container for nodes used inside the KdTree
NodeIndexType m_leaf_count
Number of leaves in the Kdtree (computed during construction)
KdTreeNearestPointQuery< Traits > nearestNeighbor(const VectorType &point) const
Computes a Query object that contains the nearest point. The returned object can be reset and reused ...
KdTreeRangeIndexQuery< Traits > rangeNeighborsIndexQuery() const
KdTreeBase::rangeNeighborsQuery.
typename Traits::NodeIndexType NodeIndexType
Type used to index nodes into the NodeContainer
IndexType pointCount() const
Get the number of points.
const NodeContainer & nodes() const
Get the internal node container.
StaticKdTreeBase(Buffers &buf)
Constructor that allows the use of prebuilt KdTree containers.
IndexType pointFromSample(IndexType sample_index) const
Return the point index associated with the specified sample index.
typename DataPoint::VectorType VectorType
VectorType given by user via DataPoint
static constexpr int MAX_DEPTH
The maximum depth of the kd-tree.
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...
typename DataPoint::Scalar Scalar
Scalar given by user via DataPoint
NodeIndexType leafCount() const
Get the number of leafs in the KdTree.
typename Traits::IndexType IndexType
Type used to index points into the PointContainer
KdTreeRangePointQuery< Traits > rangeNeighborsQuery() const
Convenience function that provides an empty range neighbor Query object.
typename Traits::PointContainer PointContainer
Container for DataPoint used inside the KdTree.
const Buffers & buffers() const
Get access to the internal buffer, for instance to prepare GPU binding.
typename Traits::DataPoint DataPoint
DataPoint given by user via Traits
typename Traits::IndexContainer IndexContainer
Container for indices used inside the KdTree.
KdTreeNearestIndexQuery< Traits > nearestNeighbor(IndexType index) const
Computes a Query object that contains the nearest point. The returned object can be reset and reused ...
IndexType sampleCount() const
Get the number of indices.
static constexpr std::size_t MAX_NODE_COUNT
The maximum number of nodes that the kd-tree can have.
KdTreeNearestIndexQuery< Traits > nearestNeighborIndexQuery() const
Convenience function that provides an empty nearest neighbor Query object.
void setMinCellSize(LeafSizeType min_cell_size)
Write leaf min size.
typename Traits::LeafSizeType LeafSizeType
Type used to store the size of leaf nodes
KdTreeKNearestIndexQuery< Traits > kNearestNeighbors(IndexType index, IndexType k) const
Computes a Query object to iterate over the k-nearest neighbors of a point. The returned object can b...
Buffers m_bufs
Buffers used to store the KdTree.
KdTreeRangePointQuery< Traits > rangeNeighbors(const VectorType &point, Scalar r) const
Computes a Query object to iterate over the neighbors that are inside a given radius....
PointContainer & points()
Get the internal point container.
const IndexContainer & samples() const
Get the internal indice container.
NodeIndexType nodeCount() const
Get the number of nodes in the KdTree.
KdTreeKNearestIndexQuery< Traits > kNearestNeighborsIndexQuery() const
Convenience function that provides an empty k-nearest neighbors Query object.
const PointContainer & points() const
Get the internal point container.
KdTreeRangeIndexQuery< Traits > rangeNeighbors(IndexType index, Scalar r) const
Computes a Query object to iterate over the neighbors that are inside a given radius....
DataPoint & pointDataFromSample(IndexType sample_index)
Return the DataPoint associated with the specified sample index.
const DataPoint & pointDataFromSample(IndexType sample_index) const
Return the DataPoint associated with the specified sample index.
static constexpr std::size_t MAX_POINT_COUNT
The maximum number of points that can be stored in the kd-tree.
LeafSizeType minCellSize() const
Read leaf min size.
KdTreeKNearestPointQuery< Traits > kNearestNeighborsQuery() 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.
Convert a custom point container to the KdTree PointContainer using DataPoint default constructor.
Public interface for dense KdTree datastructure.
Public interface for sparse KdTree datastructure.
Abstract KdTree type with KdTreeDefaultTraits.
Internal structure storing all the buffers used by the KdTree.
NodeContainer nodes
Buffer storing the nodes of the KdTree.
PointContainer points
Buffer storing the input points (read only)
IndexContainer indices
Buffer storing the indices associating the input points to the nodes.
A KdTree type with KdTreeDefaultTraits that doesn't define the build function.