hpp-fcl: include/hpp/fcl/collision_object.h Source File

hpp-fcl 1.6.0 HPP fork of FCL -- The Flexible Collision Library

collision_object.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
39 #ifndef HPP_FCL_COLLISION_OBJECT_BASE_H
40 #define HPP_FCL_COLLISION_OBJECT_BASE_H
41
42 #include <hpp/fcl/deprecated.hh>
43 #include <hpp/fcl/BV/AABB.h>
44 #include <hpp/fcl/math/transform.h>
45 #include <boost/shared_ptr.hpp>
46
47 namespace hpp
48 {
49 namespace fcl
50 {
51
53 enum OBJECT_TYPE {OT_UNKNOWN, OT_BVH, OT_GEOM, OT_OCTREE, OT_COUNT};
54
56 enum NODE_TYPE {BV_UNKNOWN, BV_AABB, BV_OBB, BV_RSS, BV_kIOS, BV_OBBRSS, BV_KDOP16, BV_KDOP18, BV_KDOP24,
57 GEOM_BOX, GEOM_SPHERE, GEOM_CAPSULE, GEOM_CONE, GEOM_CYLINDER, GEOM_CONVEX, GEOM_PLANE, GEOM_HALFSPACE, GEOM_TRIANGLE, GEOM_OCTREE, NODE_COUNT};
58
61
63 class HPP_FCL_DLLAPI CollisionGeometry
64 {
65 public:
66 CollisionGeometry() : cost_density(1),
67 threshold_occupied(1),
68 threshold_free(0)
69 {
70 }
71
72 virtual ~CollisionGeometry() {}
73
75 virtual OBJECT_TYPE getObjectType() const { return OT_UNKNOWN; }
76
78 virtual NODE_TYPE getNodeType() const { return BV_UNKNOWN; }
79
81 virtual void computeLocalAABB() = 0;
82
84 void* getUserData() const
85 {
86 return user_data;
87 }
88
90 void setUserData(void *data)
91 {
92 user_data = data;
93 }
94
96 inline bool isOccupied() const
97 { return cost_density >= threshold_occupied; }
98
100 inline bool isFree() const
101 { return cost_density <= threshold_free; }
102
104 bool isUncertain() const;
105
107 Vec3f aabb_center;
108
110 FCL_REAL aabb_radius;
111
113 AABB aabb_local;
114
116 void *user_data;
117
119 FCL_REAL cost_density;
120
122 FCL_REAL threshold_occupied;
123
125 FCL_REAL threshold_free;
126
128 virtual Vec3f computeCOM() const { return Vec3f::Zero(); }
129
131 virtual Matrix3f computeMomentofInertia() const { return Matrix3f::Constant(NAN); }
132
134 virtual FCL_REAL computeVolume() const { return 0; }
135
137 virtual Matrix3f computeMomentofInertiaRelatedToCOM() const
138 {
139 Matrix3f C = computeMomentofInertia();
140 Vec3f com = computeCOM();
141 FCL_REAL V = computeVolume();
142
143 return (Matrix3f() << C(0, 0) - V * (com[1] * com[1] + com[2] * com[2]),
144 C(0, 1) + V * com[0] * com[1],
145 C(0, 2) + V * com[0] * com[2],
146 C(1, 0) + V * com[1] * com[0],
147 C(1, 1) - V * (com[0] * com[0] + com[2] * com[2]),
148 C(1, 2) + V * com[1] * com[2],
149 C(2, 0) + V * com[2] * com[0],
150 C(2, 1) + V * com[2] * com[1],
151 C(2, 2) - V * (com[0] * com[0] + com[1] * com[1])).finished();
152 }
153
154 };
155
157 class HPP_FCL_DLLAPI CollisionObject
158 {
159 public:
160 CollisionObject(const boost::shared_ptr<CollisionGeometry> &cgeom_) :
161 cgeom(cgeom_), cgeom_const(cgeom_)
162 {
163 if (cgeom)
164 {
165 cgeom->computeLocalAABB();
166 computeAABB();
167 }
168 }
169
170 CollisionObject(const boost::shared_ptr<CollisionGeometry> &cgeom_, const Transform3f& tf) :
171 cgeom(cgeom_), cgeom_const(cgeom_), t(tf)
172 {
173 cgeom->computeLocalAABB();
174 computeAABB();
175 }
176
177 CollisionObject(const boost::shared_ptr<CollisionGeometry> &cgeom_, const Matrix3f& R, const Vec3f& T):
178 cgeom(cgeom_), cgeom_const(cgeom_), t(Transform3f(R, T))
179 {
180 cgeom->computeLocalAABB();
181 computeAABB();
182 }
183
184 ~CollisionObject()
185 {
186 }
187
189 OBJECT_TYPE getObjectType() const
190 {
191 return cgeom->getObjectType();
192 }
193
195 NODE_TYPE getNodeType() const
196 {
197 return cgeom->getNodeType();
198 }
199
201 inline const AABB& getAABB() const
202 {
203 return aabb;
204 }
205
207 inline void computeAABB()
208 {
209 if(t.getRotation().isIdentity())
210 {
211 aabb = translate(cgeom->aabb_local, t.getTranslation());
212 }
213 else
214 {
215 Vec3f center (t.transform(cgeom->aabb_center));
216 Vec3f delta(Vec3f::Constant(cgeom->aabb_radius));
217 aabb.min_ = center - delta;
218 aabb.max_ = center + delta;
219 }
220 }
221
223 void* getUserData() const
224 {
225 return user_data;
226 }
227
229 void setUserData(void *data)
230 {
231 user_data = data;
232 }
233
235 inline const Vec3f& getTranslation() const
236 {
237 return t.getTranslation();
238 }
239
241 inline const Matrix3f& getRotation() const
242 {
243 return t.getRotation();
244 }
245
247 inline const Transform3f& getTransform() const
248 {
249 return t;
250 }
251
253 void setRotation(const Matrix3f& R)
254 {
255 t.setRotation(R);
256 }
257
259 void setTranslation(const Vec3f& T)
260 {
261 t.setTranslation(T);
262 }
263
264
265
267 void setTransform(const Matrix3f& R, const Vec3f& T)
268 {
269 t.setTransform(R, T);
270 }
271
272
273
275 void setTransform(const Transform3f& tf)
276 {
277 t = tf;
278 }
279
281 bool isIdentityTransform() const
282 {
283 return t.isIdentity();
284 }
285
287 void setIdentityTransform()
288 {
289 t.setIdentity();
290 }
291
293 const boost::shared_ptr<const CollisionGeometry>& collisionGeometry() const
294 {
295 return cgeom_const;
296 }
297
299 const boost::shared_ptr<CollisionGeometry>& collisionGeometry()
300 {
301 return cgeom;
302 }
303
304 protected:
305
306 boost::shared_ptr<CollisionGeometry> cgeom;
307 boost::shared_ptr<const CollisionGeometry> cgeom_const;
308
309 Transform3f t;
310
312 mutable AABB aabb;
313
315 void *user_data;
316 };
317
318 }
319
320 } // namespace hpp
321
322 #endif
hpp::fcl::CollisionGeometry::computeVolume
virtual FCL_REAL computeVolume() const
compute the volume
Definition: collision_object.h:134
hpp::fcl::BV_RSS
@ BV_RSS
Definition: collision_object.h:56
hpp::fcl::CollisionObject::collisionGeometry
const boost::shared_ptr< const CollisionGeometry > & collisionGeometry() const
get geometry from the object instance
Definition: collision_object.h:293
hpp::fcl::CollisionObject::computeAABB
void computeAABB()
compute the AABB in world space
Definition: collision_object.h:207
hpp::fcl::CollisionObject::getTranslation
const Vec3f & getTranslation() const
get translation of the object
Definition: collision_object.h:235
hpp::fcl::CollisionObject::setRotation
void setRotation(const Matrix3f &R)
set object's rotation matrix
Definition: collision_object.h:253
hpp::fcl::CollisionObject::setTransform
void setTransform(const Transform3f &tf)
set object's transform
Definition: collision_object.h:275
hpp::fcl::Vec3f
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
hpp::fcl::GEOM_SPHERE
@ GEOM_SPHERE
Definition: collision_object.h:57
hpp::fcl::BV_AABB
@ BV_AABB
Definition: collision_object.h:56
hpp::fcl::CollisionGeometry::computeLocalAABB
virtual void computeLocalAABB()=0
compute the AABB for object in local coordinate
hpp::fcl::CollisionGeometry::getObjectType
virtual OBJECT_TYPE getObjectType() const
get the type of the object
Definition: collision_object.h:75
hpp::fcl::GEOM_HALFSPACE
@ GEOM_HALFSPACE
Definition: collision_object.h:57
hpp::fcl::CollisionGeometry::threshold_occupied
FCL_REAL threshold_occupied
threshold for occupied ( >= is occupied)
Definition: collision_object.h:122
hpp::fcl::BV_KDOP18
@ BV_KDOP18
Definition: collision_object.h:56
hpp::fcl::GEOM_OCTREE
@ GEOM_OCTREE
Definition: collision_object.h:57
hpp::fcl::CollisionObject::setIdentityTransform
void setIdentityTransform()
set the object in local coordinate
Definition: collision_object.h:287
hpp::fcl::GEOM_CONVEX
@ GEOM_CONVEX
Definition: collision_object.h:57
hpp::fcl::CollisionObject::aabb
AABB aabb
AABB in global coordinate.
Definition: collision_object.h:312
hpp::fcl::CollisionGeometry::~CollisionGeometry
virtual ~CollisionGeometry()
Definition: collision_object.h:72
hpp::fcl::CollisionGeometry::aabb_local
AABB aabb_local
AABB in local coordinate, used for tight AABB when only translation transform.
Definition: collision_object.h:113
hpp::fcl::CollisionGeometry::user_data
void * user_data
pointer to user defined data specific to this object
Definition: collision_object.h:116
hpp::fcl::CollisionGeometry::CollisionGeometry
CollisionGeometry()
Definition: collision_object.h:66
hpp::fcl::BV_kIOS
@ BV_kIOS
Definition: collision_object.h:56
hpp::fcl::OT_UNKNOWN
@ OT_UNKNOWN
Definition: collision_object.h:53
hpp::fcl::CollisionGeometry::isUncertain
bool isUncertain() const
whether the object has some uncertainty
hpp::fcl::CollisionObject::getNodeType
NODE_TYPE getNodeType() const
get the node type
Definition: collision_object.h:195
hpp::fcl::AABB
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition: AABB.h:56
hpp::fcl::CollisionGeometry::isFree
bool isFree() const
whether the object is completely free
Definition: collision_object.h:100
hpp::fcl::CollisionObject::setTranslation
void setTranslation(const Vec3f &T)
set object's translation
Definition: collision_object.h:259
hpp::fcl::GEOM_CAPSULE
@ GEOM_CAPSULE
Definition: collision_object.h:57
hpp::fcl::CollisionObject::cgeom_const
boost::shared_ptr< const CollisionGeometry > cgeom_const
Definition: collision_object.h:307
hpp::fcl::NODE_TYPE
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Definition: collision_object.h:56
AABB.h
hpp::fcl::GEOM_PLANE
@ GEOM_PLANE
Definition: collision_object.h:57
hpp::fcl::Transform3f
Simple transform class used locally by InterpMotion.
Definition: transform.h:59
hpp::fcl::CollisionObject::user_data
void * user_data
pointer to user defined data specific to this object
Definition: collision_object.h:315
hpp::fcl::FCL_REAL
double FCL_REAL
Definition: data_types.h:66
hpp::fcl::CollisionGeometry::threshold_free
FCL_REAL threshold_free
threshold for free (<= is free)
Definition: collision_object.h:125
hpp::fcl::CollisionGeometry::computeMomentofInertia
virtual Matrix3f computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition: collision_object.h:131
hpp::fcl::GEOM_CONE
@ GEOM_CONE
Definition: collision_object.h:57
hpp::fcl::OBJECT_TYPE
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
Definition: collision_object.h:53
hpp::fcl::BV_KDOP24
@ BV_KDOP24
Definition: collision_object.h:56
hpp::fcl::CollisionObject::CollisionObject
CollisionObject(const boost::shared_ptr< CollisionGeometry > &cgeom_, const Transform3f &tf)
Definition: collision_object.h:170
hpp::fcl::CollisionObject::CollisionObject
CollisionObject(const boost::shared_ptr< CollisionGeometry > &cgeom_)
Definition: collision_object.h:160
hpp::fcl::OT_OCTREE
@ OT_OCTREE
Definition: collision_object.h:53
hpp::fcl::BV_OBB
@ BV_OBB
Definition: collision_object.h:56
hpp::fcl::translate
KDOP< N > translate(const KDOP< N > &bv, const Vec3f &t)
translate the KDOP BV
hpp
Main namespace.
Definition: AABB.h:44
hpp::fcl::OT_GEOM
@ OT_GEOM
Definition: collision_object.h:53
hpp::fcl::CollisionObject::getRotation
const Matrix3f & getRotation() const
get matrix rotation of the object
Definition: collision_object.h:241
hpp::fcl::CollisionGeometry::getNodeType
virtual NODE_TYPE getNodeType() const
get the node type
Definition: collision_object.h:78
hpp::fcl::CollisionObject::setTransform
void setTransform(const Matrix3f &R, const Vec3f &T)
set object's transform
Definition: collision_object.h:267
hpp::fcl::BV_UNKNOWN
@ BV_UNKNOWN
Definition: collision_object.h:56
hpp::fcl::CollisionObject::cgeom
boost::shared_ptr< CollisionGeometry > cgeom
Definition: collision_object.h:306
hpp::fcl::CollisionObject::isIdentityTransform
bool isIdentityTransform() const
whether the object is in local coordinate
Definition: collision_object.h:281
hpp::fcl::GEOM_CYLINDER
@ GEOM_CYLINDER
Definition: collision_object.h:57
hpp::fcl::CollisionGeometry::setUserData
void setUserData(void *data)
set user data in geometry
Definition: collision_object.h:90
hpp::fcl::CollisionObject::collisionGeometry
const boost::shared_ptr< CollisionGeometry > & collisionGeometry()
get geometry from the object instance
Definition: collision_object.h:299
hpp::fcl::CollisionObject::getObjectType
OBJECT_TYPE getObjectType() const
get the type of the object
Definition: collision_object.h:189
hpp::fcl::CollisionGeometry::getUserData
void * getUserData() const
get user data in geometry
Definition: collision_object.h:84
hpp::fcl::Matrix3f
Eigen::Matrix< FCL_REAL, 3, 3 > Matrix3f
Definition: data_types.h:68
hpp::fcl::CollisionGeometry
The geometry for the object for collision or distance computation.
Definition: collision_object.h:64
hpp::fcl::CollisionGeometry::computeCOM
virtual Vec3f computeCOM() const
compute center of mass
Definition: collision_object.h:128
hpp::fcl::CollisionObject::getTransform
const Transform3f & getTransform() const
get object's transform
Definition: collision_object.h:247
hpp::fcl::CollisionGeometry::computeMomentofInertiaRelatedToCOM
virtual Matrix3f computeMomentofInertiaRelatedToCOM() const
compute the inertia matrix, related to the com
Definition: collision_object.h:137
hpp::fcl::GEOM_BOX
@ GEOM_BOX
Definition: collision_object.h:57
hpp::fcl::CollisionGeometry::aabb_center
Vec3f aabb_center
AABB center in local coordinate.
Definition: collision_object.h:107
transform.h
hpp::fcl::GEOM_TRIANGLE
@ GEOM_TRIANGLE
Definition: collision_object.h:57
hpp::fcl::NODE_COUNT
@ NODE_COUNT
Definition: collision_object.h:57
hpp::fcl::CollisionObject::setUserData
void setUserData(void *data)
set user data in object
Definition: collision_object.h:229
hpp::fcl::CollisionObject::~CollisionObject
~CollisionObject()
Definition: collision_object.h:184
hpp::fcl::CollisionObject::getUserData
void * getUserData() const
get user data in object
Definition: collision_object.h:223
hpp::fcl::BV_OBBRSS
@ BV_OBBRSS
Definition: collision_object.h:56
hpp::fcl::BV_KDOP16
@ BV_KDOP16
Definition: collision_object.h:56
hpp::fcl::CollisionObject::CollisionObject
CollisionObject(const boost::shared_ptr< CollisionGeometry > &cgeom_, const Matrix3f &R, const Vec3f &T)
Definition: collision_object.h:177
hpp::fcl::CollisionGeometry::isOccupied
bool isOccupied() const
whether the object is completely occupied
Definition: collision_object.h:96
hpp::fcl::OT_BVH
@ OT_BVH
Definition: collision_object.h:53
hpp::fcl::CollisionObject::getAABB
const AABB & getAABB() const
get the AABB in world space
Definition: collision_object.h:201
hpp::fcl::CollisionObject::t
Transform3f t
Definition: collision_object.h:309
hpp::fcl::CollisionObject
the object for collision or distance computation, contains the geometry and the transform information
Definition: collision_object.h:158
hpp::fcl::CollisionGeometry::cost_density
FCL_REAL cost_density
collision cost for unit volume
Definition: collision_object.h:119
hpp::fcl::CollisionGeometry::aabb_radius
FCL_REAL aabb_radius
AABB radius.
Definition: collision_object.h:110
hpp::fcl::OT_COUNT
@ OT_COUNT
Definition: collision_object.h:53