Skip to content

Commit 24cfcbe

Browse files
committed
GJKSolver: better runGJKAndEPA signature
This allows to see in Debug mode on which collision pair an assertion occurs.
1 parent c47058a commit 24cfcbe

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

include/hpp/fcl/narrowphase/narrowphase.h

+16-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ struct HPP_FCL_DLLAPI GJKSolver {
7676
Vec3f p1(Vec3f::Zero()), p2(Vec3f::Zero());
7777
Vec3f n(Vec3f::Zero());
7878
FCL_REAL distance((std::numeric_limits<FCL_REAL>::max)());
79-
bool gjk_and_epa_ran_successfully = runGJKAndEPA(tf1, distance, p1, p2, n);
79+
bool gjk_and_epa_ran_successfully =
80+
runGJKAndEPA(s1, tf1, s2, tf2, distance, p1, p2, n);
8081
HPP_FCL_UNUSED_VARIABLE(gjk_and_epa_ran_successfully);
8182
if (normal != NULL) *normal = n;
8283
if (contact_points != NULL) *contact_points = 0.5 * (p1 + p2);
@@ -100,9 +101,10 @@ struct HPP_FCL_DLLAPI GJKSolver {
100101
TriangleP tri(tf_1M2.transform(P1), tf_1M2.transform(P2),
101102
tf_1M2.transform(P3));
102103

103-
minkowski_difference.set(&s, &tri);
104+
bool relative_transformation_already_computed = true;
104105
bool gjk_and_epa_ran_successfully =
105-
runGJKAndEPA(tf1, distance, p1, p2, normal);
106+
runGJKAndEPA(s, tf1, tri, tf_1M2, distance, p1, p2, normal,
107+
relative_transformation_already_computed);
106108
HPP_FCL_UNUSED_VARIABLE(gjk_and_epa_ran_successfully);
107109
return (gjk.status == details::GJK::Inside);
108110
}
@@ -115,9 +117,8 @@ struct HPP_FCL_DLLAPI GJKSolver {
115117
bool shapeDistance(const S1& s1, const Transform3f& tf1, const S2& s2,
116118
const Transform3f& tf2, FCL_REAL& distance, Vec3f& p1,
117119
Vec3f& p2, Vec3f& normal) const {
118-
minkowski_difference.set(&s1, &s2, tf1, tf2);
119120
bool gjk_and_epa_ran_successfully =
120-
runGJKAndEPA(tf1, distance, p1, p2, normal);
121+
runGJKAndEPA(s1, tf1, s2, tf2, distance, p1, p2, normal);
121122
return gjk_and_epa_ran_successfully;
122123
}
123124

@@ -165,11 +166,19 @@ struct HPP_FCL_DLLAPI GJKSolver {
165166
/// This function assumes the minkowski difference has been already been set,
166167
/// i.e. `minkowski_difference.set(&s1, &s2, tf1, tf2);` has been called.
167168
/// @return true if no error occured, false otherwise.
168-
bool runGJKAndEPA(const Transform3f& tf1, FCL_REAL& distance, Vec3f& p1,
169-
Vec3f& p2, Vec3f& normal) const {
169+
template <typename S1, typename S2>
170+
bool runGJKAndEPA(
171+
const S1& s1, const Transform3f& tf1, const S2& s2,
172+
const Transform3f& tf2, FCL_REAL& distance, Vec3f& p1, Vec3f& p2,
173+
Vec3f& normal,
174+
bool relative_transformation_already_computed = false) const {
170175
bool gjk_and_epa_ran_successfully = true;
171176

172177
// Reset internal state of GJK algorithm
178+
if (relative_transformation_already_computed)
179+
minkowski_difference.set(&s1, &s2);
180+
else
181+
minkowski_difference.set(&s1, &s2, tf1, tf2);
173182
gjk.reset();
174183

175184
// Get initial guess for GJK: default, cached or bounding volume guess

0 commit comments

Comments
 (0)