33#include <NDEVR/RTree.h>
34#include <NDEVR/Thread.h>
35#include <NDEVR/BasicThread.h>
36#include <NDEVR/RWLock.h>
42 template<u
int01 t_dims,
class t_type>
50 : RTree<t_dims, t_type>(bucket_size)
53 m_indices.allocateSpace<
false>(bucket_size);
58 : RTree<t_dims, t_type>(tree)
64 : RTree<t_dims, t_type, t_bucket_size>(std::move(tree))
72 template<
class t_node_type>
77 m_nodes[root_node].clear(m_nodes[root_node].begin(),
_getBoundingBoxThreaded(0, indices, elements, 0, indices.size()));
79 if (progress !=
nullptr) progress->allowCancel(
true);
81 if (progress !=
nullptr) progress->allowCancel(
false);
83 m_indices.ensureCapacity(
cast<uint04>(1.1 * (m_indices.size())),
true,
true);
84 m_nodes.ensureCapacity(
cast<uint04>(1.1 * (m_nodes.size())),
true,
true);
96 template<
class t_node_type>
101 m_nodes[root_node].clear(m_nodes[root_node].begin(), bounds);
103 if (progress !=
nullptr) progress->allowCancel(
true);
105 if (progress !=
nullptr) progress->allowCancel(
false);
107 m_indices.ensureCapacity(
cast<uint04>(1.1 * (m_indices.size())),
true,
true);
108 m_nodes.ensureCapacity(
cast<uint04>(1.1 * (m_nodes.size())),
true,
true);
124 template<
class t_node_type>
127 uint04 level_value = pow(2U, level);
130 _balanceLeafNode(node_index, elements, indices, start, end, progress);
134 const uint04 new_left = _calculateAndSplit(node_index, elements, indices, start, end);
136 [
this, level, start, new_left, node_index, &progress, &indices, &elements] {
141 [
this, level, end, new_left, node_index, &progress, &indices, &elements] {
156 template<
class t_node_type>
161 return _getBounds(indices, elements, start, end);
165 const uint04 middle = start + (end - start) / 2;
169 [
this, &left, &indices, &elements, start, middle, top_level] {
172 [
this, &right, &indices, &elements, end, middle, top_level] {
184 RTree<t_dims, t_type, t_bucket_size>::splitLeafNode(index);
A specification of upper and lower bounds in N-dimensions.
The equivelent of std::vector but with a bit more control.
A light-weight base class for Log that allows processes to update, without the need for additional in...
Used with InfoPipe to signal that the system will be using progress.
bool addAllThreaded(const Buffer< t_node_type > &elements, InfoPipe *progress=nullptr)
Adds all elements to the tree using multi-threaded balancing.
std::mutex m_split_lock
Mutex protecting leaf node splits during multi-threaded construction.
bool addAllThreaded(const Buffer< t_node_type > &elements, uint04 start_index, uint04 end_index, InfoPipe *progress=nullptr)
Adds a range of elements to the tree using multi-threaded balancing.
Bounds< t_dims, t_type > _getBoundingBoxThreaded(uint04 top_level, const Buffer< uint04 > &indices, const Buffer< t_node_type > &elements, uint04 start, uint04 end)
Computes the bounding box of elements using multi-threaded divide and conquer.
ThreadedRTree(uint04 bucket_size)
Constructs a ThreadedRTree with the given bucket size.
void splitLeafNode(uint04 index) final override
Thread-safe override that splits a leaf node using a mutex lock.
bool _balanceLeafNodeThreaded(uint04 level, const uint04 node_index, const Buffer< t_node_type > &elements, Buffer< uint04 > &indices, uint04 start, uint04 end, ProgressInfo &progress)
Recursively balances leaf nodes using thread splitting when beneficial.
uint04 m_number_of_threads
The number of threads to use for parallel operations.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.