33#include <NDEVR/TreeIterator.h>
34#include <NDEVR/Node.h>
35#include <NDEVR/BaseValues.h>
36#include <NDEVR/Buffer.h>
37#include <NDEVR/Bounds.h>
38#include <NDEVR/ProgressInfo.h>
39#include <NDEVR/Vector.h>
40#include <NDEVR/VectorFunctions.h>
41#include <NDEVR/Intersection.h>
42#include <NDEVR/BinaryHeap.h>
52 template<
class t_node_type,
class t_type, u
int01 t_node_child_size>
55 static_assert(std::is_base_of<TreeNode, t_node_type>::value,
"t_node_type must inherit from Node");
79 std::swap(
m_nodes, tree.m_nodes);
117 for (
uint04 i = 0; i < deletion_indices.
size(); i++)
119 new_indices.
add(index);
120 if (!deletion_indices[i])
124 while (iterator.
valid())
127 t_node_type& node =
m_nodes[node_index];
131 const uint04 end = node.end();
132 for (
uint04 i = node.begin(); i < end; i++)
134 lib_assert(!deletion_indices[
m_indices[i]],
"Must Call remove values prior to removeIndices");
149 while (iterator.
valid())
152 t_node_type& node =
m_nodes[node_index];
156 const uint04 node_end = node.end();
157 for (
uint04 i = node.begin(); i < node_end; i++)
176 for (
uint04 i = 0; i < insertion_indices.
size(); i++)
178 if (!insertion_indices[i])
179 index_mapping.
add(index);
184 while (iterator.
valid())
187 t_node_type& node =
m_nodes[node_index];
191 const uint04 end = node.end();
192 for (
uint04 i = node.begin(); i < end; i++)
208 while (iterator.
valid())
211 t_node_type& node =
m_nodes[node_index];
215 const uint04 node_end = node.end();
216 for (
uint04 i = node.begin(); i < node_end; i++)
237 while (iterator.
valid())
239 const t_node_type& node =
m_nodes[iterator.
get()];
244 for (
uint04 i = node.begin(); i < end; i++)
256 template<u
int01 t_dims,
class t_buffer_type>
260 for (
uint04 i = start; i < end; i++)
262 bounds.addToBoundingBox(elements[
indices[i]]);
270 while (iterator.
valid())
272 const t_node_type& node =
m_nodes[iterator.
get()];
277 for (
uint04 i = node.begin(); i < end; i++)
291 template<
class t_buffer_type>
292 void sortVertices(
const t_buffer_type& elements, t_buffer_type& sorted)
const
315 std::swap(
m_nodes, value.m_nodes);
321 template<
bool t_use_values>
326 for (
uint04 i = 0; i < index_values.
size(); i++)
327 if (t_use_values == index_values[i])
331 template<
class t_buffer_type>
335 for (
uint04 i = start_index; i < end_index; i++)
337 if(!
isNaN(elements[i]))
358 child_node_index =
m_nodes.size();
360 for (
uint04 i = 0; i < t_node_child_size - 1; ++i)
380 for (
uint04 i = 1; i < t_node_child_size; ++i)
394 m_nodes[index].setChildNodeStart(child_node_index);
402 while (iterator.
valid())
422 template<
bool t_set_true>
426 while (iterator.
valid())
428 const t_node_type& node =
m_nodes[iterator.
get()];
432 const uint04 end = node.end();
433 for (
uint04 i = node.begin(); i < end; i++)
444 template<
bool t_is_presorted>
448 while (iterator.
valid())
450 const t_node_type& node =
m_nodes[iterator.
get()];
454 if constexpr (!t_is_presorted)
460 const uint04 end = node.begin() + node.size();
461 for(
uint04 i = node.begin(); i < end; i++)
487 template<u
int01 t_dims,
class t_type,
class t_child_tree>
488 class Tree :
public t_child_tree
492 : t_child_tree(bucket_size)
498 : t_child_tree(
std::move(tree))
503 t_child_tree::template _getAllT<true>(t_child_tree::root_node, indices);
508 t_child_tree::template _getAll<false>(t_child_tree::root_node, indices);
510 template<
class t_reference_type,
class t_buffer_type>
516 template<
class t_reference_type,
class t_buffer_type>
520 t_child_tree::template _getClosestElement<false>(t_child_tree::root_node, point, elements, max_distance_squared, epsilon, index);
523 template<
class t_reference_type,
class t_buffer_type>
529 template<
class t_reference_type,
class t_buffer_type>
533 t_child_tree::template _getClosestElement<true>(t_child_tree::root_node, point, elements, max_distance_squared, epsilon, index);
536 template<
class t_area_type,
class t_buffer_type>
539 t_child_tree::template _getEnclosedElements<false>(t_child_tree::root_node, area, indices, elements);
541 template<
class t_area_type,
class t_buffer_type>
544 t_child_tree::template _getEnclosedElements<true>(t_child_tree::root_node, area, indices, elements);
548 template<
class t_area_type,
class t_buffer_type>
549 void getChangedElements(
const t_area_type& new_area,
const t_area_type& old_area,
Buffer<bool>& indices,
const t_buffer_type& elements,
bool allow_enable,
bool allow_disable)
const
551 t_child_tree::template _getChangedElements(t_child_tree::root_node, new_area, old_area, indices, elements, allow_enable, allow_disable);
553 template<
class t_area_type,
class t_buffer_type>
556 t_child_tree::template _getEnclosedElements(t_child_tree::root_node, area, indices, elements);
559 template<
class t_area_type,
class t_buffer_type>
562 return t_child_tree::template _getNumberOfEnclosedElements(t_child_tree::root_node, area, elements);
565 template<
class t_reference_type,
class t_buffer_type>
576 t_child_tree::template _getClosestElements<false>(t_child_tree::root_node, point, elements, max_distance, epsilon, heap, size);
580 template<
class t_reference_type,
class t_buffer_type>
583 t_child_tree::template _getClosestElements<false>(t_child_tree::root_node, point, elements, max_distance, epsilon, value_heap, size);
585 template<
class t_reference_type,
class t_buffer_type>
588 t_child_tree::template _getClosestElements<true>(t_child_tree::root_node, point, elements, max_distance, epsilon, value_heap, size);
592 t_child_tree::m_indices.swapAllElements(index_a, index_b);
596 template<
bool t_has_nans,
bool t_uses_boundary,
class t_buffer_type>
599 t_child_tree::template _addValue<t_has_nans, t_uses_boundary>(t_child_tree::root_node, index, elements, rebalance);
602 template<
bool t_has_nans,
bool t_uses_boundary,
class t_buffer_type>
605 if (t_child_tree::useBulkResize(insertion_indices.
count(
true)))
607 t_child_tree::template _addValues<t_has_nans, t_uses_boundary>(t_child_tree::root_node, t_child_tree::template prepareAddAll<true>(insertion_indices), elements, is_precise, progress);
611 for (
uint04 i = 0; i < elements.size(); i++)
613 if (insertion_indices[i])
618 template<
bool t_has_nans,
bool t_uses_boundary,
class t_buffer_type>
623 template<
bool t_has_nans,
bool t_uses_boundary,
class t_buffer_type>
626 if (t_child_tree::useBulkResize(end_index - start_index))
628 t_child_tree::template _addValues<t_has_nans, t_uses_boundary>(t_child_tree::root_node, t_child_tree::template prepareAddAll(start_index, end_index, elements), elements, is_precise, progress);
632 for (
uint04 i = start_index; i < end_index; i++)
634 if constexpr (t_has_nans)
636 if (
isNaN(elements[i]))
644 template<
bool t_has_nans,
bool t_uses_boundary,
class t_buffer_type>
647 if (t_child_tree::useBulkResize(indices.
size()))
649 t_child_tree::template _addValues<t_has_nans, t_uses_boundary>(t_child_tree::root_node, indices, elements, is_precise, progress);
662 template<
class t_buffer_type>
665 t_child_tree::template _removeValue(t_child_tree::root_node, index, elements);
668 template<
class t_buffer_type>
671 if (t_child_tree::useBulkResize(insertion_indices.
count(
true)))
673 t_child_tree::template clear();
674 t_child_tree::template _addValues(t_child_tree::root_node, t_child_tree::template prepareAddAll<false>(insertion_indices), elements, progress);
678 for (
uint04 i = 0; i < elements.size(); i++)
680 if (insertion_indices[i])
686 template<
class t_buffer_type>
689 if (t_child_tree::template useBulkResize(end_index - start_index))
691 t_child_tree::template clear();
692 Buffer<uint04> indices(elements.size() - (end_index - start_index));
693 for (
uint04 i = 0; i < start_index; i++)
695 for (
uint04 i = end_index; i < elements.size(); i++)
697 t_child_tree::template _addValues(t_child_tree::root_node, indices, elements, progress);
701 for (
uint04 i = start_index; i < end_index; i++)
#define UNUSED(expr)
Definition BaseValues.hpp:433
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
Definition BinaryHeap.hpp:39
Buffer< t_value_type > sortedIndices() const
Definition BinaryHeap.hpp:92
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:57
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void add(t_type &&object)
Definition Buffer.hpp:199
void addSpace(t_index_type space_to_add)
Definition Buffer.hpp:440
bool contains(const t_type &element) const
Definition Buffer.hpp:674
constexpr t_index_type size() const
Definition Buffer.hpp:1461
decltype(auto) last()
Definition Buffer.hpp:977
void addAll(const Buffer< t_type, t_other_index_type, t_other_memory_allocator, t_other_memory_manager > &buffer)
Definition Buffer.hpp:248
decltype(auto) begin()
Definition Buffer.hpp:504
void clear()
Definition Buffer.hpp:572
t_index_type count(const t_type &element) const
Definition Buffer.hpp:728
void removeLast()
Definition Buffer.hpp:1099
Definition ProgressInfo.hpp:43
uint04 getNumberOfFreeIndices()
Definition Tree.hpp:343
uint04 m_bucket_size
Definition Tree.hpp:484
TreeBase & operator=(const TreeBase &value)
Definition Tree.hpp:304
Buffer< t_node_type, uint04, ObjectAllocator< true > > m_nodes
Definition Tree.hpp:480
void reclaimChildren(uint04 index)
Definition Tree.hpp:397
const Buffer< uint04 > & indices() const
Definition Tree.hpp:287
uint04 nodeSize() const
Definition Tree.hpp:474
void removeIndices(uint04 begin, uint04 end)
Definition Tree.hpp:145
Buffer< uint04 > prepareAddAll(const Buffer< bool > &index_values)
Definition Tree.hpp:322
Buffer< uint04 > m_available_node_positions
Definition Tree.hpp:481
void addIndices(const Buffer< bool > &insertion_indices)
Definition Tree.hpp:172
virtual ~TreeBase()
Definition Tree.hpp:91
void addIndices(uint04 begin, uint04 end)
Definition Tree.hpp:204
const t_node_type & getNode(uint04 node_id) const
Definition Tree.hpp:108
void _getAllT(const uint04 &node_index, Buffer< bool > &indices) const
Definition Tree.hpp:423
void _getAll(const uint04 &node_index, Buffer< uint04 > &indices) const
Definition Tree.hpp:445
uint04 getNumberOfNodes() const
Definition Tree.hpp:104
void removeIndex(uint04 index) const
Definition Tree.hpp:234
Bounds< t_dims, t_type > _getBounds(const Buffer< uint04 > &indices, const t_buffer_type &elements, uint04 start, uint04 end)
Definition Tree.hpp:257
TreeBase(const Buffer< t_node_type > &nodes, const Buffer< uint04 > &indices, bool is_read_only)
Definition Tree.hpp:83
void sortVertices(const t_buffer_type &elements, t_buffer_type &sorted) const
Definition Tree.hpp:292
uint04 size() const
Definition Tree.hpp:229
TreeBase(TreeBase &&tree)
Definition Tree.hpp:71
Buffer< uint04 > prepareAddAll(uint04 start_index, uint04 end_index, const t_buffer_type &elements)
Definition Tree.hpp:332
Buffer< uint04 > m_indices
Definition Tree.hpp:479
static const uint04 root_node
Definition Tree.hpp:483
uint04 indexSize() const
Definition Tree.hpp:470
TreeBase & operator=(TreeBase &&value)
Definition Tree.hpp:312
TreeBase(uint04 bucket_size)
Definition Tree.hpp:57
void splitLeafNode(uint04 index)
Definition Tree.hpp:353
void clear()
Definition Tree.hpp:94
void removeIndices(const Buffer< bool > &deletion_indices)
Definition Tree.hpp:113
void addIndex(uint04 index) const
Definition Tree.hpp:267
TreeBase(const TreeBase &tree)
Definition Tree.hpp:64
uint04 getIndex(uint04 index) const
Definition Tree.hpp:93
Buffer< uint04 > m_available_indexed_positions
Definition Tree.hpp:482
uint04 getNumberOfFreeNodes()
Definition Tree.hpp:348
void addValues(const Buffer< bool > &insertion_indices, const t_buffer_type &elements, bool is_precise, ProgressInfo *progress=nullptr)
Definition Tree.hpp:603
void closestElements(const t_reference_type &point, uint04 size, MinHeap< t_type, uint04 > &value_heap, const t_buffer_type &elements, t_type &max_distance, t_type epsilon=cast< t_type >(0)) const
Definition Tree.hpp:581
void enclosedElements(const t_area_type &area, Buffer< bool > &indices, const t_buffer_type &elements) const
Definition Tree.hpp:554
void removeValues(uint04 start_index, uint04 end_index, const t_buffer_type &elements, ProgressInfo *progress=nullptr)
Definition Tree.hpp:687
void removeValues(const Buffer< bool > &insertion_indices, const t_buffer_type &elements, ProgressInfo *progress=nullptr)
Definition Tree.hpp:669
void enclosedElements(const t_area_type &area, Buffer< uint04 > &indices, const t_buffer_type &elements) const
Definition Tree.hpp:537
void presortedEnclosedElements(const t_area_type &area, Buffer< uint04 > &indices, const t_buffer_type &elements) const
Definition Tree.hpp:542
virtual const char * getTreeType() const =0
uint04 closestElementPresorted(const t_reference_type &point, const t_buffer_type &elements, t_type epsilon=cast< t_type >(0)) const
Definition Tree.hpp:524
void addValues(uint04 start_index, uint04 end_index, const t_buffer_type &elements, bool is_precise, ProgressInfo *progress=nullptr)
Definition Tree.hpp:624
void addValues(const Buffer< uint04 > &indices, const t_buffer_type &elements, bool is_precise, ProgressInfo *progress=nullptr)
Definition Tree.hpp:645
void presortedClosestElements(const t_reference_type &point, uint04 size, MinHeap< t_type, uint04 > &value_heap, const t_buffer_type &elements, t_type &max_distance, t_type epsilon=cast< t_type >(0)) const
Definition Tree.hpp:586
void addValue(uint04 index, const t_buffer_type &elements, bool rebalance)
Definition Tree.hpp:597
void addValues(const t_buffer_type &elements, bool is_precise, ProgressInfo *progress=nullptr)
Definition Tree.hpp:619
void getAll(Buffer< uint04 > &indices) const
Definition Tree.hpp:506
void getAll(Buffer< bool > &indices) const
Definition Tree.hpp:501
void removeValue(uint04 index, const t_buffer_type &elements)
Definition Tree.hpp:663
uint04 getNumberOfEnclosedElements(const t_area_type &area, const t_buffer_type &elements) const
Definition Tree.hpp:560
void getChangedElements(const t_area_type &new_area, const t_area_type &old_area, Buffer< bool > &indices, const t_buffer_type &elements, bool allow_enable, bool allow_disable) const
Definition Tree.hpp:549
uint04 closestElement(const t_reference_type &point, const t_buffer_type &elements, t_type epsilon=cast< t_type >(0)) const
Definition Tree.hpp:511
void swapIndices(uint04 index_a, uint04 index_b)
Definition Tree.hpp:590
Tree(const t_child_tree &tree)
Definition Tree.hpp:494
void closestElements(const t_reference_type &point, uint04 size, Buffer< uint04 > &indices, const t_buffer_type &elements, t_type &max_distance, t_type epsilon=cast< t_type >(0)) const
Definition Tree.hpp:566
Tree(uint04 bucket_size)
Definition Tree.hpp:491
Tree(t_child_tree &&tree)
Definition Tree.hpp:497
uint04 closestElementPresorted(const t_reference_type &point, const t_buffer_type &elements, t_type &max_distance_squared, t_type epsilon=cast< t_type >(0)) const
Definition Tree.hpp:530
uint04 closestElement(const t_reference_type &point, const t_buffer_type &elements, t_type &max_distance_squared, t_type epsilon=cast< t_type >(0)) const
Definition Tree.hpp:517
Definition TreeIterator.hpp:38
void pop()
Definition TreeIterator.hpp:53
bool valid() const
Definition TreeIterator.hpp:49
void addAndGoToIndices(uint04 start, uint04 size)
Definition TreeIterator.hpp:71
void addAndGoToIndex(uint04 index)
Definition TreeIterator.hpp:61
uint04 get() const
Definition TreeIterator.hpp:45
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
Definition BaseValues.hpp:272