10#include "../../Common/Macro.h"
14#include <Eigen/Geometry>
17#ifndef PARSED_WITH_DOXYGEN
20 constexpr int clz(
unsigned int value)
22#if PONCA_HAS_BUILTIN_CLZ
23 return __builtin_clz(value);
30 unsigned int msb_mask = 1 << (
sizeof(
unsigned int)*8 - 1);
32 for (; (value & msb_mask) == 0; value <<= 1, ++count)
41template <
typename NodeIndex,
typename Scalar,
int DIM>
57 DIM_BITS =
sizeof(
unsigned int)*8 - internal::clz((
unsigned int)DIM),
61 using UIndex =
typename std::make_unsigned<NodeIndex>::type;
72 Scalar split_value{0};
74 UIndex split_dim : DIM_BITS;
77template <
typename Index,
typename Size>
105template <
typename Index,
typename NodeIndex,
typename DataPoint,
106 typename LeafSize = Index,
112 using Scalar =
typename DataPoint::Scalar;
113 using InnerType = _InnerNodeType;
114 using LeafType = _LeafNodeType;
132 using AabbType = Eigen::AlignedBox<Scalar, DataPoint::Dim>;
134 [[nodiscard]]
bool is_leaf()
const {
return m_is_leaf; }
135 void set_is_leaf(
bool is_leaf) { m_is_leaf = is_leaf; }
153 data.m_leaf.start = start;
154 data.m_leaf.size = (LeafSize)size;
171 data.m_inner.split_value = split_value;
172 data.m_inner.first_child_id = first_child_id;
173 data.m_inner.split_dim = split_dim;
181 [[nodiscard]] Index
leaf_start()
const {
return data.m_leaf.start; }
186 [[nodiscard]] LeafSize
leaf_size()
const {
return data.m_leaf.size; }
208 [[nodiscard]]
inline LeafType& getAsLeaf() {
return data.m_leaf; }
209 [[nodiscard]]
inline InnerType& getAsInner() {
return data.m_inner; }
210 [[nodiscard]]
inline const LeafType& getAsLeaf()
const {
return data.m_leaf; }
211 [[nodiscard]]
inline const InnerType& getAsInner()
const {
return data.m_inner; }
214 bool m_is_leaf{
true};
218 constexpr Data() : m_leaf() {}
220 constexpr Data(
const Data&d) : m_leaf(d.m_leaf) {}
229template <
typename Index,
typename NodeIndex,
typename DataPoint,
230 typename LeafSize = Index>
232 KdTreeDefaultInnerNode<NodeIndex, typename DataPoint::Scalar, DataPoint::Dim>,
233 KdTreeDefaultLeafNode<Index, LeafSize>> {
246template <
typename _DataPoint,
271 using IndexType = int;
272 using LeafSizeType =
unsigned short;
275 using PointContainer = std::vector<DataPoint>;
276 using IndexContainer = std::vector<IndexType>;
279 using NodeIndexType = std::size_t;
280 using NodeType = _NodeType<IndexType, NodeIndexType, DataPoint, LeafSizeType>;
281 using NodeContainer = std::vector<NodeType>;
The node type used by default by the kd-tree.
Scalar inner_split_value() const
The position of the AABB split of the inner node.
Index leaf_start() const
The start index of the range of the leaf node in the sample index array.
Eigen::AlignedBox< Scalar, DataPoint::Dim > AabbType
The type used to store node bounding boxes.
void configure_range(Index start, Index size, const AabbType &aabb)
Configures the range of the node in the sample index array of the kd-tree.
void configure_inner(Scalar split_value, Index first_child_id, Index split_dim)
Configures the inner node information.
int inner_split_dim() const
Which axis the split of the AABB of the inner node was done on.
@ MAX_COUNT
The maximum number of nodes that a kd-tree can have when using this node type.
LeafSize leaf_size() const
The size of the range of the leaf node in the sample index array.
Index inner_first_child_id() const
The index of the first child of the node in the node array of the kd-tree.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
@ INDEX_BITS
The bit width used to store the first child index.
The default traits type used by the kd-tree.
@ MAX_DEPTH
A compile-time constant specifying the maximum depth of the kd-tree.
_DataPoint DataPoint
The type used to store point data.