GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::LooseOrthtree< N, Scalar, T > Class Template Reference

Orthtree-based space subdivision structure, optimized for intersection queries between axis-aligned boxes. More...

#include <GREM/core/data/LooseOrthtree.hpp>

Public Types

using value_type = T
 Value type of the container.
using reference = T&
 Reference type of the container.
using const_reference = const T&
 Const reference type of the container.
using pointer = T*
 Pointer type of the container.
using const_pointer = const T*
 Const pointer type of the container.
using size_type = size_t
 Size type of the container.
using difference_type = ptrdiff_t
 Difference type of the container.
using iterator = Iterator<false>
 Iterator type of the container.
using const_iterator = Iterator<true>
 Const iterator type of the container.
using local_iterator = LocalIterator<false>
 Local iterator type for the nodes of the container.
using const_local_iterator = LocalIterator<true>
 Const local iterator type for the nodes of the container.

Public Member Functions

 LooseOrthtree () noexcept
 Construct an invalid tree that must be reset with valid world parameters before use.
 LooseOrthtree (const Box< N, Scalar > &worldBoundingBox, Scalar minOrthantSize) noexcept
 Construct an empty tree.
void reset (const Box< N, Scalar > &newWorldBoundingBox, Scalar newMinOrthantSize) noexcept
 Reset the tree to an empty state with new world parameters.
void clear () noexcept
 Erase all inserted elements from the tree.
Scalar getMinOrthantSize () const noexcept
 Get the current minimum orthant size of the tree.
Box< N, Scalar > getRootBox () const noexcept
 Get the current root box of the tree.
iterator begin () noexcept
 Get the begin iterator of the elements in the tree.
const_iterator begin () const noexcept
 Get the begin iterator of the elements in the tree.
const_iterator cbegin () const noexcept
 Get the begin iterator of the elements in the tree.
iterator end () noexcept
 Get the end iterator of the elements in the tree.
const_iterator end () const noexcept
 Get the end iterator of the elements in the tree.
const_iterator cend () const noexcept
 Get the end iterator of the elements in the tree.
size_type size () const noexcept
 Get the number of elements in the tree.
bool empty () const noexcept
 Check whether the tree is empty or not.
template<typename... Args>
iterator emplace (const Box< N, Scalar > &elementBoundingBox, Args &&... args)
 Construct a new element in the tree.
iterator insert (const Box< N, Scalar > &elementBoundingBox, const T &value)
 Copy an element into the tree.
iterator insert (const Box< N, Scalar > &elementBoundingBox, T &&value)
 Move an element into the tree.
iterator erase (const_iterator pos)
 Remove an element from the tree.
void erase (LooseOrthtreeID id)
 Remove an element from the tree.
reference operator[] (LooseOrthtreeID id)
 Get the element with a specific handle.
const_reference operator[] (LooseOrthtreeID id) const
 Get the element with a specific handle.
template<typename Callback, typename Predicate>
auto traverseNodes (Callback &&callback, Predicate &&predicate) const
 Execute a callback function for each active node of the tree, including empty internal nodes without an element.
template<typename Callback>
auto traverseNodes (Callback &&callback) const
 Execute a callback function for each active node of the tree, including empty internal nodes without an element.
template<typename Callback, typename Predicate>
auto traverseElements (Callback &&callback, Predicate &&predicate) const
 Execute a callback function for each element in the tree.
template<typename Callback>
auto traverseElements (Callback &&callback) const
 Execute a callback function for each element in the tree.
template<typename Callback>
auto test (Point< N, Scalar > point, Callback &&callback) const
 Execute a callback function for each element in the tree that might contain a given point.
bool test (Point< N, Scalar > point) const noexcept
 Check if it is possible that some element in the tree contains a given point.
template<typename Callback>
auto test (const Box< N, Scalar > &box, Callback &&callback) const
 Execute a callback function for each element in the tree that might be intersecting with a given axis-aligned box.
bool test (const Box< N, Scalar > &box) const noexcept
 Check if it is possible that some element in the tree is intersecting with a given axis-aligned box.

Friends

template<typename U>
size_type erase (LooseOrthtree &c, const U &value)
template<typename Predicate>
size_type erase_if (LooseOrthtree &c, Predicate predicate)

Detailed Description

template<size_t N, typename Scalar, typename T>
class grem::LooseOrthtree< N, Scalar, T >

Orthtree-based space subdivision structure, optimized for intersection queries between axis-aligned boxes.

Template Parameters
Nnumber of vector dimensions (must be 2 or 3).
Scalarscalar type of the axis-aligned boxes stored in the tree.
Ttype of element to store in the tree.

