A dynamic AABB tree broad-phase. More...
#include <DynamicTree.hpp>
Classes | |
struct | BranchData |
Branch data of a tree node. More... | |
struct | LeafData |
Leaf data of a tree node. More... | |
class | TreeNode |
A node in the dynamic tree. More... | |
struct | UnusedData |
Unused data of a tree node. More... | |
union | VariantData |
Variant data. More... | |
Public Types | |
using | Size = ContactCounter |
Size type. | |
using | Height = ContactCounter |
Type for heights. More... | |
Public Member Functions | |
DynamicTree () noexcept | |
Non-throwing default constructor. | |
DynamicTree (Size nodeCapacity) | |
Size initializing constructor. More... | |
DynamicTree (const DynamicTree &other) | |
Copy constructor. More... | |
DynamicTree (DynamicTree &&other) noexcept | |
Move constructor. | |
~DynamicTree () noexcept | |
Destroys the tree, freeing the node pool. | |
DynamicTree & | operator= (DynamicTree other) noexcept |
Unifying assignment operator. More... | |
void | Clear () noexcept |
Clears the dynamic tree. More... | |
Size | CreateLeaf (const AABB &aabb, const LeafData &data) |
Creates a new leaf node. More... | |
void | DestroyLeaf (Size index) noexcept |
Destroys a leaf node. More... | |
void | UpdateLeaf (Size index, const AABB &aabb) |
Updates a leaf node with a new AABB value. More... | |
LeafData | GetLeafData (Size index) const noexcept |
Gets the leaf data for the node identified by the given identifier. More... | |
void | SetLeafData (Size index, LeafData value) noexcept |
Sets the leaf data for the element at the given index to the given value. | |
AABB | GetAABB (Size index) const noexcept |
Gets the AABB for a leaf or branch (a non-unused node). More... | |
Height | GetHeight (Size index) const noexcept |
Gets the height value for the identified node. More... | |
Size | GetOther (Size index) const noexcept |
Gets the "other" index for the node at the given index. More... | |
BranchData | GetBranchData (Size index) const noexcept |
Gets the branch data for the identified node. More... | |
Size | GetRootIndex () const noexcept |
Gets the index of the "root" node if this tree has one. More... | |
Size | GetFreeIndex () const noexcept |
Gets the free index. | |
void | RebuildBottomUp () |
Builds an optimal tree. More... | |
void | ShiftOrigin (Length2 newOrigin) noexcept |
Shifts the world origin. More... | |
Size | GetNodeCapacity () const noexcept |
Gets the current node capacity of this tree. More... | |
void | Reserve (Size value) |
Reserves at least as much capacity as requested. More... | |
Size | GetNodeCount () const noexcept |
Gets the current count of allocated nodes. More... | |
Size | GetLeafCount () const noexcept |
Gets the current leaf node count. More... | |
Size | FindReference (Size index) const noexcept |
Finds first node which references the given index. More... | |
Static Public Member Functions | |
static constexpr Size | GetInvalidSize () noexcept |
Gets the invalid size value. | |
static constexpr Height | GetInvalidHeight () noexcept |
Gets the invalid height value. | |
static constexpr bool | IsUnused (Height value) noexcept |
Gets whether the given height is the height for an "unused" node. | |
static constexpr bool | IsLeaf (Height value) noexcept |
Gets whether the given height is the height for a "leaf" node. | |
static constexpr bool | IsBranch (Height value) noexcept |
Gets whether the given height is a height for a "branch" node. | |
Static Public Attributes | |
static constexpr auto | InvalidHeight = static_cast<Height>(-1) |
Invalid height constant value. | |
Private Member Functions | |
Size | AllocateNode () noexcept |
Allocates a node. More... | |
void | FreeNode (Size index) noexcept |
Frees the specified node. More... | |
Private Attributes | |
Size | m_nodeCount {0u} |
Node count. More... | |
Size | m_leafCount {0u} |
Leaf count. More... | |
Size | m_rootIndex {GetInvalidSize()} |
Index of root element in m_nodes or GetInvalidSize() . | |
Size | m_freeIndex {GetInvalidSize()} |
Free list. More... | |
Size | m_nodeCapacity {0u} |
Node capacity. More... | |
TreeNode * | m_nodes {nullptr} |
Nodes. More... | |
Friends | |
void | swap (DynamicTree &lhs, DynamicTree &rhs) noexcept |
Customized swap function for DynamicTree objects. More... | |
Related Functions | |
(Note that these are not member functions.) | |
DynamicTree::Height | GetHeight (const DynamicTree &tree) noexcept |
Gets the height of the binary tree. More... | |
AABB | GetAABB (const DynamicTree &tree) noexcept |
Gets the AABB for the given dynamic 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.
|
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. |
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. |
|
privatenoexcept |
Allocates a node.
This allocates a node from the free list that can be used as either a leaf node or a branch node.
GetNodeCapacity()
returns a value at least one greater than the value returned from GetNodeCount()
. GetNodeCount()
) is less than GetNodeCapacity()
. Reserve(GetNodeCount() + 1u)
before this if uncertain of whether any entries are available on the free list. GetInvalidSize()
. Referenced by CreateLeaf(), and RebuildBottomUp().
|
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 GetInvalidSize()
. GetFreeIndex()
will return 0 if this tree had any node capacity, else the value of GetInvalidSize()
. Referenced by playrho::d2::WorldImpl::Clear().
DynamicTree::Size playrho::d2::DynamicTree::CreateLeaf | ( | const AABB & | aabb, |
const LeafData & | data | ||
) |
Creates a new leaf node.
Creates a leaf node for a tight fitting AABB and the given data.
GetNodeCount()
) is less than std::numeric_limits<Size>::max()
. GetInvalidSize()
, then it will be set to the index returned from this method. GetLeafCount()
) will be incremented by one. GetNodeCount()
) will be incremented by one or two (if the root index had not been GetInvalidSize()
). GetInvalidSize()
. std::bad_alloc | If unable to allocate necessary memory. If this exception is thrown, this function has no effect. |
|
noexcept |
Destroys a leaf node.
|
noexcept |
Finds first node which references the given index.
GetInvalidSize()
.
|
privatenoexcept |
Frees the specified node.
Referenced by RebuildBottomUp().
Gets the AABB for a leaf or branch (a non-unused node).
index | Leaf or branch node's ID. Must be a valid ID. |
Referenced by playrho::d2::WorldImpl::FindNewContacts(), playrho::d2::Query(), playrho::d2::RayCast(), RebuildBottomUp(), and playrho::d2::WorldImpl::Synchronize().
|
inlinenoexcept |
Gets the branch data for the identified node.
Referenced by playrho::d2::Query(), and playrho::d2::RayCast().
|
inlinenoexcept |
Gets the height value for the identified node.
Referenced by playrho::d2::Query(), playrho::d2::RayCast(), RebuildBottomUp(), and UpdateLeaf().
|
inlinenoexcept |
|
inlinenoexcept |
Gets the leaf data for the node identified by the given identifier.
index | Identifier of node to get the leaf data for. |
Referenced by playrho::d2::WorldImpl::Add(), playrho::d2::WorldImpl::FindNewContacts(), playrho::d2::Query(), and playrho::d2::RayCast().
|
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.
Referenced by GetLeafCount(), GetRootIndex(), and UpdateLeaf().
|
inlinenoexcept |
Gets the index of the "root" node if this tree has one.
GetInvalidSize()
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. |
Referenced by playrho::d2::WorldImpl::ShiftOrigin().
Updates a leaf node with a new AABB value.
index | Leaf node's ID. Behavior is undefined if this is not a valid ID. |
aabb | New axis aligned bounding box for the leaf node. |
Referenced by playrho::d2::WorldImpl::Synchronize().
|
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.
|
private |
Free list.
Index to free nodes.
Referenced by AllocateNode(), Clear(), GetFreeIndex(), and Reserve().
|
private |
Leaf count.
Count of currently allocated leaf nodes.
Referenced by Clear(), CreateLeaf(), GetLeafCount(), and GetRootIndex().
|
private |
Node capacity.
Size of buffer allocated for nodes.
Referenced by AllocateNode(), Clear(), GetNodeCapacity(), GetRootIndex(), RebuildBottomUp(), Reserve(), and UpdateLeaf().
|
private |
Node count.
Count of currently allocated nodes.
Referenced by AllocateNode(), Clear(), DynamicTree(), GetNodeCount(), RebuildBottomUp(), and Reserve().
|
private |
Nodes.
Initialized on construction.
Referenced by AllocateNode(), Clear(), CreateLeaf(), RebuildBottomUp(), Reserve(), UpdateLeaf(), and ~DynamicTree().