Blender  V3.3
utility.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
3  *
4  * \version
5  * ORO_Geometry V0.2
6  *
7  * \par History
8  * - $log$
9  *
10  * \par Release
11  * $Name: $
12  * \file
13  * Included by most lrl-files to provide some general
14  * functions and macro definitions.
15  *
16  * \par history
17  * - changed layout of the comments to accommodate doxygen
18  */
19 
20 
21 #ifndef KDL_UTILITY_H
22 #define KDL_UTILITY_H
23 
24 #include "kdl-config.h"
25 #include <cstdlib>
26 #include <cassert>
27 #include <cmath>
28 
29 #ifdef NDEBUG
30 #undef assert
31 #define assert(e) ((void)0)
32 #endif
33 
35 // configurable options for the frames library.
36 
37 #ifdef KDL_INLINE
38  #ifdef _MSC_VER
39  // Microsoft Visual C
40  #define IMETHOD __forceinline
41  #else
42  // Some other compiler, e.g. gcc
43  #define IMETHOD inline
44  #endif
45 #else
46  #define IMETHOD
47 #endif
48 
49 
50 
53 #ifdef KDL_INDEX_CHECK
54  #define FRAMES_CHECKI(a) assert(a)
55 #else
56  #define FRAMES_CHECKI(a)
57 #endif
58 
59 
60 namespace KDL {
61 
62 #ifdef __GNUC__
63  // so that sin,cos can be overloaded and complete
64  // resolution of overloaded functions work.
82 #endif
83 #ifndef __GNUC__
84  //only real solution : get Rall1d and varia out of namespaces.
85  #pragma warning (disable:4786)
86 
87  inline double sin(double a) {
88  return ::sin(a);
89  }
90 
91  inline double cos(double a) {
92  return ::cos(a);
93  }
94  inline double exp(double a) {
95  return ::exp(a);
96  }
97  inline double log(double a) {
98  return ::log(a);
99  }
100  inline double tan(double a) {
101  return ::tan(a);
102  }
103  inline double cosh(double a) {
104  return ::cosh(a);
105  }
106  inline double sinh(double a) {
107  return ::sinh(a);
108  }
109  inline double sqrt(double a) {
110  return ::sqrt(a);
111  }
112  inline double atan(double a) {
113  return ::atan(a);
114  }
115  inline double acos(double a) {
116  return ::acos(a);
117  }
118  inline double asin(double a) {
119  return ::asin(a);
120  }
121  inline double tanh(double a) {
122  return ::tanh(a);
123  }
124  inline double pow(double a,double b) {
125  return ::pow(a,b);
126  }
127  inline double atan2(double a,double b) {
128  return ::atan2(a,b);
129  }
130 #endif
131 
132 
133 
134 
135 
144 template <class T>
145 class TI
146 {
147  public:
148  typedef const T& Arg;
149 };
150 
151 template <>
152 class TI<double> {
153 public:
154  typedef double Arg;
155 };
156 
157 template <>
158 class TI<int> {
159 public:
160  typedef int Arg;
161 };
162 
163 
164 
165 
166 
176 extern int STREAMBUFFERSIZE;
177 
179 extern int MAXLENFILENAME;
180 
182 extern const double PI;
183 
185 extern const double deg2rad;
186 
188 extern const double rad2deg;
189 
191 extern double epsilon;
192 
194 extern double epsilon2;
195 
197 extern int VSIZE;
198 
199 
200 
201 #ifndef _MFC_VER
202 #undef max
203 inline double max(double a,double b) {
204  if (b<a)
205  return a;
206  else
207  return b;
208 }
209 
210 #undef min
211 inline double min(double a,double b) {
212  if (b<a)
213  return b;
214  else
215  return a;
216 }
217 #endif
218 
219 
220 #ifdef _MSC_VER
221  //#pragma inline_depth( 255 )
222  //#pragma inline_recursion( on )
223  #define INLINE __forceinline
224  //#define INLINE inline
225 #else
226  #define INLINE inline
227 #endif
228 
229 
230 inline double LinComb(double alfa,double a,
231  double beta,double b ) {
232  return alfa*a+beta*b;
233 }
234 
235 inline void LinCombR(double alfa,double a,
236  double beta,double b,double& result ) {
237  result=alfa*a+beta*b;
238  }
239 
241 inline void SetToZero(double& arg) {
242  arg=0;
243 }
244 
246 inline void SetToIdentity(double& arg) {
247  arg=1;
248 }
249 
250 inline double sign(double arg) {
251  return (arg<0)?(-1):(1);
252 }
253 
254 inline double sqr(double arg) { return arg*arg;}
255 inline double Norm(double arg) {
256  return fabs( (double)arg );
257 }
258 
259 
260 #if defined(__WIN32__) && !defined(__GNUC__)
261 inline double hypot(double y,double x) { return ::_hypot(y,x);}
262 inline double abs(double x) { return ::fabs(x);}
263 #endif
264 
265 // compares whether 2 doubles are equal in an eps-interval.
266 // Does not check whether a or b represents numbers
267 // On VC6, if a/b is -INF, it returns false;
268 inline bool Equal(double a,double b,double eps=epsilon)
269 {
270  double tmp=(a-b);
271  return ((eps>tmp)&& (tmp>-eps) );
272 }
273 
274 inline void random(double& a) {
275  a = 1.98*rand()/(double)RAND_MAX -0.99;
276 }
277 
278 inline void posrandom(double& a) {
279  a = 0.001+0.99*rand()/(double)RAND_MAX;
280 }
281 
282 inline double diff(double a,double b,double dt) {
283  return (b-a)/dt;
284 }
285 //inline float diff(float a,float b,double dt) {
286 //return (b-a)/dt;
287 //}
288 inline double addDelta(double a,double da,double dt) {
289  return a+da*dt;
290 }
291 
292 //inline float addDelta(float a,float da,double dt) {
293 // return a+da*dt;
294 //}
295 
296 
297 }
298 
299 
300 
301 #endif
typedef double(DMatrix)[4][4]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
const T & Arg
Arg is used for passing the element to a function.
Definition: utility.h:148
ccl_device_inline float2 fabs(const float2 &a)
Definition: math_float2.h:222
#define T
static unsigned a[3]
Definition: RandGen.cpp:78
Definition: chain.cpp:27
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt=1)
INLINE S Norm(const Rall1d< T, V, S > &value)
Definition: rall1d.h:416
double atan2(double a, double b)
Definition: utility.h:127
double sinh(double a)
Definition: utility.h:106
const double deg2rad
the value pi/180
Definition: utility.cpp:20
INLINE Rall1d< T, V, S > sinh(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:335
double sign(double arg)
Definition: utility.h:250
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > cosh(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:343
double exp(double a)
Definition: utility.h:94
double tan(double a)
Definition: utility.h:100
INLINE void SetToIdentity(Rall1d< T, V, S > &value)
Definition: rall1d.h:460
double sqrt(double a)
Definition: utility.h:109
double acos(double a)
Definition: utility.h:115
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
Definition: rall1d.h:359
INLINE Rall1d< T, V, S > log(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:303
INLINE Rall1d< T, V, S > tanh(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:422
double pow(double a, double b)
Definition: utility.h:124
const double rad2deg
the value 180/pi
Definition: utility.cpp:21
int MAXLENFILENAME
maximal length of a file name
Definition: utility.cpp:18
double sin(double a)
Definition: utility.h:87
double tanh(double a)
Definition: utility.h:121
double cos(double a)
Definition: utility.h:91
const double PI
the value of pi
Definition: utility.cpp:19
IMETHOD void random(doubleVel &F)
Definition: framevel.hpp:44
int VSIZE
the number of derivatives used in the RN-... objects.
double epsilon2
power or 2 of epsilon
Definition: utility.cpp:23
INLINE Rall1d< T, V, S > asin(const Rall1d< T, V, S > &x)
Definition: rall1d.h:391
void SetToZero(Jacobian &jac)
Definition: jacobian.cpp:81
double log(double a)
Definition: utility.h:97
IMETHOD Vector addDelta(const Vector &a, const Vector &da, double dt=1)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:367
double min(double a, double b)
Definition: utility.h:211
INLINE void LinCombR(S alfa, const Rall1d< T, V, S > &a, const T &beta, const Rall1d< T, V, S > &b, Rall1d< T, V, S > &result)
Definition: rall1d.h:446
INLINE Rall1d< T, V, S > atan(const Rall1d< T, V, S > &x)
Definition: rall1d.h:375
double cosh(double a)
Definition: utility.h:103
IMETHOD void posrandom(doubleVel &F)
Definition: framevel.hpp:48
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
Definition: rall1d.h:399
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.
Definition: utility.cpp:22
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311
double max(double a, double b)
Definition: utility.h:203
INLINE Rall1d< T, V, S > tan(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:327
IMETHOD bool Equal(const VectorAcc &, const VectorAcc &, double=epsilon)
INLINE Rall1d< T, V, S > LinComb(S alfa, const Rall1d< T, V, S > &a, const T &beta, const Rall1d< T, V, S > &b)
Definition: rall1d.h:437
double asin(double a)
Definition: utility.h:118
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
Definition: rall1d.h:429
double atan(double a)
Definition: utility.h:112
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:295
INLINE Rall1d< T, V, S > hypot(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
Definition: rall1d.h:383
INLINE Rall1d< T, V, S > sqr(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:351
int STREAMBUFFERSIZE
Definition: utility.cpp:17
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
Definition: rall1d.h:407
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
const btScalar eps
Definition: poly34.cpp:11
ccl_device_inline float beta(float x, float y)
Definition: util/math.h:775