coal  3.0.1
Coal, The Collision Detection Library. Previously known as HPP-FCL, fork of FCL -- The Flexible Collision Library
geometric_shapes_utility.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_GEOMETRIC_SHAPES_UTILITY_H
39 #define COAL_GEOMETRIC_SHAPES_UTILITY_H
40 
41 #include <vector>
43 #include "coal/BV/BV.h"
45 
46 namespace coal {
47 
49 namespace details {
52 COAL_DLLAPI std::vector<Vec3s> getBoundVertices(const Box& box,
53  const Transform3s& tf);
54 COAL_DLLAPI std::vector<Vec3s> getBoundVertices(const Sphere& sphere,
55  const Transform3s& tf);
56 COAL_DLLAPI std::vector<Vec3s> getBoundVertices(const Ellipsoid& ellipsoid,
57  const Transform3s& tf);
58 COAL_DLLAPI std::vector<Vec3s> getBoundVertices(const Capsule& capsule,
59  const Transform3s& tf);
60 COAL_DLLAPI std::vector<Vec3s> getBoundVertices(const Cone& cone,
61  const Transform3s& tf);
62 COAL_DLLAPI std::vector<Vec3s> getBoundVertices(const Cylinder& cylinder,
63  const Transform3s& tf);
64 COAL_DLLAPI std::vector<Vec3s> getBoundVertices(const TriangleP& triangle,
65  const Transform3s& tf);
66 template <typename IndexType>
67 std::vector<Vec3s> getBoundVertices(const ConvexBaseTpl<IndexType>& convex,
68  const Transform3s& tf) {
69  std::vector<Vec3s> result(convex.num_points);
70  const std::vector<Vec3s>& points_ = *(convex.points);
71  for (std::size_t i = 0; i < convex.num_points; ++i) {
72  result[i] = tf.transform(points_[i]);
73  }
74 
75  return result;
76 }
77 } // namespace details
79 
81 template <typename BV, typename S>
82 inline void computeBV(const S& s, const Transform3s& tf, BV& bv) {
83  if (s.getSweptSphereRadius() > 0) {
84  COAL_THROW_PRETTY("Swept-sphere radius not yet supported.",
85  std::runtime_error);
86  }
87  std::vector<Vec3s> convex_bound_vertices = details::getBoundVertices(s, tf);
88  fit(&convex_bound_vertices[0], (unsigned int)convex_bound_vertices.size(),
89  bv);
90 }
91 
92 template <>
94  AABB& bv);
95 
96 template <>
98  AABB& bv);
99 
100 template <>
102  const Transform3s& tf, AABB& bv);
103 
104 template <>
106  const Transform3s& tf, AABB& bv);
107 
108 template <>
110  AABB& bv);
111 
112 template <>
114  const Transform3s& tf, AABB& bv);
115 template <>
117  const Transform3s& tf, AABB& bv);
118 
119 template <>
121  const Transform3s& tf, AABB& bv);
122 
123 template <>
125  const Transform3s& tf, AABB& bv);
126 
127 template <>
129  const Transform3s& tf, AABB& bv);
130 
131 template <>
133  AABB& bv);
134 
135 template <>
137  OBB& bv);
138 
139 template <>
141  OBB& bv);
142 
143 template <>
145  const Transform3s& tf, OBB& bv);
146 
147 template <>
149  OBB& bv);
150 
151 template <>
153  const Transform3s& tf, OBB& bv);
154 
155 template <>
157  const Transform3s& tf, OBB& bv);
158 
159 template <>
161  const Transform3s& tf, OBB& bv);
162 
163 template <>
165  const Transform3s& tf, OBB& bv);
166 
167 template <>
169  const Transform3s& tf, RSS& bv);
170 
171 template <>
173  const Transform3s& tf,
174  OBBRSS& bv);
175 
176 template <>
178  const Transform3s& tf, kIOS& bv);
179 
180 template <>
181 COAL_DLLAPI void computeBV<KDOP<16>, Halfspace>(const Halfspace& s,
182  const Transform3s& tf,
183  KDOP<16>& bv);
184 
185 template <>
186 COAL_DLLAPI void computeBV<KDOP<18>, Halfspace>(const Halfspace& s,
187  const Transform3s& tf,
188  KDOP<18>& bv);
189 
190 template <>
191 COAL_DLLAPI void computeBV<KDOP<24>, Halfspace>(const Halfspace& s,
192  const Transform3s& tf,
193  KDOP<24>& bv);
194 
195 template <>
197  OBB& bv);
198 
199 template <>
201  RSS& bv);
202 
203 template <>
205  OBBRSS& bv);
206 
207 template <>
209  kIOS& bv);
210 
211 template <>
212 COAL_DLLAPI void computeBV<KDOP<16>, Plane>(const Plane& s,
213  const Transform3s& tf,
214  KDOP<16>& bv);
215 
216 template <>
217 COAL_DLLAPI void computeBV<KDOP<18>, Plane>(const Plane& s,
218  const Transform3s& tf,
219  KDOP<18>& bv);
220 
221 template <>
222 COAL_DLLAPI void computeBV<KDOP<24>, Plane>(const Plane& s,
223  const Transform3s& tf,
224  KDOP<24>& bv);
225 
228 COAL_DLLAPI void constructBox(const AABB& bv, Box& box, Transform3s& tf);
229 
230 COAL_DLLAPI void constructBox(const OBB& bv, Box& box, Transform3s& tf);
231 
232 COAL_DLLAPI void constructBox(const OBBRSS& bv, Box& box, Transform3s& tf);
233 
234 COAL_DLLAPI void constructBox(const kIOS& bv, Box& box, Transform3s& tf);
235 
236 COAL_DLLAPI void constructBox(const RSS& bv, Box& box, Transform3s& tf);
237 
238 COAL_DLLAPI void constructBox(const KDOP<16>& bv, Box& box, Transform3s& tf);
239 
240 COAL_DLLAPI void constructBox(const KDOP<18>& bv, Box& box, Transform3s& tf);
241 
242 COAL_DLLAPI void constructBox(const KDOP<24>& bv, Box& box, Transform3s& tf);
243 
244 COAL_DLLAPI void constructBox(const AABB& bv, const Transform3s& tf_bv,
245  Box& box, Transform3s& tf);
246 
247 COAL_DLLAPI void constructBox(const OBB& bv, const Transform3s& tf_bv, Box& box,
248  Transform3s& tf);
249 
250 COAL_DLLAPI void constructBox(const OBBRSS& bv, const Transform3s& tf_bv,
251  Box& box, Transform3s& tf);
252 
253 COAL_DLLAPI void constructBox(const kIOS& bv, const Transform3s& tf_bv,
254  Box& box, Transform3s& tf);
255 
256 COAL_DLLAPI void constructBox(const RSS& bv, const Transform3s& tf_bv, Box& box,
257  Transform3s& tf);
258 
259 COAL_DLLAPI void constructBox(const KDOP<16>& bv, const Transform3s& tf_bv,
260  Box& box, Transform3s& tf);
261 
262 COAL_DLLAPI void constructBox(const KDOP<18>& bv, const Transform3s& tf_bv,
263  Box& box, Transform3s& tf);
264 
265 COAL_DLLAPI void constructBox(const KDOP<24>& bv, const Transform3s& tf_bv,
266  Box& box, Transform3s& tf);
267 
269 
271 
272 COAL_DLLAPI std::array<Halfspace, 2> transformToHalfspaces(
273  const Plane& a, const Transform3s& tf);
274 
275 } // namespace coal
276 
277 #endif
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition: AABB.h:55
Center at zero point, axis aligned box.
Definition: geometric_shapes.h:164
Capsule It is where is the distance between the point x and the capsule segment AB,...
Definition: geometric_shapes.h:381
Cone The base of the cone is at and the top is at .
Definition: geometric_shapes.h:466
Base for convex polytope.
Definition: geometric_shapes.h:691
Cylinder along Z axis. The cylinder is defined at its centroid.
Definition: geometric_shapes.h:556
Ellipsoid centered at point zero.
Definition: geometric_shapes.h:303
Half Space: this is equivalent to the Plane in ODE. A Half space has a priviledged direction: the dir...
Definition: geometric_shapes.h:963
KDOP class describes the KDOP collision structures. K is set as the template parameter,...
Definition: kDOP.h:91
Infinite plane. A plane can be viewed as two half spaces; it has no priviledged direction....
Definition: geometric_shapes.h:1054
Center at zero point sphere.
Definition: geometric_shapes.h:238
Simple transform class used locally by InterpMotion.
Definition: transform.h:55
Triangle stores the points instead of only indices of points.
Definition: geometric_shapes.h:108
A class describing the kIOS collision structure, which is a set of spheres.
Definition: kIOS.h:52
#define COAL_DLLAPI
Definition: config.hh:88
#define COAL_THROW_PRETTY(message, exception)
Definition: fwd.hh:64
Main namespace.
Definition: broadphase_bruteforce.h:44
void computeBV(const S &s, const Transform3s &tf, BV &bv)
calculate a bounding volume for a shape in a specific configuration
Definition: geometric_shapes_utility.h:82
void computeBV< OBB, Plane >(const Plane &s, const Transform3s &tf, OBB &bv)
std::array< Halfspace, 2 > transformToHalfspaces(const Plane &a, const Transform3s &tf)
void computeBV< OBB, ConvexBase32 >(const ConvexBase32 &s, const Transform3s &tf, OBB &bv)
void constructBox(const AABB &bv, Box &box, Transform3s &tf)
construct a box shape (with a configuration) from a given bounding volume
void computeBV< OBBRSS, Halfspace >(const Halfspace &s, const Transform3s &tf, OBBRSS &bv)
void computeBV< AABB, Ellipsoid >(const Ellipsoid &e, const Transform3s &tf, AABB &bv)
void computeBV< OBB, ConvexBase16 >(const ConvexBase16 &s, const Transform3s &tf, OBB &bv)
void computeBV< AABB, Sphere >(const Sphere &s, const Transform3s &tf, AABB &bv)
void computeBV< AABB, Box >(const Box &s, const Transform3s &tf, AABB &bv)
void computeBV< AABB, Capsule >(const Capsule &s, const Transform3s &tf, AABB &bv)
void computeBV< AABB, TriangleP >(const TriangleP &s, const Transform3s &tf, AABB &bv)
void computeBV< OBB, Box >(const Box &s, const Transform3s &tf, OBB &bv)
void computeBV< OBB, Cylinder >(const Cylinder &s, const Transform3s &tf, OBB &bv)
Halfspace transform(const Halfspace &a, const Transform3s &tf)
void computeBV< OBBRSS, Plane >(const Plane &s, const Transform3s &tf, OBBRSS &bv)
void fit(Vec3s *ps, unsigned int n, BV &bv)
Compute a bounding volume that fits a set of n points.
Definition: BV_fitter.h:51
void computeBV< kIOS, Halfspace >(const Halfspace &s, const Transform3s &tf, kIOS &bv)
void computeBV< RSS, Plane >(const Plane &s, const Transform3s &tf, RSS &bv)
void computeBV< OBB, Halfspace >(const Halfspace &s, const Transform3s &tf, OBB &bv)
void computeBV< RSS, Halfspace >(const Halfspace &s, const Transform3s &tf, RSS &bv)
void computeBV< kIOS, Plane >(const Plane &s, const Transform3s &tf, kIOS &bv)
void computeBV< AABB, Cylinder >(const Cylinder &s, const Transform3s &tf, AABB &bv)
void computeBV< AABB, Halfspace >(const Halfspace &s, const Transform3s &tf, AABB &bv)
void computeBV< AABB, Plane >(const Plane &s, const Transform3s &tf, AABB &bv)
void computeBV< AABB, ConvexBase32 >(const ConvexBase32 &s, const Transform3s &tf, AABB &bv)
void computeBV< AABB, Cone >(const Cone &s, const Transform3s &tf, AABB &bv)
void computeBV< AABB, ConvexBase16 >(const ConvexBase16 &s, const Transform3s &tf, AABB &bv)
void computeBV< OBB, Sphere >(const Sphere &s, const Transform3s &tf, OBB &bv)
void computeBV< OBB, Capsule >(const Capsule &s, const Transform3s &tf, OBB &bv)
void computeBV< OBB, Cone >(const Cone &s, const Transform3s &tf, OBB &bv)
Class merging the OBB and RSS, can handle collision and distance simultaneously.
Definition: OBBRSS.h:53
Oriented bounding box class.
Definition: OBB.h:51
A class for rectangle sphere-swept bounding volume.
Definition: RSS.h:53