Member Typedef Documentation

◆ value_type

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::value_type = T

Value type of the container.

◆ reference

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::reference = T&

Reference type of the container.

◆ const_reference

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::const_reference = const T&

Const reference type of the container.

◆ pointer

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::pointer = T*

Pointer type of the container.

◆ const_pointer

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::const_pointer = const T*

Const pointer type of the container.

◆ size_type

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::size_type = size_t

Size type of the container.

◆ difference_type

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::difference_type = ptrdiff_t

Difference type of the container.

◆ iterator

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::iterator = Iterator<false>

Iterator type of the container.

◆ const_iterator

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::const_iterator = Iterator<true>

Const iterator type of the container.

◆ local_iterator

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::local_iterator = LocalIterator<false>

Local iterator type for the nodes of the container.

◆ const_local_iterator

template<size_t N, typename Scalar, typename T>
using grem::LooseOrthtree< N, Scalar, T >::const_local_iterator = LocalIterator<true>

Const local iterator type for the nodes of the container.

Constructor & Destructor Documentation

◆ LooseOrthtree() [1/2]

template<size_t N, typename Scalar, typename T>
grem::LooseOrthtree< N, Scalar, T >::LooseOrthtree ( )
inlinenoexcept

Construct an invalid tree that must be reset with valid world parameters before use.

◆ LooseOrthtree() [2/2]

template<size_t N, typename Scalar, typename T>
grem::LooseOrthtree< N, Scalar, T >::LooseOrthtree ( const Box< N, Scalar > & worldBoundingBox,
Scalar minOrthantSize )
inlinenoexcept

Construct an empty tree.

Parameters
worldBoundingBoxbounding box of the world, or the full region that contains all other possible axis-aligned boxes that may be inserted into the tree.
minOrthantSizeminimum threshold for the size of a leaf orthant. This should correspond roughly to the typical width of the boxes that will be inserted into the tree.

Member Function Documentation

◆ reset()

template<size_t N, typename Scalar, typename T>
void grem::LooseOrthtree< N, Scalar, T >::reset ( const Box< N, Scalar > & newWorldBoundingBox,
Scalar newMinOrthantSize )
inlinenoexcept

Reset the tree to an empty state with new world parameters.

Parameters
newWorldBoundingBoxbounding box of the world, or the full region that contains all other possible axis-aligned boxes that may be inserted into the tree.
newMinOrthantSizeminimum threshold for the size of a leaf orthant. This should correspond roughly to the typical width of the boxes that will be inserted into the tree.
See also
clear()

◆ clear()

template<size_t N, typename Scalar, typename T>
void grem::LooseOrthtree< N, Scalar, T >::clear ( )
inlinenoexcept

Erase all inserted elements from the tree.

See also
reset()
erase()

◆ getMinOrthantSize()

template<size_t N, typename Scalar, typename T>
Scalar grem::LooseOrthtree< N, Scalar, T >::getMinOrthantSize ( ) const
inlinenodiscardnoexcept

Get the current minimum orthant size of the tree.

Returns
the minimum orthant size of the tree.

◆ getRootBox()

template<size_t N, typename Scalar, typename T>
Box< N, Scalar > grem::LooseOrthtree< N, Scalar, T >::getRootBox ( ) const
inlinenodiscardnoexcept

Get the current root box of the tree.

Returns
the root box of the tree.

◆ begin() [1/2]

template<size_t N, typename Scalar, typename T>
iterator grem::LooseOrthtree< N, Scalar, T >::begin ( )
inlinenodiscardnoexcept

Get the begin iterator of the elements in the tree.

Returns
an iterator to the first element in the sequence of elements.
Note
The element order is unspecified.

◆ begin() [2/2]

template<size_t N, typename Scalar, typename T>
const_iterator grem::LooseOrthtree< N, Scalar, T >::begin ( ) const
inlinenodiscardnoexcept

Get the begin iterator of the elements in the tree.

Returns
an iterator to the first element in the sequence of elements.
Note
The element order is unspecified.

◆ cbegin()

template<size_t N, typename Scalar, typename T>
const_iterator grem::LooseOrthtree< N, Scalar, T >::cbegin ( ) const
inlinenodiscardnoexcept

Get the begin iterator of the elements in the tree.

Returns
an iterator to the first element in the sequence of elements.
Note
The element order is unspecified.

◆ end() [1/2]

template<size_t N, typename Scalar, typename T>
iterator grem::LooseOrthtree< N, Scalar, T >::end ( )
inlinenodiscardnoexcept

Get the end iterator of the elements in the tree.

Returns
an iterator past the last element in the sequence of elements.
Note
The element order is unspecified.

