|
hpp-fcl
1.6.0
HPP fork of FCL -- The Flexible Collision Library
|
Go to the documentation of this file.
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;
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);
175 distance = -(std::numeric_limits<FCL_REAL>::max)();
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) {
239 normal =
Vec3f (0,0,0);
264 normal = (tf1.
getRotation() * (p1 - p2)).normalized();
269 epa_max_iterations, epa_tolerance);
278 assert (epa.
depth >= -eps);
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)
453 HPP_FCL_DLLAPI
bool GJKSolver::shapeIntersect<Box, Sphere>
456 FCL_REAL& distance_lower_bound,
bool enable_penetration,
459 #ifdef IS_DOXYGEN // for doxygen only
464 HPP_FCL_DLLAPI
bool GJKSolver::shapeIntersect<Box, Box>
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
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
#define HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Shape, doc)
Definition: narrowphase.h:441
GJKSolver()
default setting for GJK algorithm
Definition: narrowphase.h:295
Status
Definition: gjk.h:152
Center at zero point sphere.
Definition: geometric_shapes.h:123
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.
#define HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR(Shape1, Shape2, doc)
Definition: narrowphase.h:530
Cylinder along Z axis. The cylinder is defined at its centroid.
Definition: geometric_shapes.h:244
Center at zero point, axis aligned box.
Definition: geometric_shapes.h:87
Minkowski difference class of two shapes.
Definition: gjk.h:62
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
#define HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF(Shape, doc)
Definition: narrowphase.h:528
void setCachedGuess(const Vec3f &guess) const
Definition: narrowphase.h:313
#define SHAPE_DISTANCE_SPECIALIZATION_BASE(S1, S2)
Definition: narrowphase.h:402
@ Valid
Definition: gjk.h:152
Status evaluate(GJK &gjk, const Vec3f &guess)
Status
Definition: gjk.h:338
@ Valid
Definition: gjk.h:340
bool getClosestPoints(const MinkowskiDiff &shape, Vec3f &w0, Vec3f &w1)
class for EPA algorithm
Definition: gjk.h:278
support_func_guess_t support_hint
Definition: gjk.h:156
Half Space: this is equivalent to the Plane in ODE. The separation plane is defined as n * x = d; Poi...
Definition: geometric_shapes.h:358
#define SHAPE_INTERSECT_SPECIALIZATION_BASE(S1, S2)
Definition: narrowphase.h:369
#define HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Shape1, Shape2, doc)
Definition: narrowphase.h:443
#define SHAPE_INTERSECT_SPECIALIZATION(S1, S2)
Definition: narrowphase.h:378
Vec3f cached_guess
smart guess
Definition: narrowphase.h:345
#define SHAPE_DISTANCE_SPECIALIZATION(S1, S2)
Definition: narrowphase.h:409
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
Vec3f getCachedGuess() const
Definition: narrowphase.h:318
void enableCachedGuess(bool if_enable) const
Definition: narrowphase.h:308
Vec3f ray
Definition: gjk.h:155
Capsule It is where is the distance between the point x and the capsule segment AB,...
Definition: geometric_shapes.h:155
Cone The base of the cone is at and the top is at .
Definition: geometric_shapes.h:200
double FCL_REAL
Definition: data_types.h:66
#define HPP_FCL_DECLARE_SHAPE_TRIANGLE(Shape, doc)
Definition: narrowphase.h:499
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
void set(const ShapeBase *shape0, const ShapeBase *shape1)
Eigen::Vector2i support_func_guess_t
Definition: data_types.h:69
bool enable_cached_guess
Whether smart guess can be provided.
Definition: narrowphase.h:342
@ OutOfFaces
Definition: gjk.h:345
Main namespace.
Definition: AABB.h:44
bool hasPenetrationInformation(const MinkowskiDiff &shape)
Definition: gjk.h:220
FCL_REAL gjk_tolerance
the threshold used in GJK to stop iteration
Definition: narrowphase.h:336
unsigned int epa_max_face_num
maximum number of simplex face used in EPA algorithm
Definition: narrowphase.h:324
class for GJK algorithm
Definition: gjk.h:131
@ Inside
Definition: gjk.h:152
FCL_REAL gjk_max_iterations
maximum number of iterations used for GJK iterations
Definition: narrowphase.h:339
Infinite plane.
Definition: geometric_shapes.h:406
FCL_REAL epa_tolerance
the threshold used in EPA to stop iteration
Definition: narrowphase.h:333
FCL_REAL depth
Definition: gjk.h:353
support_func_guess_t support_func_cached_guess
smart guess for the support function
Definition: narrowphase.h:348
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.
bool getClosestPoints(const MinkowskiDiff &shape, Vec3f &w0, Vec3f &w1)
@ Failed
Definition: gjk.h:152
@ OutOfVertices
Definition: gjk.h:346
unsigned int epa_max_iterations
maximum number of iterations used for EPA iterations
Definition: narrowphase.h:330
collision and distance solver based on GJK algorithm implemented in fcl (rewritten the code from the ...
Definition: narrowphase.h:51
unsigned int epa_max_vertex_num
maximum number of simplex vertex used in EPA algorithm
Definition: narrowphase.h:327
Vec3f getGuessFromSimplex() const
get the guess from current simplex
Vec3f normal
Definition: gjk.h:352
Triangle stores the points instead of only indices of points.
Definition: geometric_shapes.h:71
FCL_REAL distance
Definition: gjk.h:170