geometric_shapes.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, 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 Willow Garage, Inc. 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 
00038 #ifndef FCL_GEOMETRIC_SHAPES_H
00039 #define FCL_GEOMETRIC_SHAPES_H
00040 
00041 #include "fcl/collision_object.h"
00042 #include "fcl/math/vec_3f.h"
00043 #include <string.h>
00044 
00045 namespace fcl
00046 {
00047 
00049 class ShapeBase : public CollisionGeometry
00050 {
00051 public:
00052   ShapeBase() {}
00053 
00055   OBJECT_TYPE getObjectType() const { return OT_GEOM; }
00056 };
00057 
00059 class Triangle2 : public ShapeBase
00060 {
00061 public:
00062   Triangle2(const Vec3f& a_, const Vec3f& b_, const Vec3f& c_) : ShapeBase(), a(a_), b(b_), c(c_)
00063   {
00064   }
00065 
00067   void computeLocalAABB();
00068   
00069   NODE_TYPE getNodeType() const { return GEOM_TRIANGLE; }
00070 
00071   Vec3f a, b, c;
00072 };
00073 
00075 class Box : public ShapeBase
00076 {
00077 public:
00078   Box(FCL_REAL x, FCL_REAL y, FCL_REAL z) : ShapeBase(), side(x, y, z)
00079   {
00080   }
00081 
00082   Box(const Vec3f& side_) : ShapeBase(), side(side_) 
00083   {
00084   }
00085 
00086   Box() {}
00087 
00089   Vec3f side;
00090 
00092   void computeLocalAABB();
00093 
00095   NODE_TYPE getNodeType() const { return GEOM_BOX; }
00096 };
00097 
00099 class Sphere : public ShapeBase
00100 {
00101 public:
00102   Sphere(FCL_REAL radius_) : ShapeBase(), radius(radius_)
00103   {
00104   }
00105   
00107   FCL_REAL radius;
00108 
00110   void computeLocalAABB();
00111 
00113   NODE_TYPE getNodeType() const { return GEOM_SPHERE; }
00114 };
00115 
00117 class Capsule : public ShapeBase
00118 {
00119 public:
00120   Capsule(FCL_REAL radius_, FCL_REAL lz_) : ShapeBase(), radius(radius_), lz(lz_)
00121   {
00122   }
00123 
00125   FCL_REAL radius;
00126 
00128   FCL_REAL lz;
00129 
00131   void computeLocalAABB();
00132 
00134   NODE_TYPE getNodeType() const { return GEOM_CAPSULE; }
00135 };
00136 
00138 class Cone : public ShapeBase
00139 {
00140 public:
00141   Cone(FCL_REAL radius_, FCL_REAL lz_) : ShapeBase(), radius(radius_), lz(lz_)
00142   {
00143   }
00144 
00146   FCL_REAL radius;
00147 
00149   FCL_REAL lz;
00150 
00152   void computeLocalAABB();
00153 
00155   NODE_TYPE getNodeType() const { return GEOM_CONE; }
00156 };
00157 
00159 class Cylinder : public ShapeBase
00160 {
00161 public:
00162   Cylinder(FCL_REAL radius_, FCL_REAL lz_) : ShapeBase(), radius(radius_), lz(lz_)
00163   {
00164   }
00165 
00166   
00168   FCL_REAL radius;
00169 
00171   FCL_REAL lz;
00172 
00174   void computeLocalAABB();
00175 
00177   NODE_TYPE getNodeType() const { return GEOM_CYLINDER; }
00178 };
00179 
00181 class Convex : public ShapeBase
00182 {
00183 public:
00185   Convex(Vec3f* plane_normals_,
00186          FCL_REAL* plane_dis_,
00187          int num_planes_,
00188          Vec3f* points_,
00189          int num_points_,
00190          int* polygons_) : ShapeBase()
00191   {
00192     plane_normals = plane_normals_;
00193     plane_dis = plane_dis_;
00194     num_planes = num_planes_;
00195     points = points_;
00196     polygons = polygons_;
00197     edges = NULL;
00198 
00199     Vec3f sum;
00200     for(int i = 0; i < num_points; ++i)
00201     {
00202       sum += points[i];
00203     }
00204 
00205     center = sum * (FCL_REAL)(1.0 / num_points);
00206 
00207     fillEdges();
00208   }
00209 
00211   Convex(const Convex& other) : ShapeBase(other)
00212   {
00213     plane_normals = other.plane_normals;
00214     plane_dis = other.plane_dis;
00215     num_planes = other.num_planes;
00216     points = other.points;
00217     polygons = other.polygons;
00218     edges = new Edge[other.num_edges];
00219     memcpy(edges, other.edges, sizeof(Edge) * num_edges);
00220   }
00221 
00222   ~Convex()
00223   {
00224     delete [] edges;
00225   }
00226 
00228   void computeLocalAABB();
00229 
00231   NODE_TYPE getNodeType() const { return GEOM_CONVEX; }
00232 
00233   
00234   Vec3f* plane_normals;
00235   FCL_REAL* plane_dis;
00236 
00239   int* polygons;
00240 
00241   Vec3f* points;
00242   int num_points;
00243   int num_edges;
00244   int num_planes;
00245 
00246   struct Edge
00247   {
00248     int first, second;
00249   };
00250 
00251   Edge* edges;
00252 
00254   Vec3f center;
00255 
00256 protected:
00258   void fillEdges();
00259 };
00260 
00261 
00265 class Halfspace : public ShapeBase
00266 {
00267 public:
00269   Halfspace(const Vec3f& n_, FCL_REAL d_) : ShapeBase(), n(n_), d(d_)
00270   {
00271     unitNormalTest();
00272   }
00273 
00275   Halfspace(FCL_REAL a, FCL_REAL b, FCL_REAL c, FCL_REAL d_) : ShapeBase(), n(a, b, c), d(d_)
00276   {
00277     unitNormalTest();
00278   }
00279 
00280   Halfspace() : ShapeBase(), n(1, 0, 0), d(0)
00281   {
00282   }
00283 
00284   FCL_REAL signedDistance(const Vec3f& p) const
00285   {
00286     return n.dot(p) - d;
00287   }
00288 
00289   FCL_REAL distance(const Vec3f& p) const
00290   {
00291     return std::abs(n.dot(p) - d);
00292   }
00293 
00295   void computeLocalAABB();
00296 
00298   NODE_TYPE getNodeType() const { return GEOM_HALFSPACE; }
00299   
00301   Vec3f n;
00302   
00304   FCL_REAL d;
00305 
00306 protected:
00307 
00309   void unitNormalTest();
00310 };
00311 
00313 class Plane : public ShapeBase
00314 {
00315 public:
00317   Plane(const Vec3f& n_, FCL_REAL d_) : ShapeBase(), n(n_), d(d_) 
00318   { 
00319     unitNormalTest(); 
00320   }
00321   
00323   Plane(FCL_REAL a, FCL_REAL b, FCL_REAL c, FCL_REAL d_) : ShapeBase(), n(a, b, c), d(d_)
00324   {
00325     unitNormalTest();
00326   }
00327 
00328   Plane() : ShapeBase(), n(1, 0, 0), d(0)
00329   {}
00330 
00331   FCL_REAL signedDistance(const Vec3f& p) const
00332   {
00333     return n.dot(p) - d;
00334   }
00335 
00336   FCL_REAL distance(const Vec3f& p) const
00337   {
00338     return std::abs(n.dot(p) - d);
00339   }
00340 
00342   void computeLocalAABB();
00343 
00345   NODE_TYPE getNodeType() const { return GEOM_PLANE; }
00346 
00348   Vec3f n;
00349 
00351   FCL_REAL d;
00352 
00353 protected:
00354   
00356   void unitNormalTest();
00357 };
00358 
00359 
00360 }
00361 
00362 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


fcl
Author(s): Jia Pan
autogenerated on Tue Jan 15 2013 16:05:30