narrowphase.h 21.1 KB
Newer Older
1
2
3
/*
 * Software License Agreement (BSD License)
 *
4
5
 *  Copyright (c) 2011-2014, Willow Garage, Inc.
 *  Copyright (c) 2014-2015, Open Source Robotics Foundation
6
 *  Copyright (c) 2018-2019, Centre National de la Recherche Scientifique
7
8
9
10
11
12
13
14
15
16
17
18
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
19
 *   * Neither the name of Open Source Robotics Foundation nor the names of its
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */

37
/** \author Jia Pan, Florent Lamiraux */
38

Joseph Mirabel's avatar
Joseph Mirabel committed
39
40
#ifndef HPP_FCL_NARROWPHASE_H
#define HPP_FCL_NARROWPHASE_H
41

42
#include <hpp/fcl/narrowphase/gjk.h>
43

44
45
namespace hpp
{
46
47
48
namespace fcl
{

49
  /// @brief collision and distance solver based on GJK algorithm implemented in fcl (rewritten the code from the GJK in bullet)
Guilhem Saurel's avatar
Guilhem Saurel committed
50
  struct HPP_FCL_DLLAPI GJKSolver
51
  {
52
53
    /// @brief intersection checking between two shapes
    template<typename S1, typename S2>
54
55
56
57
58
    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
59
60
    {
      Vec3f guess(1, 0, 0);
61
62
63
64
65
66
      support_func_guess_t support_hint;
      if(enable_cached_guess) {
        guess = cached_guess;
        support_hint = support_func_cached_guess;
      } else
        support_hint.setZero();
67
    
68
      details::MinkowskiDiff shape;
69
      shape.set (&s1, &s2, tf1, tf2);
70
  
71
      details::GJK gjk((unsigned int )gjk_max_iterations, gjk_tolerance);
72
      details::GJK::Status gjk_status = gjk.evaluate(shape, guess, support_hint);
73
74
75
76
      if(enable_cached_guess) {
        cached_guess = gjk.getGuessFromSimplex();
        support_func_cached_guess = gjk.support_hint;
      }
77
    
78
79
      Vec3f w0, w1;
      switch(gjk_status) {
80
        case details::GJK::Inside:
81
82
          if (!enable_penetration && contact_points == NULL && normal == NULL)
            return true;
83
84
          if (gjk.hasPenetrationInformation(shape)) {
            gjk.getClosestPoints (shape, w0, w1);
85
            distance_lower_bound = gjk.distance;
86
87
88
89
            if(normal) *normal = tf1.getRotation() * (w0 - w1).normalized();
            if(contact_points) *contact_points = tf1.transform((w0 + w1) / 2);
            return true;
          } else {
90
91
            details::EPA epa(epa_max_face_num, epa_max_vertex_num, epa_max_iterations, epa_tolerance);
            details::EPA::Status epa_status = epa.evaluate(gjk, -guess);
92
93
94
95
            if(epa_status & details::EPA::Valid
                || epa_status == details::EPA::OutOfFaces    // Warnings
                || epa_status == details::EPA::OutOfVertices // Warnings
                )
96
97
            {
              epa.getClosestPoints (shape, w0, w1);
98
              distance_lower_bound = -epa.depth;
99
              if(normal) *normal = tf1.getRotation() * epa.normal;
100
101
102
              if(contact_points) *contact_points = tf1.transform(w0 - epa.normal*(epa.depth *0.5));
              return true;
            }
103
            distance_lower_bound = -(std::numeric_limits<FCL_REAL>::max)();
104
105
            // EPA failed but we know there is a collision so we should
            return true;
106
          }
107
          break;
108
109
110
        case details::GJK::Valid:
          distance_lower_bound = gjk.distance;
          break;
111
112
        default:
          ;
113
      }
114

115
116
      return false;
    }
117

118
    //// @brief intersection checking between one shape and a triangle with transformation
Lucile Remigy's avatar
Lucile Remigy committed
119
    /// @return true if the shape are colliding.
120
121
122
123
124
125
126
    template<typename S>
    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
    {
      bool col;
127
128
129
130
131
132
      // Express everything in frame 1
      const Transform3f tf_1M2 (tf1.inverseTimes(tf2));
      TriangleP tri(
          tf_1M2.transform (P1),
          tf_1M2.transform (P2),
          tf_1M2.transform (P3));
133

134
      Vec3f guess(1, 0, 0);
135
136
137
138
139
140
      support_func_guess_t support_hint;
      if(enable_cached_guess) {
        guess = cached_guess;
        support_hint = support_func_cached_guess;
      } else
        support_hint.setZero();
141

142
      details::MinkowskiDiff shape;
143
      shape.set (&s, &tri);
144
  
145
      details::GJK gjk((unsigned int )gjk_max_iterations, gjk_tolerance);
146
      details::GJK::Status gjk_status = gjk.evaluate(shape, guess, support_hint);
147
148
149
150
      if(enable_cached_guess) {
        cached_guess = gjk.getGuessFromSimplex();
        support_func_cached_guess = gjk.support_hint;
      }
151

152
153
      Vec3f w0, w1;
      switch(gjk_status) {
154
        case details::GJK::Inside:
155
156
157
158
          col = true;
          if (gjk.hasPenetrationInformation(shape)) {
            gjk.getClosestPoints (shape, w0, w1);
            distance = gjk.distance;
159
            normal = tf1.getRotation() * (w0 - w1).normalized();
160
161
            p1 = p2 = tf1.transform((w0 + w1) / 2);
          } else {
162
163
            details::EPA epa(epa_max_face_num, epa_max_vertex_num, epa_max_iterations, epa_tolerance);
            details::EPA::Status epa_status = epa.evaluate(gjk, -guess);
164
165
166
167
168
169
170
            if(epa_status & details::EPA::Valid
                || epa_status == details::EPA::OutOfFaces    // Warnings
                || epa_status == details::EPA::OutOfVertices // Warnings
                )
            {
              epa.getClosestPoints (shape, w0, w1);
              distance = -epa.depth;
171
              normal = tf1.getRotation() * epa.normal;
172
173
174
              p1 = p2 = tf1.transform(w0 - epa.normal*(epa.depth *0.5));
              assert (distance <= 1e-6);
            } else {
175
              distance = -(std::numeric_limits<FCL_REAL>::max)();
176
177
178
              gjk.getClosestPoints (shape, w0, w1);
              p1 = p2 = tf1.transform (w0);
            }
179
          }
180
          break;
181
        case details::GJK::Valid:
182
        case details::GJK::Failed:
183
          col = false;
184

185
186
187
188
189
          gjk.getClosestPoints (shape, p1, p2);
          // TODO On degenerated case, the closest point may be wrong
          // (i.e. an object face normal is colinear to gjk.ray
          // assert (distance == (w0 - w1).norm());
          distance = gjk.distance;
190

191
192
193
          p1 = tf1.transform (p1);
          p2 = tf1.transform (p2);
          assert (distance > 0);
194
195
          break;
        default:
Florent Lamiraux's avatar
Florent Lamiraux committed
196
          assert (false && "should not reach type part.");
197
          return true;
198
199
200
201
202
203
        }
      return col;
    }

    /// @brief distance computation between two shapes
    template<typename S1, typename S2>
204
205
206
207
    bool shapeDistance(const S1& s1, const Transform3f& tf1,
                       const S2& s2, const Transform3f& tf2,
                       FCL_REAL& distance, Vec3f& p1, Vec3f& p2,
                       Vec3f& normal) const
208
    {
209
#ifndef NDEBUG
Florent Lamiraux's avatar
Florent Lamiraux committed
210
      FCL_REAL eps (sqrt(std::numeric_limits<FCL_REAL>::epsilon()));
211
#endif
212
      Vec3f guess(1, 0, 0);
213
214
215
216
217
218
      support_func_guess_t support_hint;
      if(enable_cached_guess) {
        guess = cached_guess;
        support_hint = support_func_cached_guess;
      } else
        support_hint.setZero();
219
220

      details::MinkowskiDiff shape;
221
      shape.set (&s1, &s2, tf1, tf2);
222
223

      details::GJK gjk((unsigned int) gjk_max_iterations, gjk_tolerance);
224
      details::GJK::Status gjk_status = gjk.evaluate(shape, guess, support_hint);
225
226
227
228
      if(enable_cached_guess) {
        cached_guess = gjk.getGuessFromSimplex();
        support_func_cached_guess = gjk.support_hint;
      }
229

Florent Lamiraux's avatar
Florent Lamiraux committed
230
231
232
233
      if(gjk_status == details::GJK::Failed)
      {
        // TODO: understand why GJK fails between cylinder and box
        assert (distance * distance < sqrt (eps));
234
        Vec3f w0, w1;
235
        gjk.getClosestPoints (shape, w0, w1);
Florent Lamiraux's avatar
Florent Lamiraux committed
236
        distance = 0;
237
238
        p1 = tf1.transform (w0);
        p2 = tf1.transform (w1);
Florent Lamiraux's avatar
Florent Lamiraux committed
239
240
241
242
        normal = Vec3f (0,0,0);
        return false;
      }
      else if(gjk_status == details::GJK::Valid)
243
        {
244
          gjk.getClosestPoints (shape, p1, p2);
245
246
247
248
          // TODO On degenerated case, the closest point may be wrong
          // (i.e. an object face normal is colinear to gjk.ray
          // assert (distance == (w0 - w1).norm());
          distance = gjk.distance;
249

250
          normal = (tf1.getRotation() * gjk.ray).normalized();
251
252
          p1 = tf1.transform (p1);
          p2 = tf1.transform (p2);
253
254
          return true;
        }
Florent Lamiraux's avatar
Florent Lamiraux committed
255
      else
256
        {
Florent Lamiraux's avatar
Florent Lamiraux committed
257
          assert (gjk_status == details::GJK::Inside);
258
259
260
          if (gjk.hasPenetrationInformation (shape)) {
            gjk.getClosestPoints (shape, p1, p2);
            distance = gjk.distance;
Joseph Mirabel's avatar
Joseph Mirabel committed
261
262
263
            // Return contact points in case of collision
            //p1 = tf1.transform (p1);
            //p2 = tf1.transform (p2);
264
            normal = (tf1.getRotation() * (p1 - p2)).normalized();
265
266
            p1 = tf1.transform(p1);
            p2 = tf1.transform(p2);
267
268
269
270
          } else {
            details::EPA epa(epa_max_face_num, epa_max_vertex_num,
                             epa_max_iterations, epa_tolerance);
            details::EPA::Status epa_status = epa.evaluate(gjk, -guess);
271
272
273
274
            if(epa_status & details::EPA::Valid
                || epa_status == details::EPA::OutOfFaces    // Warnings
                || epa_status == details::EPA::OutOfVertices // Warnings
                )
275
            {
276
277
278
              Vec3f w0, w1;
              epa.getClosestPoints (shape, w0, w1);
              assert (epa.depth >= -eps);
279
              distance = (std::min) (0., -epa.depth);
280
              normal = tf1.getRotation() * epa.normal;
281
282
              p1 = tf1.transform(w0);
              p2 = tf1.transform(w1);
283
              return false;
284
            }
285
            distance = -(std::numeric_limits<FCL_REAL>::max)();
286
            gjk.getClosestPoints (shape, p1, p2);
287
288
            p1 = tf1.transform(p1);
            p2 = tf1.transform(p2);
289
          }
290
          return false;
291
292
        }
    }
293

294
    /// @brief default setting for GJK algorithm
295
    GJKSolver()
296
    {
297
298
299
300
301
302
303
304
      gjk_max_iterations = 128;
      gjk_tolerance = 1e-6;
      epa_max_face_num = 128;
      epa_max_vertex_num = 64;
      epa_max_iterations = 255;
      epa_tolerance = 1e-6;
      enable_cached_guess = false;
      cached_guess = Vec3f(1, 0, 0);
305
      support_func_cached_guess = support_func_guess_t::Zero();
306
    }
307

308
309
310
    void enableCachedGuess(bool if_enable) const
    {
      enable_cached_guess = if_enable;
311
    }
312
313

    void setCachedGuess(const Vec3f& guess) const
314
    {
315
      cached_guess = guess;
316
    }
317
318

    Vec3f getCachedGuess() const
319
    {
320
      return cached_guess;
321
322
    }

323
324
    /// @brief maximum number of simplex face used in EPA algorithm
    unsigned int epa_max_face_num;
325

326
327
    /// @brief maximum number of simplex vertex used in EPA algorithm
    unsigned int epa_max_vertex_num;
328

329
330
    /// @brief maximum number of iterations used for EPA iterations
    unsigned int epa_max_iterations;
331

332
333
    /// @brief the threshold used in EPA to stop iteration
    FCL_REAL epa_tolerance;
334

335
336
    /// @brief the threshold used in GJK to stop iteration
    FCL_REAL gjk_tolerance;
337

338
339
    /// @brief maximum number of iterations used for GJK iterations
    FCL_REAL gjk_max_iterations;
340

341
342
    /// @brief Whether smart guess can be provided
    mutable bool enable_cached_guess;
343

344
345
    /// @brief smart guess
    mutable Vec3f cached_guess;
346
347
348

    /// @brief smart guess for the support function
    mutable support_func_guess_t support_func_cached_guess;
349
  };
350

351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
  template<>
  HPP_FCL_DLLAPI bool GJKSolver::shapeTriangleInteraction
  (const Sphere& 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;

  template<>
  HPP_FCL_DLLAPI bool GJKSolver::shapeTriangleInteraction
  (const Halfspace& 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;

  template<>
  HPP_FCL_DLLAPI bool GJKSolver::shapeTriangleInteraction
  (const Plane& 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;

#define SHAPE_INTERSECT_SPECIALIZATION_BASE(S1,S2) \
template<> \
HPP_FCL_DLLAPI bool GJKSolver::shapeIntersect<S1, S2> \
 (const S1 &s1, const Transform3f& tf1, \
  const S2 &s2, const Transform3f& tf2, \
  FCL_REAL& distance_lower_bound, \
  bool, \
  Vec3f* contact_points, Vec3f* normal) const

#define SHAPE_INTERSECT_SPECIALIZATION(S1,S2) \
  SHAPE_INTERSECT_SPECIALIZATION_BASE(S1,S2); \
  SHAPE_INTERSECT_SPECIALIZATION_BASE(S2,S1)

  SHAPE_INTERSECT_SPECIALIZATION(Sphere,Capsule);
  SHAPE_INTERSECT_SPECIALIZATION_BASE(Sphere,Sphere);
  SHAPE_INTERSECT_SPECIALIZATION(Sphere,Box);
  SHAPE_INTERSECT_SPECIALIZATION(Sphere,Halfspace);
  SHAPE_INTERSECT_SPECIALIZATION(Sphere,Plane);

  SHAPE_INTERSECT_SPECIALIZATION(Halfspace,Box);
  SHAPE_INTERSECT_SPECIALIZATION(Halfspace,Capsule);
  SHAPE_INTERSECT_SPECIALIZATION(Halfspace,Cylinder);
  SHAPE_INTERSECT_SPECIALIZATION(Halfspace,Cone);
  SHAPE_INTERSECT_SPECIALIZATION(Halfspace,Plane);

  SHAPE_INTERSECT_SPECIALIZATION(Plane,Box);
  SHAPE_INTERSECT_SPECIALIZATION(Plane,Capsule);
  SHAPE_INTERSECT_SPECIALIZATION(Plane,Cylinder);
  SHAPE_INTERSECT_SPECIALIZATION(Plane,Cone);

#undef SHAPE_INTERSECT_SPECIALIZATION
#undef SHAPE_INTERSECT_SPECIALIZATION_BASE

#define SHAPE_DISTANCE_SPECIALIZATION_BASE(S1,S2) \
template<> \
HPP_FCL_DLLAPI bool GJKSolver::shapeDistance<S1, S2> \
 (const S1& s1, const Transform3f& tf1, \
  const S2& s2, const Transform3f& tf2, \
  FCL_REAL& dist, Vec3f& p1, Vec3f& p2, Vec3f& normal) const

#define SHAPE_DISTANCE_SPECIALIZATION(S1,S2) \
  SHAPE_DISTANCE_SPECIALIZATION_BASE(S1,S2); \
  SHAPE_DISTANCE_SPECIALIZATION_BASE(S2,S1)

  SHAPE_DISTANCE_SPECIALIZATION(Sphere,Capsule);
  SHAPE_DISTANCE_SPECIALIZATION(Sphere,Box);
  SHAPE_DISTANCE_SPECIALIZATION(Sphere,Cylinder);
  SHAPE_DISTANCE_SPECIALIZATION_BASE(Sphere,Sphere);
  SHAPE_DISTANCE_SPECIALIZATION_BASE(Capsule,Capsule);
  SHAPE_DISTANCE_SPECIALIZATION_BASE(TriangleP,TriangleP);

#undef SHAPE_DISTANCE_SPECIALIZATION
#undef SHAPE_DISTANCE_SPECIALIZATION_BASE

Joseph Mirabel's avatar
Joseph Mirabel committed
423
#if __cplusplus < 201103L
Justin Carpentier's avatar
Justin Carpentier committed
424
425
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wc99-extensions"
Joseph Mirabel's avatar
Joseph Mirabel committed
426
#endif
427
428
429
430
  /// \name Shape intersection specializations
  /// \{

// param doc is the doxygen detailled description (should be enclosed in /** */
431
// and contain no dot for some obscure reasons).
432
433
434
435
#define HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape1,Shape2,doc)                     \
  /** @brief Fast implementation for Shape1-Shape2 collision. */               \
  doc                                                                          \
  template<>                                                                   \
436
    HPP_FCL_DLLAPI bool GJKSolver::shapeIntersect<Shape1, Shape2>                             \
437
438
    (const Shape1& s1, const Transform3f& tf1,                                 \
     const Shape2& s2, const Transform3f& tf2,                                 \
439
440
     FCL_REAL& distance_lower_bound, bool enable_penetration,                  \
     Vec3f* contact_points, Vec3f* normal) const
441
442
443
444
445
#define HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Shape,doc)                        \
  HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape,Shape,doc)
#define HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Shape1,Shape2,doc)                \
  HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape1,Shape2,doc);                          \
  HPP_FCL_DECLARE_SHAPE_INTERSECT(Shape2,Shape1,doc)
446

447
448
449
450
  HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Sphere,);
  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Sphere, Capsule,);
  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Sphere, Halfspace,);
  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Sphere, Plane,);
