38 #ifndef FCL_HIERARCHY_TREE_H 39 #define FCL_HIERARCHY_TREE_H 45 #include "fcl/common/warning.h" 46 #include "fcl/math/bv/AABB.h" 47 #include "fcl/broadphase/detail/morton.h" 48 #include "fcl/broadphase/detail/node_base.h" 62 using S =
typename BV::S;
70 HierarchyTree(
int bu_threshold_ = 16,
int topdown_level_ = 0);
75 void init(std::vector<NodeType*>& leaves,
int level = 0);
78 NodeType*
insert(
const BV& bv,
void* data);
81 void remove(NodeType* leaf);
90 void update(NodeType* leaf,
int lookahead_level = -1);
93 bool update(NodeType* leaf,
const BV& bv);
96 bool update(NodeType* leaf,
const BV& bv,
const Vector3<S>& vel, S margin);
99 bool update(NodeType* leaf,
const BV& bv,
const Vector3<S>& vel);
120 void extractLeaves(
const NodeType* root, std::vector<NodeType*>& leaves)
const;
131 void print(NodeType* root,
int depth);
135 typedef typename std::vector<NodeBase<BV>* >::iterator NodeVecIterator;
136 typedef typename std::vector<NodeBase<BV>* >::const_iterator NodeVecConstIterator;
140 bool operator() (
const NodeType* a,
const NodeType* b)
const 147 void bottomup(
const NodeVecIterator lbeg,
const NodeVecIterator lend);
150 NodeType* topdown(
const NodeVecIterator lbeg,
const NodeVecIterator lend);
156 void getMaxDepth(NodeType* node,
size_t depth,
size_t& max_depth)
const;
161 NodeType* topdown_0(
const NodeVecIterator lbeg,
const NodeVecIterator lend);
167 NodeType* topdown_1(
const NodeVecIterator lbeg,
const NodeVecIterator lend);
170 void init_0(std::vector<NodeType*>& leaves);
174 void init_1(std::vector<NodeType*>& leaves);
178 void init_2(std::vector<NodeType*>& leaves);
181 void init_3(std::vector<NodeType*>& leaves);
183 NodeType* mortonRecurse_0(
const NodeVecIterator lbeg,
const NodeVecIterator lend,
const uint32& split,
int bits);
185 NodeType* mortonRecurse_1(
const NodeVecIterator lbeg,
const NodeVecIterator lend,
const uint32& split,
int bits);
187 NodeType* mortonRecurse_2(
const NodeVecIterator lbeg,
const NodeVecIterator lend);
190 void update_(NodeType* leaf,
const BV& bv);
193 NodeType* sort(NodeType* n, NodeType*& r);
196 void insertLeaf(NodeType* root, NodeType* leaf);
200 NodeType* removeLeaf(NodeType* leaf);
203 void fetchLeaves(NodeType* root, std::vector<NodeType*>& leaves,
int depth = -1);
205 static size_t indexOf(NodeType* node);
208 NodeType* createNode(NodeType* parent,
212 NodeType* createNode(NodeType* parent,
217 NodeType* createNode(NodeType* parent,
220 void deleteNode(NodeType* node);
222 void recurseDeleteNode(NodeType* node);
224 void recurseRefit(NodeType* node);
226 static BV bounds(
const std::vector<NodeType*>& leaves);
228 static BV bounds(
const NodeVecIterator lbeg,
const NodeVecIterator lend);
240 int max_lookahead_level;
251 template<
typename BV>
256 template<
typename BV>
264 template<
typename BV>
271 #include "fcl/broadphase/detail/hierarchy_tree-inl.h" dynamic AABB<S> tree node
Definition: node_base.h:51
void clear()
Clear the tree.
Definition: hierarchy_tree-inl.h:113
void extractLeaves(const NodeType *root, std::vector< NodeType * > &leaves) const
extract all the leaves of the tree
Definition: hierarchy_tree-inl.h:279
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
void balanceBottomup()
balance the tree from bottom
Definition: hierarchy_tree-inl.h:222
size_t getMaxDepth() const
get the max depth of the tree
Definition: hierarchy_tree-inl.h:211
void update(NodeType *leaf, int lookahead_level=-1)
update one leaf node
Definition: hierarchy_tree-inl.h:133
size_t getMaxHeight() const
get the max height of the tree
Definition: hierarchy_tree-inl.h:202
void balanceIncremental(int iterations)
balance the tree in an incremental way
Definition: hierarchy_tree-inl.h:249
NodeType * getRoot() const
get the root of the tree
Definition: hierarchy_tree-inl.h:299
uint32 code
morton code for current BV
Definition: node_base.h:73
void refit()
refit the tree, i.e., when the leaf nodes' bounding volumes change, update the entire tree in a botto...
Definition: hierarchy_tree-inl.h:271
bool empty() const
Whether the tree is empty.
Definition: hierarchy_tree-inl.h:126
Class for hierarchy tree structure.
Definition: hierarchy_tree.h:58
void init(std::vector< NodeType * > &leaves, int level=0)
Initialize the tree by a set of leaves using algorithm with a given level.
Definition: hierarchy_tree-inl.h:71
size_t size() const
number of leaves in the tree
Definition: hierarchy_tree-inl.h:292
int bu_threshold
decide the depth to use expensive bottom-up algorithm
Definition: hierarchy_tree.h:247
void balanceTopdown()
balance the tree from top
Definition: hierarchy_tree-inl.h:236
NodeType * insert(const BV &bv, void *data)
Insest a node.
Definition: hierarchy_tree-inl.h:94
NodeType * free_node
This is a one NodeType cache, the reason is that we need to remove a node and then add it again frequ...
Definition: hierarchy_tree.h:238
void print(NodeType *root, int depth)
print the tree in a recursive way
Definition: hierarchy_tree-inl.h:313
int topdown_level
decide which topdown algorithm to use
Definition: hierarchy_tree.h:244
HierarchyTree(int bu_threshold_=16, int topdown_level_=0)
Create hierarchy tree with suitable setting. bu_threshold decides the height of tree node to start bo...
Definition: hierarchy_tree-inl.h:51