Scalar.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*
3 Copyright (c) 2003-2009 Erwin Coumans http://bullet.googlecode.com
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 
17 
18 #ifndef TF2_SCALAR_H
19 #define TF2_SCALAR_H
20 
21 #ifdef TF2_MANAGED_CODE
22 //Aligned data types not supported in managed code
23 #pragma unmanaged
24 #endif
25 
26 
27 #include <math.h>
28 #include <stdlib.h>//size_t for MSVC 6.0
29 #include <cstdlib>
30 #include <cfloat>
31 #include <float.h>
32 
33 #if defined(DEBUG) || defined (_DEBUG)
34 #define TF2_DEBUG
35 #endif
36 
37 
38 #ifdef _WIN32
39 
40  #if defined(__MINGW32__) || defined(__CYGWIN__) || (defined (_MSC_VER) && _MSC_VER < 1300)
41 
42  #define TF2SIMD_FORCE_INLINE inline
43  #define ATTRIBUTE_ALIGNED16(a) a
44  #define ATTRIBUTE_ALIGNED64(a) a
45  #define ATTRIBUTE_ALIGNED128(a) a
46  #else
47  //#define TF2_HAS_ALIGNED_ALLOCATOR
48  #pragma warning(disable : 4324) // disable padding warning
49 // #pragma warning(disable:4530) // Disable the exception disable but used in MSCV Stl warning.
50 // #pragma warning(disable:4996) //Turn off warnings about deprecated C routines
51 // #pragma warning(disable:4786) // Disable the "debug name too long" warning
52 
53  #define TF2SIMD_FORCE_INLINE __forceinline
54  #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
55  #define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a
56  #define ATTRIBUTE_ALIGNED128(a) __declspec (align(128)) a
57  #ifdef _XBOX
58  #define TF2_USE_VMX128
59 
60  #include <ppcintrinsics.h>
61  #define TF2_HAVE_NATIVE_FSEL
62  #define tf2Fsel(a,b,c) __fsel((a),(b),(c))
63  #else
64 
65 
66  #endif//_XBOX
67 
68  #endif //__MINGW32__
69 
70  #include <assert.h>
71 #ifdef TF2_DEBUG
72  #define tf2Assert assert
73 #else
74  #define tf2Assert(x)
75 #endif
76  //tf2FullAssert is optional, slows down a lot
77  #define tf2FullAssert(x)
78 
79  #define tf2Likely(_c) _c
80  #define tf2Unlikely(_c) _c
81 
82 #else
83 
84 #if defined (__CELLOS_LV2__)
85  #define TF2SIMD_FORCE_INLINE inline
86  #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
87  #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
88  #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
89  #ifndef assert
90  #include <assert.h>
91  #endif
92 #ifdef TF2_DEBUG
93  #define tf2Assert assert
94 #else
95  #define tf2Assert(x)
96 #endif
97  //tf2FullAssert is optional, slows down a lot
98  #define tf2FullAssert(x)
99 
100  #define tf2Likely(_c) _c
101  #define tf2Unlikely(_c) _c
102 
103 #else
104 
105 #ifdef USE_LIBSPE2
106 
107  #define TF2SIMD_FORCE_INLINE __inline
108  #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
109  #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
110  #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
111  #ifndef assert
112  #include <assert.h>
113  #endif
114 #ifdef TF2_DEBUG
115  #define tf2Assert assert
116 #else
117  #define tf2Assert(x)
118 #endif
119  //tf2FullAssert is optional, slows down a lot
120  #define tf2FullAssert(x)
121 
122 
123  #define tf2Likely(_c) __builtin_expect((_c), 1)
124  #define tf2Unlikely(_c) __builtin_expect((_c), 0)
125 
126 
127 #else
128  //non-windows systems
129 
130  #define TF2SIMD_FORCE_INLINE inline
131  #define ATTRIBUTE_ALIGNED16(a) a
136  #define ATTRIBUTE_ALIGNED64(a) a
137  #define ATTRIBUTE_ALIGNED128(a) a
138  #ifndef assert
139  #include <assert.h>
140  #endif
141 
142 #if defined(DEBUG) || defined (_DEBUG)
143  #define tf2Assert assert
144 #else
145  #define tf2Assert(x)
146 #endif
147 
148  //tf2FullAssert is optional, slows down a lot
149  #define tf2FullAssert(x)
150  #define tf2Likely(_c) _c
151  #define tf2Unlikely(_c) _c
152 
153 #endif // LIBSPE2
154 
155 #endif //__CELLOS_LV2__
156 #endif
157 
158 
160 typedef double tf2Scalar;
161 //this number could be bigger in double precision
162 #define TF2_LARGE_FLOAT 1e30
163 
164 
165 #define TF2_DECLARE_ALIGNED_ALLOCATOR() \
166  TF2SIMD_FORCE_INLINE void* operator new(size_t sizeInBytes) { return tf2AlignedAlloc(sizeInBytes,16); } \
167  TF2SIMD_FORCE_INLINE void operator delete(void* ptr) { tf2AlignedFree(ptr); } \
168  TF2SIMD_FORCE_INLINE void* operator new(size_t, void* ptr) { return ptr; } \
169  TF2SIMD_FORCE_INLINE void operator delete(void*, void*) { } \
170  TF2SIMD_FORCE_INLINE void* operator new[](size_t sizeInBytes) { return tf2AlignedAlloc(sizeInBytes,16); } \
171  TF2SIMD_FORCE_INLINE void operator delete[](void* ptr) { tf2AlignedFree(ptr); } \
172  TF2SIMD_FORCE_INLINE void* operator new[](size_t, void* ptr) { return ptr; } \
173  TF2SIMD_FORCE_INLINE void operator delete[](void*, void*) { } \
174 
175 
176 
177 
183 TF2SIMD_FORCE_INLINE tf2Scalar tf2Acos(tf2Scalar x) { if (x<tf2Scalar(-1)) x=tf2Scalar(-1); if (x>tf2Scalar(1)) x=tf2Scalar(1); return acos(x); }
184 TF2SIMD_FORCE_INLINE tf2Scalar tf2Asin(tf2Scalar x) { if (x<tf2Scalar(-1)) x=tf2Scalar(-1); if (x>tf2Scalar(1)) x=tf2Scalar(1); return asin(x); }
191 
192 
193 #define TF2SIMD_2_PI tf2Scalar(6.283185307179586232)
194 #define TF2SIMD_PI (TF2SIMD_2_PI * tf2Scalar(0.5))
195 #define TF2SIMD_HALF_PI (TF2SIMD_2_PI * tf2Scalar(0.25))
196 #define TF2SIMD_RADS_PER_DEG (TF2SIMD_2_PI / tf2Scalar(360.0))
197 #define TF2SIMD_DEGS_PER_RAD (tf2Scalar(360.0) / TF2SIMD_2_PI)
198 #define TF2SIMDSQRT12 tf2Scalar(0.7071067811865475244008443621048490)
199 
200 #define tf2RecipSqrt(x) ((tf2Scalar)(tf2Scalar(1.0)/tf2Sqrt(tf2Scalar(x)))) /* reciprocal square root */
201 
202 
203 #define TF2SIMD_EPSILON DBL_EPSILON
204 #define TF2SIMD_INFINITY DBL_MAX
205 
207 {
208  tf2Scalar coeff_1 = TF2SIMD_PI / 4.0f;
209  tf2Scalar coeff_2 = 3.0f * coeff_1;
210  tf2Scalar abs_y = tf2Fabs(y);
212  if (x >= 0.0f) {
213  tf2Scalar r = (x - abs_y) / (x + abs_y);
214  angle = coeff_1 - coeff_1 * r;
215  } else {
216  tf2Scalar r = (x + abs_y) / (abs_y - x);
217  angle = coeff_2 - coeff_1 * r;
218  }
219  return (y < 0.0f) ? -angle : angle;
220 }
221 
223 
225  return (((a) <= eps) && !((a) < -eps));
226 }
228  return (!((a) <= eps));
229 }
230 
231 
233  return x < tf2Scalar(0.0) ? 1 : 0;
234 }
235 
238 
239 #define TF2_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
240 
241 #ifndef tf2Fsel
243 {
244  return a >= 0 ? b : c;
245 }
246 #endif
247 #define tf2Fsels(a,b,c) (tf2Scalar)tf2Fsel(a,b,c)
248 
249 
251 {
252  long int i = 1;
253  const char *p = (const char *) &i;
254  if (p[0] == 1) // Lowest address contains the least significant byte
255  return true;
256  else
257  return false;
258 }
259 
260 
261 
264 TF2SIMD_FORCE_INLINE unsigned tf2Select(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero)
265 {
266  // Set testNz to 0xFFFFFFFF if condition is nonzero, 0x00000000 if condition is zero
267  // Rely on positive value or'ed with its negative having sign bit on
268  // and zero value or'ed with its negative (which is still zero) having sign bit off
269  // Use arithmetic shift right, shifting the sign bit through all 32 bits
270  unsigned testNz = (unsigned)(((int)condition | -(int)condition) >> 31);
271  unsigned testEqz = ~testNz;
272  return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
273 }
274 TF2SIMD_FORCE_INLINE int tf2Select(unsigned condition, int valueIfConditionNonZero, int valueIfConditionZero)
275 {
276  unsigned testNz = (unsigned)(((int)condition | -(int)condition) >> 31);
277  unsigned testEqz = ~testNz;
278  return static_cast<int>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
279 }
280 TF2SIMD_FORCE_INLINE float tf2Select(unsigned condition, float valueIfConditionNonZero, float valueIfConditionZero)
281 {
282 #ifdef TF2_HAVE_NATIVE_FSEL
283  return (float)tf2Fsel((tf2Scalar)condition - tf2Scalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
284 #else
285  return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
286 #endif
287 }
288 
289 template<typename T> TF2SIMD_FORCE_INLINE void tf2Swap(T& a, T& b)
290 {
291  T tmp = a;
292  a = b;
293  b = tmp;
294 }
295 
296 
297 //PCK: endian swapping functions
298 TF2SIMD_FORCE_INLINE unsigned tf2SwapEndian(unsigned val)
299 {
300  return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
301 }
302 
303 TF2SIMD_FORCE_INLINE unsigned short tf2SwapEndian(unsigned short val)
304 {
305  return static_cast<unsigned short>(((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
306 }
307 
309 {
310  return tf2SwapEndian((unsigned)val);
311 }
312 
313 TF2SIMD_FORCE_INLINE unsigned short tf2SwapEndian(short val)
314 {
315  return tf2SwapEndian((unsigned short) val);
316 }
317 
325 {
326  unsigned int a = 0;
327  unsigned char *dst = (unsigned char *)&a;
328  unsigned char *src = (unsigned char *)&d;
329 
330  dst[0] = src[3];
331  dst[1] = src[2];
332  dst[2] = src[1];
333  dst[3] = src[0];
334  return a;
335 }
336 
337 // unswap using char pointers
339 {
340  float d = 0.0f;
341  unsigned char *src = (unsigned char *)&a;
342  unsigned char *dst = (unsigned char *)&d;
343 
344  dst[0] = src[3];
345  dst[1] = src[2];
346  dst[2] = src[1];
347  dst[3] = src[0];
348 
349  return d;
350 }
351 
352 
353 // swap using char pointers
354 TF2SIMD_FORCE_INLINE void tf2SwapEndianDouble(double d, unsigned char* dst)
355 {
356  unsigned char *src = (unsigned char *)&d;
357 
358  dst[0] = src[7];
359  dst[1] = src[6];
360  dst[2] = src[5];
361  dst[3] = src[4];
362  dst[4] = src[3];
363  dst[5] = src[2];
364  dst[6] = src[1];
365  dst[7] = src[0];
366 
367 }
368 
369 // unswap using char pointers
370 TF2SIMD_FORCE_INLINE double tf2UnswapEndianDouble(const unsigned char *src)
371 {
372  double d = 0.0;
373  unsigned char *dst = (unsigned char *)&d;
374 
375  dst[0] = src[7];
376  dst[1] = src[6];
377  dst[2] = src[5];
378  dst[3] = src[4];
379  dst[4] = src[3];
380  dst[5] = src[2];
381  dst[6] = src[1];
382  dst[7] = src[0];
383 
384  return d;
385 }
386 
387 // returns normalized value in range [-TF2SIMD_PI, TF2SIMD_PI]
389 {
390  angleInRadians = tf2Fmod(angleInRadians, TF2SIMD_2_PI);
391  if(angleInRadians < -TF2SIMD_PI)
392  {
393  return angleInRadians + TF2SIMD_2_PI;
394  }
395  else if(angleInRadians > TF2SIMD_PI)
396  {
397  return angleInRadians - TF2SIMD_2_PI;
398  }
399  else
400  {
401  return angleInRadians;
402  }
403 }
404 
406 struct tf2TypedObject
407 {
408  tf2TypedObject(int objectType)
409  :m_objectType(objectType)
410  {
411  }
412  int m_objectType;
413  inline int getObjectType() const
414  {
415  return m_objectType;
416  }
417 };
418 #endif //TF2SIMD___SCALAR_H
tf2Asin
TF2SIMD_FORCE_INLINE tf2Scalar tf2Asin(tf2Scalar x)
Definition: Scalar.h:184
tf2Atan2
TF2SIMD_FORCE_INLINE tf2Scalar tf2Atan2(tf2Scalar x, tf2Scalar y)
Definition: Scalar.h:186
angle
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
TF2SIMD_2_PI
#define TF2SIMD_2_PI
Definition: Scalar.h:193
tf2MachineIsLittleEndian
TF2SIMD_FORCE_INLINE bool tf2MachineIsLittleEndian()
Definition: Scalar.h:250
TF2SIMD_EPSILON
#define TF2SIMD_EPSILON
Definition: Scalar.h:203
tf2Radians
TF2SIMD_FORCE_INLINE tf2Scalar tf2Radians(tf2Scalar x)
Definition: Scalar.h:236
tf2Equal
TF2SIMD_FORCE_INLINE bool tf2Equal(tf2Scalar a, tf2Scalar eps)
Definition: Scalar.h:224
tf2SwapEndian
TF2SIMD_FORCE_INLINE unsigned tf2SwapEndian(unsigned val)
Definition: Scalar.h:298
tf2Sin
TF2SIMD_FORCE_INLINE tf2Scalar tf2Sin(tf2Scalar x)
Definition: Scalar.h:181
tf2Fmod
TF2SIMD_FORCE_INLINE tf2Scalar tf2Fmod(tf2Scalar x, tf2Scalar y)
Definition: Scalar.h:190
tf2Swap
TF2SIMD_FORCE_INLINE void tf2Swap(T &a, T &b)
Definition: Scalar.h:289
tf2Sqrt
TF2SIMD_FORCE_INLINE tf2Scalar tf2Sqrt(tf2Scalar x)
Definition: Scalar.h:178
f
f
TF2SIMD_RADS_PER_DEG
#define TF2SIMD_RADS_PER_DEG
Definition: Scalar.h:196
tf2Degrees
TF2SIMD_FORCE_INLINE tf2Scalar tf2Degrees(tf2Scalar x)
Definition: Scalar.h:237
tf2Acos
TF2SIMD_FORCE_INLINE tf2Scalar tf2Acos(tf2Scalar x)
Definition: Scalar.h:183
tf2UnswapEndianFloat
TF2SIMD_FORCE_INLINE float tf2UnswapEndianFloat(unsigned int a)
Definition: Scalar.h:338
tf2NormalizeAngle
TF2SIMD_FORCE_INLINE tf2Scalar tf2NormalizeAngle(tf2Scalar angleInRadians)
Definition: Scalar.h:388
tf2UnswapEndianDouble
TF2SIMD_FORCE_INLINE double tf2UnswapEndianDouble(const unsigned char *src)
Definition: Scalar.h:370
TF2SIMD_FORCE_INLINE
#define TF2SIMD_FORCE_INLINE
Definition: Scalar.h:130
d
d
tf2TypedObject::getObjectType
int getObjectType() const
tf2Select
TF2SIMD_FORCE_INLINE unsigned tf2Select(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero)
Definition: Scalar.h:264
tf2FuzzyZero
TF2SIMD_FORCE_INLINE bool tf2FuzzyZero(tf2Scalar x)
Definition: Scalar.h:222
tf2Atan
TF2SIMD_FORCE_INLINE tf2Scalar tf2Atan(tf2Scalar x)
Definition: Scalar.h:185
tf2TypedObject::tf2TypedObject
tf2TypedObject(int objectType)
tf2Tan
TF2SIMD_FORCE_INLINE tf2Scalar tf2Tan(tf2Scalar x)
Definition: Scalar.h:182
tf2Cos
TF2SIMD_FORCE_INLINE tf2Scalar tf2Cos(tf2Scalar x)
Definition: Scalar.h:180
tf2Atan2Fast
TF2SIMD_FORCE_INLINE tf2Scalar tf2Atan2Fast(tf2Scalar y, tf2Scalar x)
Definition: Scalar.h:206
sick_scan_xd_api_test.c
c
Definition: sick_scan_xd_api_test.py:445
tf2Fsel
TF2SIMD_FORCE_INLINE tf2Scalar tf2Fsel(tf2Scalar a, tf2Scalar b, tf2Scalar c)
Definition: Scalar.h:242
tf2SwapEndianFloat
TF2SIMD_FORCE_INLINE unsigned int tf2SwapEndianFloat(float d)
tf2SwapFloat uses using char pointers to swap the endianness
Definition: Scalar.h:324
tf2SwapEndianDouble
TF2SIMD_FORCE_INLINE void tf2SwapEndianDouble(double d, unsigned char *dst)
Definition: Scalar.h:354
tf2Fabs
TF2SIMD_FORCE_INLINE tf2Scalar tf2Fabs(tf2Scalar x)
Definition: Scalar.h:179
tf2GreaterEqual
TF2SIMD_FORCE_INLINE bool tf2GreaterEqual(tf2Scalar a, tf2Scalar eps)
Definition: Scalar.h:227
sick_scan_base.h
tf2Log
TF2SIMD_FORCE_INLINE tf2Scalar tf2Log(tf2Scalar x)
Definition: Scalar.h:188
tf2TypedObject
rudimentary class to provide type info
Definition: Scalar.h:406
tf2Scalar
double tf2Scalar
The tf2Scalar type abstracts floating point numbers, to easily switch between double and single float...
Definition: Scalar.h:160
TF2SIMD_PI
#define TF2SIMD_PI
Definition: Scalar.h:194
TF2SIMD_DEGS_PER_RAD
#define TF2SIMD_DEGS_PER_RAD
Definition: Scalar.h:197
tf2Pow
TF2SIMD_FORCE_INLINE tf2Scalar tf2Pow(tf2Scalar x, tf2Scalar y)
Definition: Scalar.h:189
tf2IsNegative
TF2SIMD_FORCE_INLINE int tf2IsNegative(tf2Scalar x)
Definition: Scalar.h:232
tf2Exp
TF2SIMD_FORCE_INLINE tf2Scalar tf2Exp(tf2Scalar x)
Definition: Scalar.h:187
tf2TypedObject::m_objectType
int m_objectType
Definition: Scalar.h:412


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:10