humanoid-path-planner/hpp-fcl

TODO: avoid BVH-BVH copy in `collide`?

Opened this issue · 0 comments

BVH-BVH makes a full copy of both BVHs + BV fitting before calling collide:

std::size_t BVHCollide(const CollisionGeometry* o1, const Transform3f& tf1,
const CollisionGeometry* o2, const Transform3f& tf2,
const CollisionRequest& request,
CollisionResult& result) {
if (request.isSatisfied(result)) return result.numContacts();
MeshCollisionTraversalNode<T_BVH> node(request);
const BVHModel<T_BVH>* obj1 = static_cast<const BVHModel<T_BVH>*>(o1);
const BVHModel<T_BVH>* obj2 = static_cast<const BVHModel<T_BVH>*>(o2);
BVHModel<T_BVH>* obj1_tmp = new BVHModel<T_BVH>(*obj1);
Transform3f tf1_tmp = tf1;
BVHModel<T_BVH>* obj2_tmp = new BVHModel<T_BVH>(*obj2);
Transform3f tf2_tmp = tf2;
initialize(node, *obj1_tmp, tf1_tmp, *obj2_tmp, tf2_tmp, result);
fcl::collide(&node, request, result);

Doing this not only copies two BVHs (which can have thousands or even hundreds of thousands of vertices) but also fits them with a new BVs structure.
I think the original idea was to transform both BVH in the world frame, hence avoiding having to transform each AABB when doing the collision between leafs of the BVHs.

In practice, when doing BVH-BVH collision, there are only a few AABB collision checks, and transforming an AABB is very cheap. Is it really worth copying/fitting two BVHs in order to avoid these on-the-fly transformations?