◆ end() [2/2]

template<size_t N, typename Scalar, typename T>
const_iterator grem::LooseOrthtree< N, Scalar, T >::end ( ) const
inlinenodiscardnoexcept

Get the end iterator of the elements in the tree.

Returns
an iterator past the last element in the sequence of elements.
Note
The element order is unspecified.

◆ cend()

template<size_t N, typename Scalar, typename T>
const_iterator grem::LooseOrthtree< N, Scalar, T >::cend ( ) const
inlinenodiscardnoexcept

Get the end iterator of the elements in the tree.

Returns
an iterator past the last element in the sequence of elements.
Note
The element order is unspecified.

◆ size()

template<size_t N, typename Scalar, typename T>
size_type grem::LooseOrthtree< N, Scalar, T >::size ( ) const
inlinenodiscardnoexcept

Get the number of elements in the tree.

Returns
the number of elements.

◆ empty()

template<size_t N, typename Scalar, typename T>
bool grem::LooseOrthtree< N, Scalar, T >::empty ( ) const
inlinenodiscardnoexcept

Check whether the tree is empty or not.

Returns
true if there are no elements, false otherwise.

◆ emplace()

template<size_t N, typename Scalar, typename T>
template<typename... Args>
iterator grem::LooseOrthtree< N, Scalar, T >::emplace ( const Box< N, Scalar > & elementBoundingBox,
Args &&... args )
inline

Construct a new element in the tree.

Parameters
elementBoundingBoxaxis-aligned bounding box of the element.
argsconstructor arguments for the new element.
Returns
an iterator to the newly inserted element.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the element constructor.
See also
insert()

◆ insert() [1/2]

template<size_t N, typename Scalar, typename T>
iterator grem::LooseOrthtree< N, Scalar, T >::insert ( const Box< N, Scalar > & elementBoundingBox,
const T & value )
inline

Copy an element into the tree.

Parameters
elementBoundingBoxaxis-aligned bounding box of the element.
valuevalue to be copied into the tree.
Returns
an iterator to the newly inserted element.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the element copy constructor.
See also
emplace()

◆ insert() [2/2]

template<size_t N, typename Scalar, typename T>
iterator grem::LooseOrthtree< N, Scalar, T >::insert ( const Box< N, Scalar > & elementBoundingBox,
T && value )
inline

Move an element into the tree.

Parameters
elementBoundingBoxaxis-aligned bounding box of the element.
valuevalue to be moved into the tree.
Returns
an iterator to the newly inserted element.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the element move constructor.
See also
emplace()

◆ erase() [1/2]

template<size_t N, typename Scalar, typename T>
iterator grem::LooseOrthtree< N, Scalar, T >::erase ( const_iterator pos)
inline

Remove an element from the tree.

Parameters
positerator to the element to remove. Must be valid.
Returns
an iterator to the next element after the erased element.
See also
clear()

◆ erase() [2/2]

template<size_t N, typename Scalar, typename T>
void grem::LooseOrthtree< N, Scalar, T >::erase ( LooseOrthtreeID id)
inline

Remove an element from the tree.

Parameters
idhandle to the element to remove. Must be valid.
See also
clear()

◆ operator[]() [1/2]

template<size_t N, typename Scalar, typename T>
reference grem::LooseOrthtree< N, Scalar, T >::operator[] ( LooseOrthtreeID id)
inlinenodiscard

Get the element with a specific handle.

Parameters
idhandle to the element to get. Must be valid.
Returns
a reference to the given element, valid until the next mutation to the tree.

◆ operator[]() [2/2]

template<size_t N, typename Scalar, typename T>
const_reference grem::LooseOrthtree< N, Scalar, T >::operator[] ( LooseOrthtreeID id) const
inlinenodiscard

Get the element with a specific handle.

Parameters
idhandle to the element to get. Must be valid.
Returns
a read-only reference to the given element, valid until the next mutation to the tree.

◆ traverseNodes() [1/2]

template<size_t N, typename Scalar, typename T>
template<typename Callback, typename Predicate>
auto grem::LooseOrthtree< N, Scalar, T >::traverseNodes ( Callback && callback,
Predicate && predicate ) const
inline

Execute a callback function for each active node of the tree, including empty internal nodes without an element.

