coal/broadphase/broadphase_dynamic_AABB_tree_array-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_ARRAY_INL_H
39 #define COAL_BROAD_PHASE_DYNAMIC_AABB_TREE_ARRAY_INL_H
40 
43 
44 #if COAL_HAVE_OCTOMAP
45 #include "coal/octree.h"
46 #endif
47 
48 namespace coal {
49 namespace detail {
50 namespace dynamic_AABB_tree_array {
51 
52 #if COAL_HAVE_OCTOMAP
53 
54 //==============================================================================
55 template <typename Derived>
56 bool collisionRecurse_(
58  size_t root1_id, const OcTree* tree2, const OcTree::OcTreeNode* root2,
59  const AABB& root2_bv, const Eigen::MatrixBase<Derived>& translation2,
62  nodes1 + root1_id;
63  if (!root2) {
64  if (root1->isLeaf()) {
65  CollisionObject* obj1 = static_cast<CollisionObject*>(root1->data);
66 
67  if (!obj1->collisionGeometry()->isFree()) {
68  const AABB& root_bv_t = translate(root2_bv, translation2);
69  if (root1->bv.overlap(root_bv_t)) {
70  Box* box = new Box();
71  Transform3s box_tf;
73  tf2.translation() = translation2;
74  constructBox(root2_bv, tf2, *box, box_tf);
75 
76  box->cost_density = tree2->getDefaultOccupancy();
77 
78  CollisionObject obj2(shared_ptr<CollisionGeometry>(box), box_tf);
79  return (*callback)(obj1, &obj2);
80  }
81  }
82  } else {
83  if (collisionRecurse_(nodes1, root1->children[0], tree2, nullptr,
84  root2_bv, translation2, callback))
85  return true;
86  if (collisionRecurse_(nodes1, root1->children[1], tree2, nullptr,
87  root2_bv, translation2, callback))
88  return true;
89  }
90 
91  return false;
92  } else if (root1->isLeaf() && !tree2->nodeHasChildren(root2)) {
93  CollisionObject* obj1 = static_cast<CollisionObject*>(root1->data);
94  if (!tree2->isNodeFree(root2) && !obj1->collisionGeometry()->isFree()) {
95  const AABB& root_bv_t = translate(root2_bv, translation2);
96  if (root1->bv.overlap(root_bv_t)) {
97  Box* box = new Box();
98  Transform3s box_tf;
100  tf2.translation() = translation2;
101  constructBox(root2_bv, tf2, *box, box_tf);
102 
103  box->cost_density = root2->getOccupancy();
104  box->threshold_occupied = tree2->getOccupancyThres();
105 
106  CollisionObject obj2(shared_ptr<CollisionGeometry>(box), box_tf);
107  return (*callback)(obj1, &obj2);
108  } else
109  return false;
110  } else
111  return false;
112  }
113 
114  const AABB& root_bv_t = translate(root2_bv, translation2);
115  if (tree2->isNodeFree(root2) || !root1->bv.overlap(root_bv_t)) return false;
116 
117  if (!tree2->nodeHasChildren(root2) ||
118  (!root1->isLeaf() && (root1->bv.size() > root2_bv.size()))) {
119  if (collisionRecurse_(nodes1, root1->children[0], tree2, root2, root2_bv,
120  translation2, callback))
121  return true;
122  if (collisionRecurse_(nodes1, root1->children[1], tree2, root2, root2_bv,
123  translation2, callback))
124  return true;
125  } else {
126  for (unsigned int i = 0; i < 8; ++i) {
127  if (tree2->nodeChildExists(root2, i)) {
128  const OcTree::OcTreeNode* child = tree2->getNodeChild(root2, i);
129  AABB child_bv;
130  computeChildBV(root2_bv, i, child_bv);
131 
132  if (collisionRecurse_(nodes1, root1_id, tree2, child, child_bv,
133  translation2, callback))
134  return true;
135  } else {
136  AABB child_bv;
137  computeChildBV(root2_bv, i, child_bv);
138  if (collisionRecurse_(nodes1, root1_id, tree2, nullptr, child_bv,
139  translation2, callback))
140  return true;
141  }
142  }
143  }
144 
145  return false;
146 }
147 
148 //==============================================================================
149 template <typename Derived>
150 bool distanceRecurse_(
152  size_t root1_id, const OcTree* tree2, const OcTree::OcTreeNode* root2,
153  const AABB& root2_bv, const Eigen::MatrixBase<Derived>& translation2,
156  nodes1 + root1_id;
157  if (root1->isLeaf() && !tree2->nodeHasChildren(root2)) {
158  if (tree2->isNodeOccupied(root2)) {
159  Box* box = new Box();
160  Transform3s box_tf;
162  tf2.translation() = translation2;
163  constructBox(root2_bv, tf2, *box, box_tf);
164  CollisionObject obj(shared_ptr<CollisionGeometry>(box), box_tf);
165  return (*callback)(static_cast<CollisionObject*>(root1->data), &obj,
166  min_dist);
167  } else
168  return false;
169  }
170 
171  if (!tree2->isNodeOccupied(root2)) return false;
172 
173  if (!tree2->nodeHasChildren(root2) ||
174  (!root1->isLeaf() && (root1->bv.size() > root2_bv.size()))) {
175  const AABB& aabb2 = translate(root2_bv, translation2);
176 
177  CoalScalar d1 = aabb2.distance((nodes1 + root1->children[0])->bv);
178  CoalScalar d2 = aabb2.distance((nodes1 + root1->children[1])->bv);
179 
180  if (d2 < d1) {
181  if (d2 < min_dist) {
182  if (distanceRecurse_(nodes1, root1->children[1], tree2, root2, root2_bv,
183  translation2, callback, min_dist))
184  return true;
185  }
186 
187  if (d1 < min_dist) {
188  if (distanceRecurse_(nodes1, root1->children[0], tree2, root2, root2_bv,
189  translation2, callback, min_dist))
190  return true;
191  }
192  } else {
193  if (d1 < min_dist) {
194  if (distanceRecurse_(nodes1, root1->children[0], tree2, root2, root2_bv,
195  translation2, callback, min_dist))
196  return true;
197  }
198 
199  if (d2 < min_dist) {
200  if (distanceRecurse_(nodes1, root1->children[1], tree2, root2, root2_bv,
201  translation2, callback, min_dist))
202  return true;
203  }
204  }
205  } else {
206  for (unsigned int i = 0; i < 8; ++i) {
207  if (tree2->nodeChildExists(root2, i)) {
208  const OcTree::OcTreeNode* child = tree2->getNodeChild(root2, i);
209  AABB child_bv;
210  computeChildBV(root2_bv, i, child_bv);
211 
212  const AABB& aabb2 = translate(child_bv, translation2);
213  CoalScalar d = root1->bv.distance(aabb2);
214 
215  if (d < min_dist) {
216  if (distanceRecurse_(nodes1, root1_id, tree2, child, child_bv,
217  translation2, callback, min_dist))
218  return true;
219  }
220  }
221  }
222  }
223 
224  return false;
225 }
226 
227 #endif
228 
229 } // namespace dynamic_AABB_tree_array
230 } // namespace detail
231 } // namespace coal
232 
233 #endif
coal::detail::implementation_array::NodeBase::data
void * data
Definition: coal/broadphase/detail/node_base_array.h:60
octree.h
geometric_shapes.d1
float d1
Definition: scripts/geometric_shapes.py:31
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::detail::implementation_array::NodeBase::bv
BV bv
Definition: coal/broadphase/detail/node_base_array.h:51
coal::detail::implementation_array::NodeBase
Definition: coal/broadphase/detail/node_base_array.h:50
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::OcTree::isNodeOccupied
bool isNodeOccupied(const OcTreeNode *node) const
whether one node is completely occupied
Definition: coal/octree.h:159
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::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::detail::implementation_array::NodeBase::isLeaf
bool isLeaf() const
Definition: coal/broadphase/detail/node_base_array-inl.h:51
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
broadphase_dynamic_AABB_tree_array.h
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
coal::OcTree::getDefaultOccupancy
CoalScalar getDefaultOccupancy() const
Definition: coal/octree.h:231
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::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
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
coal::detail::implementation_array::NodeBase::children
size_t children[2]
Definition: coal/broadphase/detail/node_base_array.h:59


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