hpp-fcl  1.7.1
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 <limits>
43 
44 #include <hpp/fcl/deprecated.hh>
45 #include <hpp/fcl/fwd.hh>
46 #include <hpp/fcl/BV/AABB.h>
47 #include <hpp/fcl/math/transform.h>
48 
49 namespace hpp
50 {
51 namespace fcl
52 {
53 
56 
60 
63 
66 {
67 public:
68 
70  : aabb_center(Vec3f::Constant((std::numeric_limits<FCL_REAL>::max)()))
71  , aabb_radius(-1)
72  , cost_density(1)
73  , threshold_occupied(1)
74  , threshold_free(0)
75  {
76  }
77 
80  : aabb_center(other.aabb_center)
81  , aabb_radius(other.aabb_radius)
82  , cost_density(other.cost_density)
83  , threshold_occupied(other.threshold_occupied)
84  , threshold_free(other.threshold_free)
85  {
86  }
87 
88  virtual ~CollisionGeometry() {}
89 
91  virtual CollisionGeometry* clone() const = 0;
92 
94  bool operator==(const CollisionGeometry & other) const
95  {
96  return
97  cost_density == other.cost_density
98  && threshold_occupied == other.threshold_occupied
99  && threshold_free == other.threshold_free
100  && aabb_center == other.aabb_center
101  && aabb_radius == other.aabb_radius
102  && aabb_local == other.aabb_local
103 // && user_data == other.user_data
104  ;
105  }
106 
108  bool operator!=(const CollisionGeometry & other) const
109  {
110  return !(*this == other);
111  }
112 
114  virtual OBJECT_TYPE getObjectType() const { return OT_UNKNOWN; }
115 
117  virtual NODE_TYPE getNodeType() const { return BV_UNKNOWN; }
118 
120  virtual void computeLocalAABB() = 0;
121 
123  void* getUserData() const
124  {
125  return user_data;
126  }
127 
129  void setUserData(void *data)
130  {
131  user_data = data;
132  }
133 
135  inline bool isOccupied() const
136  { return cost_density >= threshold_occupied; }
137 
139  inline bool isFree() const
140  { return cost_density <= threshold_free; }
141 
143  bool isUncertain() const;
144 
147 
150 
153 
155  void *user_data;
156 
159 
162 
165 
167  virtual Vec3f computeCOM() const { return Vec3f::Zero(); }
168 
170  virtual Matrix3f computeMomentofInertia() const { return Matrix3f::Constant(NAN); }
171 
173  virtual FCL_REAL computeVolume() const { return 0; }
174 
177  {
178  Matrix3f C = computeMomentofInertia();
179  Vec3f com = computeCOM();
180  FCL_REAL V = computeVolume();
181 
182  return (Matrix3f() << C(0, 0) - V * (com[1] * com[1] + com[2] * com[2]),
183  C(0, 1) + V * com[0] * com[1],
184  C(0, 2) + V * com[0] * com[2],
185  C(1, 0) + V * com[1] * com[0],
186  C(1, 1) - V * (com[0] * com[0] + com[2] * com[2]),
187  C(1, 2) + V * com[1] * com[2],
188  C(2, 0) + V * com[2] * com[0],
189  C(2, 1) + V * com[2] * com[1],
190  C(2, 2) - V * (com[0] * com[0] + com[1] * com[1])).finished();
191  }
192 
193  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
194 
195 };
196 
199 {
200 public:
201  CollisionObject(const shared_ptr<CollisionGeometry> &cgeom_) :
202  cgeom(cgeom_), cgeom_const(cgeom_)
203  {
204  if (cgeom)
205  {
206  cgeom->computeLocalAABB();
207  computeAABB();
208  }
209  }
210 
211  CollisionObject(const shared_ptr<CollisionGeometry> &cgeom_, const Transform3f& tf) :
212  cgeom(cgeom_), cgeom_const(cgeom_), t(tf)
213  {
214  cgeom->computeLocalAABB();
215  computeAABB();
216  }
217 
218  CollisionObject(const shared_ptr<CollisionGeometry> &cgeom_, const Matrix3f& R, const Vec3f& T):
219  cgeom(cgeom_), cgeom_const(cgeom_), t(Transform3f(R, T))
220  {
221  cgeom->computeLocalAABB();
222  computeAABB();
223  }
224 
226  {
227  }
228 
231  {
232  return cgeom->getObjectType();
233  }
234 
237  {
238  return cgeom->getNodeType();
239  }
240 
242  inline const AABB& getAABB() const
243  {
244  return aabb;
245  }
246 
248  inline void computeAABB()
249  {
250  if(t.getRotation().isIdentity())
251  {
252  aabb = translate(cgeom->aabb_local, t.getTranslation());
253  }
254  else
255  {
256  Vec3f center (t.transform(cgeom->aabb_center));
257  Vec3f delta(Vec3f::Constant(cgeom->aabb_radius));
258  aabb.min_ = center - delta;
259  aabb.max_ = center + delta;
260  }
261  }
262 
264  void* getUserData() const
265  {
266  return user_data;
267  }
268 
270  void setUserData(void *data)
271  {
272  user_data = data;
273  }
274 
276  inline const Vec3f& getTranslation() const
277  {
278  return t.getTranslation();
279  }
280 
282  inline const Matrix3f& getRotation() const
283  {
284  return t.getRotation();
285  }
286 
288  inline const Transform3f& getTransform() const
289  {
290  return t;
291  }
292 
294  void setRotation(const Matrix3f& R)
295  {
296  t.setRotation(R);
297  }
298 
300  void setTranslation(const Vec3f& T)
301  {
302  t.setTranslation(T);
303  }
304 
305 
306 
308  void setTransform(const Matrix3f& R, const Vec3f& T)
309  {
310  t.setTransform(R, T);
311  }
312 
313 
314 
316  void setTransform(const Transform3f& tf)
317  {
318  t = tf;
319  }
320 
322  bool isIdentityTransform() const
323  {
324  return t.isIdentity();
325  }
326 
329  {
330  t.setIdentity();
331  }
332 
334  const shared_ptr<const CollisionGeometry>& collisionGeometry() const
335  {
336  return cgeom_const;
337  }
338 
340  const shared_ptr<CollisionGeometry>& collisionGeometry()
341  {
342  return cgeom;
343  }
344 
345 protected:
346 
347  shared_ptr<CollisionGeometry> cgeom;
348  shared_ptr<const CollisionGeometry> cgeom_const;
349 
351 
353  mutable AABB aabb;
354 
356  void *user_data;
357 };
358 
359 }
360 
361 } // namespace hpp
362 
363 #endif
Definition: collision_object.h:59
const Matrix3f & getRotation() const
get matrix rotation of the object
Definition: collision_object.h:282
Simple transform class used locally by InterpMotion.
Definition: transform.h:58
FCL_REAL cost_density
collision cost for unit volume
Definition: collision_object.h:158
bool operator==(const CollisionGeometry &other) const
Equality operator.
Definition: collision_object.h:94
virtual Matrix3f computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition: collision_object.h:170
~CollisionObject()
Definition: collision_object.h:225
Definition: collision_object.h:58
Definition: collision_object.h:59
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
Definition: collision_object.h:55
CollisionGeometry()
Definition: collision_object.h:69
Main namespace.
Definition: AABB.h:43
Definition: collision_object.h:58
NODE_TYPE getNodeType() const
get the node type
Definition: collision_object.h:236
void * user_data
pointer to user defined data specific to this object
Definition: collision_object.h:356
const shared_ptr< CollisionGeometry > & collisionGeometry()
get geometry from the object instance
Definition: collision_object.h:340
CollisionGeometry(const CollisionGeometry &other)
Copy constructor.
Definition: collision_object.h:79
Eigen::Matrix< FCL_REAL, 3, 3 > Matrix3f
Definition: data_types.h:68
virtual Vec3f computeCOM() const
compute center of mass
Definition: collision_object.h:167
CollisionObject(const shared_ptr< CollisionGeometry > &cgeom_, const Transform3f &tf)
Definition: collision_object.h:211
Definition: collision_object.h:59
Definition: collision_object.h:58
KDOP< N > translate(const KDOP< N > &bv, const Vec3f &t)
translate the KDOP BV
const shared_ptr< const CollisionGeometry > & collisionGeometry() const
get geometry from the object instance
Definition: collision_object.h:334
FCL_REAL threshold_occupied
threshold for occupied ( >= is occupied)
Definition: collision_object.h:161
Definition: collision_object.h:58
bool isOccupied() const
whether the object is completely occupied
Definition: collision_object.h:135
const Transform3f & getTransform() const
get object&#39;s transform
Definition: collision_object.h:288
bool isFree() const
whether the object is completely free
Definition: collision_object.h:139
void setIdentityTransform()
set the object in local coordinate
Definition: collision_object.h:328
void setTransform(const Transform3f &tf)
set object&#39;s transform
Definition: collision_object.h:316
Definition: collision_object.h:59
virtual NODE_TYPE getNodeType() const
get the node type
Definition: collision_object.h:117
Definition: collision_object.h:55
AABB aabb_local
AABB in local coordinate, used for tight AABB when only translation transform.
Definition: collision_object.h:152
Definition: collision_object.h:55
void setTransform(const Matrix3f &R, const Vec3f &T)
set object&#39;s transform
Definition: collision_object.h:308
void setRotation(const Matrix3f &R)
set object&#39;s rotation matrix
Definition: collision_object.h:294
void * user_data
pointer to user defined data specific to this object
Definition: collision_object.h:155
double FCL_REAL
Definition: data_types.h:66
OBJECT_TYPE getObjectType() const
get the type of the object
Definition: collision_object.h:230
Definition: collision_object.h:58
void setUserData(void *data)
set user data in geometry
Definition: collision_object.h:129
Definition: collision_object.h:59
virtual OBJECT_TYPE getObjectType() const
get the type of the object
Definition: collision_object.h:114
Definition: collision_object.h:55
AABB aabb
AABB in global coordinate.
Definition: collision_object.h:353
void * getUserData() const
get user data in geometry
Definition: collision_object.h:123
CollisionObject(const shared_ptr< CollisionGeometry > &cgeom_, const Matrix3f &R, const Vec3f &T)
Definition: collision_object.h:218
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition: AABB.h:55
Definition: collision_object.h:58
FCL_REAL aabb_radius
AABB radius.
Definition: collision_object.h:149
Definition: collision_object.h:55
void setUserData(void *data)
set user data in object
Definition: collision_object.h:270
virtual Matrix3f computeMomentofInertiaRelatedToCOM() const
compute the inertia matrix, related to the com
Definition: collision_object.h:176
Definition: collision_object.h:58
Definition: collision_object.h:59
bool isIdentityTransform() const
whether the object is in local coordinate
Definition: collision_object.h:322
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18, kDOP24), basic shape (box, sphere, capsule, cone, cylinder, convex, plane, triangle), and octree
Definition: collision_object.h:58
virtual FCL_REAL computeVolume() const
compute the volume
Definition: collision_object.h:173
void setTranslation(const Vec3f &T)
set object&#39;s translation
Definition: collision_object.h:300
FCL_REAL threshold_free
threshold for free (<= is free)
Definition: collision_object.h:164
Vec3f aabb_center
AABB center in local coordinate.
Definition: collision_object.h:146
Definition: collision_object.h:59
shared_ptr< const CollisionGeometry > cgeom_const
Definition: collision_object.h:348
const AABB & getAABB() const
get the AABB in world space
Definition: collision_object.h:242
const Vec3f & getTranslation() const
get translation of the object
Definition: collision_object.h:276
Definition: collision_object.h:55
Definition: collision_object.h:59
Transform3f t
Definition: collision_object.h:350
CollisionObject(const shared_ptr< CollisionGeometry > &cgeom_)
Definition: collision_object.h:201
virtual ~CollisionGeometry()
Definition: collision_object.h:88
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
void computeAABB()
compute the AABB in world space
Definition: collision_object.h:248
the object for collision or distance computation, contains the geometry and the transform information...
Definition: collision_object.h:198
Definition: collision_object.h:58
void * getUserData() const
get user data in object
Definition: collision_object.h:264
The geometry for the object for collision or distance computation.
Definition: collision_object.h:65
Definition: collision_object.h:59
Definition: collision_object.h:59
shared_ptr< CollisionGeometry > cgeom
Definition: collision_object.h:347
Definition: collision_object.h:59
bool operator!=(const CollisionGeometry &other) const
Difference operator.
Definition: collision_object.h:108
#define HPP_FCL_DLLAPI
Definition: config.hh:64
Definition: collision_object.h:58