Parameters
callbackfunction to execute, which should accept the following parameters (though they don't need to be used):
  • const grem::Box<N, Scalar>& looseBounds: an axis-aligned box that defines the region that an element's bounding box must be fully contained within in order to belong to the node.
  • const_local_iterator first: a read-only iterator to the beginning of the range of elements in the node.
  • const_local_iterator last: a read-only iterator to one past the end of the range of elements in the node.
The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
predicatecondition that must be met in order to traverse deeper into the tree. Must return bool and accept the following parameter:
  • const grem::Box<N, Scalar>& boundingBox: an axis-aligned box spanning all elements in the branch.
The predicate function should return a bool that is true if the next node should be traversed, or false if the branch should be ignored.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback or predicate functions.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
See also
traverseElements()
test()

◆ traverseNodes() [2/2]

template<size_t N, typename Scalar, typename T>
template<typename Callback>
auto grem::LooseOrthtree< N, Scalar, T >::traverseNodes ( Callback && callback) const
inline

Execute a callback function for each active node of the tree, including empty internal nodes without an element.

Parameters
callbackfunction to execute, which should accept the following parameters (though they don't need to be used):
  • const grem::Box<N, Scalar>& looseBounds: an axis-aligned box that defines the region that an element's bounding box must be fully contained within in order to belong to the node.
  • const_local_iterator first: a read-only iterator to the beginning of the range of elements in the node.
  • const_local_iterator last: a read-only iterator to one past the end of the range of elements in the node.
The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback function.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
See also
traverseElements()
test()

◆ traverseElements() [1/2]

template<size_t N, typename Scalar, typename T>
template<typename Callback, typename Predicate>
auto grem::LooseOrthtree< N, Scalar, T >::traverseElements ( Callback && callback,
Predicate && predicate ) const
inline

Execute a callback function for each element in the tree.

Parameters
callbackfunction to execute, which should accept the following parameter:
  • const T& element: a read-only reference to the element.
The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
predicatecondition that must be met in order to traverse deeper into the tree. Must return bool and accept the following parameter:
  • const grem::Box<N, Scalar>& boundingBox: an axis-aligned box spanning all elements in the branch.
The predicate function should return a bool that is true if the next node should be traversed, or false if the branch should be ignored.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback or predicate functions.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
See also
traverseNodes()
test()

◆ traverseElements() [2/2]

template<size_t N, typename Scalar, typename T>
template<typename Callback>
auto grem::LooseOrthtree< N, Scalar, T >::traverseElements ( Callback && callback) const
inline

Execute a callback function for each element in the tree.

Parameters
callbackfunction to execute, which should accept the following parameter:
  • const T& element: a read-only reference to the element.
The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback function.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
See also
traverseNodes()
test()

◆ test() [1/4]

template<size_t N, typename Scalar, typename T>
template<typename Callback>
auto grem::LooseOrthtree< N, Scalar, T >::test ( Point< N, Scalar > point,
Callback && callback ) const
inline

Execute a callback function for each element in the tree that might contain a given point.

Parameters
pointpoint to test.
callbackfunction to execute, which should accept the following parameter:
  • const T& element: a read-only reference to the element.
The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback function.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
See also
traverseNodes()
traverseElements()

◆ test() [2/4]

template<size_t N, typename Scalar, typename T>
bool grem::LooseOrthtree< N, Scalar, T >::test ( Point< N, Scalar > point) const
inlinenodiscardnoexcept

Check if it is possible that some element in the tree contains a given point.

Parameters
pointpoint to test.
Returns
true if some element might contain the point, false otherwise.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
See also
traverseNodes()
traverseElements()

◆ test() [3/4]

template<size_t N, typename Scalar, typename T>
template<typename Callback>
auto grem::LooseOrthtree< N, Scalar, T >::test ( const Box< N, Scalar > & box,
Callback && callback ) const
inline

Execute a callback function for each element in the tree that might be intersecting with a given axis-aligned box.

Parameters
boxbox to test.
callbackfunction to execute, which should accept the following parameter:
  • const T& element: a read-only reference to the element.
The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback function.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
See also
traverseNodes()
traverseElements()

◆ test() [4/4]

template<size_t N, typename Scalar, typename T>
bool grem::LooseOrthtree< N, Scalar, T >::test ( const Box< N, Scalar > & box) const
inlinenodiscardnoexcept

Check if it is possible that some element in the tree is intersecting with a given axis-aligned box.

Parameters
boxbox to test.
Returns
true if some element might be intersecting with the box, false otherwise.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
See also
traverseNodes()
traverseElements()

◆ erase

template<size_t N, typename Scalar, typename T>
template<typename U>
size_type erase ( LooseOrthtree< N, Scalar, T > & c,
const U & value )
friend

◆ erase_if

template<size_t N, typename Scalar, typename T>
template<typename Predicate>
size_type erase_if ( LooseOrthtree< N, Scalar, T > & c,
Predicate predicate )
friend

The documentation for this class was generated from the following file: