All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends

gjk_libccd.h

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_GJK_LIBCCD_H
00039 #define FCL_GJK_LIBCCD_H
00040 
00041 #include "fcl/shape/geometric_shapes.h"
00042 #include "fcl/math/transform.h"
00043 
00044 #include <ccd/ccd.h>
00045 #include <ccd/quat.h>
00046 
00047 namespace fcl
00048 {
00049 
00050 namespace details
00051 {
00052 
00054 typedef void (*GJKSupportFunction)(const void* obj, const ccd_vec3_t* dir_, ccd_vec3_t* v);
00055 typedef void (*GJKCenterFunction)(const void* obj, ccd_vec3_t* c);
00056 
00058 template<typename T>
00059 class GJKInitializer
00060 {
00061 public:
00063   static GJKSupportFunction getSupportFunction() { return NULL; }
00064 
00066   static GJKCenterFunction getCenterFunction() { return NULL; }
00067 
00071   static void* createGJKObject(const T& s, const Transform3f& tf) { return NULL; }
00072 
00074   static void deleteGJKObject(void* o) {}
00075 };
00076 
00078 template<>
00079 class GJKInitializer<Cylinder>
00080 {
00081 public:
00082   static GJKSupportFunction getSupportFunction();
00083   static GJKCenterFunction getCenterFunction();
00084   static void* createGJKObject(const Cylinder& s, const Transform3f& tf);
00085   static void deleteGJKObject(void* o);
00086 };
00087 
00089 template<>
00090 class GJKInitializer<Sphere>
00091 {
00092 public:
00093   static GJKSupportFunction getSupportFunction();
00094   static GJKCenterFunction getCenterFunction();
00095   static void* createGJKObject(const Sphere& s, const Transform3f& tf);
00096   static void deleteGJKObject(void* o);
00097 };
00098 
00100 template<>
00101 class GJKInitializer<Box>
00102 {
00103 public:
00104   static GJKSupportFunction getSupportFunction();
00105   static GJKCenterFunction getCenterFunction();
00106   static void* createGJKObject(const Box& s, const Transform3f& tf);
00107   static void deleteGJKObject(void* o);
00108 };
00109 
00111 template<>
00112 class GJKInitializer<Capsule>
00113 {
00114 public:
00115   static GJKSupportFunction getSupportFunction();
00116   static GJKCenterFunction getCenterFunction();
00117   static void* createGJKObject(const Capsule& s, const Transform3f& tf);
00118   static void deleteGJKObject(void* o);
00119 };
00120 
00122 template<>
00123 class GJKInitializer<Cone>
00124 {
00125 public:
00126   static GJKSupportFunction getSupportFunction();
00127   static GJKCenterFunction getCenterFunction();
00128   static void* createGJKObject(const Cone& s, const Transform3f& tf);
00129   static void deleteGJKObject(void* o);
00130 };
00131 
00133 template<>
00134 class GJKInitializer<Convex>
00135 {
00136 public:
00137   static GJKSupportFunction getSupportFunction();
00138   static GJKCenterFunction getCenterFunction();
00139   static void* createGJKObject(const Convex& s, const Transform3f& tf);
00140   static void deleteGJKObject(void* o);
00141 };
00142 
00144 GJKSupportFunction triGetSupportFunction();
00145 
00146 GJKCenterFunction triGetCenterFunction();
00147 
00148 void* triCreateGJKObject(const Vec3f& P1, const Vec3f& P2, const Vec3f& P3);
00149 
00150 void* triCreateGJKObject(const Vec3f& P1, const Vec3f& P2, const Vec3f& P3, const Transform3f& tf);
00151 
00152 void triDeleteGJKObject(void* o);
00153 
00155 bool GJKCollide(void* obj1, ccd_support_fn supp1, ccd_center_fn cen1,
00156                 void* obj2, ccd_support_fn supp2, ccd_center_fn cen2,
00157                 unsigned int max_iterations, FCL_REAL tolerance,
00158                 Vec3f* contact_points, FCL_REAL* penetration_depth, Vec3f* normal);
00159 
00160 bool GJKDistance(void* obj1, ccd_support_fn supp1,
00161                  void* obj2, ccd_support_fn supp2,
00162                  unsigned int max_iterations, FCL_REAL tolerance,
00163                  FCL_REAL* dist);
00164 
00165 
00166 } // details
00167 
00168 
00169 }
00170 
00171 #endif