1 |
|
|
/* |
2 |
|
|
* Software License Agreement (BSD License) |
3 |
|
|
* |
4 |
|
|
* Copyright (c) 2014, CNRS-LAAS |
5 |
|
|
* All rights reserved. |
6 |
|
|
* |
7 |
|
|
* Redistribution and use in source and binary forms, with or without |
8 |
|
|
* modification, are permitted provided that the following conditions |
9 |
|
|
* are met: |
10 |
|
|
* |
11 |
|
|
* * Redistributions of source code must retain the above copyright |
12 |
|
|
* notice, this list of conditions and the following disclaimer. |
13 |
|
|
* * Redistributions in binary form must reproduce the above |
14 |
|
|
* copyright notice, this list of conditions and the following |
15 |
|
|
* disclaimer in the documentation and/or other materials provided |
16 |
|
|
* with the distribution. |
17 |
|
|
* * Neither the name of Willow Garage, Inc. nor the names of its |
18 |
|
|
* contributors may be used to endorse or promote products derived |
19 |
|
|
* from this software without specific prior written permission. |
20 |
|
|
* |
21 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
22 |
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
23 |
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
24 |
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
25 |
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
26 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
27 |
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
28 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
29 |
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
31 |
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
32 |
|
|
* POSSIBILITY OF SUCH DAMAGE. |
33 |
|
|
*/ |
34 |
|
|
|
35 |
|
|
/** \author Florent Lamiraux */ |
36 |
|
|
|
37 |
|
|
#ifndef HPP_FCL_INTERNAL_SHAPE_SHAPE_FUNC_H |
38 |
|
|
#define HPP_FCL_INTERNAL_SHAPE_SHAPE_FUNC_H |
39 |
|
|
|
40 |
|
|
/// @cond INTERNAL |
41 |
|
|
|
42 |
|
|
#include <hpp/fcl/collision_data.h> |
43 |
|
|
#include <hpp/fcl/collision_utility.h> |
44 |
|
|
#include <hpp/fcl/narrowphase/narrowphase.h> |
45 |
|
|
#include <hpp/fcl/shape/geometric_shapes_traits.h> |
46 |
|
|
|
47 |
|
|
namespace hpp { |
48 |
|
|
namespace fcl { |
49 |
|
|
|
50 |
|
|
template <typename T_SH1, typename T_SH2> |
51 |
|
|
HPP_FCL_DLLAPI FCL_REAL ShapeShapeDistance(const CollisionGeometry* o1, |
52 |
|
|
const Transform3f& tf1, |
53 |
|
|
const CollisionGeometry* o2, |
54 |
|
|
const Transform3f& tf2, |
55 |
|
|
const GJKSolver* nsolver, |
56 |
|
|
const DistanceRequest& request, |
57 |
|
|
DistanceResult& result); |
58 |
|
|
|
59 |
|
|
template <typename T_SH1, typename T_SH2> |
60 |
|
|
struct ShapeShapeCollider { |
61 |
|
2307410 |
static std::size_t run(const CollisionGeometry* o1, const Transform3f& tf1, |
62 |
|
|
const CollisionGeometry* o2, const Transform3f& tf2, |
63 |
|
|
const GJKSolver* nsolver, |
64 |
|
|
const CollisionRequest& request, |
65 |
|
|
CollisionResult& result) { |
66 |
✓✗✗✓
|
2307410 |
if (request.isSatisfied(result)) return result.numContacts(); |
67 |
|
|
|
68 |
✓✗ |
2307410 |
DistanceResult distanceResult; |
69 |
✓✗ |
2307410 |
DistanceRequest distanceRequest(request.enable_contact); |
70 |
✓✗ |
2307410 |
FCL_REAL distance = ShapeShapeDistance<T_SH1, T_SH2>( |
71 |
|
|
o1, tf1, o2, tf2, nsolver, distanceRequest, distanceResult); |
72 |
|
|
|
73 |
|
2307410 |
size_t num_contacts = 0; |
74 |
|
2307410 |
const Vec3f& p1 = distanceResult.nearest_points[0]; |
75 |
|
2307410 |
const Vec3f& p2 = distanceResult.nearest_points[1]; |
76 |
|
2307410 |
FCL_REAL distToCollision = distance - request.security_margin; |
77 |
|
|
|
78 |
✓✗ |
2307410 |
internal::updateDistanceLowerBoundFromLeaf(request, result, distToCollision, |
79 |
|
|
p1, p2); |
80 |
✓✓✓✓
|
2314680 |
if (distToCollision <= request.collision_distance_threshold && |
81 |
✓✗ |
7270 |
result.numContacts() < request.num_max_contacts) { |
82 |
✓✗ |
7270 |
if (result.numContacts() < request.num_max_contacts) { |
83 |
|
7270 |
const Vec3f& p1 = distanceResult.nearest_points[0]; |
84 |
|
7270 |
const Vec3f& p2 = distanceResult.nearest_points[1]; |
85 |
|
|
|
86 |
✓✓✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
14540 |
Contact contact( |
87 |
✓✗ |
7270 |
o1, o2, distanceResult.b1, distanceResult.b2, (p1 + p2) / 2, |
88 |
|
|
(distance <= 0 ? distanceResult.normal : (p2 - p1).normalized()), |
89 |
|
|
-distance); |
90 |
|
|
|
91 |
✓✗ |
7270 |
result.addContact(contact); |
92 |
|
|
} |
93 |
|
7270 |
num_contacts = result.numContacts(); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
2307410 |
return num_contacts; |
97 |
|
|
} |
98 |
|
|
}; |
99 |
|
|
|
100 |
|
|
template <typename ShapeType1, typename ShapeType2> |
101 |
|
1225032 |
std::size_t ShapeShapeCollide(const CollisionGeometry* o1, |
102 |
|
|
const Transform3f& tf1, |
103 |
|
|
const CollisionGeometry* o2, |
104 |
|
|
const Transform3f& tf2, const GJKSolver* nsolver, |
105 |
|
|
const CollisionRequest& request, |
106 |
|
|
CollisionResult& result) { |
107 |
|
1225032 |
return ShapeShapeCollider<ShapeType1, ShapeType2>::run( |
108 |
|
1225032 |
o1, tf1, o2, tf2, nsolver, request, result); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
#define SHAPE_SHAPE_DISTANCE_SPECIALIZATION(T1, T2) \ |
112 |
|
|
template <> \ |
113 |
|
|
HPP_FCL_DLLAPI FCL_REAL ShapeShapeDistance<T1, T2>( \ |
114 |
|
|
const CollisionGeometry* o1, const Transform3f& tf1, \ |
115 |
|
|
const CollisionGeometry* o2, const Transform3f& tf2, \ |
116 |
|
|
const GJKSolver* nsolver, const DistanceRequest& request, \ |
117 |
|
|
DistanceResult& result); \ |
118 |
|
|
template <> \ |
119 |
|
|
HPP_FCL_DLLAPI FCL_REAL ShapeShapeDistance<T2, T1>( \ |
120 |
|
|
const CollisionGeometry* o1, const Transform3f& tf1, \ |
121 |
|
|
const CollisionGeometry* o2, const Transform3f& tf2, \ |
122 |
|
|
const GJKSolver* nsolver, const DistanceRequest& request, \ |
123 |
|
|
DistanceResult& result) |
124 |
|
|
|
125 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Box, Halfspace); |
126 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Box, Plane); |
127 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Box, Sphere); |
128 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Capsule, Capsule); |
129 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Capsule, Halfspace); |
130 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Capsule, Plane); |
131 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Cone, Halfspace); |
132 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Cone, Plane); |
133 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Cylinder, Halfspace); |
134 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Cylinder, Plane); |
135 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Sphere, Halfspace); |
136 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Sphere, Plane); |
137 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Sphere, Sphere); |
138 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(Sphere, Cylinder); |
139 |
|
|
|
140 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(ConvexBase, Halfspace); |
141 |
|
|
SHAPE_SHAPE_DISTANCE_SPECIALIZATION(TriangleP, Halfspace); |
142 |
|
|
|
143 |
|
|
#undef SHAPE_SHAPE_DISTANCE_SPECIALIZATION |
144 |
|
|
|
145 |
|
|
#define SHAPE_SHAPE_COLLIDE_SPECIALIZATION(T1, T2) \ |
146 |
|
|
template <> \ |
147 |
|
|
struct ShapeShapeCollider<T1, T2> { \ |
148 |
|
|
static HPP_FCL_DLLAPI std::size_t run(const CollisionGeometry* o1, \ |
149 |
|
|
const Transform3f& tf1, \ |
150 |
|
|
const CollisionGeometry* o2, \ |
151 |
|
|
const Transform3f& tf2, \ |
152 |
|
|
const GJKSolver* nsolver, \ |
153 |
|
|
const CollisionRequest& request, \ |
154 |
|
|
CollisionResult& result); \ |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
SHAPE_SHAPE_COLLIDE_SPECIALIZATION(Sphere, Sphere); |
158 |
|
|
|
159 |
|
|
#undef SHAPE_SHAPE_COLLIDE_SPECIALIZATION |
160 |
|
|
} // namespace fcl |
161 |
|
|
|
162 |
|
|
} // namespace hpp |
163 |
|
|
|
164 |
|
|
/// @endcond |
165 |
|
|
|
166 |
|
|
#endif |