38 #ifndef FCL_HIERARCHY_TREE_ARRAY_H 39 #define FCL_HIERARCHY_TREE_ARRAY_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_array.h" 56 namespace implementation_array
63 using S =
typename BV::S;
68 bool operator() (
size_t a,
size_t b)
const 70 if((a != NULL_NODE) && (b != NULL_NODE))
71 return nodes[a].code < nodes[b].code;
72 else if(a == NULL_NODE)
73 return split < nodes[b].code;
74 else if(b == NULL_NODE)
75 return nodes[a].code < split;
89 HierarchyTree(
int bu_threshold_ = 16,
int topdown_level_ = 0);
94 void init(NodeType* leaves,
int n_leaves_,
int level = 0);
97 size_t insert(
const BV& bv,
void* data);
100 void remove(
size_t leaf);
109 void update(
size_t leaf,
int lookahead_level = -1);
112 bool update(
size_t leaf,
const BV& bv);
115 bool update(
size_t leaf,
const BV& bv,
const Vector3<S>& vel, S margin);
118 bool update(
size_t leaf,
const BV& bv,
const Vector3<S>& vel);
151 void print(
size_t root,
int depth);
156 void bottomup(
size_t* lbeg,
size_t* lend);
159 size_t topdown(
size_t* lbeg,
size_t* lend);
165 void getMaxDepth(
size_t node,
size_t depth,
size_t& max_depth)
const;
170 size_t topdown_0(
size_t* lbeg,
size_t* lend);
176 size_t topdown_1(
size_t* lbeg,
size_t* lend);
179 void init_0(NodeType* leaves,
int n_leaves_);
183 void init_1(NodeType* leaves,
int n_leaves_);
187 void init_2(NodeType* leaves,
int n_leaves_);
190 void init_3(NodeType* leaves,
int n_leaves_);
192 size_t mortonRecurse_0(
size_t* lbeg,
size_t* lend,
const uint32& split,
int bits);
194 size_t mortonRecurse_1(
size_t* lbeg,
size_t* lend,
const uint32& split,
int bits);
196 size_t mortonRecurse_2(
size_t* lbeg,
size_t* lend);
199 void update_(
size_t leaf,
const BV& bv);
202 void insertLeaf(
size_t root,
size_t leaf);
206 size_t removeLeaf(
size_t leaf);
209 void fetchLeaves(
size_t root, NodeType*& leaves,
int depth = -1);
211 size_t indexOf(
size_t node);
213 size_t allocateNode();
216 size_t createNode(
size_t parent,
221 size_t createNode(
size_t parent,
225 size_t createNode(
size_t parent,
228 void deleteNode(
size_t node);
230 void recurseRefit(
size_t node);
236 size_t n_nodes_alloc;
242 int max_lookahead_level;
252 static const size_t NULL_NODE = -1;
255 template<
typename BV>
260 template<
typename BV>
265 bool operator() (
size_t i,
size_t j)
const;
278 template<
typename BV>
279 size_t select(
size_t query,
size_t node1,
size_t node2,
NodeBase<BV>* nodes);
283 template<
typename BV>
284 size_t select(
const BV& query,
size_t node1,
size_t node2,
NodeBase<BV>* nodes);
290 #include "fcl/broadphase/detail/hierarchy_tree_array-inl.h" Class for hierarchy tree structure.
Definition: hierarchy_tree_array.h:61
bool empty() const
Whether the tree is empty.
Definition: hierarchy_tree_array-inl.h:309
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
void clear()
Clear the tree.
Definition: hierarchy_tree_array-inl.h:291
void print(size_t root, int depth)
print the tree in a recursive way
Definition: hierarchy_tree_array-inl.h:503
int topdown_level
decide which topdown algorithm to use
Definition: hierarchy_tree_array.h:246
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_array-inl.h:54
void refit()
refit the tree, i.e., when the leaf nodes' bounding volumes change, update the entire tree in a botto...
Definition: hierarchy_tree_array-inl.h:458
size_t getMaxDepth() const
get the max depth of the tree
Definition: hierarchy_tree_array-inl.h:370
size_t getRoot() const
get the root of the tree
Definition: hierarchy_tree_array-inl.h:489
size_t insert(const BV &bv, void *data)
Initialize the tree by a set of leaves using algorithm with a given level.
Definition: hierarchy_tree_array-inl.h:272
void balanceBottomup()
balance the tree from bottom
Definition: hierarchy_tree_array-inl.h:381
NodeType * getNodes() const
get the pointer to the nodes array
Definition: hierarchy_tree_array-inl.h:496
Definition: node_base_array.h:53
int bu_threshold
decide the depth to use expensive bottom-up algorithm
Definition: hierarchy_tree_array.h:249
void balanceTopdown()
balance the tree from top
Definition: hierarchy_tree_array-inl.h:410
void init(NodeType *leaves, int n_leaves_, int level=0)
Initialize the tree by a set of leaves using algorithm with a given level.
Definition: hierarchy_tree_array-inl.h:80
size_t getMaxHeight() const
get the max height of the tree
Definition: hierarchy_tree_array-inl.h:361
void update(size_t leaf, int lookahead_level=-1)
update one leaf node
Definition: hierarchy_tree_array-inl.h:316
Functor comparing two nodes.
Definition: hierarchy_tree_array.h:261
void balanceIncremental(int iterations)
balance the tree in an incremental way
Definition: hierarchy_tree_array-inl.h:436
size_t size() const
number of leaves in the tree
Definition: hierarchy_tree_array-inl.h:482
void extractLeaves(size_t root, NodeType *&leaves) const
extract all the leaves of the tree
Definition: hierarchy_tree_array-inl.h:466