1 |
|
|
/* |
2 |
|
|
* Software License Agreement (BSD License) |
3 |
|
|
* |
4 |
|
|
* Copyright (c) 2011-2014, Willow Garage, Inc. |
5 |
|
|
* Copyright (c) 2014-2015, 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 |
|
|
|
36 |
|
|
/** \author Jia Pan */ |
37 |
|
|
|
38 |
|
|
#ifndef HPP_FCL_KIOS_H |
39 |
|
|
#define HPP_FCL_KIOS_H |
40 |
|
|
|
41 |
|
|
#include <hpp/fcl/BV/OBB.h> |
42 |
|
|
|
43 |
|
|
namespace hpp { |
44 |
|
|
namespace fcl { |
45 |
|
|
|
46 |
|
|
struct CollisionRequest; |
47 |
|
|
|
48 |
|
|
/// @addtogroup Bounding_Volume |
49 |
|
|
/// @{ |
50 |
|
|
|
51 |
|
|
/// @brief A class describing the kIOS collision structure, which is a set of |
52 |
|
|
/// spheres. |
53 |
|
|
class HPP_FCL_DLLAPI kIOS { |
54 |
|
|
/// @brief One sphere in kIOS |
55 |
|
|
struct HPP_FCL_DLLAPI kIOS_Sphere { |
56 |
|
|
Vec3f o; |
57 |
|
|
FCL_REAL r; |
58 |
|
|
|
59 |
|
|
bool operator==(const kIOS_Sphere& other) const { |
60 |
|
|
return o == other.o && r == other.r; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
bool operator!=(const kIOS_Sphere& other) const { |
64 |
|
|
return !(*this == other); |
65 |
|
|
} |
66 |
|
|
}; |
67 |
|
|
|
68 |
|
|
/// @brief generate one sphere enclosing two spheres |
69 |
|
19611 |
static kIOS_Sphere encloseSphere(const kIOS_Sphere& s0, |
70 |
|
|
const kIOS_Sphere& s1) { |
71 |
✓✗✓✗
|
19611 |
Vec3f d = s1.o - s0.o; |
72 |
✓✗ |
19611 |
FCL_REAL dist2 = d.squaredNorm(); |
73 |
|
19611 |
FCL_REAL diff_r = s1.r - s0.r; |
74 |
|
|
|
75 |
|
|
/** The sphere with the larger radius encloses the other */ |
76 |
✓✓ |
19611 |
if (diff_r * diff_r >= dist2) { |
77 |
✓✓ |
2533 |
if (s1.r > s0.r) |
78 |
✓✗ |
1224 |
return s1; |
79 |
|
|
else |
80 |
✓✗ |
1309 |
return s0; |
81 |
|
|
} else /** spheres partially overlapping or disjoint */ |
82 |
|
|
{ |
83 |
|
17078 |
float dist = (float)std::sqrt(dist2); |
84 |
✓✗ |
17078 |
kIOS_Sphere s; |
85 |
|
17078 |
s.r = dist + s0.r + s1.r; |
86 |
✓✗ |
17078 |
if (dist > 0) |
87 |
✓✗✓✗ ✓✗ |
17078 |
s.o = s0.o + d * ((s.r - s0.r) / dist); |
88 |
|
|
else |
89 |
|
|
s.o = s0.o; |
90 |
|
17078 |
return s; |
91 |
|
|
} |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
public: |
95 |
|
|
/// @brief Equality operator |
96 |
|
|
bool operator==(const kIOS& other) const { |
97 |
|
|
bool res = obb == other.obb && num_spheres == other.num_spheres; |
98 |
|
|
if (!res) return false; |
99 |
|
|
|
100 |
|
|
for (size_t k = 0; k < num_spheres; ++k) { |
101 |
|
|
if (spheres[k] != other.spheres[k]) return false; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
return true; |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
/// @brief Difference operator |
108 |
|
|
bool operator!=(const kIOS& other) const { return !(*this == other); } |
109 |
|
|
|
110 |
|
|
/// @brief The (at most) five spheres for intersection |
111 |
|
|
kIOS_Sphere spheres[5]; |
112 |
|
|
|
113 |
|
|
/// @brief The number of spheres, no larger than 5 |
114 |
|
|
unsigned int num_spheres; |
115 |
|
|
|
116 |
|
|
/// @ OBB related with kIOS |
117 |
|
|
OBB obb; |
118 |
|
|
|
119 |
|
|
/// @brief Check whether the kIOS contains a point |
120 |
|
|
bool contain(const Vec3f& p) const; |
121 |
|
|
|
122 |
|
|
/// @brief Check collision between two kIOS |
123 |
|
|
bool overlap(const kIOS& other) const; |
124 |
|
|
|
125 |
|
|
/// @brief Check collision between two kIOS |
126 |
|
|
bool overlap(const kIOS& other, const CollisionRequest&, |
127 |
|
|
FCL_REAL& sqrDistLowerBound) const; |
128 |
|
|
|
129 |
|
|
/// @brief The distance between two kIOS |
130 |
|
|
FCL_REAL distance(const kIOS& other, Vec3f* P = NULL, Vec3f* Q = NULL) const; |
131 |
|
|
|
132 |
|
|
/// @brief A simple way to merge the kIOS and a point |
133 |
|
|
kIOS& operator+=(const Vec3f& p); |
134 |
|
|
|
135 |
|
|
/// @brief Merge the kIOS and another kIOS |
136 |
|
|
kIOS& operator+=(const kIOS& other) { |
137 |
|
|
*this = *this + other; |
138 |
|
|
return *this; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
/// @brief Return the merged kIOS of current kIOS and the other one |
142 |
|
|
kIOS operator+(const kIOS& other) const; |
143 |
|
|
|
144 |
|
|
/// @brief size of the kIOS (used in BV_Splitter to order two kIOSs) |
145 |
|
|
FCL_REAL size() const; |
146 |
|
|
|
147 |
|
|
/// @brief Center of the kIOS |
148 |
|
42248 |
const Vec3f& center() const { return spheres[0].o; } |
149 |
|
|
|
150 |
|
|
/// @brief Width of the kIOS |
151 |
|
|
FCL_REAL width() const; |
152 |
|
|
|
153 |
|
|
/// @brief Height of the kIOS |
154 |
|
|
FCL_REAL height() const; |
155 |
|
|
|
156 |
|
|
/// @brief Depth of the kIOS |
157 |
|
|
FCL_REAL depth() const; |
158 |
|
|
|
159 |
|
|
/// @brief Volume of the kIOS |
160 |
|
|
FCL_REAL volume() const; |
161 |
|
|
}; |
162 |
|
|
|
163 |
|
|
/// @brief Translate the kIOS BV |
164 |
|
|
HPP_FCL_DLLAPI kIOS translate(const kIOS& bv, const Vec3f& t); |
165 |
|
|
|
166 |
|
|
/// @brief Check collision between two kIOSs, b1 is in configuration (R0, T0) |
167 |
|
|
/// and b2 is in identity. |
168 |
|
|
/// @todo Not efficient |
169 |
|
|
HPP_FCL_DLLAPI bool overlap(const Matrix3f& R0, const Vec3f& T0, const kIOS& b1, |
170 |
|
|
const kIOS& b2); |
171 |
|
|
|
172 |
|
|
/// @brief Check collision between two kIOSs, b1 is in configuration (R0, T0) |
173 |
|
|
/// and b2 is in identity. |
174 |
|
|
/// @todo Not efficient |
175 |
|
|
HPP_FCL_DLLAPI bool overlap(const Matrix3f& R0, const Vec3f& T0, const kIOS& b1, |
176 |
|
|
const kIOS& b2, const CollisionRequest& request, |
177 |
|
|
FCL_REAL& sqrDistLowerBound); |
178 |
|
|
|
179 |
|
|
/// @brief Approximate distance between two kIOS bounding volumes |
180 |
|
|
/// @todo P and Q is not returned, need implementation |
181 |
|
|
HPP_FCL_DLLAPI FCL_REAL distance(const Matrix3f& R0, const Vec3f& T0, |
182 |
|
|
const kIOS& b1, const kIOS& b2, |
183 |
|
|
Vec3f* P = NULL, Vec3f* Q = NULL); |
184 |
|
|
|
185 |
|
|
} // namespace fcl |
186 |
|
|
|
187 |
|
|
} // namespace hpp |
188 |
|
|
|
189 |
|
|
#endif |