58 template <
typename BV1,
typename BV2>
60 static void convert(
const BV1& bv1,
const Transform3f&
tf1, BV2& bv2);
61 static void convert(
const BV1& bv1, BV2& bv2);
66 struct Converter<AABB, AABB> {
67 static void convert(
const AABB& bv1,
const Transform3f&
tf1, AABB& bv2) {
68 const Vec3f& center = bv1.center();
69 FCL_REAL r = (bv1.max_ - bv1.min_).norm() * 0.5;
70 const Vec3f center2 = tf1.transform(center);
71 bv2.min_ = center2 - Vec3f::Constant(r);
72 bv2.max_ = center2 + Vec3f::Constant(r);
75 static void convert(
const AABB& bv1, AABB& bv2) { bv2 = bv1; }
79 struct Converter<AABB, OBB> {
80 static void convert(
const AABB& bv1,
const Transform3f& tf1, OBB& bv2) {
81 bv2.To = tf1.transform(bv1.center());
82 bv2.extent.noalias() = (bv1.max_ - bv1.min_) * 0.5;
83 bv2.axes = tf1.getRotation();
86 static void convert(
const AABB& bv1, OBB& bv2) {
87 bv2.To = bv1.center();
88 bv2.extent.noalias() = (bv1.max_ - bv1.min_) * 0.5;
89 bv2.axes.setIdentity();
94 struct Converter<OBB, OBB> {
95 static void convert(
const OBB& bv1,
const Transform3f& tf1, OBB& bv2) {
96 bv2.extent = bv1.extent;
97 bv2.To = tf1.transform(bv1.To);
98 bv2.axes.noalias() = tf1.getRotation() * bv1.axes;
101 static void convert(
const OBB& bv1, OBB& bv2) { bv2 = bv1; }
105 struct Converter<OBBRSS, OBB> {
106 static void convert(
const OBBRSS& bv1,
const Transform3f& tf1, OBB& bv2) {
107 Converter<OBB, OBB>::convert(bv1.obb, tf1, bv2);
110 static void convert(
const OBBRSS& bv1, OBB& bv2) {
111 Converter<OBB, OBB>::convert(bv1.obb, bv2);
116 struct Converter<RSS, OBB> {
117 static void convert(
const RSS& bv1,
const Transform3f& tf1, OBB& bv2) {
118 bv2.extent =
Vec3f(bv1.length[0] * 0.5 + bv1.radius,
119 bv1.length[1] * 0.5 + bv1.radius, bv1.radius);
120 bv2.To = tf1.transform(bv1.Tr);
121 bv2.axes.noalias() = tf1.getRotation() * bv1.axes;
124 static void convert(
const RSS& bv1, OBB& bv2) {
125 bv2.extent =
Vec3f(bv1.length[0] * 0.5 + bv1.radius,
126 bv1.length[1] * 0.5 + bv1.radius, bv1.radius);
132 template <
typename BV1>
133 struct Converter<BV1, AABB> {
134 static void convert(
const BV1& bv1,
const Transform3f& tf1, AABB& bv2) {
135 const Vec3f& center = bv1.center();
136 FCL_REAL r =
Vec3f(bv1.width(), bv1.height(), bv1.depth()).norm() * 0.5;
137 const Vec3f center2 = tf1.transform(center);
138 bv2.min_ = center2 - Vec3f::Constant(r);
139 bv2.max_ = center2 + Vec3f::Constant(r);
142 static void convert(
const BV1& bv1, AABB& bv2) {
143 const Vec3f& center = bv1.center();
144 FCL_REAL r =
Vec3f(bv1.width(), bv1.height(), bv1.depth()).norm() * 0.5;
145 bv2.min_ = center - Vec3f::Constant(r);
146 bv2.max_ = center + Vec3f::Constant(r);
150 template <
typename BV1>
151 struct Converter<BV1, OBB> {
152 static void convert(
const BV1& bv1,
const Transform3f& tf1, OBB& bv2) {
154 Converter<BV1, AABB>::convert(bv1, bv);
155 Converter<AABB, OBB>::convert(bv, tf1, bv2);
158 static void convert(
const BV1& bv1, OBB& bv2) {
160 Converter<BV1, AABB>::convert(bv1, bv);
161 Converter<AABB, OBB>::convert(bv, bv2);
166 struct Converter<OBB, RSS> {
167 static void convert(
const OBB& bv1,
const Transform3f& tf1, RSS& bv2) {
168 bv2.Tr = tf1.transform(bv1.To);
169 bv2.axes.noalias() = tf1.getRotation() * bv1.axes;
171 bv2.radius = bv1.extent[2];
172 bv2.length[0] = 2 * (bv1.extent[0] - bv2.radius);
173 bv2.length[1] = 2 * (bv1.extent[1] - bv2.radius);
176 static void convert(
const OBB& bv1, RSS& bv2) {
180 bv2.radius = bv1.extent[2];
181 bv2.length[0] = 2 * (bv1.extent[0] - bv2.radius);
182 bv2.length[1] = 2 * (bv1.extent[1] - bv2.radius);
187 struct Converter<RSS, RSS> {
188 static void convert(
const RSS& bv1,
const Transform3f& tf1, RSS& bv2) {
189 bv2.Tr = tf1.transform(bv1.Tr);
190 bv2.axes.noalias() = tf1.getRotation() * bv1.axes;
192 bv2.radius = bv1.radius;
193 bv2.length[0] = bv1.length[0];
194 bv2.length[1] = bv1.length[1];
197 static void convert(
const RSS& bv1, RSS& bv2) { bv2 = bv1; }
201 struct Converter<OBBRSS, RSS> {
202 static void convert(
const OBBRSS& bv1,
const Transform3f& tf1, RSS& bv2) {
203 Converter<RSS, RSS>::convert(bv1.rss, tf1, bv2);
206 static void convert(
const OBBRSS& bv1, RSS& bv2) {
207 Converter<RSS, RSS>::convert(bv1.rss, bv2);
212 struct Converter<AABB, RSS> {
213 static void convert(
const AABB& bv1,
const Transform3f& tf1, RSS& bv2) {
214 bv2.Tr = tf1.transform(bv1.center());
217 FCL_REAL d[3] = {bv1.width(), bv1.height(), bv1.depth()};
218 Eigen::DenseIndex
id[3] = {0, 1, 2};
220 for (Eigen::DenseIndex i = 1; i < 3; ++i) {
221 for (Eigen::DenseIndex j = i; j > 0; --j) {
222 if (d[j] > d[j - 1]) {
229 Eigen::DenseIndex tmp =
id[j];
237 const Vec3f extent = (bv1.max_ - bv1.min_) * 0.5;
238 bv2.radius = extent[
id[2]];
239 bv2.length[0] = (extent[
id[0]] - bv2.radius) * 2;
240 bv2.length[1] = (extent[
id[1]] - bv2.radius) * 2;
243 const bool left_hand = (
id[0] == (
id[1] + 1) % 3);
245 bv2.axes.col(0) = -R.col(
id[0]);
247 bv2.axes.col(0) = R.col(
id[0]);
248 bv2.axes.col(1) = R.col(
id[1]);
249 bv2.axes.col(2) = R.col(
id[2]);
252 static void convert(
const AABB& bv1, RSS& bv2) {
253 convert(bv1, Transform3f(), bv2);
258 struct Converter<AABB, OBBRSS> {
259 static void convert(
const AABB& bv1,
const Transform3f& tf1, OBBRSS& bv2) {
260 Converter<AABB, OBB>::convert(bv1, tf1, bv2.obb);
261 Converter<AABB, RSS>::convert(bv1, tf1, bv2.rss);
264 static void convert(
const AABB& bv1, OBBRSS& bv2) {
265 Converter<AABB, OBB>::convert(bv1, bv2.obb);
266 Converter<AABB, RSS>::convert(bv1, bv2.rss);
276 template <
typename BV1,
typename BV2>
278 details::Converter<BV1, BV2>::convert(bv1, tf1, bv2);
283 template <
typename BV1,
typename BV2>
284 static inline void convertBV(
const BV1& bv1, BV2& bv2) {
285 details::Converter<BV1, BV2>::convert(bv1, bv2);
Eigen::Matrix< FCL_REAL, 3, 3 > Matrix3f
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
static void convertBV(const BV1 &bv1, const Transform3f &tf1, BV2 &bv2)
Convert a bounding volume of type BV1 in configuration tf1 to bounding volume of type BV2 in identity...