bodies.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 * 
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 * 
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 * 
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 * 
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
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 // #include <BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h>
00044 // #include <BulletCollision/CollisionShapes/btTriangleMesh.h>
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); // (x, y, z) = (length, width, height)      
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     class Mesh : public Body
00302     {   
00303     public:
00305         Mesh(void) : Body()
00306         {
00307             m_type = shapes::MESH;
00308             m_btMeshShape = NULL;
00309             m_btMesh = NULL;
00310         }
00311         
00312         Mesh(const shapes::Shape *shape) : Body()
00313         {
00314             m_type = shapes::MESH;      
00315             m_btMeshShape = NULL;
00316             m_btMesh = NULL;
00317             setDimensions(shape);
00318         }
00319         
00320         virtual ~Mesh(void)
00321         {
00322             if (m_btMeshShape)
00323                 delete m_btMeshShape;
00324             if (m_btMesh)
00325                 delete m_btMesh;
00326         }
00327         
00328         \\\ \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.
00329         virtual bool containsPoint(const tf::Vector3 &p) const;
00330 
00331         \\\ \brief This function is approximate. It returns the volume of the AABB enclosing the shape 
00332         virtual double computeVolume(void) const;
00333         virtual void computeBoundingSphere(BoundingSphere &sphere) const;
00334         virtual bool intersectsRay(const tf::Vector3& origin, const tf::Vector3 &dir, std::vector<tf::Vector3> *intersections = NULL, unsigned int count = 0) const;
00335         
00336     protected:
00337 
00338         virtual void useDimensions(const shapes::Shape *shape);
00339         virtual void updateInternalData(void);
00340         
00341         btBvhTriangleMeshShape  *m_btMeshShape;
00342         btTriangleMesh          *m_btMesh;
00343         tf::Transform              m_iPose;
00344         tf::Vector3                m_center;
00345         tf::Vector3                m_aabbMin;
00346         tf::Vector3                m_aabbMax;
00347         double                   m_radiusB;
00348         double                   m_radiusBSqr;
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


pr2_navigation_self_filter
Author(s): Eitan Marder-Eppstein
autogenerated on Fri Apr 5 2019 02:18:37