451

452
453
454
455
456
457
458
  template<>
  HPP_FCL_DLLAPI bool GJKSolver::shapeIntersect<Box, Sphere>
  (const Box& s1, const Transform3f& tf1,
   const Sphere& s2, const Transform3f& tf2,
   FCL_REAL& distance_lower_bound, bool enable_penetration,
   Vec3f* contact_points, Vec3f* normal) const;

459
460
461
462
#ifdef IS_DOXYGEN // for doxygen only
  /** \todo currently disabled and to re-enable it, API of function
   *  \ref obbDisjointAndLowerBoundDistance should be modified.
   *  */
463
464
  template<>
  HPP_FCL_DLLAPI bool GJKSolver::shapeIntersect<Box, Box>
465
466
467
468
469
470
    (const Box& s1, const Transform3f& tf1,
     const Box& s2, const Transform3f& tf2,
     FCL_REAL& distance_lower_bound, bool enable_penetration,
     Vec3f* contact_points, Vec3f* normal) const;
#endif
  //HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Box,);
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Box, Halfspace,);
  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Box, Plane,);

  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Capsule, Halfspace,);
  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Capsule, Plane,);

  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Cylinder, Halfspace,);
  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Cylinder, Plane,);

  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Cone, Halfspace,);
  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Cone, Plane,);

  HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Halfspace,);

  HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF(Plane,);
  HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR(Plane, Halfspace,);
