|
49 | 49 | #include <hpp/fcl/shape/geometric_shapes.h>
|
50 | 50 | #include <hpp/fcl/narrowphase/narrowphase.h>
|
51 | 51 | #include <hpp/fcl/internal/traversal.h>
|
| 52 | +#include <hpp/fcl/internal/shape_shape_func.h> |
52 | 53 |
|
53 |
| -#include <limits> |
54 |
| -#include <vector> |
55 | 54 | #include <cassert>
|
56 | 55 |
|
57 | 56 | namespace hpp {
|
@@ -204,38 +203,42 @@ class MeshCollisionTraversalNode : public BVHCollisionTraversalNode<BV> {
|
204 | 203 |
|
205 | 204 | TriangleP tri1(P1, P2, P3);
|
206 | 205 | 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); |
218 | 206 |
|
| 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; |
219 | 227 | const FCL_REAL distToCollision = distance - this->request.security_margin;
|
| 228 | + |
| 229 | + internal::updateDistanceLowerBoundFromLeaf(this->request, *(this->result), |
| 230 | + distToCollision, p1, p2, normal); |
| 231 | + |
220 | 232 | if (distToCollision <=
|
221 | 233 | this->request.collision_distance_threshold) { // collision
|
222 | 234 | sqrDistLowerBound = 0;
|
223 | 235 | 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 |
| - // } |
230 | 236 | this->result->addContact(Contact(this->model1, this->model2,
|
231 | 237 | primitive_id1, primitive_id2, p1, p2,
|
232 | 238 | normal, distance));
|
233 | 239 | }
|
234 | 240 | } else
|
235 | 241 | sqrDistLowerBound = distToCollision * distToCollision;
|
236 |
| - |
237 |
| - internal::updateDistanceLowerBoundFromLeaf(this->request, *this->result, |
238 |
| - distToCollision, p1, p2, normal); |
239 | 242 | }
|
240 | 243 |
|
241 | 244 | Vec3f* vertices1;
|
|
0 commit comments