coal/BV/BV.h
Go to the documentation of this file.
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 
38 #ifndef COAL_BV_H
39 #define COAL_BV_H
40 
41 #include "coal/BV/kDOP.h"
42 #include "coal/BV/AABB.h"
43 #include "coal/BV/OBB.h"
44 #include "coal/BV/RSS.h"
45 #include "coal/BV/OBBRSS.h"
46 #include "coal/BV/kIOS.h"
47 #include "coal/math/transform.h"
48 
50 namespace coal {
51 
53 namespace details {
54 
57 template <typename BV1, typename BV2>
58 struct Converter {
59  static void convert(const BV1& bv1, const Transform3s& tf1, BV2& bv2);
60  static void convert(const BV1& bv1, BV2& bv2);
61 };
62 
64 template <>
65 struct Converter<AABB, AABB> {
66  static void convert(const AABB& bv1, const Transform3s& tf1, AABB& bv2) {
67  const Vec3s& center = bv1.center();
68  CoalScalar r = (bv1.max_ - bv1.min_).norm() * 0.5;
69  const Vec3s center2 = tf1.transform(center);
70  bv2.min_ = center2 - Vec3s::Constant(r);
71  bv2.max_ = center2 + Vec3s::Constant(r);
72  }
73 
74  static void convert(const AABB& bv1, AABB& bv2) { bv2 = bv1; }
75 };
76 
77 template <>
78 struct Converter<AABB, OBB> {
79  static void convert(const AABB& bv1, const Transform3s& tf1, OBB& bv2) {
80  bv2.To = tf1.transform(bv1.center());
81  bv2.extent.noalias() = (bv1.max_ - bv1.min_) * 0.5;
82  bv2.axes = tf1.getRotation();
83  }
84 
85  static void convert(const AABB& bv1, OBB& bv2) {
86  bv2.To = bv1.center();
87  bv2.extent.noalias() = (bv1.max_ - bv1.min_) * 0.5;
88  bv2.axes.setIdentity();
89  }
90 };
91 
92 template <>
93 struct Converter<OBB, OBB> {
94  static void convert(const OBB& bv1, const Transform3s& tf1, OBB& bv2) {
95  bv2.extent = bv1.extent;
96  bv2.To = tf1.transform(bv1.To);
97  bv2.axes.noalias() = tf1.getRotation() * bv1.axes;
98  }
99 
100  static void convert(const OBB& bv1, OBB& bv2) { bv2 = bv1; }
101 };
102 
103 template <>
104 struct Converter<OBBRSS, OBB> {
105  static void convert(const OBBRSS& bv1, const Transform3s& tf1, OBB& bv2) {
106  Converter<OBB, OBB>::convert(bv1.obb, tf1, bv2);
107  }
108 
109  static void convert(const OBBRSS& bv1, OBB& bv2) {
110  Converter<OBB, OBB>::convert(bv1.obb, bv2);
111  }
112 };
113 
114 template <>
115 struct Converter<RSS, OBB> {
116  static void convert(const RSS& bv1, const Transform3s& tf1, OBB& bv2) {
117  bv2.extent = Vec3s(bv1.length[0] * 0.5 + bv1.radius,
118  bv1.length[1] * 0.5 + bv1.radius, bv1.radius);
119  bv2.To = tf1.transform(bv1.Tr);
120  bv2.axes.noalias() = tf1.getRotation() * bv1.axes;
121  }
122 
123  static void convert(const RSS& bv1, OBB& bv2) {
124  bv2.extent = Vec3s(bv1.length[0] * 0.5 + bv1.radius,
125  bv1.length[1] * 0.5 + bv1.radius, bv1.radius);
126  bv2.To = bv1.Tr;
127  bv2.axes = bv1.axes;
128  }
129 };
130 
131 template <typename BV1>
132 struct Converter<BV1, AABB> {
133  static void convert(const BV1& bv1, const Transform3s& tf1, AABB& bv2) {
134  const Vec3s& center = bv1.center();
135  CoalScalar r = Vec3s(bv1.width(), bv1.height(), bv1.depth()).norm() * 0.5;
136  const Vec3s center2 = tf1.transform(center);
137  bv2.min_ = center2 - Vec3s::Constant(r);
138  bv2.max_ = center2 + Vec3s::Constant(r);
139  }
140 
141  static void convert(const BV1& bv1, AABB& bv2) {
142  const Vec3s& center = bv1.center();
143  CoalScalar r = Vec3s(bv1.width(), bv1.height(), bv1.depth()).norm() * 0.5;
144  bv2.min_ = center - Vec3s::Constant(r);
145  bv2.max_ = center + Vec3s::Constant(r);
146  }
147 };
148 
149 template <typename BV1>
150 struct Converter<BV1, OBB> {
151  static void convert(const BV1& bv1, const Transform3s& tf1, OBB& bv2) {
152  AABB bv;
153  Converter<BV1, AABB>::convert(bv1, bv);
154  Converter<AABB, OBB>::convert(bv, tf1, bv2);
155  }
156 
157  static void convert(const BV1& bv1, OBB& bv2) {
158  AABB bv;
159  Converter<BV1, AABB>::convert(bv1, bv);
160  Converter<AABB, OBB>::convert(bv, bv2);
161  }
162 };
163 
164 template <>
165 struct Converter<OBB, RSS> {
166  static void convert(const OBB& bv1, const Transform3s& tf1, RSS& bv2) {
167  bv2.Tr = tf1.transform(bv1.To);
168  bv2.axes.noalias() = tf1.getRotation() * bv1.axes;
169 
170  bv2.radius = bv1.extent[2];
171  bv2.length[0] = 2 * (bv1.extent[0] - bv2.radius);
172  bv2.length[1] = 2 * (bv1.extent[1] - bv2.radius);
173  }
174 
175  static void convert(const OBB& bv1, RSS& bv2) {
176  bv2.Tr = bv1.To;
177  bv2.axes = bv1.axes;
178 
179  bv2.radius = bv1.extent[2];
180  bv2.length[0] = 2 * (bv1.extent[0] - bv2.radius);
181  bv2.length[1] = 2 * (bv1.extent[1] - bv2.radius);
182  }
183 };
184 
185 template <>
186 struct Converter<RSS, RSS> {
187  static void convert(const RSS& bv1, const Transform3s& tf1, RSS& bv2) {
188  bv2.Tr = tf1.transform(bv1.Tr);
189  bv2.axes.noalias() = tf1.getRotation() * bv1.axes;
190 
191  bv2.radius = bv1.radius;
192  bv2.length[0] = bv1.length[0];
193  bv2.length[1] = bv1.length[1];
194  }
195 
196  static void convert(const RSS& bv1, RSS& bv2) { bv2 = bv1; }
197 };
198 
199 template <>
200 struct Converter<OBBRSS, RSS> {
201  static void convert(const OBBRSS& bv1, const Transform3s& tf1, RSS& bv2) {
202  Converter<RSS, RSS>::convert(bv1.rss, tf1, bv2);
203  }
204 
205  static void convert(const OBBRSS& bv1, RSS& bv2) {
206  Converter<RSS, RSS>::convert(bv1.rss, bv2);
207  }
208 };
209 
210 template <>
211 struct Converter<AABB, RSS> {
212  static void convert(const AABB& bv1, const Transform3s& tf1, RSS& bv2) {
213  bv2.Tr = tf1.transform(bv1.center());
214 
216  CoalScalar d[3] = {bv1.width(), bv1.height(), bv1.depth()};
217  Eigen::DenseIndex id[3] = {0, 1, 2};
218 
219  for (Eigen::DenseIndex i = 1; i < 3; ++i) {
220  for (Eigen::DenseIndex j = i; j > 0; --j) {
221  if (d[j] > d[j - 1]) {
222  {
223  CoalScalar tmp = d[j];
224  d[j] = d[j - 1];
225  d[j - 1] = tmp;
226  }
227  {
228  Eigen::DenseIndex tmp = id[j];
229  id[j] = id[j - 1];
230  id[j - 1] = tmp;
231  }
232  }
233  }
234  }
235 
236  const Vec3s extent = (bv1.max_ - bv1.min_) * 0.5;
237  bv2.radius = extent[id[2]];
238  bv2.length[0] = (extent[id[0]] - bv2.radius) * 2;
239  bv2.length[1] = (extent[id[1]] - bv2.radius) * 2;
240 
241  const Matrix3s& R = tf1.getRotation();
242  const bool left_hand = (id[0] == (id[1] + 1) % 3);
243  if (left_hand)
244  bv2.axes.col(0) = -R.col(id[0]);
245  else
246  bv2.axes.col(0) = R.col(id[0]);
247  bv2.axes.col(1) = R.col(id[1]);
248  bv2.axes.col(2) = R.col(id[2]);
249  }
250 
251  static void convert(const AABB& bv1, RSS& bv2) {
252  convert(bv1, Transform3s(), bv2);
253  }
254 };
255 
256 template <>
257 struct Converter<AABB, OBBRSS> {
258  static void convert(const AABB& bv1, const Transform3s& tf1, OBBRSS& bv2) {
259  Converter<AABB, OBB>::convert(bv1, tf1, bv2.obb);
260  Converter<AABB, RSS>::convert(bv1, tf1, bv2.rss);
261  }
262 
263  static void convert(const AABB& bv1, OBBRSS& bv2) {
264  Converter<AABB, OBB>::convert(bv1, bv2.obb);
265  Converter<AABB, RSS>::convert(bv1, bv2.rss);
266  }
267 };
268 
269 } // namespace details
270 
272 
275 template <typename BV1, typename BV2>
276 static inline void convertBV(const BV1& bv1, const Transform3s& tf1, BV2& bv2) {
277  details::Converter<BV1, BV2>::convert(bv1, tf1, bv2);
278 }
279 
282 template <typename BV1, typename BV2>
283 static inline void convertBV(const BV1& bv1, BV2& bv2) {
284  details::Converter<BV1, BV2>::convert(bv1, bv2);
285 }
286 
287 } // namespace coal
288 
289 #endif
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
gjk.tf1
tuple tf1
Definition: test/scripts/gjk.py:27
OBB.h
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
octree.r
r
Definition: octree.py:9
R
R
RSS.h
coal::Transform3s
Simple transform class used locally by InterpMotion.
Definition: coal/math/transform.h:55
kDOP.h
transform.h
d
d
kIOS.h
coal::Matrix3s
Eigen::Matrix< CoalScalar, 3, 3 > Matrix3s
Definition: coal/data_types.h:81
OBBRSS.h
coal::convertBV
static void convertBV(const BV1 &bv1, const Transform3s &tf1, BV2 &bv2)
Convert a bounding volume of type BV1 in configuration tf1 to bounding volume of type BV2 in identity...
Definition: coal/BV/BV.h:276
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
AABB.h


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:57