Skip to content

Commit 55c5131

Browse files
committed
BVH-BVH: use ShapeShapeDistance instead of GJKSolver
1 parent 8cec4df commit 55c5131

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

include/hpp/fcl/internal/traversal_node_bvhs.h

+25-22
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@
4949
#include <hpp/fcl/shape/geometric_shapes.h>
5050
#include <hpp/fcl/narrowphase/narrowphase.h>
5151
#include <hpp/fcl/internal/traversal.h>
52+
#include <hpp/fcl/internal/shape_shape_func.h>
5253

53-
#include <limits>
54-
#include <vector>
5554
#include <cassert>
5655

5756
namespace hpp {
@@ -204,38 +203,42 @@ class MeshCollisionTraversalNode : public BVHCollisionTraversalNode<BV> {
204203

205204
TriangleP tri1(P1, P2, P3);
206205
TriangleP tri2(Q1, Q2, Q3);
207-
GJKSolver solver;
208-
Vec3f p1,
209-
p2; // closest points if no collision contact points if collision.
210-
Vec3f normal;
211-
FCL_REAL distance;
212-
// If the security margin is negative, we have to compute the penetration
213-
// to get the correct distance to compare to the security margin.
214-
bool compute_penetration =
215-
(this->request.enable_contact || this->request.security_margin < 0);
216-
solver.shapeDistance(tri1, this->tf1, tri2, this->tf2, distance,
217-
compute_penetration, p1, p2, normal);
218206

207+
// TODO(louis): MeshCollisionTraversalNode should have its own GJKSolver.
208+
GJKSolver solver(this->request);
209+
210+
// When reaching this point, `this->solver` has already been set up
211+
// by the CollisionRequest `this->request`.
212+
// The only thing we need to (and can) pass to `ShapeShapeDistance` is
213+
// whether or not penetration information is should be computed in case of
214+
// collision.
215+
const bool compute_penetration =
216+
this->request.enable_contact || (this->request.security_margin < 0);
217+
const DistanceRequest distanceRequest(compute_penetration,
218+
compute_penetration);
219+
DistanceResult distanceResult;
220+
FCL_REAL distance = ShapeShapeDistance<TriangleP, TriangleP>(
221+
&tri1, this->tf1, &tri2, this->tf2, &solver, distanceRequest,
222+
distanceResult);
223+
224+
const Vec3f& p1 = distanceResult.nearest_points[0];
225+
const Vec3f& p2 = distanceResult.nearest_points[1];
226+
const Vec3f& normal = distanceResult.normal;
219227
const FCL_REAL distToCollision = distance - this->request.security_margin;
228+
229+
internal::updateDistanceLowerBoundFromLeaf(this->request, *(this->result),
230+
distToCollision, p1, p2, normal);
231+
220232
if (distToCollision <=
221233
this->request.collision_distance_threshold) { // collision
222234
sqrDistLowerBound = 0;
223235
if (this->result->numContacts() < this->request.num_max_contacts) {
224-
// How much (Q1, Q2, Q3) should be moved so that all vertices are
225-
// above (P1, P2, P3).
226-
// The normal is already computed by GJK, no need to recompute it.
227-
// if (distance > 0) {
228-
// normal = (p2 - p1).normalized();
229-
// }
230236
this->result->addContact(Contact(this->model1, this->model2,
231237
primitive_id1, primitive_id2, p1, p2,
232238
normal, distance));
233239
}
234240
} else
235241
sqrDistLowerBound = distToCollision * distToCollision;
236-
237-
internal::updateDistanceLowerBoundFromLeaf(this->request, *this->result,
238-
distToCollision, p1, p2, normal);
239242
}
240243

241244
Vec3f* vertices1;

0 commit comments

Comments
 (0)