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();
239 return m_indices[sample_index];
265 KdTreeKNearestIndexQuery<Traits> k_nearest_neighbors(
IndexType index,
IndexType k)
const
267 return KdTreeKNearestIndexQuery<Traits>(
this, k, index);
270 KdTreeNearestPointQuery<Traits> nearest_neighbor(
const VectorType& point)
const
272 return KdTreeNearestPointQuery<Traits>(
this, point);
275 KdTreeNearestIndexQuery<Traits> nearest_neighbor(
IndexType index)
const
277 return KdTreeNearestIndexQuery<Traits>(
this, index);
280 KdTreeRangePointQuery<Traits> range_neighbors(
const VectorType& point,
Scalar r)
const
282 return KdTreeRangePointQuery<Traits>(
this, r, point);
285 KdTreeRangeIndexQuery<Traits> range_neighbors(
IndexType index,
Scalar r)
const
287 return KdTreeRangeIndexQuery<Traits>(
this, r, index);
292 inline bool valid()
const;
293 inline void print(std::ostream& os,
bool verbose =
false)
const;
315 template<
typename Po
intUserContainer,
typename IndexUserContainer,
typename Converter>
317 IndexUserContainer sampling,
325 template<
typename Po
intUserContainer,
typename IndexUserContainer>
327 IndexUserContainer sampling)
351template <
typename Traits>
363 template<
typename Po
intUserContainer>
367 this->
build(std::forward<PointUserContainer>(points));
385template <
typename Traits>
392 static constexpr bool SUPPORTS_SUBSAMPLING =
false;
399 template<
typename Po
intUserContainer>
403 this->
build(std::forward<PointUserContainer>(points));
411 template<
typename Po
intUserContainer,
typename IndexUserContainer>
415 this->
buildWithSampling(std::forward<PointUserContainer>(points), std::move(sampling));
421#include "./kdTree.hpp"
424template <
typename Traits>
[KdTreeSparse type definition]
typename Traits::DataPoint DataPoint
DataPoint given by user via Traits.
void set_min_cell_size(LeafSizeType min_cell_size)
Write leaf min size.
typename DataPoint::Scalar Scalar
Scalar given by user via DataPoint.
typename Traits::NodeType NodeType
Type of nodes used inside the KdTree.
typename Traits::IndexType IndexType
Type used to index points into the PointContainer.
LeafSizeType min_cell_size() const
Read leaf min size.
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.
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.
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.
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.
IndexType pointFromSample(IndexType sample_index) const
Return the point index associated with the specified sample index.
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.
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...
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.