487

488
489
490
491
492
493
494
495
496
#undef HPP_FCL_DECLARE_SHAPE_INTERSECT
#undef HPP_FCL_DECLARE_SHAPE_INTERSECT_SELF
#undef HPP_FCL_DECLARE_SHAPE_INTERSECT_PAIR

  /// \}

  /// \name Shape triangle interaction specializations
  /// \{

497
498
// param doc is the doxygen detailled description (should be enclosed in /** */
// and contain no dot for some obscure reasons).
499
500
501
#define HPP_FCL_DECLARE_SHAPE_TRIANGLE(Shape,doc)                              \
  /** @brief Fast implementation for Shape-Triangle interaction. */            \
  doc                                                                          \
502
  template<> HPP_FCL_DLLAPI bool GJKSolver::shapeTriangleInteraction<Shape>                   \
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
    (const Shape& 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

  HPP_FCL_DECLARE_SHAPE_TRIANGLE(Sphere,);
  HPP_FCL_DECLARE_SHAPE_TRIANGLE(Halfspace,);
  HPP_FCL_DECLARE_SHAPE_TRIANGLE(Plane,);

#undef HPP_FCL_DECLARE_SHAPE_TRIANGLE

  /// \}

  /// \name Shape distance specializations
  /// \{

// param doc is the doxygen detailled description (should be enclosed in /** */
519
// and contain no dot for some obscure reasons).
520
#define HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape1,Shape2,doc)                      \
521
522
  /** @brief Fast implementation for Shape1-Shape2 distance. */                \
  doc                                                                          \
523
  template<>                                                                   \
524
    bool HPP_FCL_DLLAPI GJKSolver::shapeDistance<Shape1, Shape2>                              \
525
526
527
    (const Shape1& s1, const Transform3f& tf1,                                 \
     const Shape2& s2, const Transform3f& tf2,                                 \
     FCL_REAL& dist, Vec3f& p1, Vec3f& p2, Vec3f& normal) const
528
529
530
531
532
533
534
535
536
537
538
539
#define HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF(Shape,doc)                         \
  HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape,Shape,doc)
#define HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR(Shape1,Shape2,doc)                 \
  HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape1,Shape2,doc);                           \
  HPP_FCL_DECLARE_SHAPE_DISTANCE(Shape2,Shape1,doc)

  HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR(Sphere, Box,);
  HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR(Sphere, Capsule,);
  HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR(Sphere, Cylinder,);
  HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF(Sphere,);

  HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF(Capsule,
540
541
      /** Closest points are based on two line-segments. */
      );
542
543

  HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF(TriangleP,
544
545
      /** Do not run EPA algorithm to compute penetration depth. Use a dedicated method. */
      );
546
547
548
549

#undef HPP_FCL_DECLARE_SHAPE_DISTANCE
#undef HPP_FCL_DECLARE_SHAPE_DISTANCE_SELF
#undef HPP_FCL_DECLARE_SHAPE_DISTANCE_PAIR
550
551

  /// \}
Joseph Mirabel's avatar
Joseph Mirabel committed
552
#if __cplusplus < 201103L
Justin Carpentier's avatar
Justin Carpentier committed
553
#pragma GCC diagnostic pop
Joseph Mirabel's avatar
Joseph Mirabel committed
554
#endif
555
556
}

557
558
} // namespace hpp

559
#endif