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