coal/broadphase/broadphase_dynamic_AABB_tree-inl.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 COAL_BROAD_PHASE_DYNAMIC_AABB_TREE_INL_H
39 #define COAL_BROAD_PHASE_DYNAMIC_AABB_TREE_INL_H
40 
42 
43 #include <limits>
44 
45 #if COAL_HAVE_OCTOMAP
46 #include "coal/octree.h"
47 #endif
48 
49 #include "coal/BV/BV.h"
51 
52 namespace coal {
53 namespace detail {
54 
55 namespace dynamic_AABB_tree {
56 
57 #if COAL_HAVE_OCTOMAP
58 
59 //==============================================================================
60 template <typename Derived>
61 bool collisionRecurse_(DynamicAABBTreeCollisionManager::DynamicAABBNode* root1,
62  const OcTree* tree2, const OcTree::OcTreeNode* root2,
63  const AABB& root2_bv,
64  const Eigen::MatrixBase<Derived>& translation2,
66  if (!root2) {
67  if (root1->isLeaf()) {
68  CollisionObject* obj1 = static_cast<CollisionObject*>(root1->data);
69 
70  if (!obj1->collisionGeometry()->isFree()) {
71  const AABB& root2_bv_t = translate(root2_bv, translation2);
72  if (root1->bv.overlap(root2_bv_t)) {
73  Box* box = new Box();
74  Transform3s box_tf;
76  tf2.translation() = translation2;
77  constructBox(root2_bv, tf2, *box, box_tf);
78 
79  box->cost_density =
80  tree2->getOccupancyThres(); // thresholds are 0, 1, so uncertain
81 
82  CollisionObject obj2(shared_ptr<CollisionGeometry>(box), box_tf);
83  return (*callback)(obj1, &obj2);
84  }
85  }
86  } else {
87  if (collisionRecurse_(root1->children[0], tree2, nullptr, root2_bv,
88  translation2, callback))
89  return true;
90  if (collisionRecurse_(root1->children[1], tree2, nullptr, root2_bv,
91  translation2, callback))
92  return true;
93  }
94 
95  return false;
96  } else if (root1->isLeaf() && !tree2->nodeHasChildren(root2)) {
97  CollisionObject* obj1 = static_cast<CollisionObject*>(root1->data);
98 
99  if (!tree2->isNodeFree(root2) && !obj1->collisionGeometry()->isFree()) {
100  const AABB& root2_bv_t = translate(root2_bv, translation2);
101  if (root1->bv.overlap(root2_bv_t)) {
102  Box* box = new Box();
103  Transform3s box_tf;
105  tf2.translation() = translation2;
106  constructBox(root2_bv, tf2, *box, box_tf);
107 
108  box->cost_density = root2->getOccupancy();
109  box->threshold_occupied = tree2->getOccupancyThres();
110 
111  CollisionObject obj2(shared_ptr<CollisionGeometry>(box), box_tf);
112  return (*callback)(obj1, &obj2);
113  } else
114  return false;
115  } else
116  return false;
117  }
118 
119  const AABB& root2_bv_t = translate(root2_bv, translation2);
120  if (tree2->isNodeFree(root2) || !root1->bv.overlap(root2_bv_t)) return false;
121 
122  if (!tree2->nodeHasChildren(root2) ||
123  (!root1->isLeaf() && (root1->bv.size() > root2_bv.size()))) {
124  if (collisionRecurse_(root1->children[0], tree2, root2, root2_bv,
125  translation2, callback))
126  return true;
127  if (collisionRecurse_(root1->children[1], tree2, root2, root2_bv,
128  translation2, callback))
129  return true;
130  } else {
131  for (unsigned int i = 0; i < 8; ++i) {
132  if (tree2->nodeChildExists(root2, i)) {
133  const OcTree::OcTreeNode* child = tree2->getNodeChild(root2, i);
134  AABB child_bv;
135  computeChildBV(root2_bv, i, child_bv);
136 
137  if (collisionRecurse_(root1, tree2, child, child_bv, translation2,
138  callback))
139  return true;
140  } else {
141  AABB child_bv;
142  computeChildBV(root2_bv, i, child_bv);
143  if (collisionRecurse_(root1, tree2, nullptr, child_bv, translation2,
144  callback))
145  return true;
146  }
147  }
148  }
149  return false;
150 }
151 
152 //==============================================================================
153 template <typename Derived>
154 bool distanceRecurse_(DynamicAABBTreeCollisionManager::DynamicAABBNode* root1,
155  const OcTree* tree2, const OcTree::OcTreeNode* root2,
156  const AABB& root2_bv,
157  const Eigen::MatrixBase<Derived>& translation2,
159  if (root1->isLeaf() && !tree2->nodeHasChildren(root2)) {
160  if (tree2->isNodeOccupied(root2)) {
161  Box* box = new Box();
162  Transform3s box_tf;
164  tf2.translation() = translation2;
165  constructBox(root2_bv, tf2, *box, box_tf);
166  CollisionObject obj(shared_ptr<CollisionGeometry>(box), box_tf);
167  return (*callback)(static_cast<CollisionObject*>(root1->data), &obj,
168  min_dist);
169  } else
170  return false;
171  }
172 
173  if (!tree2->isNodeOccupied(root2)) return false;
174 
175  if (!tree2->nodeHasChildren(root2) ||
176  (!root1->isLeaf() && (root1->bv.size() > root2_bv.size()))) {
177  const AABB& aabb2 = translate(root2_bv, translation2);
178  CoalScalar d1 = aabb2.distance(root1->children[0]->bv);
179  CoalScalar d2 = aabb2.distance(root1->children[1]->bv);
180 
181  if (d2 < d1) {
182  if (d2 < min_dist) {
183  if (distanceRecurse_(root1->children[1], tree2, root2, root2_bv,
184  translation2, callback, min_dist))
185  return true;
186  }
187 
188  if (d1 < min_dist) {
189  if (distanceRecurse_(root1->children[0], tree2, root2, root2_bv,
190  translation2, callback, min_dist))
191  return true;
192  }
193  } else {
194  if (d1 < min_dist) {
195  if (distanceRecurse_(root1->children[0], tree2, root2, root2_bv,
196  translation2, callback, min_dist))
197  return true;
198  }
199 
200  if (d2 < min_dist) {
201  if (distanceRecurse_(root1->children[1], tree2, root2, root2_bv,
202  translation2, callback, min_dist))
203  return true;
204  }
205  }
206  } else {
207  for (unsigned int i = 0; i < 8; ++i) {
208  if (tree2->nodeChildExists(root2, i)) {
209  const OcTree::OcTreeNode* child = tree2->getNodeChild(root2, i);
210  AABB child_bv;
211  computeChildBV(root2_bv, i, child_bv);
212  const AABB& aabb2 = translate(child_bv, translation2);
213 
214  CoalScalar d = root1->bv.distance(aabb2);
215 
216  if (d < min_dist) {
217  if (distanceRecurse_(root1, tree2, child, child_bv, translation2,
218  callback, min_dist))
219  return true;
220  }
221  }
222  }
223  }
224 
225  return false;
226 }
227 
228 #endif
229 
230 } // namespace dynamic_AABB_tree
231 } // namespace detail
232 } // namespace coal
233 
234 #endif
octree.h
geometric_shapes.d1
float d1
Definition: scripts/geometric_shapes.py:31
broadphase_dynamic_AABB_tree.h
collision_manager.callback
callback
Definition: collision_manager.py:27
collision_manager.box
box
Definition: collision_manager.py:11
coal::AABB::distance
CoalScalar distance(const AABB &other) const
Distance between two AABBs.
Definition: AABB.cpp:114
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::detail::NodeBase::data
void * data
Definition: coal/broadphase/detail/node_base.h:65
coal::OcTree::isNodeOccupied
bool isNodeOccupied(const OcTreeNode *node) const
whether one node is completely occupied
Definition: coal/octree.h:159
BV.h
coal::AABB
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition: coal/BV/AABB.h:55
coal::Box
Center at zero point, axis aligned box.
Definition: coal/shape/geometric_shapes.h:166
coal::Transform3s
Simple transform class used locally by InterpMotion.
Definition: coal/math/transform.h:55
coal::OcTree::nodeHasChildren
bool nodeHasChildren(const OcTreeNode *node) const
return true if node has at least one child
Definition: coal/octree.h:268
coal::OcTree::isNodeFree
bool isNodeFree(const OcTreeNode *node) const
whether one node is completely free
Definition: coal/octree.h:165
coal::constructBox
COAL_DLLAPI void constructBox(const AABB &bv, Box &box, Transform3s &tf)
construct a box shape (with a configuration) from a given bounding volume
Definition: geometric_shapes_utility.cpp:1011
coal::OcTree::getNodeChild
OcTreeNode * getNodeChild(OcTreeNode *node, unsigned int childIdx)
Definition: coal/octree.h:240
d
d
coal::detail::NodeBase::children
NodeBase< BV > * children[2]
for leaf node, children nodes
Definition: coal/broadphase/detail/node_base.h:64
coal::OcTree::getOccupancyThres
CoalScalar getOccupancyThres() const
the threshold used to decide whether one node is occupied, this is NOT the octree occupied_thresold
Definition: coal/octree.h:225
coal::computeChildBV
static void computeChildBV(const AABB &root_bv, unsigned int i, AABB &child_bv)
compute the bounding volume of an octree node's i-th child
Definition: coal/octree.h:299
coal::Transform3s::Identity
static Transform3s Identity()
Definition: coal/math/transform.h:68
coal::DistanceCallBackBase
Base callback class for distance queries. This class can be supersed by child classes to provide desi...
Definition: coal/broadphase/broadphase_callbacks.h:72
coal::OcTree::nodeChildExists
bool nodeChildExists(const OcTreeNode *node, unsigned int childIdx) const
return true if the child at childIdx exists
Definition: coal/octree.h:259
coal::CollisionObject
the object for collision or distance computation, contains the geometry and the transform information
Definition: coal/collision_object.h:214
gjk.tf2
tuple tf2
Definition: test/scripts/gjk.py:36
coal::translate
static AABB translate(const AABB &aabb, const Vec3s &t)
translate the center of AABB by t
Definition: coal/BV/AABB.h:233
coal::detail::NodeBase::isLeaf
bool isLeaf() const
whether is a leaf
Definition: coal/broadphase/detail/node_base-inl.h:54
coal::OcTree::OcTreeNode
octomap::OcTreeNode OcTreeNode
Definition: coal/octree.h:63
coal::OcTree
Octree is one type of collision geometry which can encode uncertainty information in the sensor data.
Definition: coal/octree.h:53
geometric_shapes_utility.h
coal::CollisionCallBackBase
Base callback class for collision queries. This class can be supersed by child classes to provide des...
Definition: coal/broadphase/broadphase_callbacks.h:49
coal::detail::NodeBase::bv
BV bv
the bounding volume for the node
Definition: coal/broadphase/detail/node_base.h:51
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::detail::NodeBase
dynamic AABB tree node
Definition: coal/broadphase/detail/node_base.h:49
coal::AABB::size
CoalScalar size() const
Size of the AABB (used in BV_Splitter to order two AABBs)
Definition: coal/BV/AABB.h:161
coal::CollisionObject::collisionGeometry
const shared_ptr< const CollisionGeometry > collisionGeometry() const
get shared pointer to collision geometry of the object instance
Definition: coal/collision_object.h:311


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:57