Blender V2.61 - r43446

utility.h

Go to the documentation of this file.
00001 /***************************************************************************** 
00002  *  \author 
00003  *      Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
00004  *
00005  *  \version 
00006  *      ORO_Geometry V0.2
00007  *
00008  *  \par History
00009  *      - $log$
00010  *
00011  *  \par Release
00012  *      $Name:  $ 
00013  *  \file
00014  *    Included by most lrl-files to provide some general
00015  *    functions and macro definitions.
00016  *  
00017  *  \par history
00018  *   - changed layout of the comments to accomodate doxygen
00019  */
00020 
00021 
00022 #ifndef KDL_UTILITY_H
00023 #define KDL_UTILITY_H
00024 
00025 #include "kdl-config.h"
00026 #include <cstdlib>
00027 #include <cassert>
00028 #include <cmath>
00029 
00030 
00032 // configurable options for the frames library.
00033 
00034 #ifdef KDL_INLINE
00035     #ifdef _MSC_VER
00036         // Microsoft Visual C
00037         #define IMETHOD __forceinline
00038     #else
00039         // Some other compiler, e.g. gcc
00040         #define IMETHOD inline
00041     #endif
00042 #else
00043     #define IMETHOD
00044 #endif
00045 
00046 
00047 
00050 #ifdef KDL_INDEX_CHECK
00051     #define FRAMES_CHECKI(a) assert(a)
00052 #else
00053     #define FRAMES_CHECKI(a)
00054 #endif
00055 
00056 
00057 namespace KDL {
00058 
00059 #ifdef __GNUC__
00060     // so that sin,cos can be overloaded and complete 
00061     // resolution of overloaded functions work.
00062     using ::sin;
00063     using ::cos;
00064     using ::exp;
00065     using ::log;
00066     using ::sin;
00067     using ::cos;
00068     using ::tan;
00069     using ::sinh;
00070     using ::cosh;
00071     using ::pow;
00072     using ::sqrt;
00073     using ::atan;
00074     using ::hypot;
00075     using ::asin;
00076     using ::acos;
00077     using ::tanh;
00078     using ::atan2;
00079 #endif
00080 #ifndef __GNUC__
00081     //only real solution : get Rall1d and varia out of namespaces.
00082     #pragma warning (disable:4786)
00083 
00084     inline double sin(double a) {
00085         return ::sin(a);
00086     }
00087     
00088     inline double cos(double a) {
00089         return ::cos(a);
00090     }
00091     inline double exp(double a) {
00092         return ::exp(a);
00093     }
00094     inline double log(double a) {
00095         return ::log(a);
00096     }
00097     inline double tan(double a) {
00098         return ::tan(a);
00099     }
00100     inline double cosh(double a) {
00101         return ::cosh(a);
00102     }
00103     inline double sinh(double a) {
00104         return ::sinh(a);
00105     }
00106     inline double sqrt(double a) {
00107         return ::sqrt(a);
00108     }
00109     inline double atan(double a) {
00110         return ::atan(a);
00111     }
00112     inline double acos(double a) {
00113         return ::acos(a);
00114     }
00115     inline double asin(double a) {
00116         return ::asin(a);
00117     }
00118     inline double tanh(double a) {
00119         return ::tanh(a);
00120     }
00121     inline double pow(double a,double b) {
00122         return ::pow(a,b);
00123     }
00124     inline double atan2(double a,double b) {
00125         return ::atan2(a,b);
00126     }
00127 #endif  
00128 
00129 
00130 
00131 
00132 
00141 template <class T>
00142 class TI
00143 {
00144     public:
00145         typedef const T& Arg; 
00146 };
00147 
00148 template <>
00149 class TI<double> {
00150 public:
00151     typedef double Arg;
00152 };
00153 
00154 template <>
00155 class TI<int> {
00156 public:
00157     typedef int Arg;
00158 };
00159 
00160 
00161 
00162 
00163 
00172 
00173 extern int          STREAMBUFFERSIZE;
00174 
00176 extern int          MAXLENFILENAME;
00177 
00179 extern const double PI;
00180 
00182 extern const double deg2rad;
00183 
00185 extern const double rad2deg;
00186 
00188 extern double     epsilon;
00189 
00191 extern double     epsilon2;
00192 
00194 extern int          VSIZE;
00195 
00196 
00197 
00198 #ifndef _MFC_VER
00199 #undef max
00200 inline double max(double a,double b) {
00201     if (b<a) 
00202         return a;
00203     else
00204         return b;
00205 }
00206 
00207 #undef min
00208 inline double min(double a,double b) {
00209     if (b<a) 
00210         return b;
00211     else
00212         return a;
00213 }
00214 #endif
00215 
00216 
00217 #ifdef _MSC_VER
00218     //#pragma inline_depth( 255 )
00219     //#pragma inline_recursion( on )
00220     #define INLINE __forceinline
00221     //#define INLINE inline
00222 #else
00223     #define INLINE inline
00224 #endif
00225 
00226 
00227 inline double LinComb(double alfa,double a,
00228         double beta,double b ) {
00229             return alfa*a+beta*b;
00230 }
00231 
00232 inline void LinCombR(double alfa,double a,
00233         double beta,double b,double& result ) {
00234             result=alfa*a+beta*b;
00235          }
00236 
00238 inline void SetToZero(double& arg) {
00239     arg=0;
00240 }
00241 
00243 inline void SetToIdentity(double& arg) {
00244     arg=1;
00245 }
00246 
00247 inline double sign(double arg) {
00248     return (arg<0)?(-1):(1);
00249 }
00250 
00251 inline double sqr(double arg) { return arg*arg;}
00252 inline double Norm(double arg) {
00253     return fabs(  (double)arg );
00254 }
00255 
00256 
00257 #if defined(__WIN32__) && !defined(__GNUC__)
00258 inline double hypot(double y,double x) { return ::_hypot(y,x);}
00259 inline double abs(double x) { return ::fabs(x);}
00260 #endif
00261 
00262 // compares whether 2 doubles are equal in an eps-interval.
00263 // Does not check whether a or b represents numbers
00264 // On VC6, if a/b is -INF, it returns false;
00265 inline bool Equal(double a,double b,double eps=epsilon)
00266 {
00267     double tmp=(a-b);
00268     return ((eps>tmp)&& (tmp>-eps) );
00269 }
00270 
00271 inline void random(double& a) {
00272     a = 1.98*rand()/(double)RAND_MAX -0.99;
00273 }
00274 
00275 inline void posrandom(double& a) {
00276     a = 0.001+0.99*rand()/(double)RAND_MAX;
00277 }
00278 
00279 inline double diff(double a,double b,double dt) {
00280     return (b-a)/dt;
00281 }
00282 //inline float diff(float a,float b,double dt) {
00283 //return (b-a)/dt;
00284 //}
00285 inline double addDelta(double a,double da,double dt) {
00286     return a+da*dt;
00287 }
00288 
00289 //inline float addDelta(float a,float da,double dt) {
00290 //  return a+da*dt;
00291 //}
00292 
00293 
00294 }
00295 
00296 
00297 
00298 #endif