40 #ifdef COAL_HAVE_OCTOMAP
52 namespace dynamic_AABB_tree {
58 const AABB& root2_bv,
const Transform3s&
tf2,
61 if (root1->isLeaf()) {
62 CollisionObject* obj1 =
static_cast<CollisionObject*
>(root1->data);
64 if (!obj1->collisionGeometry()->isFree()) {
69 if (obb1.overlap(obb2)) {
74 box->cost_density = tree2->getDefaultOccupancy();
76 CollisionObject obj2(shared_ptr<CollisionGeometry>(
box), box_tf);
81 if (collisionRecurse_(root1->children[0], tree2,
nullptr, root2_bv,
tf2,
84 if (collisionRecurse_(root1->children[1], tree2,
nullptr, root2_bv,
tf2,
90 }
else if (root1->isLeaf() && !tree2->nodeHasChildren(root2)) {
91 CollisionObject* obj1 =
static_cast<CollisionObject*
>(root1->data);
93 if (!tree2->isNodeFree(root2) && !obj1->collisionGeometry()->isFree()) {
98 if (obb1.overlap(obb2)) {
103 box->cost_density = root2->getOccupancy();
104 box->threshold_occupied = tree2->getOccupancyThres();
106 CollisionObject obj2(shared_ptr<CollisionGeometry>(
box), box_tf);
118 if (tree2->isNodeFree(root2) || !obb1.overlap(obb2))
return false;
120 if (!tree2->nodeHasChildren(root2) ||
121 (!root1->isLeaf() && (root1->bv.size() > root2_bv.size()))) {
122 if (collisionRecurse_(root1->children[0], tree2, root2, root2_bv,
tf2,
125 if (collisionRecurse_(root1->children[1], tree2, root2, root2_bv,
tf2,
129 for (
unsigned int i = 0; i < 8; ++i) {
130 if (tree2->nodeChildExists(root2, i)) {
135 if (collisionRecurse_(root1, tree2, child, child_bv,
tf2,
callback))
140 if (collisionRecurse_(root1, tree2,
nullptr, child_bv,
tf2,
callback))
151 const AABB& root2_bv,
const Transform3s&
tf2,
153 if (root1->isLeaf() && !tree2->nodeHasChildren(root2)) {
154 if (tree2->isNodeOccupied(root2)) {
155 Box*
box =
new Box();
158 CollisionObject obj(shared_ptr<CollisionGeometry>(
box), box_tf);
159 return (*
callback)(
static_cast<CollisionObject*
>(root1->data), &obj,
165 if (!tree2->isNodeOccupied(root2))
return false;
167 if (!tree2->nodeHasChildren(root2) ||
168 (!root1->isLeaf() && (root1->bv.size() > root2_bv.size()))) {
173 CoalScalar d2 = aabb2.distance(root1->children[1]->bv);
177 if (distanceRecurse_(root1->children[1], tree2, root2, root2_bv,
tf2,
183 if (distanceRecurse_(root1->children[0], tree2, root2, root2_bv,
tf2,
189 if (distanceRecurse_(root1->children[0], tree2, root2, root2_bv,
tf2,
195 if (distanceRecurse_(root1->children[1], tree2, root2, root2_bv,
tf2,
201 for (
unsigned int i = 0; i < 8; ++i) {
202 if (tree2->nodeChildExists(root2, i)) {
212 if (distanceRecurse_(root1, tree2, child, child_bv,
tf2,
callback,
226 const AABB& root2_bv,
const Transform3s&
tf2,
228 if (
tf2.rotation().isIdentity())
229 return collisionRecurse_(root1, tree2, root2, root2_bv,
tf2.translation(),
232 return collisionRecurse_(root1, tree2, root2, root2_bv,
tf2,
callback);
238 const AABB& root2_bv,
const Transform3s&
tf2,
240 if (
tf2.rotation().isIdentity())
241 return distanceRecurse_(root1, tree2, root2, root2_bv,
tf2.translation(),
244 return distanceRecurse_(root1, tree2, root2, root2_bv,
tf2,
callback,
265 const auto& halfspace =
277 const auto& halfspace =
306 const auto& halfspace =
321 const auto& halfspace =
331 return node1->
bv.overlap(node2->
bv);
349 (!root1->
isLeaf() && (root1->
bv.size() > root2->
bv.size()))) {
371 query_node.
data = query;
373 query_node.
parent =
nullptr;
395 if (root->
isLeaf())
return false;
414 return (*
callback)(root1_obj, root2_obj, min_dist);
418 (!root1->
isLeaf() && (root1->
bv.size() > root2->
bv.size()))) {
479 return (*
callback)(root_obj, query, min_dist);
513 if (root->
isLeaf())
return false;
547 const std::vector<CollisionObject*>& other_objs) {
548 if (other_objs.empty())
return;
553 std::vector<DynamicAABBNode*> leaves(other_objs.size());
554 table.rehash(other_objs.size());
555 for (
size_t i = 0,
size = other_objs.size(); i <
size; ++i) {
558 node->
bv = other_objs[i]->getAABB();
561 node->
data = other_objs[i];
562 table[other_objs[i]] = node;
588 size_t num =
dtree.size();
594 size_t height =
dtree.getMaxHeight();
600 dtree.balanceTopdown();
608 for (
auto it =
table.cbegin(); it !=
table.cend(); ++it) {
612 if (node->
bv.volume() <= 0.)
614 std::invalid_argument)
625 const auto it =
table.find(updated_obj);
626 if (it !=
table.end()) {
628 if (!(node->
bv == updated_obj->
getAABB()))
642 const std::vector<CollisionObject*>& updated_objs) {
643 for (
size_t i = 0,
size = updated_objs.size(); i <
size; ++i)
656 std::vector<CollisionObject*>& objs)
const {
657 objs.resize(this->
size());
660 std::bind(&DynamicAABBTable::value_type::first, std::placeholders::_1));
667 if (
size() == 0)
return;
669 #if COAL_HAVE_OCTOMAP
692 if (
size() == 0)
return;
693 CoalScalar min_dist = (std::numeric_limits<CoalScalar>::max)();
695 #if COAL_HAVE_OCTOMAP
718 if (
size() == 0)
return;
726 if (
size() == 0)
return;
727 CoalScalar min_dist = (std::numeric_limits<CoalScalar>::max)();
739 if ((
size() == 0) || (other_manager->
size() == 0))
return;
751 if ((
size() == 0) || (other_manager->
size() == 0))
return;
752 CoalScalar min_dist = (std::numeric_limits<CoalScalar>::max)();