Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00037 #ifndef GEOMETRIC_SHAPES_POINT_INCLUSION_
00038 #define GEOMETRIC_SHAPES_POINT_INCLUSION_
00039
00040 #include "pr2_navigation_self_filter/shapes.h"
00041 #include <tf/LinearMath/Transform.h>
00042 #include <tf/LinearMath/Vector3.h>
00043
00044
00045 #include <vector>
00046
00056 namespace bodies
00057 {
00058
00060 struct BoundingSphere
00061 {
00062 tf::Vector3 center;
00063 double radius;
00064 };
00065
00069 class Body
00070 {
00071 public:
00072
00073 Body(void)
00074 {
00075 m_scale = 1.0;
00076 m_padding = 0.0;
00077 m_pose.setIdentity();
00078 m_type = shapes::UNKNOWN_SHAPE;
00079 }
00080
00081 virtual ~Body(void)
00082 {
00083 }
00084
00086 shapes::ShapeType getType(void) const
00087 {
00088 return m_type;
00089 }
00090
00093 void setScale(double scale)
00094 {
00095 m_scale = scale;
00096 updateInternalData();
00097 }
00098
00100 double getScale(void) const
00101 {
00102 return m_scale;
00103 }
00104
00107 void setPadding(double padd)
00108 {
00109 m_padding = padd;
00110 updateInternalData();
00111 }
00112
00114 double getPadding(void) const
00115 {
00116 return m_padding;
00117 }
00118
00120 void setPose(const tf::Transform &pose)
00121 {
00122 m_pose = pose;
00123 updateInternalData();
00124 }
00125
00127 const tf::Transform& getPose(void) const
00128 {
00129 return m_pose;
00130 }
00131
00133 void setDimensions(const shapes::Shape *shape)
00134 {
00135 useDimensions(shape);
00136 updateInternalData();
00137 }
00138
00140 bool containsPoint(double x, double y, double z) const
00141 {
00142 return containsPoint(tf::Vector3(tfScalar(x), tfScalar(y), tfScalar(z)));
00143 }
00144
00149 virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const = 0;
00150
00152 virtual bool containsPoint(const tf::Vector3 &p, bool verbose = false) const = 0;
00153
00156 virtual double computeVolume(void) const = 0;
00157
00160 virtual void computeBoundingSphere(BoundingSphere &sphere) const = 0;
00161
00162 protected:
00163
00164 virtual void updateInternalData(void) = 0;
00165 virtual void useDimensions(const shapes::Shape *shape) = 0;
00166
00167 shapes::ShapeType m_type;
00168 tf::Transform m_pose;
00169 double m_scale;
00170 double m_padding;
00171 };
00172
00174 class Sphere : public Body
00175 {
00176 public:
00177 Sphere(void) : Body()
00178 {
00179 m_type = shapes::SPHERE;
00180 }
00181
00182 Sphere(const shapes::Shape *shape) : Body()
00183 {
00184 m_type = shapes::SPHERE;
00185 setDimensions(shape);
00186 }
00187
00188 virtual ~Sphere(void)
00189 {
00190 }
00191
00192 virtual bool containsPoint(const tf::Vector3 &p, bool verbose=false) const;
00193 virtual double computeVolume(void) const;
00194 virtual void computeBoundingSphere(BoundingSphere &sphere) const;
00195 virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const;
00196
00197 protected:
00198
00199 virtual void useDimensions(const shapes::Shape *shape);
00200 virtual void updateInternalData(void);
00201
00202 tf::Vector3 m_center;
00203 double m_radius;
00204 double m_radiusU;
00205 double m_radius2;
00206 };
00207
00209 class Cylinder : public Body
00210 {
00211 public:
00212 Cylinder(void) : Body()
00213 {
00214 m_type = shapes::CYLINDER;
00215 }
00216
00217 Cylinder(const shapes::Shape *shape) : Body()
00218 {
00219 m_type = shapes::CYLINDER;
00220 setDimensions(shape);
00221 }
00222
00223 virtual ~Cylinder(void)
00224 {
00225 }
00226
00227 virtual bool containsPoint(const tf::Vector3 &p, bool verbose=false) const;
00228 virtual double computeVolume(void) const;
00229 virtual void computeBoundingSphere(BoundingSphere &sphere) const;
00230 virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const;
00231
00232 protected:
00233
00234 virtual void useDimensions(const shapes::Shape *shape);
00235 virtual void updateInternalData(void);
00236
00237 tf::Vector3 m_center;
00238 tf::Vector3 m_normalH;
00239 tf::Vector3 m_normalB1;
00240 tf::Vector3 m_normalB2;
00241
00242 double m_length;
00243 double m_length2;
00244 double m_radius;
00245 double m_radiusU;
00246 double m_radiusB;
00247 double m_radiusBSqr;
00248 double m_radius2;
00249 double m_d1;
00250 double m_d2;
00251 };
00252
00254 class Box : public Body
00255 {
00256 public:
00257 Box(void) : Body()
00258 {
00259 m_type = shapes::BOX;
00260 }
00261
00262 Box(const shapes::Shape *shape) : Body()
00263 {
00264 m_type = shapes::BOX;
00265 setDimensions(shape);
00266 }
00267
00268 virtual ~Box(void)
00269 {
00270 }
00271
00272 virtual bool containsPoint(const tf::Vector3 &p, bool verbose = false) const;
00273 virtual double computeVolume(void) const;
00274 virtual void computeBoundingSphere(BoundingSphere &sphere) const;
00275 virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const;
00276
00277 protected:
00278
00279 virtual void useDimensions(const shapes::Shape *shape);
00280 virtual void updateInternalData(void);
00281
00282 tf::Vector3 m_center;
00283 tf::Vector3 m_normalL;
00284 tf::Vector3 m_normalW;
00285 tf::Vector3 m_normalH;
00286
00287 tf::Vector3 m_corner1;
00288 tf::Vector3 m_corner2;
00289
00290 double m_length;
00291 double m_width;
00292 double m_height;
00293 double m_length2;
00294 double m_width2;
00295 double m_height2;
00296 double m_radiusB;
00297 double m_radius2;
00298 };
00299
00300
00301
00302
00303
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00354 class ConvexMesh : public Body
00355 {
00356 public:
00357
00358 ConvexMesh(void) : Body()
00359 {
00360 m_type = shapes::MESH;
00361 }
00362
00363 ConvexMesh(const shapes::Shape *shape) : Body()
00364 {
00365 m_type = shapes::MESH;
00366 setDimensions(shape);
00367 }
00368
00369 virtual ~ConvexMesh(void)
00370 {
00371 }
00372
00373 virtual bool containsPoint(const tf::Vector3 &p, bool verbose = false) const;
00374 virtual double computeVolume(void) const;
00375
00376 virtual void computeBoundingSphere(BoundingSphere &sphere) const;
00377 virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const;
00378
00379 protected:
00380
00381 virtual void useDimensions(const shapes::Shape *shape);
00382 virtual void updateInternalData(void);
00383
00384 unsigned int countVerticesBehindPlane(const tf::tfVector4& planeNormal) const;
00385 bool isPointInsidePlanes(const tf::Vector3& point) const;
00386
00387 std::vector<tf::tfVector4> m_planes;
00388 std::vector<tf::Vector3> m_vertices;
00389 std::vector<tf::Vector3> m_scaledVertices;
00390 std::vector<unsigned int> m_triangles;
00391 tf::Transform m_iPose;
00392
00393 tf::Vector3 m_center;
00394 tf::Vector3 m_meshCenter;
00395 double m_radiusB;
00396 double m_radiusBSqr;
00397 double m_meshRadiusB;
00398
00399 tf::Vector3 m_boxOffset;
00400 Box m_boundingBox;
00401 };
00402
00403
00405 Body* createBodyFromShape(const shapes::Shape *shape);
00406
00408 void mergeBoundingSpheres(const std::vector<BoundingSphere> &spheres, BoundingSphere &mergedSphere);
00409
00410 }
00411
00412 #endif