38#ifndef COAL_INTERNAL_SHAPE_SHAPE_FUNC_H 39#define COAL_INTERNAL_SHAPE_SHAPE_FUNC_H 50template <
typename ShapeType1,
typename ShapeType2>
51struct ShapeShapeDistancer {
52 static CoalScalar run(
const CollisionGeometry* o1,
const Transform3s& tf1,
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;
63 ShapeShapeDistancer<ShapeType1, ShapeType2>::run(
64 o1, tf1, o2, tf2, nsolver, request.enable_signed_distance, p1, p2,
67 result.update(distance, o1, o2, DistanceResult::NONE, DistanceResult::NONE,
73 static CoalScalar run(
const CollisionGeometry* o1,
const Transform3s& tf1,
74 const CollisionGeometry* o2,
const Transform3s& tf2,
75 const GJKSolver* nsolver,
76 const bool compute_signed_distance, Vec3s& p1,
77 Vec3s& p2, Vec3s& normal) {
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);
92template <
typename ShapeType1,
typename ShapeType2>
99 return ShapeShapeDistancer<ShapeType1, ShapeType2>::run(
100 o1, tf1, o2, tf2, nsolver, request, result);
114template <
typename ShapeType1,
typename ShapeType2>
115CoalScalar 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,
121 return ::coal::ShapeShapeDistancer<ShapeType1, ShapeType2>::run(
122 o1, tf1, o2, tf2, nsolver, compute_signed_distance, p1, p2, normal);
135template <
typename ShapeType1,
typename ShapeType2>
136struct 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);
146 Vec3s p1, p2, normal;
148 o1, tf1, o2, tf2, nsolver, compute_penetration, p1, p2, normal);
150 size_t num_contacts = 0;
153 internal::updateDistanceLowerBoundFromLeaf(request, result, distToCollision,
155 if (distToCollision <= request.collision_distance_threshold &&
156 result.numContacts() < request.num_max_contacts) {
157 if (result.numContacts() < request.num_max_contacts) {
158 Contact contact(o1, o2, Contact::NONE, Contact::NONE, p1, p2, normal,
160 result.addContact(contact);
162 num_contacts = result.numContacts();
169template <
typename ShapeType1,
typename ShapeType2>
176 return ShapeShapeCollider<ShapeType1, ShapeType2>::run(
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; \ 285SHAPE_SHAPE_DISTANCE_SPECIALIZATION(
Box,
Plane)
286SHAPE_SHAPE_DISTANCE_SPECIALIZATION(
Box,
Sphere)
287SHAPE_SELF_DISTANCE_SPECIALIZATION(
Capsule)
291SHAPE_SHAPE_DISTANCE_SPECIALIZATION(
Cone,
Plane)
296SHAPE_SELF_DISTANCE_SPECIALIZATION(
Sphere)
305SHAPE_SELF_DISTANCE_SPECIALIZATION(
TriangleP)
308SHAPE_SELF_DISTANCE_SPECIALIZATION(
Plane)
309SHAPE_SELF_DISTANCE_SPECIALIZATION(
Halfspace)
311#undef SHAPE_SHAPE_DISTANCE_SPECIALIZATION 312#undef SHAPE_SELF_DISTANCE_SPECIALIZATION Center at zero point, axis aligned box.
Definition geometric_shapes.h:166
Capsule It is where is the distance between the point x and the capsule segment AB,...
Definition geometric_shapes.h:383
The geometry for the object for collision or distance computation.
Definition collision_object.h:94
Cone The base of the cone is at and the top is at .
Definition geometric_shapes.h:467
Base for convex polytope.
Definition geometric_shapes.h:645
Cylinder along Z axis. The cylinder is defined at its centroid.
Definition geometric_shapes.h:560
Ellipsoid centered at point zero.
Definition geometric_shapes.h:305
Half Space: this is equivalent to the Plane in ODE. A Half space has a priviledged direction: the dir...
Definition geometric_shapes.h:892
Infinite plane. A plane can be viewed as two half spaces; it has no priviledged direction....
Definition geometric_shapes.h:983
Center at zero point sphere.
Definition geometric_shapes.h:240
Triangle stores the points instead of only indices of points.
Definition geometric_shapes.h:110
CoalScalar distance(const Matrix3s &R0, const Vec3s &T0, const kIOS &b1, const kIOS &b2, Vec3s *P=NULL, Vec3s *Q=NULL)
Approximate distance between two kIOS bounding volumes.
Definition collision_data.h:1174
Main namespace.
Definition broadphase_bruteforce.h:44
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition data_types.h:77
double CoalScalar
Definition data_types.h:76
request to the collision algorithm
Definition collision_data.h:311
collision result
Definition collision_data.h:390
request to the distance computation
Definition collision_data.h:985
distance result
Definition collision_data.h:1051
collision and distance solver based on the GJK and EPA algorithms. Originally, GJK and EPA were imple...
Definition narrowphase.h:57