bodies.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
37 #ifndef GEOMETRIC_SHAPES_POINT_INCLUSION_
38 #define GEOMETRIC_SHAPES_POINT_INCLUSION_
39 
42 #include <tf/LinearMath/Vector3.h>
43 // #include <BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h>
44 // #include <BulletCollision/CollisionShapes/btTriangleMesh.h>
45 #include <vector>
46 
56 namespace bodies
57 {
58 
61  {
63  double radius;
64  };
65 
69  class Body
70  {
71  public:
72 
73  Body(void)
74  {
75  m_scale = 1.0;
76  m_padding = 0.0;
77  m_pose.setIdentity();
78  m_type = shapes::UNKNOWN_SHAPE;
79  }
80 
81  virtual ~Body(void)
82  {
83  }
84 
87  {
88  return m_type;
89  }
90 
93  void setScale(double scale)
94  {
95  m_scale = scale;
96  updateInternalData();
97  }
98 
100  double getScale(void) const
101  {
102  return m_scale;
103  }
104 
107  void setPadding(double padd)
108  {
109  m_padding = padd;
110  updateInternalData();
111  }
112 
114  double getPadding(void) const
115  {
116  return m_padding;
117  }
118 
120  void setPose(const tf::Transform &pose)
121  {
122  m_pose = pose;
123  updateInternalData();
124  }
125 
127  const tf::Transform& getPose(void) const
128  {
129  return m_pose;
130  }
131 
133  void setDimensions(const shapes::Shape *shape)
134  {
135  useDimensions(shape);
136  updateInternalData();
137  }
138 
140  bool containsPoint(double x, double y, double z) const
141  {
142  return containsPoint(tf::Vector3(tfScalar(x), tfScalar(y), tfScalar(z)));
143  }
144 
149  virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const = 0;
150 
152  virtual bool containsPoint(const tf::Vector3 &p, bool verbose = false) const = 0;
153 
156  virtual double computeVolume(void) const = 0;
157 
160  virtual void computeBoundingSphere(BoundingSphere &sphere) const = 0;
161 
162  protected:
163 
164  virtual void updateInternalData(void) = 0;
165  virtual void useDimensions(const shapes::Shape *shape) = 0;
166 
169  double m_scale;
170  double m_padding;
171  };
172 
174  class Sphere : public Body
175  {
176  public:
177  Sphere(void) : Body()
178  {
179  m_type = shapes::SPHERE;
180  }
181 
182  Sphere(const shapes::Shape *shape) : Body()
183  {
184  m_type = shapes::SPHERE;
185  setDimensions(shape);
186  }
187 
188  virtual ~Sphere(void)
189  {
190  }
191 
192  virtual bool containsPoint(const tf::Vector3 &p, bool verbose=false) const;
193  virtual double computeVolume(void) const;
194  virtual void computeBoundingSphere(BoundingSphere &sphere) const;
195  virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const;
196 
197  protected:
198 
199  virtual void useDimensions(const shapes::Shape *shape);
200  virtual void updateInternalData(void);
201 
203  double m_radius;
204  double m_radiusU;
205  double m_radius2;
206  };
207 
209  class Cylinder : public Body
210  {
211  public:
212  Cylinder(void) : Body()
213  {
214  m_type = shapes::CYLINDER;
215  }
216 
217  Cylinder(const shapes::Shape *shape) : Body()
218  {
219  m_type = shapes::CYLINDER;
220  setDimensions(shape);
221  }
222 
223  virtual ~Cylinder(void)
224  {
225  }
226 
227  virtual bool containsPoint(const tf::Vector3 &p, bool verbose=false) const;
228  virtual double computeVolume(void) const;
229  virtual void computeBoundingSphere(BoundingSphere &sphere) const;
230  virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const;
231 
232  protected:
233 
234  virtual void useDimensions(const shapes::Shape *shape);
235  virtual void updateInternalData(void);
236 
241 
242  double m_length;
243  double m_length2;
244  double m_radius;
245  double m_radiusU;
246  double m_radiusB;
247  double m_radiusBSqr;
248  double m_radius2;
249  double m_d1;
250  double m_d2;
251  };
252 
254  class Box : public Body
255  {
256  public:
257  Box(void) : Body()
258  {
259  m_type = shapes::BOX;
260  }
261 
262  Box(const shapes::Shape *shape) : Body()
263  {
264  m_type = shapes::BOX;
265  setDimensions(shape);
266  }
267 
268  virtual ~Box(void)
269  {
270  }
271 
272  virtual bool containsPoint(const tf::Vector3 &p, bool verbose = false) const;
273  virtual double computeVolume(void) const;
274  virtual void computeBoundingSphere(BoundingSphere &sphere) const;
275  virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const;
276 
277  protected:
278 
279  virtual void useDimensions(const shapes::Shape *shape); // (x, y, z) = (length, width, height)
280  virtual void updateInternalData(void);
281 
286 
289 
290  double m_length;
291  double m_width;
292  double m_height;
293  double m_length2;
294  double m_width2;
295  double m_height2;
296  double m_radiusB;
297  double m_radius2;
298  };
299 
300  /*
301  class Mesh : public Body
302  {
303  public:
305  Mesh(void) : Body()
306  {
307  m_type = shapes::MESH;
308  m_btMeshShape = NULL;
309  m_btMesh = NULL;
310  }
311 
312  Mesh(const shapes::Shape *shape) : Body()
313  {
314  m_type = shapes::MESH;
315  m_btMeshShape = NULL;
316  m_btMesh = NULL;
317  setDimensions(shape);
318  }
319 
320  virtual ~Mesh(void)
321  {
322  if (m_btMeshShape)
323  delete m_btMeshShape;
324  if (m_btMesh)
325  delete m_btMesh;
326  }
327 
328  \\\ \brief The mesh is considered to be concave, so this function is implemented with raycasting. This is a bit slow and not so accurate for very small triangles.
329  virtual bool containsPoint(const tf::Vector3 &p) const;
330 
331  \\\ \brief This function is approximate. It returns the volume of the AABB enclosing the shape
332  virtual double computeVolume(void) const;
333  virtual void computeBoundingSphere(BoundingSphere &sphere) const;
334  virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const;
335 
336  protected:
337 
338  virtual void useDimensions(const shapes::Shape *shape);
339  virtual void updateInternalData(void);
340 
341  btBvhTriangleMeshShape *m_btMeshShape;
342  btTriangleMesh *m_btMesh;
343  tf::Transform m_iPose;
344  tf::Vector3 m_center;
345  tf::Vector3 m_aabbMin;
346  tf::Vector3 m_aabbMax;
347  double m_radiusB;
348  double m_radiusBSqr;
349 
350  };
351  */
352 
354  class ConvexMesh : public Body
355  {
356  public:
357 
358  ConvexMesh(void) : Body()
359  {
360  m_type = shapes::MESH;
361  }
362 
363  ConvexMesh(const shapes::Shape *shape) : Body()
364  {
365  m_type = shapes::MESH;
366  setDimensions(shape);
367  }
368 
369  virtual ~ConvexMesh(void)
370  {
371  }
372 
373  virtual bool containsPoint(const tf::Vector3 &p, bool verbose = false) const;
374  virtual double computeVolume(void) const;
375 
376  virtual void computeBoundingSphere(BoundingSphere &sphere) const;
377  virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const;
378 
379  protected:
380 
381  virtual void useDimensions(const shapes::Shape *shape);
382  virtual void updateInternalData(void);
383 
384  unsigned int countVerticesBehindPlane(const tf::tfVector4& planeNormal) const;
385  bool isPointInsidePlanes(const tf::Vector3& point) const;
386 
387  std::vector<tf::tfVector4> m_planes;
388  std::vector<tf::Vector3> m_vertices;
389  std::vector<tf::Vector3> m_scaledVertices;
390  std::vector<unsigned int> m_triangles;
392 
395  double m_radiusB;
396  double m_radiusBSqr;
398 
401  };
402 
403 
405  Body* createBodyFromShape(const shapes::Shape *shape);
406 
408  void mergeBoundingSpheres(const std::vector<BoundingSphere> &spheres, BoundingSphere &mergedSphere);
409 
410 }
411 
412 #endif
double m_radiusU
Definition: bodies.h:245
double getScale(void) const
Retrieve the current scale.
Definition: bodies.h:100
tf::Vector3 m_center
Definition: bodies.h:237
tf::Vector3 m_normalW
Definition: bodies.h:284
virtual ~Body(void)
Definition: bodies.h:81
tf::Vector3 m_normalH
Definition: bodies.h:285
tf::Vector3 m_center
Definition: bodies.h:282
double m_length
Definition: bodies.h:242
shapes::ShapeType getType(void) const
Get the type of shape this body represents.
Definition: bodies.h:86
Box(void)
Definition: bodies.h:257
tf::Vector3 center
Definition: bodies.h:62
double tfScalar
Definition of a cylinder.
Definition: bodies.h:209
Body(void)
Definition: bodies.h:73
virtual ~Cylinder(void)
Definition: bodies.h:223
virtual ~ConvexMesh(void)
Definition: bodies.h:369
tf::Vector3 m_meshCenter
Definition: bodies.h:394
Definition of a sphere.
Definition: bodies.h:174
double m_radiusB
Definition: bodies.h:296
double m_d2
Definition: bodies.h:250
Box(const shapes::Shape *shape)
Definition: bodies.h:262
void setScale(double scale)
If the dimension of the body should be scaled, this method sets the scale. Default is 1...
Definition: bodies.h:93
double m_padding
Definition: bodies.h:170
tf::Vector3 m_normalB2
Definition: bodies.h:240
tf::Vector3 m_normalH
Definition: bodies.h:238
double m_radiusBSqr
Definition: bodies.h:247
void setPose(const tf::Transform &pose)
Set the pose of the body. Default is identity.
Definition: bodies.h:120
Definition of a sphere that bounds another object.
Definition: bodies.h:60
shapes::ShapeType m_type
Definition: bodies.h:167
std::vector< tf::tfVector4 > m_planes
Definition: bodies.h:387
void mergeBoundingSpheres(const std::vector< BoundingSphere > &spheres, BoundingSphere &mergedSphere)
Compute a bounding sphere to enclose a set of bounding spheres.
Definition: bodies.cpp:71
A basic definition of a shape. Shapes are considered centered at origin.
Definition: shapes.h:58
double m_radius2
Definition: bodies.h:297
Definition of a convex mesh. Convex hull is computed for a given shape::Mesh.
Definition: bodies.h:354
tf::Transform m_iPose
Definition: bodies.h:391
double m_length2
Definition: bodies.h:243
double getPadding(void) const
Retrieve the current padding.
Definition: bodies.h:114
tf::Vector3 m_normalL
Definition: bodies.h:283
tf::Vector3 m_corner1
Definition: bodies.h:287
Definition of a box.
Definition: bodies.h:254
Body * createBodyFromShape(const shapes::Shape *shape)
Create a body from a given shape.
Definition: bodies.cpp:44
tf::Transform m_pose
Definition: bodies.h:168
double m_radiusBSqr
Definition: bodies.h:396
ShapeType
A list of known shape types.
Definition: shapes.h:52
double m_width2
Definition: bodies.h:294
double m_radius2
Definition: bodies.h:248
double m_radiusU
Definition: bodies.h:204
double m_radius2
Definition: bodies.h:205
virtual ~Box(void)
Definition: bodies.h:268
virtual ~Sphere(void)
Definition: bodies.h:188
bool containsPoint(double x, double y, double z) const
Check is a point is inside the body.
Definition: bodies.h:140
Sphere(void)
Definition: bodies.h:177
tf::Vector3 m_center
Definition: bodies.h:393
double m_height2
Definition: bodies.h:295
tf::Vector3 m_normalB1
Definition: bodies.h:239
tf::Vector3 m_boxOffset
Definition: bodies.h:399
std::vector< unsigned int > m_triangles
Definition: bodies.h:390
double m_scale
Definition: bodies.h:169
Cylinder(const shapes::Shape *shape)
Definition: bodies.h:217
double m_radiusB
Definition: bodies.h:395
double m_height
Definition: bodies.h:292
double m_radius
Definition: bodies.h:203
ConvexMesh(const shapes::Shape *shape)
Definition: bodies.h:363
void setDimensions(const shapes::Shape *shape)
Set the dimensions of the body (from corresponding shape)
Definition: bodies.h:133
double m_radius
Definition: bodies.h:244
double m_radiusB
Definition: bodies.h:246
Sphere(const shapes::Shape *shape)
Definition: bodies.h:182
tf::Vector3 m_corner2
Definition: bodies.h:288
const tf::Transform & getPose(void) const
Retrieve the pose of the body.
Definition: bodies.h:127
ConvexMesh(void)
Definition: bodies.h:358
double m_length2
Definition: bodies.h:293
Cylinder(void)
Definition: bodies.h:212
double m_d1
Definition: bodies.h:249
A body is a shape + its pose. Point inclusion, ray intersection can be tested, volumes and bounding s...
Definition: bodies.h:69
void setPadding(double padd)
If constant padding should be added to the body, this method sets the padding. Default is 0...
Definition: bodies.h:107
std::vector< tf::Vector3 > m_scaledVertices
Definition: bodies.h:389
double m_width
Definition: bodies.h:291
std::vector< tf::Vector3 > m_vertices
Definition: bodies.h:388
double m_meshRadiusB
Definition: bodies.h:397
Definition: bodies.h:56
double m_length
Definition: bodies.h:290
tf::Vector3 m_center
Definition: bodies.h:202


pr2_navigation_self_filter
Author(s): Eitan Marder-Eppstein
autogenerated on Mon Jun 10 2019 14:28:54