hierarchy_tree.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2016, Open Source Robotics Foundation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Open Source Robotics Foundation nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
38 #ifndef FCL_HIERARCHY_TREE_H
39 #define FCL_HIERARCHY_TREE_H
40 
41 #include <vector>
42 #include <map>
43 #include <functional>
44 #include <iostream>
45 #include "fcl/common/warning.h"
46 #include "fcl/math/bv/AABB.h"
49 
50 namespace fcl
51 {
52 
53 namespace detail
54 {
55 
57 template<typename BV>
58 class FCL_EXPORT HierarchyTree
59 {
60 public:
61 
62  using S = typename BV::S;
63 
65 
70  HierarchyTree(int bu_threshold_ = 16, int topdown_level_ = 0);
71 
72  ~HierarchyTree();
73 
75  void init(std::vector<NodeType*>& leaves, int level = 0);
76 
78  NodeType* insert(const BV& bv, void* data);
79 
81  void remove(NodeType* leaf);
82 
84  void clear();
85 
87  bool empty() const;
88 
100  void update(NodeType* leaf, int lookahead_level = -1);
101 
103  bool update(NodeType* leaf, const BV& bv);
104 
106  bool update(NodeType* leaf, const BV& bv, const Vector3<S>& vel, S margin);
107 
109  bool update(NodeType* leaf, const BV& bv, const Vector3<S>& vel);
110 
112  size_t getMaxHeight() const;
113 
115  size_t getMaxDepth() const;
116 
118  void balanceBottomup();
119 
121  void balanceTopdown();
122 
124  void balanceIncremental(int iterations);
125 
127  void refit();
128 
130  void extractLeaves(const NodeType* root, std::vector<NodeType*>& leaves) const;
131 
133  size_t size() const;
134 
136  NodeType* getRoot() const;
137 
138  NodeType*& getRoot();
139 
141  void print(NodeType* root, int depth);
142 
143 private:
144 
145  typedef typename std::vector<NodeBase<BV>* >::iterator NodeVecIterator;
146  typedef typename std::vector<NodeBase<BV>* >::const_iterator NodeVecConstIterator;
147 
149  {
150  bool operator() (const NodeType* a, const NodeType* b) const
151  {
152  return a->code < b->code;
153  }
154  };
155 
157  void bottomup(const NodeVecIterator lbeg, const NodeVecIterator lend);
158 
160  NodeType* topdown(const NodeVecIterator lbeg, const NodeVecIterator lend);
161 
163  size_t getMaxHeight(NodeType* node) const;
164 
166  void getMaxDepth(NodeType* node, size_t depth, size_t& max_depth) const;
167 
171  NodeType* topdown_0(const NodeVecIterator lbeg, const NodeVecIterator lend);
172 
177  NodeType* topdown_1(const NodeVecIterator lbeg, const NodeVecIterator lend);
178 
180  void init_0(std::vector<NodeType*>& leaves);
181 
184  void init_1(std::vector<NodeType*>& leaves);
185 
188  void init_2(std::vector<NodeType*>& leaves);
189 
191  void init_3(std::vector<NodeType*>& leaves);
192 
193  NodeType* mortonRecurse_0(const NodeVecIterator lbeg, const NodeVecIterator lend, const uint32& split, int bits);
194 
195  NodeType* mortonRecurse_1(const NodeVecIterator lbeg, const NodeVecIterator lend, const uint32& split, int bits);
196 
197  NodeType* mortonRecurse_2(const NodeVecIterator lbeg, const NodeVecIterator lend);
198 
200  void update_(NodeType* leaf, const BV& bv);
201 
203  NodeType* sort(NodeType* n, NodeType*& r);
204 
210  // leaf node.
211  void insertLeaf(NodeType* const sub_root, NodeType* const leaf);
212 
219  // adjusted.
220  NodeType* removeLeaf(NodeType* const leaf);
221 
223  void fetchLeaves(NodeType* root, std::vector<NodeType*>& leaves, int depth = -1);
224 
225  static size_t indexOf(NodeType* node);
226 
228  NodeType* createNode(NodeType* parent,
229  const BV& bv,
230  void* data);
231 
232  NodeType* createNode(NodeType* parent,
233  const BV& bv1,
234  const BV& bv2,
235  void* data);
236 
237  NodeType* createNode(NodeType* parent,
238  void* data);
239 
240  void deleteNode(NodeType* node);
241 
242  void recurseDeleteNode(NodeType* node);
243 
244  void recurseRefit(NodeType* node);
245 
246 protected:
248 
249  size_t n_leaves;
250 
251  unsigned int opath;
252 
255 
257 
258 public:
261 
264 };
265 
267 template<typename BV>
268 bool nodeBaseLess(NodeBase<BV>* a, NodeBase<BV>* b, int d);
269 
272 template<typename BV>
273 size_t select(
274  const NodeBase<BV>& query,
275  const NodeBase<BV>& node1,
276  const NodeBase<BV>& node2);
277 
280 template<typename BV>
281 size_t select(
282  const BV& query, const NodeBase<BV>& node1, const NodeBase<BV>& node2);
283 
284 } // namespace detail
285 } // namespace fcl
286 
288 
289 #endif
fcl::detail::HierarchyTree::root_node
NodeType * root_node
Definition: hierarchy_tree.h:247
fcl::detail::HierarchyTree::opath
unsigned int opath
Definition: hierarchy_tree.h:251
fcl::detail::HierarchyTree::bu_threshold
int bu_threshold
decide the depth to use expensive bottom-up algorithm
Definition: hierarchy_tree.h:263
fcl::uint32
std::uint32_t uint32
Definition: types.h:62
hierarchy_tree-inl.h
fcl::detail::HierarchyTree::max_lookahead_level
int max_lookahead_level
Definition: hierarchy_tree.h:256
fcl::detail::HierarchyTree< fcl::AABB< S > >::S
typename fcl::AABB< S > ::S S
Definition: hierarchy_tree.h:62
warning.h
fcl::Vector3
Eigen::Matrix< S, 3, 1 > Vector3
Definition: types.h:70
fcl::detail::HierarchyTree::topdown_level
int topdown_level
decide which topdown algorithm to use
Definition: hierarchy_tree.h:260
fcl::detail::NodeBase
dynamic AABB tree node
Definition: node_base.h:51
fcl::detail::select
size_t select(const NodeBase< BV > &query, const NodeBase< BV > &node1, const NodeBase< BV > &node2)
select from node1 and node2 which is close to a given query. 0 for node1 and 1 for node2
Definition: hierarchy_tree-inl.h:1079
fcl::detail::HierarchyTree::SortByMorton
Definition: hierarchy_tree.h:148
fcl::detail::nodeBaseLess
bool nodeBaseLess(NodeBase< BV > *a, NodeBase< BV > *b, int d)
Compare two nodes accoording to the d-th dimension of node center.
Definition: hierarchy_tree-inl.h:1050
r
S r
Definition: test_sphere_box.cpp:171
fcl::detail::HierarchyTree::free_node
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:254
fcl::detail::HierarchyTree::n_leaves
size_t n_leaves
Definition: hierarchy_tree.h:249
morton.h
fcl::detail::HierarchyTree::NodeType
NodeBase< BV > NodeType
Definition: hierarchy_tree.h:64
fcl::detail::NodeBase::code
uint32 code
morton code for current BV
Definition: node_base.h:73
fcl::detail::HierarchyTree::NodeVecIterator
std::vector< NodeBase< BV > * >::iterator NodeVecIterator
Definition: hierarchy_tree.h:145
fcl::detail::HierarchyTree::NodeVecConstIterator
std::vector< NodeBase< BV > * >::const_iterator NodeVecConstIterator
Definition: hierarchy_tree.h:146
AABB.h
fcl
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
node_base.h
fcl::detail::HierarchyTree
Class for hierarchy tree structure.
Definition: hierarchy_tree.h:58


fcl
Author(s):
autogenerated on Tue Dec 5 2023 03:40:48