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

Binary tree-based space subdivision container, Z-ordered using morton codes, optimized for intersection queries between axis-aligned boxes. More...

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

Public Types

using value_type = Pair<Box<N, Scalar>, T>
 Value type of the container.
using reference = Pair<const Box<N, Scalar>, T>&
 Reference type of the container.
using const_reference = const Pair<const Box<N, Scalar>, T>&
 Const reference type of the container.
using pointer = Pair<const Box<N, Scalar>, T>*
 Pointer type of the container.
using const_pointer = const Pair<const Box<N, Scalar>, 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 = pointer
 Iterator type of the container.
using const_iterator = const_pointer
 Const iterator type of the container.

Public Member Functions

 LinearBoundingVolumeHierarchy () noexcept=default
 Construct an empty tree.
void clear () noexcept
 Erase all inserted elements from 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.
void erase (const_iterator pos)
 Remove an element from the tree.
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.

Detailed Description

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

Binary tree-based space subdivision container, Z-ordered using morton codes, optimized for intersection queries between axis-aligned boxes.

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

Member Typedef Documentation

◆ value_type

template<size_t N, typename Scalar, typename T>
using grem::LinearBoundingVolumeHierarchy< N, Scalar, T >::value_type = Pair<Box<N, Scalar>, T>

Value type of the container.

◆ reference

template<size_t N, typename Scalar, typename T>
using grem::LinearBoundingVolumeHierarchy< N, Scalar, T >::reference = Pair<const Box<N, Scalar>, T>&

Reference type of the container.

◆ const_reference

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

Const reference type of the container.

◆ pointer

template<size_t N, typename Scalar, typename T>
using grem::LinearBoundingVolumeHierarchy< N, Scalar, T >::pointer = Pair<const Box<N, Scalar>, T>*

Pointer type of the container.

◆ const_pointer

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

Const pointer type of the container.

◆ size_type

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

Size type of the container.

◆ difference_type

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

Difference type of the container.

◆ iterator

template<size_t N, typename Scalar, typename T>
using grem::LinearBoundingVolumeHierarchy< N, Scalar, T >::iterator = pointer

Iterator type of the container.

◆ const_iterator

template<size_t N, typename Scalar, typename T>
using grem::LinearBoundingVolumeHierarchy< N, Scalar, T >::const_iterator = const_pointer

Const iterator type of the container.

Constructor & Destructor Documentation

◆ LinearBoundingVolumeHierarchy()

template<size_t N, typename Scalar, typename T>
grem::LinearBoundingVolumeHierarchy< N, Scalar, T >::LinearBoundingVolumeHierarchy ( )
defaultnoexcept

Construct an empty tree.

Member Function Documentation

◆ clear()

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

Erase all inserted elements from the tree.

See also
erase()

◆ begin() [1/2]

template<size_t N, typename Scalar, typename T>
iterator grem::LinearBoundingVolumeHierarchy< 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::LinearBoundingVolumeHierarchy< 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::LinearBoundingVolumeHierarchy< 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::LinearBoundingVolumeHierarchy< 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::LinearBoundingVolumeHierarchy< 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::LinearBoundingVolumeHierarchy< 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::LinearBoundingVolumeHierarchy< 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::LinearBoundingVolumeHierarchy< 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::LinearBoundingVolumeHierarchy< 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.
Warning
The returned iterator is invalidated on the next call to any non-const member function on the tree.
See also
insert()

◆ insert() [1/2]

template<size_t N, typename Scalar, typename T>
iterator grem::LinearBoundingVolumeHierarchy< 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.
Warning
The returned iterator is invalidated on the next call to any non-const member function on the tree.
See also
emplace()

◆ insert() [2/2]

template<size_t N, typename Scalar, typename T>
iterator grem::LinearBoundingVolumeHierarchy< 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.
Warning
The returned iterator is invalidated on the next call to any non-const member function on the tree.
See also
emplace()

◆ erase()

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

Remove an element from the tree.

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

◆ traverseNodes() [1/2]

template<size_t N, typename Scalar, typename T>
template<typename Callback, typename Predicate>
auto grem::LinearBoundingVolumeHierarchy< 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>& boundingBox: an axis-aligned box that defines the region that an element's bounding box must be intersecting in order to belong to the node.
  • const T* element: a non-owning read-only pointer to the element occupying the node, or nullptr if it does not have one.
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.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseElements()
test()

◆ traverseNodes() [2/2]

template<size_t N, typename Scalar, typename T>
template<typename Callback>
auto grem::LinearBoundingVolumeHierarchy< 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>& boundingBox: an axis-aligned box that defines the region that an element's bounding box must be intersecting in order to belong to the node.
  • const T* element: a non-owning read-only pointer to the element occupying the node, or nullptr if it does not have one.
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.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseElements()
test()

◆ traverseElements() [1/2]

template<size_t N, typename Scalar, typename T>
template<typename Callback, typename Predicate>
auto grem::LinearBoundingVolumeHierarchy< 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.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseNodes()
test()

◆ traverseElements() [2/2]

template<size_t N, typename Scalar, typename T>
template<typename Callback>
auto grem::LinearBoundingVolumeHierarchy< 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.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseNodes()
test()

◆ test() [1/4]

template<size_t N, typename Scalar, typename T>
template<typename Callback>
auto grem::LinearBoundingVolumeHierarchy< 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.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseNodes()
traverseElements()

◆ test() [2/4]

template<size_t N, typename Scalar, typename T>
bool grem::LinearBoundingVolumeHierarchy< 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.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseNodes()
traverseElements()

◆ test() [3/4]

template<size_t N, typename Scalar, typename T>
template<typename Callback>
auto grem::LinearBoundingVolumeHierarchy< 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.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseNodes()
traverseElements()

◆ test() [4/4]

template<size_t N, typename Scalar, typename T>
bool grem::LinearBoundingVolumeHierarchy< 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.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseNodes()
traverseElements()

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