FCL  0.6.0
Flexible Collision Library
gjk_libccd.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2016, Open Source Robotics Foundation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Open Source Robotics Foundation nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
38 #ifndef FCL_NARROWPHASE_DETAIL_GJKLIBCCD_H
39 #define FCL_NARROWPHASE_DETAIL_GJKLIBCCD_H
40 
41 #include <ccd/ccd.h>
42 #include <ccd/quat.h>
43 #include <ccd/vec3.h>
44 #include "fcl/geometry/shape/box.h"
45 #include "fcl/geometry/shape/capsule.h"
46 #include "fcl/geometry/shape/cone.h"
47 #include "fcl/geometry/shape/convex.h"
48 #include "fcl/geometry/shape/cylinder.h"
49 #include "fcl/geometry/shape/ellipsoid.h"
50 #include "fcl/geometry/shape/halfspace.h"
51 #include "fcl/geometry/shape/plane.h"
52 #include "fcl/geometry/shape/sphere.h"
53 #include "fcl/geometry/shape/triangle_p.h"
54 #include "fcl/narrowphase/detail/convexity_based_algorithm/simplex.h"
55 #include "fcl/narrowphase/detail/convexity_based_algorithm/gjk_libccd.h"
56 
57 namespace fcl
58 {
59 
60 namespace detail
61 {
62 
64 
65 using GJKSupportFunction = void (*)(const void* obj, const ccd_vec3_t* dir_, ccd_vec3_t* v);
66 using GJKCenterFunction = void (*)(const void* obj, ccd_vec3_t* c);
67 
69 template <typename S, typename T>
71 {
72 public:
74  static GJKSupportFunction getSupportFunction() { return nullptr; }
75 
77  static GJKCenterFunction getCenterFunction() { return nullptr; }
78 
82  static void* createGJKObject(const T& /* s */, const Transform3<S>& /*tf*/) { return nullptr; }
83 
85  static void deleteGJKObject(void* o) {}
86 };
87 
89 template <typename S>
91 {
92 public:
93  static GJKSupportFunction getSupportFunction();
94  static GJKCenterFunction getCenterFunction();
95  static void* createGJKObject(const Cylinder<S>& s, const Transform3<S>& tf);
96  static void deleteGJKObject(void* o);
97 };
98 
100 template <typename S>
101 class GJKInitializer<S, Sphere<S>>
102 {
103 public:
104  static GJKSupportFunction getSupportFunction();
105  static GJKCenterFunction getCenterFunction();
106  static void* createGJKObject(const Sphere<S>& s, const Transform3<S>& tf);
107  static void deleteGJKObject(void* o);
108 };
109 
111 template <typename S>
113 {
114 public:
115  static GJKSupportFunction getSupportFunction();
116  static GJKCenterFunction getCenterFunction();
117  static void* createGJKObject(const Ellipsoid<S>& s, const Transform3<S>& tf);
118  static void deleteGJKObject(void* o);
119 };
120 
122 template <typename S>
123 class GJKInitializer<S, Box<S>>
124 {
125 public:
126  static GJKSupportFunction getSupportFunction();
127  static GJKCenterFunction getCenterFunction();
128  static void* createGJKObject(const Box<S>& s, const Transform3<S>& tf);
129  static void deleteGJKObject(void* o);
130 };
131 
133 template <typename S>
135 {
136 public:
137  static GJKSupportFunction getSupportFunction();
138  static GJKCenterFunction getCenterFunction();
139  static void* createGJKObject(const Capsule<S>& s, const Transform3<S>& tf);
140  static void deleteGJKObject(void* o);
141 };
142 
144 template <typename S>
145 class GJKInitializer<S, Cone<S>>
146 {
147 public:
148  static GJKSupportFunction getSupportFunction();
149  static GJKCenterFunction getCenterFunction();
150  static void* createGJKObject(const Cone<S>& s, const Transform3<S>& tf);
151  static void deleteGJKObject(void* o);
152 };
153 
155 template <typename S>
156 class GJKInitializer<S, Convex<S>>
157 {
158 public:
159  static GJKSupportFunction getSupportFunction();
160  static GJKCenterFunction getCenterFunction();
161  static void* createGJKObject(const Convex<S>& s, const Transform3<S>& tf);
162  static void deleteGJKObject(void* o);
163 };
164 
166 GJKSupportFunction triGetSupportFunction();
167 
168 GJKCenterFunction triGetCenterFunction();
169 
170 template <typename S>
171 void* triCreateGJKObject(const Vector3<S>& P1, const Vector3<S>& P2, const Vector3<S>& P3);
172 
173 template <typename S>
174 void* triCreateGJKObject(const Vector3<S>& P1, const Vector3<S>& P2, const Vector3<S>& P3, const Transform3<S>& tf);
175 
176 void triDeleteGJKObject(void* o);
177 
179 template <typename S>
180 bool GJKCollide(
181  void* obj1,
182  ccd_support_fn supp1,
183  ccd_center_fn cen1,
184  void* obj2,
185  ccd_support_fn supp2,
186  ccd_center_fn cen2,
187  unsigned int max_iterations,
188  S tolerance,
189  Vector3<S>* contact_points,
190  S* penetration_depth,
191  Vector3<S>* normal);
192 
193 template <typename S>
194 bool GJKDistance(void* obj1, ccd_support_fn supp1,
195  void* obj2, ccd_support_fn supp2,
196  unsigned int max_iterations, S tolerance,
197  S* dist, Vector3<S>* p1, Vector3<S>* p2);
198 
199 } // namespace detail
200 } // namespace fcl
201 
202 #include "fcl/narrowphase/detail/convexity_based_algorithm/gjk_libccd-inl.h"
203 
204 #endif
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
Center at zero point ellipsoid.
Definition: ellipsoid.h:48
static void * createGJKObject(const T &, const Transform3< S > &)
Get GJK object from a shape Notice that only local transformation is applied. Gloal transformation ar...
Definition: gjk_libccd.h:82
initialize GJK stuffs
Definition: gjk_libccd.h:70
static GJKCenterFunction getCenterFunction()
Get GJK center function.
Definition: gjk_libccd.h:77
Center at zero point capsule.
Definition: capsule.h:48
Center at zero point, axis aligned box.
Definition: box.h:48
static void deleteGJKObject(void *o)
Delete GJK object.
Definition: gjk_libccd.h:85
Convex polytope.
Definition: convex.h:48
Center at zero cylinder.
Definition: cylinder.h:48
Center at zero cone.
Definition: cone.h:48
Center at zero point sphere.
Definition: sphere.h:48
static GJKSupportFunction getSupportFunction()
Get GJK support function.
Definition: gjk_libccd.h:74