9#include "./kdTreeTraits.h"
19#include <Eigen/Geometry>
21#include "../../Common/Assert.h"
23#include "Query/kdTreeNearestQueries.h"
24#include "Query/kdTreeKNearestQueries.h"
25#include "Query/kdTreeRangeQueries.h"
28template <
typename Traits>
class KdTreeBase;
29template <
typename Traits>
class KdTreeDenseBase;
30template <
typename Traits>
class KdTreeSparseBase;
44#ifdef PARSED_WITH_DOXYGEN
46template <
typename DataPo
int>
50template <
typename DataPo
int>
63#ifdef PARSED_WITH_DOXYGEN
65template <
typename DataPo
int>
69template <
typename DataPo
int>
81#ifdef PARSED_WITH_DOXYGEN
83template <
typename DataPo
int>
87template <
typename DataPo
int>
102template <
typename Traits>
115 using Scalar =
typename DataPoint::Scalar;
127 static constexpr bool SUPPORTS_SUBSAMPLING =
false;
129 static_assert(std::is_same<typename PointContainer::value_type, DataPoint>::value,
130 "PointContainer must contain DataPoints");
133 static_assert(std::is_signed<IndexType>::value,
"Index type must be signed");
135 static_assert(std::is_same<typename IndexContainer::value_type, IndexType>::value,
"Index type mismatch");
136 static_assert(std::is_same<typename NodeContainer::value_type, NodeType>::value,
"Node type mismatch");
138 static_assert(
MAX_DEPTH > 0,
"Max depth must be strictly positive");
147 template<
typename Po
intUserContainer,
typename Converter>
148 inline void build(PointUserContainer&& points, Converter c);
153 template <
typename Input>
156 using InputContainer =
typename std::remove_reference<Input>::type;
157 if constexpr (std::is_same<InputContainer, PointContainer>::value)
158 o = std::forward<Input>(i);
160 std::transform(i.cbegin(), i.cend(), std::back_inserter(o),
161 [](
const typename InputContainer::value_type &p) ->
DataPoint { return DataPoint(p); });
168 template<
typename Po
intUserContainer>
169 inline void build(PointUserContainer&& points)
181 return m_nodes.size();
230 PONCA_DEBUG_ASSERT(min_cell_size > 0);
239 return m_indices[sample_index];
412 [[nodiscard]]
inline bool valid()
const;
413 inline void print(std::ostream& os,
bool verbose =
false)
const;
435 template<
typename Po
intUserContainer,
typename IndexUserContainer,
typename Converter>
437 IndexUserContainer sampling,
445 template<
typename Po
intUserContainer,
typename IndexUserContainer>
447 IndexUserContainer sampling)
471template <
typename Traits>
483 template<
typename Po
intUserContainer>
487 this->
build(std::forward<PointUserContainer>(points));
505template <
typename Traits>
512 static constexpr bool SUPPORTS_SUBSAMPLING =
false;
519 template<
typename Po
intUserContainer>
523 this->
build(std::forward<PointUserContainer>(points));
531 template<
typename Po
intUserContainer,
typename IndexUserContainer>
535 this->
buildWithSampling(std::forward<PointUserContainer>(points), std::move(sampling));
541#include "./kdTree.hpp"
544template <
typename Traits>
[KdTreeSparse type definition]
KdTreeNearestIndexQuery< Traits > nearestNeighbor(IndexType index) const
Computes a Query object that contains the nearest point. The returned object can be reset and reused ...
void setMinCellSize(LeafSizeType min_cell_size)
Write leaf min size.
typename Traits::DataPoint DataPoint
DataPoint given by user via Traits.
typename DataPoint::Scalar Scalar
Scalar given by user via DataPoint.
typename Traits::NodeType NodeType
Type of nodes used inside the KdTree.
LeafSizeType minCellSize() const
Read leaf min size.
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.
KdTreeRangeIndexQuery< Traits > rangeNeighborsIndexQuery() const
KdTreeBase::rangeNeighborsQuery.
KdTreeKNearestIndexQuery< Traits > kNearestNeighborsIndexQuery() const
Convenience function that provides an empty k-nearest neighbors Query object.
void build(PointUserContainer &&points, Converter c)
Generate a tree from a custom contained type converted using the specified converter.
typename Traits::IndexContainer IndexContainer
Container for indices used inside 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...
KdTreeKNearestPointQuery< Traits > kNearestNeighborsQuery() const
Convenience function that provides an empty k-nearest neighbors Query object.
static constexpr std::size_t MAX_POINT_COUNT
The maximum number of points that can be stored in the kd-tree.
typename Traits::NodeContainer NodeContainer
Container for nodes used inside the KdTree.
KdTreeNearestIndexQuery< Traits > nearestNeighborQuery() const
Convenience function that provides an empty nearest neighbor Query object.
KdTreeRangePointQuery< Traits > rangeNeighbors(const VectorType &point, Scalar r) const
Computes a Query object to iterate over the neighbors that are inside a given radius....
static constexpr std::size_t MAX_NODE_COUNT
The maximum number of nodes that the kd-tree can have.
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.
KdTreeRangeIndexQuery< Traits > rangeNeighbors(IndexType index, Scalar r) const
Computes a Query object to iterate over the neighbors that are inside a given radius....
NodeIndexType m_leaf_count
Number of leaves in the Kdtree (computed during construction)
void clear()
Clear tree data.
void buildWithSampling(PointUserContainer &&points, IndexUserContainer sampling)
Generate a tree sampled from a custom contained type converted using a KdTreeBase::DefaultConverter.
static constexpr int MAX_DEPTH
The maximum depth of the kd-tree.
const DataPoint & pointDataFromSample(IndexType sample_index) const
Return the DataPoint associated with the specified sample index.
LeafSizeType m_min_cell_size
Minimal number of points per leaf.
KdTreeNearestIndexQuery< Traits > nearestNeighborIndexQuery() const
Convenience function that provides an empty nearest neighbor Query object.
IndexType pointFromSample(IndexType sample_index) const
Return the point index associated with the specified sample index.
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...
typename NodeType::AabbType AabbType
Bounding box type given by user via NodeType.
typename Traits::LeafSizeType LeafSizeType
Type used to store the size of leaf nodes.
DataPoint & pointDataFromSample(IndexType sample_index)
Return the DataPoint associated with the specified sample index.
typename DataPoint::VectorType VectorType
VectorType given by user via DataPoint.
KdTreeNearestPointQuery< Traits > nearestNeighbor(const VectorType &point) const
Computes a Query object that contains the nearest point. The returned object can be reset and reused ...
void buildWithSampling(PointUserContainer &&points, IndexUserContainer sampling, Converter c)
Generate a tree sampled from a custom contained type converted using a Converter
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 KdTreeBase::DefaultConve...
Extension of the Query class that allows to read the result of a k-nearest neighbors search on the Kd...
Extension of the Query class that allows to read the result of a nearest neighbor search on the KdTre...
Extension of the Query class that allows to read the result of a range neighbors search on the KdTree...
Customizable base class for KdTreeSparse datastructure.
KdTreeSparseBase(PointUserContainer &&points, IndexUserContainer sampling)
Constructor generating a tree sampled from a custom contained type converted using a KdTreeBase::Defa...
KdTreeSparseBase(PointUserContainer &&points)
Constructor generating a tree from a custom contained type converted using a KdTreeBase::DefaultConve...
KdTreeSparseBase()=default
Default constructor creating an empty tree.
void buildWithSampling(PointUserContainer &&points, IndexUserContainer sampling, Converter c)
Generate a tree sampled from a custom contained type converted using a Converter
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.
[KdTreeDense type definition]
Abstract KdTree type with KdTreeDefaultTraits.