A dynamic AABB tree broad-phase. More...
#include <playrho/d2/DynamicTree.hpp>
Classes | |
class | TreeNode |
A node in the dynamic tree. More... | |
Public Types | |
using | Height = DynamicTreeSize |
Type for heights. More... | |
using | Size = DynamicTreeSize |
Size type. | |
Public Member Functions | |
DynamicTree () noexcept | |
Non-throwing default constructor. More... | |
DynamicTree (const DynamicTree &other) | |
Copy constructor. More... | |
DynamicTree (DynamicTree &&other) noexcept | |
Move constructor. | |
DynamicTree (Size nodeCapacity) | |
Size initializing constructor. More... | |
~DynamicTree () noexcept | |
Destroys the tree, freeing the node pool. | |
void | Clear () noexcept |
Clears the dynamic tree. More... | |
Size | CreateLeaf (const AABB &aabb, const Contactable &data) |
Creates a new leaf node. More... | |
void | DestroyLeaf (Size index) noexcept |
Destroys a leaf node. More... | |
Size | FindReference (Size index) const noexcept |
Finds first node which references the given index. More... | |
AABB | GetAABB (Size index) const noexcept |
Gets the AABB for a leaf or branch (a non-unused node). More... | |
DynamicTreeBranchData | GetBranchData (Size index) const noexcept |
Gets the branch data for the identified node. More... | |
Size | GetFreeIndex () const noexcept |
Gets the free index. | |
Height | GetHeight (Size index) const noexcept |
Gets the height value for the identified node. More... | |
Size | GetLeafCount () const noexcept |
Gets the current leaf node count. More... | |
Contactable | GetLeafData (Size index) const noexcept |
Gets the leaf data for the node identified by the given identifier. More... | |
const TreeNode & | GetNode (Size index) const noexcept |
Gets the node identified by the given identifier. More... | |
Size | GetNodeCapacity () const noexcept |
Gets the current node capacity of this tree. More... | |
Size | GetNodeCount () const noexcept |
Gets the current count of allocated nodes. More... | |
Size | GetOther (Size index) const noexcept |
Gets the "other" index for the node at the given index. More... | |
Size | GetRootIndex () const noexcept |
Gets the index of the "root" node if this tree has one. More... | |
DynamicTree & | operator= (DynamicTree other) noexcept |
Unifying assignment operator. More... | |
void | RebuildBottomUp () |
Builds an optimal tree. More... | |
void | Reserve (Size value) |
Reserves at least as much capacity as requested. More... | |
void | ShiftOrigin (const Length2 &newOrigin) noexcept |
Shifts the world origin. More... | |
void | UpdateLeaf (Size index, const AABB &aabb) |
Updates a leaf node with a new AABB value. More... | |
Static Public Member Functions | |
static constexpr bool | IsBranch (Height value) noexcept |
Gets whether the given height is a height for a "branch" node. | |
static constexpr bool | IsLeaf (Height value) noexcept |
Gets whether the given height is the height for a "leaf" node. | |
static constexpr bool | IsUnused (Height value) noexcept |
Gets whether the given height is the height for an "unused" node. | |
Static Public Attributes | |
static constexpr auto | InvalidHeight = static_cast<Height>(-1) |
Invalid height constant value. | |
static constexpr auto | InvalidSize = static_cast<Size>(-1) |
Invalid size constant value. | |
Friends | |
void | swap (DynamicTree &lhs, DynamicTree &rhs) noexcept |
Customized swap function for DynamicTree objects. More... | |
Related Functions | |
(Note that these are not member functions.) | |
auto | FindIndex (const DynamicTree &tree, const Contactable &c) noexcept -> DynamicTree::Size |
Finds index of node matching given contactble using a linear search. More... | |
AABB | GetAABB (const DynamicTree &tree) noexcept |
Gets the AABB for the given dynamic tree. More... | |
DynamicTree::Height | GetHeight (const DynamicTree &tree) noexcept |
Gets the height of the binary tree. More... | |
bool | TestOverlap (const DynamicTree &tree, DynamicTree::Size leafIdA, DynamicTree::Size leafIdB) noexcept |
Tests for overlap of the elements identified in the given dynamic tree. | |
A dynamic AABB tree broad-phase.
A dynamic tree arranges data in a binary tree to accelerate queries such as volume queries and ray casts. Leafs are proxies with an AABB.
btDbvt
. Type for heights.
Size
type due to the binary nature of this tree structure.
|
defaultnoexcept |
Non-throwing default constructor.
GetNodeCapacity()
returns 0. GetNodeCount()
returns 0. GetFreeIndex()
and GetRootIndex()
return InvalidSize
.
|
explicit |
Size initializing constructor.
nodeCapacity | Node capacity. If zero, this is the same as calling the default constructor except this isn't recognized as non-throwing. |
GetNodeCapacity()
returns value of the next power of two of the result of nodeCapacity
minus one, where a nodeCapacity
of zero results in GetNodeCapacity()
returning zero. GetNodeCount()
returns 0. GetFreeIndex()
and GetRootIndex()
return InvalidSize
. std::bad_alloc | If unable to allocate non-zero sized memory. |
playrho::d2::DynamicTree::DynamicTree | ( | const DynamicTree & | other | ) |
Copy constructor.
std::bad_alloc | If unable to allocate non-zero sized memory. |
|
noexcept |
Clears the dynamic tree.
Clears the leafs and branches from this tree. This does not deallocate any memory nor reduce this tree's capacity; this only reduces this tree's usage of that capacity.
GetLeafCount()
will return 0. GetNodeCount()
will return 0. GetRootIndex()
will return InvalidSize
. GetFreeIndex()
will return 0 if this tree had any node capacity, else the value of InvalidSize
. DynamicTree::Size playrho::d2::DynamicTree::CreateLeaf | ( | const AABB & | aabb, |
const Contactable & | data | ||
) |
Creates a new leaf node.
Creates a leaf node for a tight fitting AABB and the given data.
GetLeafCount()
) is less than std::numeric_limits<Size>::max()
. GetNodeCount()
) is at least one or two less than std::numeric_limits<Size>::max()
depending on whether root index is InvalidSize
or not. InvalidSize
, then it will be set to the index returned from this function. GetLeafCount()
is incremented by one. GetNodeCount()
) will be incremented by one or two (if the root index had not been InvalidSize
). InvalidSize
. std::bad_alloc | If unable to allocate necessary memory. If this exception is thrown, this function has no effect. |
|
noexcept |
Destroys a leaf node.
index | Identifier of node to destroy. |
index
is less than GetNodeCapacity()
and IsLeaf(GetNode(index).GetHeight())
is true. GetLeafCount()
is decremented by one.
|
noexcept |
Finds first node which references the given index.
InvalidSize
. Gets the AABB for a leaf or branch (a non-unused node).
index | Leaf or branch node's ID. Must be a valid ID. |
index
is less than GetNodeCapacity()
and IsUnused(GetNode(index).GetHeight())
is false. Referenced by playrho::d2::Query(), playrho::d2::RayCast(), and RebuildBottomUp().
|
inlinenoexcept |
Gets the branch data for the identified node.
index | Identifier of node to get branch data for. |
index
is less than GetNodeCapacity()
. Referenced by playrho::d2::Query(), and playrho::d2::RayCast().
|
inlinenoexcept |
Gets the height value for the identified node.
index | Identifier of node to get "height" for. |
index
is less than GetNodeCapacity()
. Referenced by playrho::d2::Query(), playrho::d2::RayCast(), RebuildBottomUp(), and UpdateLeaf().
|
inlinenoexcept |
Gets the current leaf node count.
Gets the current leaf node count.
|
inlinenoexcept |
Gets the leaf data for the node identified by the given identifier.
index | Identifier of node to get the leaf data for. |
index
is less than GetNodeCapacity()
and IsLeaf(GetNode(index).GetHeight())
is true. Referenced by playrho::d2::Query(), and playrho::d2::RayCast().
|
inlinenoexcept |
Gets the node identified by the given identifier.
index | Identifier of node to get. |
index
is less than GetNodeCapacity()
.
|
inlinenoexcept |
Gets the current node capacity of this tree.
|
inlinenoexcept |
Gets the current count of allocated nodes.
Referenced by CreateLeaf(), and RebuildBottomUp().
|
inlinenoexcept |
Gets the "other" index for the node at the given index.
index | Identifier of node to get "other" for. |
Referenced by GetLeafCount(), GetRootIndex(), and UpdateLeaf().
|
inlinenoexcept |
Gets the index of the "root" node if this tree has one.
InvalidSize
if this tree is "empty", else index to "root" node. Referenced by playrho::d2::Query(), and playrho::d2::RayCast().
|
noexcept |
Unifying assignment operator.
void playrho::d2::DynamicTree::RebuildBottomUp | ( | ) |
Builds an optimal tree.
std::bad_alloc | If unable to allocate necessary memory. |
void playrho::d2::DynamicTree::Reserve | ( | Size | value | ) |
Reserves at least as much capacity as requested.
std::bad_alloc | If unable to allocate necessary memory. If this exception is thrown, this function has no effect. |
GetNodeCapacity()
returns a new capacity that's at least as much as the requested capacity if that's greater than before. GetFreeIndex()
returns the value of GetNodeCount()
if the new capacity is greater than before. Referenced by CreateLeaf(), and RebuildBottomUp().
|
noexcept |
Shifts the world origin.
position -= newOrigin
. newOrigin | the new origin with respect to the old origin. |
Updates a leaf node with a new AABB value.
index | Leaf node's ID. |
aabb | New axis aligned bounding box for the leaf node. |
index
is less than GetNodeCapacity()
and IsLeaf(GetNode(index).GetHeight())
is true.
|
related |
Finds index of node matching given contactble using a linear search.
DynamicTree::InvalidSize
.
|
related |
Gets the AABB for the given dynamic tree.
Gets the AABB that encloses all other AABB instances that are within the given dynamic tree.
|
related |
Gets the height of the binary tree.
|
friend |
Customized swap function for DynamicTree
objects.
Swappable
named requirement.