39 #ifndef HPP_FCL_NARROWPHASE_H 40 #define HPP_FCL_NARROWPHASE_H 53 template<
typename S1,
typename S2>
57 bool enable_penetration,
62 if(enable_cached_guess) {
64 support_hint = support_func_cached_guess;
66 support_hint.setZero();
69 shape.
set (&s1, &s2, tf1, tf2);
71 details::GJK gjk((
unsigned int )gjk_max_iterations, gjk_tolerance);
73 if(enable_cached_guess) {
81 if (!enable_penetration && contact_points == NULL && normal == NULL)
86 if(normal) *normal = tf1.
getRotation() * (w0 - w1).normalized();
87 if(contact_points) *contact_points = tf1.
transform((w0 + w1) / 2);
90 details::EPA epa(epa_max_face_num, epa_max_vertex_num, epa_max_iterations, epa_tolerance);
98 distance_lower_bound = -epa.
depth;
103 distance_lower_bound = -(std::numeric_limits<FCL_REAL>::max)();
109 distance_lower_bound = gjk.
distance;
121 bool shapeTriangleInteraction
130 tf_1M2.transform (P1),
131 tf_1M2.transform (P2),
132 tf_1M2.transform (P3));
134 Vec3f guess(1, 0, 0);
136 if(enable_cached_guess) {
137 guess = cached_guess;
138 support_hint = support_func_cached_guess;
140 support_hint.setZero();
143 shape.
set (&s, &tri);
145 details::GJK gjk((
unsigned int )gjk_max_iterations, gjk_tolerance);
147 if(enable_cached_guess) {
159 normal = tf1.
getRotation() * (w0 - w1).normalized();
162 details::EPA epa(epa_max_face_num, epa_max_vertex_num, epa_max_iterations, epa_tolerance);
170 distance = -epa.
depth;
173 assert (distance <= 1e-6);
175 distance = -(std::numeric_limits<FCL_REAL>::max)();
193 assert (distance > 0);
196 assert (
false &&
"should not reach type part.");
203 template<
typename S1,
typename S2>
210 FCL_REAL eps (sqrt(std::numeric_limits<FCL_REAL>::epsilon()));
212 Vec3f guess(1, 0, 0);
214 if(enable_cached_guess) {
215 guess = cached_guess;
216 support_hint = support_func_cached_guess;
218 support_hint.setZero();
221 shape.
set (&s1, &s2, tf1, tf2);
223 details::GJK gjk((
unsigned int) gjk_max_iterations, gjk_tolerance);
225 if(enable_cached_guess) {
233 assert (distance * distance < sqrt (eps));
239 normal =
Vec3f (0,0,0);
264 normal = (tf1.
getRotation() * (p1 - p2)).normalized();
269 epa_max_iterations, epa_tolerance);
278 assert (epa.
depth >= -eps);
279 distance = (std::min) (0., -epa.
depth);
285 distance = -(std::numeric_limits<FCL_REAL>::max)();
297 gjk_max_iterations = 128;
298 gjk_tolerance = 1e-6;
299 epa_max_face_num = 128;
300 epa_max_vertex_num = 64;
301 epa_max_iterations = 255;
302 epa_tolerance = 1e-6;
303 enable_cached_guess =
false;
304 cached_guess =
Vec3f(1, 0, 0);
305 support_func_cached_guess = support_func_guess_t::Zero();
310 enable_cached_guess = if_enable;
315 cached_guess = guess;
369 #define SHAPE_INTERSECT_SPECIALIZATION_BASE(S1,S2) \ 371 HPP_FCL_DLLAPI bool GJKSolver::shapeIntersect<S1, S2> \ 372 (const S1 &s1, const Transform3f& tf1, \ 373 const S2 &s2, const Transform3f& tf2, \ 374 FCL_REAL& distance_lower_bound, \ 376 Vec3f* contact_points, Vec3f* normal) const 378 #define SHAPE_INTERSECT_SPECIALIZATION(S1,S2) \ 379 SHAPE_INTERSECT_SPECIALIZATION_BASE(S1,S2); \ 380 SHAPE_INTERSECT_SPECIALIZATION_BASE(S2,S1) 399 #undef SHAPE_INTERSECT_SPECIALIZATION 400 #undef SHAPE_INTERSECT_SPECIALIZATION_BASE 402 #define SHAPE_DISTANCE_SPECIALIZATION_BASE(S1,S2) \ 404 HPP_FCL_DLLAPI bool GJKSolver::shapeDistance<S1, S2> \ 405 (const S1& s1, const Transform3f& tf1, \ 406 const S2& s2, const Transform3f& tf2, \ 407 FCL_REAL& dist, Vec3f& p1, Vec3f& p2, Vec3f& normal) const 409 #define SHAPE_DISTANCE_SPECIALIZATION(S1,S2) \ 410 SHAPE_DISTANCE_SPECIALIZATION_BASE(S1,S2); \ 411 SHAPE_DISTANCE_SPECIALIZATION_BASE(S2,S1) 420 #undef SHAPE_DISTANCE_SPECIALIZATION 421 #undef SHAPE_DISTANCE_SPECIALIZATION_BASE 423 #if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)) 424 #pragma GCC diagnostic push 425 #pragma GCC diagnostic ignored "-Wc99-extensions" 432 #define HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape1,Shape2,doc) \ 436 HPP_FCL_DLLAPI bool GJKSolver::shapeIntersect<Shape1, Shape2> \ 437 (const Shape1& s1, const Transform3f& tf1, \ 438 const Shape2& s2, const Transform3f& tf2, \ 439 FCL_REAL& distance_lower_bound, bool enable_penetration, \ 440 Vec3f* contact_points, Vec3f* normal) const 441 #define HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Shape,doc) \ 442 HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape,Shape,doc) 443 #define HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Shape1,Shape2,doc) \ 444 HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape1,Shape2,doc); \ 445 HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape2,Shape1,doc) 454 (
const Box& s1,
const Transform3f& tf1,
455 const Sphere& s2,
const Transform3f& tf2,
456 FCL_REAL& distance_lower_bound,
bool enable_penetration,
459 #ifdef IS_DOXYGEN // for doxygen only 465 (
const Box& s1,
const Transform3f& tf1,
466 const Box& s2,
const Transform3f& tf2,
467 FCL_REAL& distance_lower_bound,
bool enable_penetration,
488 #undef HPP_FCL_DECLARE_SHAPE_INTERSECT 489 #undef HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF 490 #undef HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR 499 #define HPP_FCL_DECLARE_SHAPE_TRIANGLE(Shape,doc) \ 502 template<> HPP_FCL_DLLAPI bool GJKSolver::shapeTriangleInteraction<Shape> \ 503 (const Shape& s, const Transform3f& tf1, const Vec3f& P1, const Vec3f& P2, \ 504 const Vec3f& P3, const Transform3f& tf2, FCL_REAL& distance, \ 505 Vec3f& p1, Vec3f& p2, Vec3f& normal) const 511 #undef HPP_FCL_DECLARE_SHAPE_TRIANGLE 520 #define HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape1,Shape2,doc) \ 524 bool HPP_FCL_DLLAPI GJKSolver::shapeDistance<Shape1, Shape2> \ 525 (const Shape1& s1, const Transform3f& tf1, \ 526 const Shape2& s2, const Transform3f& tf2, \ 527 FCL_REAL& dist, Vec3f& p1, Vec3f& p2, Vec3f& normal) const 528 #define HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF(Shape,doc) \ 529 HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape,Shape,doc) 530 #define HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR(Shape1,Shape2,doc) \ 531 HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape1,Shape2,doc); \ 532 HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape2,Shape1,doc) 547 #undef HPP_FCL_DECLARE_SHAPE_DISTANCE 548 #undef HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF 549 #undef HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR 552 #if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)) 553 #pragma GCC diagnostic pop
unsigned int epa_max_iterations
maximum number of iterations used for EPA iterations
Definition: narrowphase.h:330
support_func_guess_t support_hint
Definition: gjk.h:156
Status
Definition: gjk.h:338
Main namespace.
Definition: AABB.h:43
unsigned int epa_max_face_num
maximum number of simplex face used in EPA algorithm
Definition: narrowphase.h:324
bool enable_cached_guess
Whether smart guess can be provided.
Definition: narrowphase.h:342
#define HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF(Shape, doc)
Definition: narrowphase.h:528
Half Space: this is equivalent to the Plane in ODE. The separation plane is defined as n * x = d; Poi...
Definition: geometric_shapes.h:357
#define SHAPE_DISTANCE_SPECIALIZATION(S1, S2)
Definition: narrowphase.h:409
bool getClosestPoints(const MinkowskiDiff &shape, Vec3f &w0, Vec3f &w1)
GJKSolver()
default setting for GJK algorithm
Definition: narrowphase.h:295
void set(const ShapeBase *shape0, const ShapeBase *shape1)
Infinite plane.
Definition: geometric_shapes.h:405
class for GJK algorithm
Definition: gjk.h:130
Vec3f ray
Definition: gjk.h:155
Minkowski difference class of two shapes.
Definition: gjk.h:61
class for EPA algorithm
Definition: gjk.h:277
Status evaluate(const MinkowskiDiff &shape, const Vec3f &guess, const support_func_guess_t &supportHint=support_func_guess_t::Zero())
GJK algorithm, given the initial value guess.
bool getClosestPoints(const MinkowskiDiff &shape, Vec3f &w0, Vec3f &w1)
Vec3f getGuessFromSimplex() const
get the guess from current simplex
#define SHAPE_DISTANCE_SPECIALIZATION_BASE(S1, S2)
Definition: narrowphase.h:402
FCL_REAL distance(const Matrix3f &R0, const Vec3f &T0, const kIOS &b1, const kIOS &b2, Vec3f *P=NULL, Vec3f *Q=NULL)
Approximate distance between two kIOS bounding volumes.
double FCL_REAL
Definition: data_types.h:66
unsigned int epa_max_vertex_num
maximum number of simplex vertex used in EPA algorithm
Definition: narrowphase.h:327
Status
Definition: gjk.h:152
void enableCachedGuess(bool if_enable) const
Definition: narrowphase.h:308
Triangle stores the points instead of only indices of points.
Definition: geometric_shapes.h:70
Eigen::Vector2i support_func_guess_t
Definition: data_types.h:69
FCL_REAL depth
Definition: gjk.h:353
FCL_REAL distance
Definition: gjk.h:170
#define SHAPE_INTERSECT_SPECIALIZATION_BASE(S1, S2)
Definition: narrowphase.h:369
FCL_REAL gjk_max_iterations
maximum number of iterations used for GJK iterations
Definition: narrowphase.h:339
bool shapeDistance(const S1 &s1, const Transform3f &tf1, const S2 &s2, const Transform3f &tf2, FCL_REAL &distance, Vec3f &p1, Vec3f &p2, Vec3f &normal) const
distance computation between two shapes
Definition: narrowphase.h:204
Center at zero point sphere.
Definition: geometric_shapes.h:122
Vec3f cached_guess
smart guess
Definition: narrowphase.h:345
bool shapeTriangleInteraction(const S &s, const Transform3f &tf1, const Vec3f &P1, const Vec3f &P2, const Vec3f &P3, const Transform3f &tf2, FCL_REAL &distance, Vec3f &p1, Vec3f &p2, Vec3f &normal) const
intersection checking between one shape and a triangle with transformation
Definition: narrowphase.h:122
Status evaluate(GJK &gjk, const Vec3f &guess)
bool shapeIntersect(const S1 &s1, const Transform3f &tf1, const S2 &s2, const Transform3f &tf2, FCL_REAL &distance_lower_bound, bool enable_penetration, Vec3f *contact_points, Vec3f *normal) const
intersection checking between two shapes
Definition: narrowphase.h:54
#define HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Shape, doc)
Definition: narrowphase.h:441
#define HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Shape1, Shape2, doc)
Definition: narrowphase.h:443
#define SHAPE_INTERSECT_SPECIALIZATION(S1, S2)
Definition: narrowphase.h:378
#define HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR(Shape1, Shape2, doc)
Definition: narrowphase.h:530
collision and distance solver based on GJK algorithm implemented in fcl (rewritten the code from the ...
Definition: narrowphase.h:50
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
FCL_REAL gjk_tolerance
the threshold used in GJK to stop iteration
Definition: narrowphase.h:336
Vec3f normal
Definition: gjk.h:352
support_func_guess_t support_func_cached_guess
smart guess for the support function
Definition: narrowphase.h:348
Vec3f getCachedGuess() const
Definition: narrowphase.h:318
void setCachedGuess(const Vec3f &guess) const
Definition: narrowphase.h:313
bool hasPenetrationInformation(const MinkowskiDiff &shape)
Definition: gjk.h:220
FCL_REAL epa_tolerance
the threshold used in EPA to stop iteration
Definition: narrowphase.h:333
#define HPP_FCL_DECLARE_SHAPE_TRIANGLE(Shape, doc)
Definition: narrowphase.h:499
#define HPP_FCL_DLLAPI
Definition: config.hh:64