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>;
137 : m_is_leaf(n.m_is_leaf)
141 data.m_leaf = n.data.m_leaf;
145 data.m_inner = n.data.m_inner;
153 m_is_leaf = n.m_is_leaf;
156 data.m_leaf = n.data.m_leaf;
160 data.m_inner = n.data.m_inner;
167 constexpr KdTreeCustomizableNode(
const KdTreeCustomizableNode& n)
168 : m_is_leaf(n.m_is_leaf)
172 data.m_leaf = n.data.m_leaf;
176 data.m_inner = n.data.m_inner;
180 constexpr KdTreeCustomizableNode& operator=(
const KdTreeCustomizableNode& n)
184 m_is_leaf = n.m_is_leaf;
187 data.m_leaf = n.data.m_leaf;
191 data.m_inner = n.data.m_inner;
198 ~KdTreeCustomizableNode() {}
200 [[nodiscard]]
bool is_leaf()
const {
return m_is_leaf; }
201 void set_is_leaf(
bool is_leaf) { m_is_leaf = is_leaf; }
219 data.m_leaf.start = start;
220 data.m_leaf.size = (LeafSize)size;
237 data.m_inner.split_value = split_value;
238 data.m_inner.first_child_id = first_child_id;
239 data.m_inner.split_dim = split_dim;
247 [[nodiscard]] Index
leaf_start()
const {
return data.m_leaf.start; }
252 [[nodiscard]] LeafSize
leaf_size()
const {
return data.m_leaf.size; }
274 [[nodiscard]]
inline LeafType& getAsLeaf() {
return data.m_leaf; }
275 [[nodiscard]]
inline InnerType& getAsInner() {
return data.m_inner; }
276 [[nodiscard]]
inline const LeafType& getAsLeaf()
const {
return data.m_leaf; }
277 [[nodiscard]]
inline const InnerType& getAsInner()
const {
return data.m_inner; }
280 bool m_is_leaf{
true};
284 constexpr Data() : m_leaf() {}
293template <
typename Index,
typename NodeIndex,
typename DataPoint,
294 typename LeafSize = Index>
296 KdTreeDefaultInnerNode<NodeIndex, typename DataPoint::Scalar, DataPoint::Dim>,
297 KdTreeDefaultLeafNode<Index, LeafSize>> {
310template <
typename _DataPoint,
335 using IndexType = int;
336 using LeafSizeType =
unsigned short;
339 using PointContainer = std::vector<DataPoint>;
340 using IndexContainer = std::vector<IndexType>;
343 using NodeIndexType = std::size_t;
344 using NodeType = _NodeType<IndexType, NodeIndexType, DataPoint, LeafSizeType>;
345 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.