Blender V4.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
60namespace KDL {
61
62#ifdef __GNUC__
63 // so that sin,cos can be overloaded and complete
64 // resolution of overloaded functions work.
65 using ::sin;
66 using ::cos;
67 using ::exp;
68 using ::log;
69 using ::sin;
70 using ::cos;
71 using ::tan;
72 using ::sinh;
73 using ::cosh;
74 using ::pow;
75 using ::sqrt;
76 using ::atan;
77 using ::hypot;
78 using ::asin;
79 using ::acos;
80 using ::tanh;
81 using ::atan2;
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
144template <class T>
145class TI
146{
147 public:
148 typedef const T& Arg;
149};
150
151template <>
152class TI<double> {
153public:
154 typedef double Arg;
155};
156
157template <>
158class TI<int> {
159public:
160 typedef int Arg;
161};
162
163
164
165
166
176extern int STREAMBUFFERSIZE;
177
179extern int MAXLENFILENAME;
180
182extern const double PI;
183
185extern const double deg2rad;
186
188extern const double rad2deg;
189
191extern double epsilon;
192
194extern double epsilon2;
195
197extern int VSIZE;
198
199
200
201#ifndef _MFC_VER
202#undef max
203inline double max(double a,double b) {
204 if (b<a)
205 return a;
206 else
207 return b;
208}
209
210#undef min
211inline 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
230inline double LinComb(double alfa,double a,
231 double beta,double b ) {
232 return alfa*a+beta*b;
233}
234
235inline void LinCombR(double alfa,double a,
236 double beta,double b,double& result ) {
237 result=alfa*a+beta*b;
238 }
239
241inline void SetToZero(double& arg) {
242 arg=0;
243}
244
246inline void SetToIdentity(double& arg) {
247 arg=1;
248}
249
250inline double sign(double arg) {
251 return (arg<0)?(-1):(1);
252}
253
254inline double sqr(double arg) { return arg*arg;}
255inline double Norm(double arg) {
256 return fabs( (double)arg );
257}
258
259
260#if defined(__WIN32__) && !defined(__GNUC__)
261inline double hypot(double y,double x) { return ::_hypot(y,x);}
262inline 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;
268inline bool Equal(double a,double b,double eps=epsilon)
269{
270 double tmp=(a-b);
271 return ((eps>tmp)&& (tmp>-eps) );
272}
273
274inline void random(double& a) {
275 a = 1.98*rand()/(double)RAND_MAX -0.99;
276}
277
278inline void posrandom(double& a) {
279 a = 0.001+0.99*rand()/(double)RAND_MAX;
280}
281
282inline 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//}
288inline 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]
const T & Arg
Arg is used for passing the element to a function.
Definition utility.h:148
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline float2 fabs(const float2 a)
Definition chain.cpp:27
INLINE Rall1d< T, V, S > atan(const Rall1d< T, V, S > &x)
Definition rall1d.h:375
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt=1)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition rall1d.h:311
INLINE S Norm(const Rall1d< T, V, S > &value)
Definition rall1d.h:416
INLINE Rall1d< T, V, S > tan(const Rall1d< T, V, S > &arg)
Definition rall1d.h:327
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
Definition rall1d.h:367
const double deg2rad
the value pi/180
Definition utility.cpp:20
double sign(double arg)
Definition utility.h:250
INLINE Rall1d< T, V, S > hypot(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
Definition rall1d.h:383
INLINE void SetToIdentity(Rall1d< T, V, S > &value)
Definition rall1d.h:460
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
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
Definition rall1d.h:295
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
Definition rall1d.h:429
INLINE Rall1d< T, V, S > sqr(const Rall1d< T, V, S > &arg)
Definition rall1d.h:351
const double rad2deg
the value 180/pi
Definition utility.cpp:21
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
Definition rall1d.h:359
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
int MAXLENFILENAME
maximal length of a file name
Definition utility.cpp:18
const double PI
the value of pi
Definition utility.cpp:19
INLINE Rall1d< T, V, S > sinh(const Rall1d< T, V, S > &arg)
Definition rall1d.h:335
IMETHOD void random(doubleVel &F)
Definition framevel.hpp:44
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
Definition rall1d.h:407
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
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
Definition rall1d.h:399
void SetToZero(Jacobian &jac)
Definition jacobian.cpp:81
IMETHOD Vector addDelta(const Vector &a, const Vector &da, double dt=1)
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 > cosh(const Rall1d< T, V, S > &arg)
Definition rall1d.h:343
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition rall1d.h:319
IMETHOD void posrandom(doubleVel &F)
Definition framevel.hpp:48
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.
Definition utility.cpp:22
IMETHOD bool Equal(const VectorAcc &, const VectorAcc &, double=epsilon)
int STREAMBUFFERSIZE
Definition utility.cpp:17
const btScalar eps
Definition poly34.cpp:11
#define min(a, b)
Definition sort.c:32
float max
ccl_device_inline float beta(float x, float y)
Definition util/math.h:833