38 #ifndef COAL_INTERNAL_SHAPE_SHAPE_FUNC_H
39 #define COAL_INTERNAL_SHAPE_SHAPE_FUNC_H
50 template <
typename ShapeType1,
typename ShapeType2>
51 struct ShapeShapeDistancer {
53 const CollisionGeometry* o2,
const Transform3s&
tf2,
54 const GJKSolver* nsolver,
55 const DistanceRequest& request,
56 DistanceResult& result) {
57 if (request.isSatisfied(result))
return result.min_distance;
64 o1,
tf1, o2,
tf2, nsolver, request.enable_signed_distance,
p1, p2,
74 const CollisionGeometry* o2,
const Transform3s&
tf2,
75 const GJKSolver* nsolver,
76 const bool compute_signed_distance,
Vec3s&
p1,
78 const ShapeType1* obj1 =
static_cast<const ShapeType1*
>(o1);
79 const ShapeType2* obj2 =
static_cast<const ShapeType2*
>(o2);
80 return nsolver->shapeDistance(*obj1,
tf1, *obj2,
tf2,
81 compute_signed_distance,
p1, p2, normal);
92 template <
typename ShapeType1,
typename ShapeType2>
93 CoalScalar ShapeShapeDistance(
const CollisionGeometry* o1,
94 const Transform3s&
tf1,
95 const CollisionGeometry* o2,
96 const Transform3s&
tf2,
const GJKSolver* nsolver,
97 const DistanceRequest& request,
98 DistanceResult& result) {
100 o1,
tf1, o2,
tf2, nsolver, request, result);
114 template <
typename ShapeType1,
typename ShapeType2>
115 CoalScalar ShapeShapeDistance(
const CollisionGeometry* o1,
116 const Transform3s&
tf1,
117 const CollisionGeometry* o2,
118 const Transform3s&
tf2,
const GJKSolver* nsolver,
119 const bool compute_signed_distance,
Vec3s&
p1,
122 o1,
tf1, o2,
tf2, nsolver, compute_signed_distance,
p1, p2, normal);
135 template <
typename ShapeType1,
typename ShapeType2>
136 struct ShapeShapeCollider {
137 static std::size_t
run(
const CollisionGeometry* o1,
const Transform3s&
tf1,
138 const CollisionGeometry* o2,
const Transform3s&
tf2,
139 const GJKSolver* nsolver,
140 const CollisionRequest& request,
141 CollisionResult& result) {
142 if (request.isSatisfied(result))
return result.numContacts();
144 const bool compute_penetration =
145 request.enable_contact || (request.security_margin < 0);
148 o1,
tf1, o2,
tf2, nsolver, compute_penetration,
p1, p2, normal);
150 size_t num_contacts = 0;
155 if (distToCollision <= request.collision_distance_threshold &&
156 result.numContacts() < request.num_max_contacts) {
157 if (result.numContacts() < request.num_max_contacts) {
160 result.addContact(contact);
162 num_contacts = result.numContacts();
169 template <
typename ShapeType1,
typename ShapeType2>
170 std::size_t ShapeShapeCollide(
const CollisionGeometry* o1,
171 const Transform3s&
tf1,
172 const CollisionGeometry* o2,
173 const Transform3s&
tf2,
const GJKSolver* nsolver,
174 const CollisionRequest& request,
175 CollisionResult& result) {
177 o1,
tf1, o2,
tf2, nsolver, request, result);
217 #define SHAPE_SHAPE_DISTANCE_SPECIALIZATION(T1, T2) \
219 COAL_DLLAPI CoalScalar internal::ShapeShapeDistance<T1, T2>( \
220 const CollisionGeometry* o1, const Transform3s& tf1, \
221 const CollisionGeometry* o2, const Transform3s& tf2, \
222 const GJKSolver* nsolver, const bool compute_signed_distance, Vec3s& p1, \
223 Vec3s& p2, Vec3s& normal); \
225 COAL_DLLAPI CoalScalar internal::ShapeShapeDistance<T2, T1>( \
226 const CollisionGeometry* o1, const Transform3s& tf1, \
227 const CollisionGeometry* o2, const Transform3s& tf2, \
228 const GJKSolver* nsolver, const bool compute_signed_distance, Vec3s& p1, \
229 Vec3s& p2, Vec3s& normal); \
231 inline COAL_DLLAPI CoalScalar ShapeShapeDistance<T1, T2>( \
232 const CollisionGeometry* o1, const Transform3s& tf1, \
233 const CollisionGeometry* o2, const Transform3s& tf2, \
234 const GJKSolver* nsolver, const DistanceRequest& request, \
235 DistanceResult& result) { \
238 result.b1 = DistanceResult::NONE; \
239 result.b2 = DistanceResult::NONE; \
240 result.min_distance = internal::ShapeShapeDistance<T1, T2>( \
241 o1, tf1, o2, tf2, nsolver, request.enable_signed_distance, \
242 result.nearest_points[0], result.nearest_points[1], result.normal); \
243 return result.min_distance; \
246 inline COAL_DLLAPI CoalScalar ShapeShapeDistance<T2, T1>( \
247 const CollisionGeometry* o1, const Transform3s& tf1, \
248 const CollisionGeometry* o2, const Transform3s& tf2, \
249 const GJKSolver* nsolver, const DistanceRequest& request, \
250 DistanceResult& result) { \
253 result.b1 = DistanceResult::NONE; \
254 result.b2 = DistanceResult::NONE; \
255 result.min_distance = internal::ShapeShapeDistance<T2, T1>( \
256 o1, tf1, o2, tf2, nsolver, request.enable_signed_distance, \
257 result.nearest_points[0], result.nearest_points[1], result.normal); \
258 return result.min_distance; \
261 #define SHAPE_SELF_DISTANCE_SPECIALIZATION(T) \
263 COAL_DLLAPI CoalScalar internal::ShapeShapeDistance<T, T>( \
264 const CollisionGeometry* o1, const Transform3s& tf1, \
265 const CollisionGeometry* o2, const Transform3s& tf2, \
266 const GJKSolver* nsolver, const bool compute_signed_distance, Vec3s& p1, \
267 Vec3s& p2, Vec3s& normal); \
269 inline COAL_DLLAPI CoalScalar ShapeShapeDistance<T, T>( \
270 const CollisionGeometry* o1, const Transform3s& tf1, \
271 const CollisionGeometry* o2, const Transform3s& tf2, \
272 const GJKSolver* nsolver, const DistanceRequest& request, \
273 DistanceResult& result) { \
276 result.b1 = DistanceResult::NONE; \
277 result.b2 = DistanceResult::NONE; \
278 result.min_distance = internal::ShapeShapeDistance<T, T>( \
279 o1, tf1, o2, tf2, nsolver, request.enable_signed_distance, \
280 result.nearest_points[0], result.nearest_points[1], result.normal); \
281 return result.min_distance; \
284 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Box, Halfspace)
285 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Box, Plane)
286 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Box, Sphere)
287 SHAPE_SELF_DISTANCE_SPECIALIZATION(Capsule)
288 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Capsule, Halfspace)
289 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Capsule, Plane)
290 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Cone, Halfspace)
291 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Cone, Plane)
292 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Cylinder, Halfspace)
293 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Cylinder, Plane)
294 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Sphere, Halfspace)
295 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Sphere, Plane)
296 SHAPE_SELF_DISTANCE_SPECIALIZATION(Sphere)
297 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Sphere, Cylinder)
298 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Sphere, Capsule)
299 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Ellipsoid, Halfspace)
300 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Ellipsoid, Plane)
301 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(ConvexBase, Halfspace)
302 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(ConvexBase, Plane)
303 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(TriangleP, Halfspace)
304 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(TriangleP, Plane)
305 SHAPE_SELF_DISTANCE_SPECIALIZATION(TriangleP)
306 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(TriangleP, Sphere)
307 SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Plane, Halfspace)
308 SHAPE_SELF_DISTANCE_SPECIALIZATION(Plane)
309 SHAPE_SELF_DISTANCE_SPECIALIZATION(Halfspace)
311 #undef SHAPE_SHAPE_DISTANCE_SPECIALIZATION
312 #undef SHAPE_SELF_DISTANCE_SPECIALIZATION