40 #if HPP_FCL_HAVE_OCTOMAP
46 namespace dynamic_AABB_tree_array {
48 #if HPP_FCL_HAVE_OCTOMAP
51 bool collisionRecurse_(
54 const AABB& root2_bv,
const Transform3f&
tf2,
59 if (root1->isLeaf()) {
60 CollisionObject* obj1 =
static_cast<CollisionObject*
>(root1->data);
62 if (!obj1->collisionGeometry()->isFree()) {
67 if (obb1.overlap(obb2)) {
72 box->cost_density = tree2->getDefaultOccupancy();
74 CollisionObject obj2(shared_ptr<CollisionGeometry>(
box), box_tf);
79 if (collisionRecurse_(nodes1, root1->children[0], tree2,
nullptr,
82 if (collisionRecurse_(nodes1, root1->children[1], tree2,
nullptr,
88 }
else if (root1->isLeaf() && !tree2->nodeHasChildren(root2)) {
89 CollisionObject* obj1 =
static_cast<CollisionObject*
>(root1->data);
90 if (!tree2->isNodeFree(root2) && !obj1->collisionGeometry()->isFree()) {
95 if (obb1.overlap(obb2)) {
100 box->cost_density = root2->getOccupancy();
101 box->threshold_occupied = tree2->getOccupancyThres();
103 CollisionObject obj2(shared_ptr<CollisionGeometry>(
box), box_tf);
115 if (tree2->isNodeFree(root2) || !obb1.overlap(obb2))
return false;
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,
122 if (collisionRecurse_(nodes1, root1->children[1], tree2, root2, root2_bv,
126 for (
unsigned int i = 0; i < 8; ++i) {
127 if (tree2->nodeChildExists(root2, i)) {
132 if (collisionRecurse_(nodes1, root1_id, tree2, child, child_bv,
tf2,
138 if (collisionRecurse_(nodes1, root1_id, tree2,
nullptr, child_bv,
tf2,
149 bool distanceRecurse_(
152 const AABB& root2_bv,
const Transform3f&
tf2,
156 if (root1->isLeaf() && !tree2->nodeHasChildren(root2)) {
157 if (tree2->isNodeOccupied(root2)) {
158 Box*
box =
new Box();
161 CollisionObject obj(shared_ptr<CollisionGeometry>(
box), box_tf);
162 return (*
callback)(
static_cast<CollisionObject*
>(root1->data), &obj,
168 if (!tree2->isNodeOccupied(root2))
return false;
170 if (!tree2->nodeHasChildren(root2) ||
171 (!root1->isLeaf() && (root1->bv.size() > root2_bv.size()))) {
175 FCL_REAL d1 = aabb2.distance((nodes1 + root1->children[0])->bv);
176 FCL_REAL d2 = aabb2.distance((nodes1 + root1->children[1])->bv);
180 if (distanceRecurse_(nodes1, root1->children[1], tree2, root2, root2_bv,
186 if (distanceRecurse_(nodes1, root1->children[0], tree2, root2, root2_bv,
192 if (distanceRecurse_(nodes1, root1->children[0], tree2, root2, root2_bv,
198 if (distanceRecurse_(nodes1, root1->children[1], tree2, root2, root2_bv,
204 for (
unsigned int i = 0; i < 8; ++i) {
205 if (tree2->nodeChildExists(root2, i)) {
212 FCL_REAL d = root1->bv.distance(aabb2);
215 if (distanceRecurse_(nodes1, root1_id, tree2, child, child_bv,
tf2,
239 if (!root1->
bv.overlap(root2->
bv))
return false;
244 if (!root1->
bv.overlap(root2->
bv))
return false;
247 (!root1->
isLeaf() && (root1->
bv.size() > root2->
bv.size()))) {
270 if (!root->
bv.overlap(query->
getAABB()))
return false;
293 if (root->
isLeaf())
return false;
319 return (*
callback)(root1_obj, root2_obj, min_dist);
323 (!root1->
isLeaf() && (root1->
bv.size() > root2->
bv.size()))) {
394 return (*
callback)(root_obj, query, min_dist);
430 if (root->
isLeaf())
return false;
445 #if HPP_FCL_HAVE_OCTOMAP
453 if (
tf2.rotation().isIdentity())
454 return collisionRecurse_(nodes1, root1_id, tree2, root2, root2_bv,
457 return collisionRecurse_(nodes1, root1_id, tree2, root2, root2_bv,
tf2,
467 if (
tf2.rotation().isIdentity())
468 return distanceRecurse_(nodes1, root1_id, tree2, root2, root2_bv,
471 return distanceRecurse_(nodes1, root1_id, tree2, root2, root2_bv,
tf2,
499 const std::vector<CollisionObject*>& other_objs) {
500 if (other_objs.empty())
return;
506 table.rehash(other_objs.size());
507 for (
size_t i = 0,
size = other_objs.size(); i <
size; ++i) {
508 leaves[i].
bv = other_objs[i]->getAABB();
511 leaves[i].
data = other_objs[i];
512 table[other_objs[i]] = i;
515 int n_leaves = (int)other_objs.size();
533 size_t node =
table[obj];
541 int num = (int)
dtree.size();
547 int height = (int)
dtree.getMaxHeight();
553 dtree.balanceTopdown();
561 for (
auto it =
table.cbegin(), end =
table.cend(); it != end; ++it) {
563 size_t node = it->second;
576 const auto it =
table.find(updated_obj);
577 if (it !=
table.end()) {
578 size_t node = it->second;
579 if (!(
dtree.getNodes()[node].bv == updated_obj->
getAABB()))
594 const std::vector<CollisionObject*>& updated_objs) {
595 for (
size_t i = 0,
size = updated_objs.size(); i <
size; ++i)
608 std::vector<CollisionObject*>& objs)
const {
609 objs.resize(this->
size());
612 std::bind(&DynamicAABBTable::value_type::first, std::placeholders::_1));
619 if (
size() == 0)
return;
621 #if HPP_FCL_HAVE_OCTOMAP
644 if (
size() == 0)
return;
645 FCL_REAL min_dist = (std::numeric_limits<FCL_REAL>::max)();
647 #if HPP_FCL_HAVE_OCTOMAP
670 if (
size() == 0)
return;
679 if (
size() == 0)
return;
680 FCL_REAL min_dist = (std::numeric_limits<FCL_REAL>::max)();
692 if ((
size() == 0) || (other_manager->
size() == 0))
return;
705 if ((
size() == 0) || (other_manager->
size() == 0))
return;
706 FCL_REAL min_dist = (std::numeric_limits<FCL_REAL>::max)();
714 return dtree.empty();