hpp-fcl 2.2.0
HPP fork of FCL -- The Flexible Collision Library
Loading...
Searching...
No Matches
narrowphase.h
Go to the documentation of this file.
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2011-2014, Willow Garage, Inc.
5 * Copyright (c) 2014-2015, Open Source Robotics Foundation
6 * Copyright (c) 2018-2019, Centre National de la Recherche Scientifique
7 * All rights reserved.
8 * Copyright (c) 2021-2022, INRIA
9 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
20 * * Neither the name of Open Source Robotics Foundation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
40#ifndef HPP_FCL_NARROWPHASE_H
41#define HPP_FCL_NARROWPHASE_H
42
43#include <limits>
44#include <iostream>
45
48
49namespace hpp {
50namespace fcl {
51
55 typedef Eigen::Array<FCL_REAL, 1, 2> Array2d;
56
58 template <typename S1, typename S2>
60 const S1& s1, const S2& s2, Vec3f& guess,
61 support_func_guess_t& support_hint) const {
62 switch (gjk_initial_guess) {
63 case GJKInitialGuess::DefaultGuess:
64 guess = Vec3f(1, 0, 0);
65 support_hint.setZero();
66 break;
67 case GJKInitialGuess::CachedGuess:
68 guess = cached_guess;
69 support_hint = support_func_cached_guess;
70 break;
71 case GJKInitialGuess::BoundingVolumeGuess:
72 if (s1.aabb_local.volume() < 0 || s2.aabb_local.volume() < 0) {
74 "computeLocalAABB must have been called on the shapes before "
75 "using "
76 "GJKInitialGuess::BoundingVolumeGuess.",
77 std::logic_error);
78 }
79 guess.noalias() = s1.aabb_local.center() -
80 (shape.oR1 * s2.aabb_local.center() + shape.ot1);
81 support_hint.setZero();
82 break;
83 default:
84 HPP_FCL_THROW_PRETTY("Wrong initial guess for GJK.", std::logic_error);
85 }
86 // TODO: use gjk_initial_guess instead
89 if (enable_cached_guess) {
90 guess = cached_guess;
91 support_hint = support_func_cached_guess;
92 }
94
95 gjk.setDistanceEarlyBreak(distance_upper_bound);
96
97 gjk.gjk_variant = gjk_variant;
98 gjk.convergence_criterion = gjk_convergence_criterion;
99 gjk.convergence_criterion_type = gjk_convergence_criterion_type;
100 }
101
103 template <typename S1, typename S2>
104 bool shapeIntersect(const S1& s1, const Transform3f& tf1, const S2& s2,
105 const Transform3f& tf2, FCL_REAL& distance_lower_bound,
106 bool enable_penetration, Vec3f* contact_points,
107 Vec3f* normal) const {
109 shape.set(&s1, &s2, tf1, tf2);
110
111 Vec3f guess;
112 support_func_guess_t support_hint;
113 details::GJK gjk((unsigned int)gjk_max_iterations, gjk_tolerance);
114 initialize_gjk(gjk, shape, s1, s2, guess, support_hint);
115
116 details::GJK::Status gjk_status = gjk.evaluate(shape, guess, support_hint);
119 if (gjk_initial_guess == GJKInitialGuess::CachedGuess ||
120 enable_cached_guess) {
121 cached_guess = gjk.getGuessFromSimplex();
122 support_func_cached_guess = gjk.support_hint;
123 }
125
126 Vec3f w0, w1;
127 switch (gjk_status) {
128 case details::GJK::Inside:
129 if (!enable_penetration && contact_points == NULL && normal == NULL)
130 return true;
131 if (gjk.hasPenetrationInformation(shape)) {
132 gjk.getClosestPoints(shape, w0, w1);
133 distance_lower_bound = gjk.distance;
134 if (normal)
135 (*normal).noalias() = tf1.getRotation() * (w0 - w1).normalized();
136 if (contact_points) *contact_points = tf1.transform((w0 + w1) / 2);
137 return true;
138 } else {
139 details::EPA epa(epa_max_face_num, epa_max_vertex_num,
140 epa_max_iterations, epa_tolerance);
141 details::EPA::Status epa_status = epa.evaluate(gjk, -guess);
142 if (epa_status & details::EPA::Valid ||
143 epa_status == details::EPA::OutOfFaces // Warnings
144 || epa_status == details::EPA::OutOfVertices // Warnings
145 ) {
146 epa.getClosestPoints(shape, w0, w1);
147 distance_lower_bound = -epa.depth;
148 if (normal) (*normal).noalias() = tf1.getRotation() * epa.normal;
149 if (contact_points)
150 *contact_points =
151 tf1.transform(w0 - epa.normal * (epa.depth * 0.5));
152 return true;
153 } else if (epa_status == details::EPA::FallBack) {
154 epa.getClosestPoints(shape, w0, w1);
155 distance_lower_bound = -epa.depth; // Should be zero
156 if (normal) (*normal).noalias() = tf1.getRotation() * epa.normal;
157 if (contact_points) *contact_points = tf1.transform(w0);
158 return true;
159 }
160 distance_lower_bound = -(std::numeric_limits<FCL_REAL>::max)();
161 // EPA failed but we know there is a collision so we should
162 return true;
163 }
164 break;
165 case details::GJK::Valid:
166 distance_lower_bound = gjk.distance;
167 break;
168 default:;
169 }
170
171 return false;
172 }
173
177 template <typename S>
178 bool shapeTriangleInteraction(const S& s, const Transform3f& tf1,
179 const Vec3f& P1, const Vec3f& P2,
180 const Vec3f& P3, const Transform3f& tf2,
181 FCL_REAL& distance, Vec3f& p1, Vec3f& p2,
182 Vec3f& normal) const {
183 bool col;
184 // Express everything in frame 1
185 const Transform3f tf_1M2(tf1.inverseTimes(tf2));
186 TriangleP tri(tf_1M2.transform(P1), tf_1M2.transform(P2),
187 tf_1M2.transform(P3));
188
190 shape.set(&s, &tri);
191
192 Vec3f guess;
193 support_func_guess_t support_hint;
194 details::GJK gjk((unsigned int)gjk_max_iterations, gjk_tolerance);
195 initialize_gjk(gjk, shape, s, tri, guess, support_hint);
196
197 details::GJK::Status gjk_status = gjk.evaluate(shape, guess, support_hint);
198
201 if (gjk_initial_guess == GJKInitialGuess::CachedGuess ||
202 enable_cached_guess) {
203 cached_guess = gjk.getGuessFromSimplex();
204 support_func_cached_guess = gjk.support_hint;
205 }
207
208 Vec3f w0, w1;
209 switch (gjk_status) {
210 case details::GJK::Inside:
211 col = true;
212 if (gjk.hasPenetrationInformation(shape)) {
213 gjk.getClosestPoints(shape, w0, w1);
214 distance = gjk.distance;
215 normal.noalias() = tf1.getRotation() * (w0 - w1).normalized();
216 p1 = p2 = tf1.transform((w0 + w1) / 2);
217 } else {
218 details::EPA epa(epa_max_face_num, epa_max_vertex_num,
219 epa_max_iterations, epa_tolerance);
220 details::EPA::Status epa_status = epa.evaluate(gjk, -guess);
221 if (epa_status & details::EPA::Valid ||
222 epa_status == details::EPA::OutOfFaces // Warnings
223 || epa_status == details::EPA::OutOfVertices // Warnings
224 ) {
225 epa.getClosestPoints(shape, w0, w1);
226 distance = -epa.depth;
227 normal.noalias() = tf1.getRotation() * epa.normal;
228 p1 = p2 = tf1.transform(w0 - epa.normal * (epa.depth * 0.5));
229 assert(distance <= 1e-6);
230 } else {
231 distance = -(std::numeric_limits<FCL_REAL>::max)();
232 gjk.getClosestPoints(shape, w0, w1);
233 p1 = p2 = tf1.transform(w0);
234 }
235 }
236 break;
237 case details::GJK::Valid:
238 case details::GJK::Failed:
239 col = false;
240
241 gjk.getClosestPoints(shape, p1, p2);
242 // TODO On degenerated case, the closest point may be wrong
243 // (i.e. an object face normal is colinear to gjk.ray
244 // assert (distance == (w0 - w1).norm());
245 distance = gjk.distance;
246
247 p1 = tf1.transform(p1);
248 p2 = tf1.transform(p2);
249 assert(distance > 0);
250 break;
251 default:
252 assert(false && "should not reach type part.");
253 return true;
254 }
255 return col;
256 }
257
259 template <typename S1, typename S2>
260 bool shapeDistance(const S1& s1, const Transform3f& tf1, const S2& s2,
261 const Transform3f& tf2, FCL_REAL& distance, Vec3f& p1,
262 Vec3f& p2, Vec3f& normal) const {
263#ifndef NDEBUG
264 FCL_REAL eps(sqrt(std::numeric_limits<FCL_REAL>::epsilon()));
265#endif
267 shape.set(&s1, &s2, tf1, tf2);
268
269 Vec3f guess;
270 support_func_guess_t support_hint;
271 details::GJK gjk((unsigned int)gjk_max_iterations, gjk_tolerance);
272 initialize_gjk(gjk, shape, s1, s2, guess, support_hint);
273
274 details::GJK::Status gjk_status = gjk.evaluate(shape, guess, support_hint);
275 if (gjk_initial_guess == GJKInitialGuess::CachedGuess ||
276 enable_cached_guess) {
277 cached_guess = gjk.getGuessFromSimplex();
278 support_func_cached_guess = gjk.support_hint;
279 }
280
281 if (gjk_status == details::GJK::Failed) {
282 // TODO: understand why GJK fails between cylinder and box
283 assert(distance * distance < sqrt(eps));
284 Vec3f w0, w1;
285 gjk.getClosestPoints(shape, w0, w1);
286 distance = 0;
287 p1 = tf1.transform(w0);
288 p2 = tf1.transform(w1);
289 normal.setZero();
290 return false;
291 } else if (gjk_status == details::GJK::Valid) {
292 gjk.getClosestPoints(shape, p1, p2);
293 // TODO On degenerated case, the closest point may be wrong
294 // (i.e. an object face normal is colinear to gjk.ray
295 // assert (distance == (w0 - w1).norm());
296 distance = gjk.distance;
297
298 normal.noalias() = tf1.getRotation() * gjk.ray;
299 normal.normalize();
300 p1 = tf1.transform(p1);
301 p2 = tf1.transform(p2);
302 return true;
303 } else {
304 assert(gjk_status == details::GJK::Inside);
305 if (gjk.hasPenetrationInformation(shape)) {
306 gjk.getClosestPoints(shape, p1, p2);
307 distance = gjk.distance;
308 // Return contact points in case of collision
309 // p1 = tf1.transform (p1);
310 // p2 = tf1.transform (p2);
311 normal.noalias() = tf1.getRotation() * (p1 - p2);
312 normal.normalize();
313 p1 = tf1.transform(p1);
314 p2 = tf1.transform(p2);
315 } else {
316 details::EPA epa(epa_max_face_num, epa_max_vertex_num,
317 epa_max_iterations, epa_tolerance);
318 details::EPA::Status epa_status = epa.evaluate(gjk, -guess);
319 if (epa_status & details::EPA::Valid ||
320 epa_status == details::EPA::OutOfFaces // Warnings
321 || epa_status == details::EPA::OutOfVertices // Warnings
322 || epa_status == details::EPA::FallBack) {
323 Vec3f w0, w1;
324 epa.getClosestPoints(shape, w0, w1);
325 assert(epa.depth >= -eps);
326 distance = (std::min)(0., -epa.depth);
327 normal.noalias() = tf1.getRotation() * epa.normal;
328 p1 = tf1.transform(w0);
329 p2 = tf1.transform(w1);
330 return false;
331 }
332 distance = -(std::numeric_limits<FCL_REAL>::max)();
333 gjk.getClosestPoints(shape, p1, p2);
334 p1 = tf1.transform(p1);
335 p2 = tf1.transform(p2);
336 }
337 return false;
338 }
339 }
340
345 gjk_max_iterations = 128;
346 gjk_tolerance = 1e-6;
347 epa_max_face_num = 128;
348 epa_max_vertex_num = 64;
349 epa_max_iterations = 255;
350 epa_tolerance = 1e-6;
351 enable_cached_guess = false; // TODO: use gjk_initial_guess instead
352 cached_guess = Vec3f(1, 0, 0);
353 support_func_cached_guess = support_func_guess_t::Zero();
354 distance_upper_bound = (std::numeric_limits<FCL_REAL>::max)();
355 gjk_initial_guess = GJKInitialGuess::DefaultGuess;
356 gjk_variant = GJKVariant::DefaultGJK;
357 gjk_convergence_criterion = GJKConvergenceCriterion::VDB;
358 gjk_convergence_criterion_type = GJKConvergenceCriterionType::Relative;
359 }
360
365 GJKSolver(const DistanceRequest& request) {
366 cached_guess = Vec3f(1, 0, 0);
367 support_func_cached_guess = support_func_guess_t::Zero();
368 distance_upper_bound = (std::numeric_limits<FCL_REAL>::max)();
369
370 // EPS settings
371 epa_max_face_num = 128;
372 epa_max_vertex_num = 64;
373 epa_max_iterations = 255;
374 epa_tolerance = 1e-6;
375
376 set(request);
377 }
378
383 void set(const DistanceRequest& request) {
384 gjk_initial_guess = request.gjk_initial_guess;
385 // TODO: use gjk_initial_guess instead
386 enable_cached_guess = request.enable_cached_gjk_guess;
387 gjk_variant = request.gjk_variant;
388 gjk_convergence_criterion = request.gjk_convergence_criterion;
389 gjk_convergence_criterion_type = request.gjk_convergence_criterion_type;
390 gjk_tolerance = request.gjk_tolerance;
391 gjk_max_iterations = request.gjk_max_iterations;
392 if (gjk_initial_guess == GJKInitialGuess::CachedGuess ||
393 enable_cached_guess) {
394 cached_guess = request.cached_gjk_guess;
395 support_func_cached_guess = request.cached_support_func_guess;
396 }
397 }
398
403 GJKSolver(const CollisionRequest& request) {
404 cached_guess = Vec3f(1, 0, 0);
405 support_func_cached_guess = support_func_guess_t::Zero();
406 distance_upper_bound = (std::numeric_limits<FCL_REAL>::max)();
407
408 // EPS settings
409 epa_max_face_num = 128;
410 epa_max_vertex_num = 64;
411 epa_max_iterations = 255;
412 epa_tolerance = 1e-6;
413
414 set(request);
415 }
416
421 void set(const CollisionRequest& request) {
422 gjk_initial_guess = request.gjk_initial_guess;
423 // TODO: use gjk_initial_guess instead
424 enable_cached_guess = request.enable_cached_gjk_guess;
425 gjk_variant = request.gjk_variant;
426 gjk_convergence_criterion = request.gjk_convergence_criterion;
427 gjk_convergence_criterion_type = request.gjk_convergence_criterion_type;
428 gjk_tolerance = request.gjk_tolerance;
429 gjk_max_iterations = request.gjk_max_iterations;
430 if (gjk_initial_guess == GJKInitialGuess::CachedGuess ||
431 enable_cached_guess) {
432 cached_guess = request.cached_gjk_guess;
433 support_func_cached_guess = request.cached_support_func_guess;
434 }
435
436 // The distance upper bound should be at least greater to the requested
437 // security margin. Otherwise, we will likely miss some collisions.
438 distance_upper_bound = (std::max)(
439 0., (std::max)(request.distance_upper_bound, request.security_margin));
440 }
441
443 GJKSolver(const GJKSolver& other) = default;
444
447 bool operator==(const GJKSolver& other) const {
448 return epa_max_face_num == other.epa_max_face_num &&
449 epa_max_vertex_num == other.epa_max_vertex_num &&
450 epa_max_iterations == other.epa_max_iterations &&
451 epa_tolerance == other.epa_tolerance &&
452 gjk_max_iterations == other.gjk_max_iterations &&
453 enable_cached_guess ==
454 other.enable_cached_guess && // TODO: use gjk_initial_guess
455 // instead
456 cached_guess == other.cached_guess &&
457 support_func_cached_guess == other.support_func_cached_guess &&
458 distance_upper_bound == other.distance_upper_bound &&
459 gjk_initial_guess == other.gjk_initial_guess &&
460 gjk_variant == other.gjk_variant &&
461 gjk_convergence_criterion == other.gjk_convergence_criterion &&
462 gjk_convergence_criterion_type ==
464 }
466
467 bool operator!=(const GJKSolver& other) const { return !(*this == other); }
468
470 unsigned int epa_max_face_num;
471
473 unsigned int epa_max_vertex_num;
474
476 unsigned int epa_max_iterations;
477
480
483
485 mutable size_t gjk_max_iterations;
486
489 HPP_FCL_DEPRECATED_MESSAGE("Use gjk_initial_guess instead")
490 mutable bool enable_cached_guess;
491
493 mutable Vec3f cached_guess;
494
496 mutable GJKInitialGuess gjk_initial_guess;
497
499 mutable GJKVariant gjk_variant;
500
502 mutable GJKConvergenceCriterion gjk_convergence_criterion;
503
505 mutable GJKConvergenceCriterionType gjk_convergence_criterion_type;
506
508 mutable support_func_guess_t support_func_cached_guess;
509
514 mutable FCL_REAL distance_upper_bound;
515
516 public:
517 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
518};
519
520template <>
521HPP_FCL_DLLAPI bool GJKSolver::shapeTriangleInteraction(
522 const Sphere& s, const Transform3f& tf1, const Vec3f& P1, const Vec3f& P2,
523 const Vec3f& P3, const Transform3f& tf2, FCL_REAL& distance, Vec3f& p1,
524 Vec3f& p2, Vec3f& normal) const;
525
526template <>
527HPP_FCL_DLLAPI bool GJKSolver::shapeTriangleInteraction(
528 const Halfspace& s, const Transform3f& tf1, const Vec3f& P1,
529 const Vec3f& P2, const Vec3f& P3, const Transform3f& tf2,
530 FCL_REAL& distance, Vec3f& p1, Vec3f& p2, Vec3f& normal) const;
531
532template <>
533HPP_FCL_DLLAPI bool GJKSolver::shapeTriangleInteraction(
534 const Plane& s, const Transform3f& tf1, const Vec3f& P1, const Vec3f& P2,
535 const Vec3f& P3, const Transform3f& tf2, FCL_REAL& distance, Vec3f& p1,
536 Vec3f& p2, Vec3f& normal) const;
537
538#define SHAPE_INTERSECT_SPECIALIZATION_BASE(S1, S2) \
539 template <> \
540 HPP_FCL_DLLAPI bool GJKSolver::shapeIntersect<S1, S2>( \
541 const S1& s1, const Transform3f& tf1, const S2& s2, \
542 const Transform3f& tf2, FCL_REAL& distance_lower_bound, bool, \
543 Vec3f* contact_points, Vec3f* normal) const
544
545#define SHAPE_INTERSECT_SPECIALIZATION(S1, S2) \
546 SHAPE_INTERSECT_SPECIALIZATION_BASE(S1, S2); \
547 SHAPE_INTERSECT_SPECIALIZATION_BASE(S2, S1)
548
554
560
565
566#undef SHAPE_INTERSECT_SPECIALIZATION
567#undef SHAPE_INTERSECT_SPECIALIZATION_BASE
568
569#define SHAPE_DISTANCE_SPECIALIZATION_BASE(S1, S2) \
570 template <> \
571 HPP_FCL_DLLAPI bool GJKSolver::shapeDistance<S1, S2>( \
572 const S1& s1, const Transform3f& tf1, const S2& s2, \
573 const Transform3f& tf2, FCL_REAL& dist, Vec3f& p1, Vec3f& p2, \
574 Vec3f& normal) const
575
576#define SHAPE_DISTANCE_SPECIALIZATION(S1, S2) \
577 SHAPE_DISTANCE_SPECIALIZATION_BASE(S1, S2); \
578 SHAPE_DISTANCE_SPECIALIZATION_BASE(S2, S1)
579
586
587#undef SHAPE_DISTANCE_SPECIALIZATION
588#undef SHAPE_DISTANCE_SPECIALIZATION_BASE
589
590#if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600))
591#pragma GCC diagnostic push
592#pragma GCC diagnostic ignored "-Wc99-extensions"
593#endif
596
597// param doc is the doxygen detailled description (should be enclosed in /** */
598// and contain no dot for some obscure reasons).
599#define HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape1, Shape2, doc) \
600 \
601 doc template <> \
602 HPP_FCL_DLLAPI bool GJKSolver::shapeIntersect<Shape1, Shape2>( \
603 const Shape1& s1, const Transform3f& tf1, const Shape2& s2, \
604 const Transform3f& tf2, FCL_REAL& distance_lower_bound, \
605 bool enable_penetration, Vec3f* contact_points, Vec3f* normal) const
606#define HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Shape, doc) \
607 HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape, Shape, doc)
608#define HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Shape1, Shape2, doc) \
609 HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape1, Shape2, doc); \
610 HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape2, Shape1, doc)
611
616
617template <>
618HPP_FCL_DLLAPI bool GJKSolver::shapeIntersect<Box, Sphere>(
619 const Box& s1, const Transform3f& tf1, const Sphere& s2,
620 const Transform3f& tf2, FCL_REAL& distance_lower_bound,
621 bool enable_penetration, Vec3f* contact_points, Vec3f* normal) const;
622
623#ifdef IS_DOXYGEN // for doxygen only
627template <>
628HPP_FCL_DLLAPI bool GJKSolver::shapeIntersect<Box, Box>(
629 const Box& s1, const Transform3f& tf1, const Box& s2,
630 const Transform3f& tf2, FCL_REAL& distance_lower_bound,
631 bool enable_penetration, Vec3f* contact_points, Vec3f* normal) const;
632#endif
633// HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Box,);
636
639
642
645
647
650
651#undef HPP_FCL_DECLARE_SHAPE_INTERSECT
652#undef HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF
653#undef HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR
654
656
659
660// param doc is the doxygen detailled description (should be enclosed in /** */
661// and contain no dot for some obscure reasons).
662#define HPP_FCL_DECLARE_SHAPE_TRIANGLE(Shape, doc) \
663 \
664 doc template <> \
665 HPP_FCL_DLLAPI bool GJKSolver::shapeTriangleInteraction<Shape>( \
666 const Shape& s, const Transform3f& tf1, const Vec3f& P1, \
667 const Vec3f& P2, const Vec3f& P3, const Transform3f& tf2, \
668 FCL_REAL& distance, Vec3f& p1, Vec3f& p2, Vec3f& normal) const
669
673
674#undef HPP_FCL_DECLARE_SHAPE_TRIANGLE
675
677
680
681// param doc is the doxygen detailled description (should be enclosed in /** */
682// and contain no dot for some obscure reasons).
683#define HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape1, Shape2, doc) \
684 \
685 doc template <> \
686 bool HPP_FCL_DLLAPI GJKSolver::shapeDistance<Shape1, Shape2>( \
687 const Shape1& s1, const Transform3f& tf1, const Shape2& s2, \
688 const Transform3f& tf2, FCL_REAL& dist, Vec3f& p1, Vec3f& p2, \
689 Vec3f& normal) const
690#define HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF(Shape, doc) \
691 HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape, Shape, doc)
692#define HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR(Shape1, Shape2, doc) \
693 HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape1, Shape2, doc); \
694 HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape2, Shape1, doc)
695
700
702 Capsule,
705
707 TriangleP,
711
712#undef HPP_FCL_DECLARE_SHAPE_DISTANCE
713#undef HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF
714#undef HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR
715
717#if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600))
718#pragma GCC diagnostic pop
719#endif
720} // namespace fcl
721
722} // namespace hpp
723
724#endif
Center at zero point, axis aligned box.
Definition: geometric_shapes.h:125
Capsule It is where is the distance between the point x and the capsule segment AB,...
Definition: geometric_shapes.h:333
Cone The base of the cone is at and the top is at .
Definition: geometric_shapes.h:414
Cylinder along Z axis. The cylinder is defined at its centroid.
Definition: geometric_shapes.h:501
Half Space: this is equivalent to the Plane in ODE. The separation plane is defined as n * x = d; Poi...
Definition: geometric_shapes.h:729
Infinite plane.
Definition: geometric_shapes.h:810
Center at zero point sphere.
Definition: geometric_shapes.h:196
Simple transform class used locally by InterpMotion.
Definition: transform.h:54
Transform3f inverseTimes(const Transform3f &other) const
inverse the transform and multiply with another
Definition: transform.h:170
const Matrix3f & getRotation() const
get rotation
Definition: transform.h:109
Vec3f transform(const Eigen::MatrixBase< Derived > &v) const
transform a given vector by the transform
Definition: transform.h:153
Triangle stores the points instead of only indices of points.
Definition: geometric_shapes.h:71
#define HPP_FCL_DLLAPI
Definition: config.hh:64
#define HPP_FCL_DEPRECATED_MESSAGE(message)
Definition: deprecated.hh:38
#define HPP_FCL_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
Definition: fwd.hh:84
#define HPP_FCL_COMPILER_DIAGNOSTIC_PUSH
Definition: fwd.hh:82
#define HPP_FCL_COMPILER_DIAGNOSTIC_POP
Definition: fwd.hh:83
#define HPP_FCL_THROW_PRETTY(message, exception)
Definition: fwd.hh:57
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.
GJKVariant
Variant to use for the GJK algorithm.
Definition: data_types.h:83
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:66
GJKConvergenceCriterionType
Wether the convergence criterion is scaled on the norm of the solution or not.
Definition: data_types.h:93
GJKConvergenceCriterion
Which convergence criterion is used to stop the algorithm (when the shapes are not in collision)....
Definition: data_types.h:89
GJKInitialGuess
Initial guess to use for the GJK algorithm DefaultGuess: Vec3f(1, 0, 0) CachedGuess: previous vector ...
Definition: data_types.h:80
double FCL_REAL
Definition: data_types.h:65
Eigen::Vector2i support_func_guess_t
Definition: data_types.h:72
Main namespace.
Definition: broadphase_bruteforce.h:44
#define HPP_FCL_DECLARE_SHAPE_TRIANGLE(Shape, doc)
Definition: narrowphase.h:662
#define SHAPE_INTERSECT_SPECIALIZATION(S1, S2)
Definition: narrowphase.h:545
#define HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR(Shape1, Shape2, doc)
Definition: narrowphase.h:692
#define SHAPE_DISTANCE_SPECIALIZATION_BASE(S1, S2)
Definition: narrowphase.h:569
#define HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Shape1, Shape2, doc)
Definition: narrowphase.h:608
#define SHAPE_INTERSECT_SPECIALIZATION_BASE(S1, S2)
Definition: narrowphase.h:538
#define HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Shape, doc)
Definition: narrowphase.h:606
#define HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF(Shape, doc)
Definition: narrowphase.h:690
#define SHAPE_DISTANCE_SPECIALIZATION(S1, S2)
Definition: narrowphase.h:576
request to the collision algorithm
Definition: collision_data.h:235
FCL_REAL distance_upper_bound
Distance above which GJK solver makes an early stopping. GJK stops searching for the closest points w...
Definition: collision_data.h:263
FCL_REAL security_margin
Distance below which objects are considered in collision. See Collision.
Definition: collision_data.h:251
request to the distance computation
Definition: collision_data.h:392
collision and distance solver based on GJK algorithm implemented in fcl (rewritten the code from the ...
Definition: narrowphase.h:54
unsigned int epa_max_face_num
maximum number of simplex face used in EPA algorithm
Definition: narrowphase.h:470
GJKConvergenceCriterion gjk_convergence_criterion
Criterion used to stop GJK.
Definition: narrowphase.h:502
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:104
unsigned int epa_max_vertex_num
maximum number of simplex vertex used in EPA algorithm
Definition: narrowphase.h:473
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:260
void set(const DistanceRequest &request)
setter from a DistanceRequest
Definition: narrowphase.h:383
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:178
GJKVariant gjk_variant
Variant to use for the GJK algorithm.
Definition: narrowphase.h:499
GJKSolver(const GJKSolver &other)=default
Copy constructor.
GJKInitialGuess gjk_initial_guess
which warm start to use for GJK
Definition: narrowphase.h:496
unsigned int epa_max_iterations
maximum number of iterations used for EPA iterations
Definition: narrowphase.h:476
Eigen::Array< FCL_REAL, 1, 2 > Array2d
Definition: narrowphase.h:55
bool operator!=(const GJKSolver &other) const
Definition: narrowphase.h:467
bool operator==(const GJKSolver &other) const
Definition: narrowphase.h:447
FCL_REAL distance_upper_bound
Distance above which the GJK solver stoppes its computations and processes to an early stopping....
Definition: narrowphase.h:514
GJKSolver(const CollisionRequest &request)
Constructor from a CollisionRequest.
Definition: narrowphase.h:403
FCL_REAL gjk_tolerance
the threshold used in GJK to stop iteration
Definition: narrowphase.h:482
Vec3f cached_guess
smart guess
Definition: narrowphase.h:493
GJKConvergenceCriterionType gjk_convergence_criterion_type
Relative or absolute.
Definition: narrowphase.h:505
void initialize_gjk(details::GJK &gjk, const details::MinkowskiDiff &shape, const S1 &s1, const S2 &s2, Vec3f &guess, support_func_guess_t &support_hint) const
initialize GJK
Definition: narrowphase.h:59
bool enable_cached_guess
Whether smart guess can be provided @Deprecated Use gjk_initial_guess instead.
Definition: narrowphase.h:490
GJKSolver(const DistanceRequest &request)
Constructor from a DistanceRequest.
Definition: narrowphase.h:365
FCL_REAL epa_tolerance
the threshold used in EPA to stop iteration
Definition: narrowphase.h:479
GJKSolver()
Default constructor for GJK algorithm.
Definition: narrowphase.h:344
void set(const CollisionRequest &request)
setter from a CollisionRequest
Definition: narrowphase.h:421
size_t gjk_max_iterations
maximum number of iterations used for GJK iterations
Definition: narrowphase.h:485
support_func_guess_t support_func_cached_guess
smart guess for the support function
Definition: narrowphase.h:508
GJKVariant gjk_variant
whether to enable the Nesterov accleration of GJK
Definition: collision_data.h:129
Vec3f cached_gjk_guess
the gjk initial guess set by user
Definition: collision_data.h:144
GJKInitialGuess gjk_initial_guess
Definition: collision_data.h:121
GJKConvergenceCriterion gjk_convergence_criterion
convergence criterion used to stop GJK
Definition: collision_data.h:132
size_t gjk_max_iterations
maximum iteration for the GJK algorithm
Definition: collision_data.h:141
support_func_guess_t cached_support_func_guess
the support function initial guess set by user
Definition: collision_data.h:147
FCL_REAL gjk_tolerance
tolerance for the GJK algorithm
Definition: collision_data.h:138
bool enable_cached_gjk_guess
whether enable gjk initial guess @Deprecated Use gjk_initial_guess instead
Definition: collision_data.h:126
GJKConvergenceCriterionType gjk_convergence_criterion_type
convergence criterion used to stop GJK
Definition: collision_data.h:135
class for EPA algorithm
Definition: gjk.h:312
Vec3f normal
Definition: gjk.h:381
Status
Definition: gjk.h:367
Status evaluate(GJK &gjk, const Vec3f &guess)
FCL_REAL depth
Definition: gjk.h:382
bool getClosestPoints(const MinkowskiDiff &shape, Vec3f &w0, Vec3f &w1)
class for GJK algorithm
Definition: gjk.h:141
void setDistanceEarlyBreak(const FCL_REAL &dup)
Distance threshold for early break. GJK stops when it proved the distance is more than this threshold...
Definition: gjk.h:245
bool hasPenetrationInformation(const MinkowskiDiff &shape)
Definition: gjk.h:230
support_func_guess_t support_hint
Definition: gjk.h:172
Status
Status of the GJK algorithm: Valid: GJK converged and the shapes are not in collision....
Definition: gjk.h:165
bool getClosestPoints(const MinkowskiDiff &shape, Vec3f &w0, Vec3f &w1)
GJKConvergenceCriterion convergence_criterion
Definition: gjk.h:170
GJKConvergenceCriterionType convergence_criterion_type
Definition: gjk.h:171
FCL_REAL distance
Definition: gjk.h:186
Vec3f ray
Definition: gjk.h:168
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.
GJKVariant gjk_variant
Definition: gjk.h:169
Vec3f getGuessFromSimplex() const
get the guess from current simplex
Minkowski difference class of two shapes.
Definition: gjk.h:59
Vec3f ot1
translation from shape1 to shape0 such that .
Definition: gjk.h:79
Matrix3f oR1
rotation from shape1 to shape0 such that .
Definition: gjk.h:75
void set(const ShapeBase *shape0, const ShapeBase *shape1)