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 DataPoint = typename Traits::DataPoint; \
142 using IndexType = typename Traits::IndexType; \
143 using LeafSizeType = typename Traits::LeafSizeType; \
144 using PointContainer = typename Traits::PointContainer; \
145 using IndexContainer = typename Traits::IndexContainer; \
146 using NodeIndexType = typename Traits::NodeIndexType; \
147 using NodeType = typename Traits::NodeType; \
148 using NodeContainer = typename Traits::NodeContainer; \
149 using Scalar = typename DataPoint::Scalar; \
150 using VectorType = typename DataPoint::VectorType; \
151 using AabbType = typename NodeType::AabbType;
161 size_t points_size{0};
162 size_t nodes_size{0};
163 size_t indices_size{0};
165 PONCA_MULTIARCH
inline Buffers() =
default;
168 const size_t _points_size,
const size_t _nodes_size,
169 const size_t _indices_size)
170 :
points(_points),
nodes(_nodes),
indices(_indices), points_size(_points_size), nodes_size(_nodes_size),
171 indices_size(_indices_size)
184 static constexpr bool SUPPORTS_SUBSAMPLING =
false;
187 static_assert(std::is_signed_v<IndexType>,
"Index type must be signed");
188 static_assert(
MAX_DEPTH > 0,
"Max depth must be strictly positive");
430 PONCA_MULTIARCH_HOST [[
nodiscard]]
inline bool valid()
const;
431 PONCA_MULTIARCH_HOST
inline void print(std::ostream&
os,
bool verbose =
false)
const;
456 template <
typename Traits>
467 template <
typename Po
intUserContainer,
typename Po
intConverter>
473 template <
typename Input>
477 if constexpr (std::is_same_v<InputContainer, PointContainer> && std::is_copy_assignable_v<DataPoint>)
478 o = std::forward<Input>(
i);
481 i.cbegin(),
i.cend(), std::back_inserter(
o),
482 [](
const typename InputContainer::value_type&
p) ->
DataPoint { return DataPoint(p); });
489 template <
typename Po
intUserContainer>
504 template <
typename Po
intUserContainer,
typename IndexUserContainer,
typename Po
intConverter>
513 template <
typename Po
intUserContainer,
typename IndexUserContainer>
539 template <
typename Traits>
551 template <
typename Po
intUserContainer>
554 Base::build(std::forward<PointUserContainer>(
points));
571 template <
typename Traits>
578 static constexpr bool SUPPORTS_SUBSAMPLING =
true;
585 template <
typename Po
intUserContainer>
588 this->
build(std::forward<PointUserContainer>(
points));
597 template <
typename Po
intUserContainer,
typename IndexUserContainer>
606#include "./kdTree.hpp"
609template <
typename Traits>
Aggregator class used to declare specialized structures using CRTP.
typename Traits::DataPoint DataPoint
DataPoint given by user via Traits
typename Traits::IndexType IndexType
Type used to index points into the PointContainer
typename Traits::NodeIndexType NodeIndexType
Type used to index nodes into the NodeContainer
void build(PointUserContainer &&points)
Generate a tree from a custom contained type converted using DefaultConverter.
typename Traits::PointContainer PointContainer
Container for DataPoint used inside the KdTree.
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 buildWithSampling(PointUserContainer &&points, IndexUserContainer &&sampling)
Generate a tree sampled from a custom contained type converted using a KdTreeBase::DefaultConverter.
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...
void buildWithSampling(PointUserContainer &&points, IndexUserContainer &&sampling, PointConverter c)
Generate a tree sampled from a custom contained type converted using a Converter
KdTreeSparseBase()=default
Default constructor creating an empty tree.
Customizable static base class for KdTree datastructure implementations.
IndexType pointFromSample(IndexType sample_index) const
Return the point index associated with the specified sample index.
Buffers m_bufs
Buffers used to store the KdTree.
typename Traits::NodeIndexType NodeIndexType
Type used to index nodes into the NodeContainer
typename DataPoint::VectorType VectorType
VectorType given by user via DataPoint
const IndexContainer & samples() const
Get the internal indice container.
const NodeContainer & nodes() const
Get the internal node container.
LeafSizeType m_min_cell_size
Minimal number of points per leaf.
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...
StaticKdTreeBase(Buffers &buf)
Constructor that allows the use of prebuilt KdTree containers.
KdTreeNearestIndexQuery< Traits > nearestNeighbor(IndexType index) const
Computes a Query object that contains the nearest point. The returned object can be reset and reused ...
typename Traits::IndexContainer IndexContainer
Container for indices used inside the KdTree.
KdTreeRangePointQuery< Traits > rangeNeighborsQuery() const
Convenience function that provides an empty range neighbor Query object.
static constexpr std::size_t MAX_POINT_COUNT
The maximum number of points that can be stored in the kd-tree.
KdTreeKNearestIndexQuery< Traits > kNearestNeighborsIndexQuery() const
Convenience function that provides an empty k-nearest neighbors Query object.
static constexpr std::size_t MAX_NODE_COUNT
The maximum number of nodes that the kd-tree can have.
KdTreeRangeIndexQuery< Traits > rangeNeighborsIndexQuery() const
KdTreeBase::rangeNeighborsQuery.
typename Traits::IndexType IndexType
Type used to index points into the PointContainer
KdTreeRangeIndexQuery< Traits > rangeNeighbors(IndexType index, Scalar r) const
Computes a Query object to iterate over the neighbors that are inside a given radius....
KdTreeNearestPointQuery< Traits > nearestNeighbor(const VectorType &point) const
Computes a Query object that contains the nearest point. The returned object can be reset and reused ...
const Buffers & buffers() const
Get access to the internal buffer, for instance to prepare GPU binding.
KdTreeRangePointQuery< Traits > rangeNeighbors(const VectorType &point, 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.
PointContainer & points()
Get the internal point container.
typename Traits::LeafSizeType LeafSizeType
Type used to store the size of leaf nodes
IndexType pointCount() const
Get the number of points.
typename Traits::NodeContainer NodeContainer
Container for nodes used inside the KdTree
NodeIndexType leafCount() const
Get the number of leafs in the KdTree.
void setMinCellSize(LeafSizeType min_cell_size)
Write leaf min size.
KdTreeKNearestPointQuery< Traits > kNearestNeighborsQuery() const
Convenience function that provides an empty k-nearest neighbors Query object.
typename DataPoint::Scalar Scalar
Scalar given by user via DataPoint
NodeIndexType nodeCount() const
Get the number of nodes in the KdTree.
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 Traits::DataPoint DataPoint
DataPoint given by user via Traits
const DataPoint & pointDataFromSample(IndexType sample_index) const
Return the DataPoint associated with the specified sample index.
static constexpr int MAX_DEPTH
The maximum depth of the kd-tree.
const PointContainer & points() const
Get the internal point container.
IndexType sampleCount() const
Get the number of indices.
typename Traits::PointContainer PointContainer
Container for DataPoint used inside the KdTree.
KdTreeNearestIndexQuery< Traits > nearestNeighborIndexQuery() const
Convenience function that provides an empty nearest neighbor Query object.
NodeIndexType m_leaf_count
Number of leaves in the Kdtree (computed during construction)
LeafSizeType minCellSize() const
Read leaf min size.
KdTreeNearestIndexQuery< Traits > nearestNeighborQuery() const
Convenience function that provides an empty nearest neighbor 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.
IndexContainer indices
Buffer storing the indices associating the input points to the nodes.
NodeContainer nodes
Buffer storing the nodes of the KdTree.
PointContainer points
Buffer storing the input points (read only)
A KdTree type with KdTreeDefaultTraits that doesn't define the build function.