28 #ifndef MIRTK_CutilMath_H 29 #define MIRTK_CutilMath_H 31 #if !defined(__CUDACC__) 37 #include "mirtk/Config.h" 38 #include "mirtk/CudaRuntime.h" 58 #if !defined(__CUDACC__) 60 inline float fminf(
float a,
float b)
65 inline float fmaxf(
float a,
float b)
70 inline float rsqrtf(
float x)
72 return 1.0f / sqrtf(x);
75 #endif // !defined(__CUDACC__) 80 MIRTKCU_API
inline float2 make_float2(
float s)
82 return make_float2(s, s);
84 MIRTKCU_API
inline float2 make_float2(float3 a)
86 return make_float2(a.x, a.y);
88 MIRTKCU_API
inline float2 make_float2(int2 a)
90 return make_float2(
float(a.x),
float(a.y));
92 MIRTKCU_API
inline float2 make_float2(uint2 a)
94 return make_float2(
float(a.x),
float(a.y));
97 MIRTKCU_API
inline int2 make_int2(
int s)
99 return make_int2(s, s);
101 MIRTKCU_API
inline int2 make_int2(int3 a)
103 return make_int2(a.x, a.y);
105 MIRTKCU_API
inline int2 make_int2(uint2 a)
107 return make_int2(
int(a.x),
int(a.y));
109 MIRTKCU_API
inline int2 make_int2(float2 a)
111 return make_int2(
int(a.x),
int(a.y));
114 MIRTKCU_API
inline uint2 make_uint2(uint s)
116 return make_uint2(s, s);
118 MIRTKCU_API
inline uint2 make_uint2(uint3 a)
120 return make_uint2(a.x, a.y);
122 MIRTKCU_API
inline uint2 make_uint2(int2 a)
124 return make_uint2(uint(a.x), uint(a.y));
127 MIRTKCU_API
inline float3 make_float3(
float s)
129 return make_float3(s, s, s);
131 MIRTKCU_API
inline float3 make_float3(float2 a)
133 return make_float3(a.x, a.y, 0.0f);
135 MIRTKCU_API
inline float3 make_float3(float2 a,
float s)
137 return make_float3(a.x, a.y, s);
139 MIRTKCU_API
inline float3 make_float3(float4 a)
141 return make_float3(a.x, a.y, a.z);
143 MIRTKCU_API
inline float3 make_float3(int3 a)
145 return make_float3(
float(a.x),
float(a.y),
float(a.z));
147 MIRTKCU_API
inline float3 make_float3(uint3 a)
149 return make_float3(
float(a.x),
float(a.y),
float(a.z));
152 MIRTKCU_API
inline int3 make_int3(
int s)
154 return make_int3(s, s, s);
156 MIRTKCU_API
inline int3 make_int3(int2 a)
158 return make_int3(a.x, a.y, 0);
160 MIRTKCU_API
inline int3 make_int3(int2 a,
int s)
162 return make_int3(a.x, a.y, s);
164 MIRTKCU_API
inline int3 make_int3(uint3 a)
166 return make_int3(
int(a.x),
int(a.y),
int(a.z));
168 MIRTKCU_API
inline int3 make_int3(float3 a)
170 return make_int3(
int(a.x),
int(a.y),
int(a.z));
173 MIRTKCU_API
inline uint3 make_uint3(uint s)
175 return make_uint3(s, s, s);
177 MIRTKCU_API
inline uint3 make_uint3(uint2 a)
179 return make_uint3(a.x, a.y, 0);
181 MIRTKCU_API
inline uint3 make_uint3(uint2 a, uint s)
183 return make_uint3(a.x, a.y, s);
185 MIRTKCU_API
inline uint3 make_uint3(uint4 a)
187 return make_uint3(a.x, a.y, a.z);
189 MIRTKCU_API
inline uint3 make_uint3(int3 a)
191 return make_uint3(uint(a.x), uint(a.y), uint(a.z));
194 MIRTKCU_API
inline float4 make_float4(
float s)
196 return make_float4(s, s, s, s);
198 MIRTKCU_API
inline float4 make_float4(float3 a)
200 return make_float4(a.x, a.y, a.z, 0.0f);
202 MIRTKCU_API
inline float4 make_float4(float3 a,
float w)
204 return make_float4(a.x, a.y, a.z, w);
206 MIRTKCU_API
inline float4 make_float4(int4 a)
208 return make_float4(
float(a.x),
float(a.y),
float(a.z),
float(a.w));
210 MIRTKCU_API
inline float4 make_float4(uint4 a)
212 return make_float4(
float(a.x),
float(a.y),
float(a.z),
float(a.w));
215 MIRTKCU_API
inline int4 make_int4(
int s)
217 return make_int4(s, s, s, s);
219 MIRTKCU_API
inline int4 make_int4(int3 a)
221 return make_int4(a.x, a.y, a.z, 0);
223 MIRTKCU_API
inline int4 make_int4(int3 a,
int w)
225 return make_int4(a.x, a.y, a.z, w);
227 MIRTKCU_API
inline int4 make_int4(uint4 a)
229 return make_int4(
int(a.x),
int(a.y),
int(a.z),
int(a.w));
231 MIRTKCU_API
inline int4 make_int4(float4 a)
233 return make_int4(
int(a.x),
int(a.y),
int(a.z),
int(a.w));
237 MIRTKCU_API
inline uint4 make_uint4(uint s)
239 return make_uint4(s, s, s, s);
241 MIRTKCU_API
inline uint4 make_uint4(uint3 a)
243 return make_uint4(a.x, a.y, a.z, 0);
245 MIRTKCU_API
inline uint4 make_uint4(uint3 a, uint w)
247 return make_uint4(a.x, a.y, a.z, w);
249 MIRTKCU_API
inline uint4 make_uint4(int4 a)
251 return make_uint4(uint(a.x), uint(a.y), uint(a.z), uint(a.w));
258 MIRTKCU_API
inline float2 operator-(float2 &a)
260 return make_float2(-a.x, -a.y);
262 MIRTKCU_API
inline int2 operator-(int2 &a)
264 return make_int2(-a.x, -a.y);
266 MIRTKCU_API
inline float3 operator-(float3 &a)
268 return make_float3(-a.x, -a.y, -a.z);
270 MIRTKCU_API
inline int3 operator-(int3 &a)
272 return make_int3(-a.x, -a.y, -a.z);
274 MIRTKCU_API
inline float4 operator-(float4 &a)
276 return make_float4(-a.x, -a.y, -a.z, -a.w);
278 MIRTKCU_API
inline int4 operator-(int4 &a)
280 return make_int4(-a.x, -a.y, -a.z, -a.w);
287 MIRTKCU_API
inline float2 operator+(float2 a, float2 b)
289 return make_float2(a.x + b.x, a.y + b.y);
291 MIRTKCU_API
inline void operator+=(float2 &a, float2 b)
293 a.x += b.x; a.y += b.y;
295 MIRTKCU_API
inline float2 operator+(float2 a,
float b)
297 return make_float2(a.x + b, a.y + b);
299 MIRTKCU_API
inline float2 operator+(
float b, float2 a)
301 return make_float2(a.x + b, a.y + b);
303 MIRTKCU_API
inline void operator+=(float2 &a,
float b)
308 MIRTKCU_API
inline int2 operator+(int2 a, int2 b)
310 return make_int2(a.x + b.x, a.y + b.y);
312 MIRTKCU_API
inline void operator+=(int2 &a, int2 b)
314 a.x += b.x; a.y += b.y;
316 MIRTKCU_API
inline int2 operator+(int2 a,
int b)
318 return make_int2(a.x + b, a.y + b);
320 MIRTKCU_API
inline int2 operator+(
int b, int2 a)
322 return make_int2(a.x + b, a.y + b);
324 MIRTKCU_API
inline void operator+=(int2 &a,
int b)
329 MIRTKCU_API
inline uint2 operator+(uint2 a, uint2 b)
331 return make_uint2(a.x + b.x, a.y + b.y);
333 MIRTKCU_API
inline void operator+=(uint2 &a, uint2 b)
335 a.x += b.x; a.y += b.y;
337 MIRTKCU_API
inline uint2 operator+(uint2 a, uint b)
339 return make_uint2(a.x + b, a.y + b);
341 MIRTKCU_API
inline uint2 operator+(uint b, uint2 a)
343 return make_uint2(a.x + b, a.y + b);
345 MIRTKCU_API
inline void operator+=(uint2 &a, uint b)
351 MIRTKCU_API
inline float3 operator+(float3 a, float3 b)
353 return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
355 MIRTKCU_API
inline void operator+=(float3 &a, float3 b)
357 a.x += b.x; a.y += b.y; a.z += b.z;
359 MIRTKCU_API
inline float3 operator+(float3 a,
float b)
361 return make_float3(a.x + b, a.y + b, a.z + b);
363 MIRTKCU_API
inline void operator+=(float3 &a,
float b)
365 a.x += b; a.y += b; a.z += b;
368 MIRTKCU_API
inline int3 operator+(int3 a, int3 b)
370 return make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
372 MIRTKCU_API
inline void operator+=(int3 &a, int3 b)
374 a.x += b.x; a.y += b.y; a.z += b.z;
376 MIRTKCU_API
inline int3 operator+(int3 a,
int b)
378 return make_int3(a.x + b, a.y + b, a.z + b);
380 MIRTKCU_API
inline void operator+=(int3 &a,
int b)
382 a.x += b; a.y += b; a.z += b;
385 MIRTKCU_API
inline uint3 operator+(uint3 a, uint3 b)
387 return make_uint3(a.x + b.x, a.y + b.y, a.z + b.z);
389 MIRTKCU_API
inline void operator+=(uint3 &a, uint3 b)
391 a.x += b.x; a.y += b.y; a.z += b.z;
393 MIRTKCU_API
inline uint3 operator+(uint3 a, uint b)
395 return make_uint3(a.x + b, a.y + b, a.z + b);
397 MIRTKCU_API
inline void operator+=(uint3 &a, uint b)
399 a.x += b; a.y += b; a.z += b;
402 MIRTKCU_API
inline int3 operator+(
int b, int3 a)
404 return make_int3(a.x + b, a.y + b, a.z + b);
406 MIRTKCU_API
inline uint3 operator+(uint b, uint3 a)
408 return make_uint3(a.x + b, a.y + b, a.z + b);
410 MIRTKCU_API
inline float3 operator+(
float b, float3 a)
412 return make_float3(a.x + b, a.y + b, a.z + b);
415 MIRTKCU_API
inline float4 operator+(float4 a, float4 b)
417 return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
419 MIRTKCU_API
inline void operator+=(float4 &a, float4 b)
421 a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
423 MIRTKCU_API
inline float4 operator+(float4 a,
float b)
425 return make_float4(a.x + b, a.y + b, a.z + b, a.w + b);
427 MIRTKCU_API
inline float4 operator+(
float b, float4 a)
429 return make_float4(a.x + b, a.y + b, a.z + b, a.w + b);
431 MIRTKCU_API
inline void operator+=(float4 &a,
float b)
433 a.x += b; a.y += b; a.z += b; a.w += b;
436 MIRTKCU_API
inline int4 operator+(int4 a, int4 b)
438 return make_int4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
440 MIRTKCU_API
inline void operator+=(int4 &a, int4 b)
442 a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
444 MIRTKCU_API
inline int4 operator+(int4 a,
int b)
446 return make_int4(a.x + b, a.y + b, a.z + b, a.w + b);
448 MIRTKCU_API
inline int4 operator+(
int b, int4 a)
450 return make_int4(a.x + b, a.y + b, a.z + b, a.w + b);
452 MIRTKCU_API
inline void operator+=(int4 &a,
int b)
454 a.x += b; a.y += b; a.z += b; a.w += b;
457 MIRTKCU_API
inline uint4 operator+(uint4 a, uint4 b)
459 return make_uint4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
461 MIRTKCU_API
inline void operator+=(uint4 &a, uint4 b)
463 a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
465 MIRTKCU_API
inline uint4 operator+(uint4 a, uint b)
467 return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b);
469 MIRTKCU_API
inline uint4 operator+(uint b, uint4 a)
471 return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b);
473 MIRTKCU_API
inline void operator+=(uint4 &a, uint b)
475 a.x += b; a.y += b; a.z += b; a.w += b;
482 MIRTKCU_API
inline float2 operator-(float2 a, float2 b)
484 return make_float2(a.x - b.x, a.y - b.y);
486 MIRTKCU_API
inline void operator-=(float2 &a, float2 b)
488 a.x -= b.x; a.y -= b.y;
490 MIRTKCU_API
inline float2 operator-(float2 a,
float b)
492 return make_float2(a.x - b, a.y - b);
494 MIRTKCU_API
inline float2 operator-(
float b, float2 a)
496 return make_float2(b - a.x, b - a.y);
498 MIRTKCU_API
inline void operator-=(float2 &a,
float b)
503 MIRTKCU_API
inline int2 operator-(int2 a, int2 b)
505 return make_int2(a.x - b.x, a.y - b.y);
507 MIRTKCU_API
inline void operator-=(int2 &a, int2 b)
509 a.x -= b.x; a.y -= b.y;
511 MIRTKCU_API
inline int2 operator-(int2 a,
int b)
513 return make_int2(a.x - b, a.y - b);
515 MIRTKCU_API
inline int2 operator-(
int b, int2 a)
517 return make_int2(b - a.x, b - a.y);
519 MIRTKCU_API
inline void operator-=(int2 &a,
int b)
524 MIRTKCU_API
inline uint2 operator-(uint2 a, uint2 b)
526 return make_uint2(a.x - b.x, a.y - b.y);
528 MIRTKCU_API
inline void operator-=(uint2 &a, uint2 b)
530 a.x -= b.x; a.y -= b.y;
532 MIRTKCU_API
inline uint2 operator-(uint2 a, uint b)
534 return make_uint2(a.x - b, a.y - b);
536 MIRTKCU_API
inline uint2 operator-(uint b, uint2 a)
538 return make_uint2(b - a.x, b - a.y);
540 MIRTKCU_API
inline void operator-=(uint2 &a, uint b)
545 MIRTKCU_API
inline float3 operator-(float3 a, float3 b)
547 return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
549 MIRTKCU_API
inline void operator-=(float3 &a, float3 b)
551 a.x -= b.x; a.y -= b.y; a.z -= b.z;
553 MIRTKCU_API
inline float3 operator-(float3 a,
float b)
555 return make_float3(a.x - b, a.y - b, a.z - b);
557 MIRTKCU_API
inline float3 operator-(
float b, float3 a)
559 return make_float3(b - a.x, b - a.y, b - a.z);
561 MIRTKCU_API
inline void operator-=(float3 &a,
float b)
563 a.x -= b; a.y -= b; a.z -= b;
566 MIRTKCU_API
inline int3 operator-(int3 a, int3 b)
568 return make_int3(a.x - b.x, a.y - b.y, a.z - b.z);
570 MIRTKCU_API
inline void operator-=(int3 &a, int3 b)
572 a.x -= b.x; a.y -= b.y; a.z -= b.z;
574 MIRTKCU_API
inline int3 operator-(int3 a,
int b)
576 return make_int3(a.x - b, a.y - b, a.z - b);
578 MIRTKCU_API
inline int3 operator-(
int b, int3 a)
580 return make_int3(b - a.x, b - a.y, b - a.z);
582 MIRTKCU_API
inline void operator-=(int3 &a,
int b)
584 a.x -= b; a.y -= b; a.z -= b;
587 MIRTKCU_API
inline uint3 operator-(uint3 a, uint3 b)
589 return make_uint3(a.x - b.x, a.y - b.y, a.z - b.z);
591 MIRTKCU_API
inline void operator-=(uint3 &a, uint3 b)
593 a.x -= b.x; a.y -= b.y; a.z -= b.z;
595 MIRTKCU_API
inline uint3 operator-(uint3 a, uint b)
597 return make_uint3(a.x - b, a.y - b, a.z - b);
599 MIRTKCU_API
inline uint3 operator-(uint b, uint3 a)
601 return make_uint3(b - a.x, b - a.y, b - a.z);
603 MIRTKCU_API
inline void operator-=(uint3 &a, uint b)
605 a.x -= b; a.y -= b; a.z -= b;
608 MIRTKCU_API
inline float4 operator-(float4 a, float4 b)
610 return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
612 MIRTKCU_API
inline void operator-=(float4 &a, float4 b)
614 a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
616 MIRTKCU_API
inline float4 operator-(float4 a,
float b)
618 return make_float4(a.x - b, a.y - b, a.z - b, a.w - b);
620 MIRTKCU_API
inline void operator-=(float4 &a,
float b)
622 a.x -= b; a.y -= b; a.z -= b; a.w -= b;
625 MIRTKCU_API
inline int4 operator-(int4 a, int4 b)
627 return make_int4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
629 MIRTKCU_API
inline void operator-=(int4 &a, int4 b)
631 a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
633 MIRTKCU_API
inline int4 operator-(int4 a,
int b)
635 return make_int4(a.x - b, a.y - b, a.z - b, a.w - b);
637 MIRTKCU_API
inline int4 operator-(
int b, int4 a)
639 return make_int4(b - a.x, b - a.y, b - a.z, b - a.w);
641 MIRTKCU_API
inline void operator-=(int4 &a,
int b)
643 a.x -= b; a.y -= b; a.z -= b; a.w -= b;
646 MIRTKCU_API
inline uint4 operator-(uint4 a, uint4 b)
648 return make_uint4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
650 MIRTKCU_API
inline void operator-=(uint4 &a, uint4 b)
652 a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
654 MIRTKCU_API
inline uint4 operator-(uint4 a, uint b)
656 return make_uint4(a.x - b, a.y - b, a.z - b, a.w - b);
658 MIRTKCU_API
inline uint4 operator-(uint b, uint4 a)
660 return make_uint4(b - a.x, b - a.y, b - a.z, b - a.w);
662 MIRTKCU_API
inline void operator-=(uint4 &a, uint b)
664 a.x -= b; a.y -= b; a.z -= b; a.w -= b;
671 MIRTKCU_API
inline float2 operator*(float2 a, float2 b)
673 return make_float2(a.x * b.x, a.y * b.y);
675 MIRTKCU_API
inline void operator*=(float2 &a, float2 b)
677 a.x *= b.x; a.y *= b.y;
679 MIRTKCU_API
inline float2 operator*(float2 a,
float b)
681 return make_float2(a.x * b, a.y * b);
683 MIRTKCU_API
inline float2 operator*(
float b, float2 a)
685 return make_float2(b * a.x, b * a.y);
687 MIRTKCU_API
inline void operator*=(float2 &a,
float b)
692 MIRTKCU_API
inline int2 operator*(int2 a, int2 b)
694 return make_int2(a.x * b.x, a.y * b.y);
696 MIRTKCU_API
inline void operator*=(int2 &a, int2 b)
698 a.x *= b.x; a.y *= b.y;
700 MIRTKCU_API
inline int2 operator*(int2 a,
int b)
702 return make_int2(a.x * b, a.y * b);
704 MIRTKCU_API
inline int2 operator*(
int b, int2 a)
706 return make_int2(b * a.x, b * a.y);
708 MIRTKCU_API
inline void operator*=(int2 &a,
int b)
713 MIRTKCU_API
inline uint2 operator*(uint2 a, uint2 b)
715 return make_uint2(a.x * b.x, a.y * b.y);
717 MIRTKCU_API
inline void operator*=(uint2 &a, uint2 b)
719 a.x *= b.x; a.y *= b.y;
721 MIRTKCU_API
inline uint2 operator*(uint2 a, uint b)
723 return make_uint2(a.x * b, a.y * b);
725 MIRTKCU_API
inline uint2 operator*(uint b, uint2 a)
727 return make_uint2(b * a.x, b * a.y);
729 MIRTKCU_API
inline void operator*=(uint2 &a, uint b)
734 MIRTKCU_API
inline float3 operator*(float3 a, float3 b)
736 return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
738 MIRTKCU_API
inline void operator*=(float3 &a, float3 b)
740 a.x *= b.x; a.y *= b.y; a.z *= b.z;
742 MIRTKCU_API
inline float3 operator*(float3 a,
float b)
744 return make_float3(a.x * b, a.y * b, a.z * b);
746 MIRTKCU_API
inline float3 operator*(
float b, float3 a)
748 return make_float3(b * a.x, b * a.y, b * a.z);
750 MIRTKCU_API
inline void operator*=(float3 &a,
float b)
752 a.x *= b; a.y *= b; a.z *= b;
755 MIRTKCU_API
inline int3 operator*(int3 a, int3 b)
757 return make_int3(a.x * b.x, a.y * b.y, a.z * b.z);
759 MIRTKCU_API
inline void operator*=(int3 &a, int3 b)
761 a.x *= b.x; a.y *= b.y; a.z *= b.z;
763 MIRTKCU_API
inline int3 operator*(int3 a,
int b)
765 return make_int3(a.x * b, a.y * b, a.z * b);
767 MIRTKCU_API
inline int3 operator*(
int b, int3 a)
769 return make_int3(b * a.x, b * a.y, b * a.z);
771 MIRTKCU_API
inline void operator*=(int3 &a,
int b)
773 a.x *= b; a.y *= b; a.z *= b;
776 MIRTKCU_API
inline uint3 operator*(uint3 a, uint3 b)
778 return make_uint3(a.x * b.x, a.y * b.y, a.z * b.z);
780 MIRTKCU_API
inline void operator*=(uint3 &a, uint3 b)
782 a.x *= b.x; a.y *= b.y; a.z *= b.z;
784 MIRTKCU_API
inline uint3 operator*(uint3 a, uint b)
786 return make_uint3(a.x * b, a.y * b, a.z * b);
788 MIRTKCU_API
inline uint3 operator*(uint b, uint3 a)
790 return make_uint3(b * a.x, b * a.y, b * a.z);
792 MIRTKCU_API
inline void operator*=(uint3 &a, uint b)
794 a.x *= b; a.y *= b; a.z *= b;
797 MIRTKCU_API
inline float4 operator*(float4 a, float4 b)
799 return make_float4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
801 MIRTKCU_API
inline void operator*=(float4 &a, float4 b)
803 a.x *= b.x; a.y *= b.y; a.z *= b.z; a.w *= b.w;
805 MIRTKCU_API
inline float4 operator*(float4 a,
float b)
807 return make_float4(a.x * b, a.y * b, a.z * b, a.w * b);
809 MIRTKCU_API
inline float4 operator*(
float b, float4 a)
811 return make_float4(b * a.x, b * a.y, b * a.z, b * a.w);
813 MIRTKCU_API
inline void operator*=(float4 &a,
float b)
815 a.x *= b; a.y *= b; a.z *= b; a.w *= b;
818 MIRTKCU_API
inline int4 operator*(int4 a, int4 b)
820 return make_int4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
822 MIRTKCU_API
inline void operator*=(int4 &a, int4 b)
824 a.x *= b.x; a.y *= b.y; a.z *= b.z; a.w *= b.w;
826 MIRTKCU_API
inline int4 operator*(int4 a,
int b)
828 return make_int4(a.x * b, a.y * b, a.z * b, a.w * b);
830 MIRTKCU_API
inline int4 operator*(
int b, int4 a)
832 return make_int4(b * a.x, b * a.y, b * a.z, b * a.w);
834 MIRTKCU_API
inline void operator*=(int4 &a,
int b)
836 a.x *= b; a.y *= b; a.z *= b; a.w *= b;
839 MIRTKCU_API
inline uint4 operator*(uint4 a, uint4 b)
841 return make_uint4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
843 MIRTKCU_API
inline void operator*=(uint4 &a, uint4 b)
845 a.x *= b.x; a.y *= b.y; a.z *= b.z; a.w *= b.w;
847 MIRTKCU_API
inline uint4 operator*(uint4 a, uint b)
849 return make_uint4(a.x * b, a.y * b, a.z * b, a.w * b);
851 MIRTKCU_API
inline uint4 operator*(uint b, uint4 a)
853 return make_uint4(b * a.x, b * a.y, b * a.z, b * a.w);
855 MIRTKCU_API
inline void operator*=(uint4 &a, uint b)
857 a.x *= b; a.y *= b; a.z *= b; a.w *= b;
864 MIRTKCU_API
inline float2 operator/(float2 a, float2 b)
866 return make_float2(a.x / b.x, a.y / b.y);
868 MIRTKCU_API
inline void operator/=(float2 &a, float2 b)
870 a.x /= b.x; a.y /= b.y;
872 MIRTKCU_API
inline float2 operator/(float2 a,
float b)
874 return make_float2(a.x / b, a.y / b);
876 MIRTKCU_API
inline void operator/=(float2 &a,
float b)
880 MIRTKCU_API
inline float2 operator/(
float b, float2 a)
882 return make_float2(b / a.x, b / a.y);
885 MIRTKCU_API
inline float3 operator/(float3 a, float3 b)
887 return make_float3(a.x / b.x, a.y / b.y, a.z / b.z);
889 MIRTKCU_API
inline void operator/=(float3 &a, float3 b)
891 a.x /= b.x; a.y /= b.y; a.z /= b.z;
893 MIRTKCU_API
inline float3 operator/(float3 a,
float b)
895 return make_float3(a.x / b, a.y / b, a.z / b);
897 MIRTKCU_API
inline void operator/=(float3 &a,
float b)
899 a.x /= b; a.y /= b; a.z /= b;
901 MIRTKCU_API
inline float3 operator/(
float b, float3 a)
903 return make_float3(b / a.x, b / a.y, b / a.z);
906 MIRTKCU_API
inline float4 operator/(float4 a, float4 b)
908 return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
910 MIRTKCU_API
inline void operator/=(float4 &a, float4 b)
912 a.x /= b.x; a.y /= b.y; a.z /= b.z; a.w /= b.w;
914 MIRTKCU_API
inline float4 operator/(float4 a,
float b)
916 return make_float4(a.x / b, a.y / b, a.z / b, a.w / b);
918 MIRTKCU_API
inline void operator/=(float4 &a,
float b)
920 a.x /= b; a.y /= b; a.z /= b; a.w /= b;
922 MIRTKCU_API
inline float4 operator/(
float b, float4 a){
923 return make_float4(b / a.x, b / a.y, b / a.z, b / a.w);
930 MIRTKCU_API
inline float2 fminf(float2 a, float2 b)
932 return make_float2(fminf(a.x,b.x), fminf(a.y,b.y));
934 MIRTKCU_API
inline float3 fminf(float3 a, float3 b)
936 return make_float3(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z));
938 MIRTKCU_API
inline float4 fminf(float4 a, float4 b)
940 return make_float4(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z), fminf(a.w,b.w));
943 MIRTKCU_API
inline int2 min(int2 a, int2 b)
945 return make_int2(min(a.x,b.x), min(a.y,b.y));
947 MIRTKCU_API
inline int3 min(int3 a, int3 b)
949 return make_int3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z));
951 MIRTKCU_API
inline int4 min(int4 a, int4 b)
953 return make_int4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w));
956 MIRTKCU_API
inline uint2 min(uint2 a, uint2 b)
958 return make_uint2(min(a.x,b.x), min(a.y,b.y));
960 MIRTKCU_API
inline uint3 min(uint3 a, uint3 b)
962 return make_uint3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z));
964 MIRTKCU_API
inline uint4 min(uint4 a, uint4 b)
966 return make_uint4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w));
969 MIRTKCU_API
inline uint min(uint2 a)
973 MIRTKCU_API
inline uint min(uint3 a)
975 return min(a.x,min(a.y, a.z));
977 MIRTKCU_API
inline uint min(uint4 a)
979 return min(min(a.x, a.y),min(a.z, a.w));
982 MIRTKCU_API
inline float min(float2 a)
986 MIRTKCU_API
inline float min(float3 a)
988 return min(a.x,min(a.y, a.z));
990 MIRTKCU_API
inline float min(float4 a)
992 return min(min(a.x, a.y),min(a.z, a.w));
999 MIRTKCU_API
inline float2 fmaxf(float2 a, float2 b)
1001 return make_float2(fmaxf(a.x,b.x), fmaxf(a.y,b.y));
1003 MIRTKCU_API
inline float3 fmaxf(float3 a, float3 b)
1005 return make_float3(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z));
1007 MIRTKCU_API
inline float4 fmaxf(float4 a, float4 b)
1009 return make_float4(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z), fmaxf(a.w,b.w));
1012 MIRTKCU_API
inline int2 max(int2 a, int2 b)
1014 return make_int2(max(a.x,b.x), max(a.y,b.y));
1016 MIRTKCU_API
inline int3 max(int3 a, int3 b)
1018 return make_int3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z));
1020 MIRTKCU_API
inline int4 max(int4 a, int4 b)
1022 return make_int4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w));
1025 MIRTKCU_API
inline uint2 max(uint2 a, uint2 b)
1027 return make_uint2(max(a.x,b.x), max(a.y,b.y));
1029 MIRTKCU_API
inline uint3 max(uint3 a, uint3 b)
1031 return make_uint3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z));
1033 MIRTKCU_API
inline uint4 max(uint4 a, uint4 b)
1035 return make_uint4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w));
1038 MIRTKCU_API
inline uint max(uint2 a)
1040 return max(a.x,a.y);
1042 MIRTKCU_API
inline uint max(uint3 a)
1044 return max(a.x,max(a.y, a.z));
1046 MIRTKCU_API
inline uint max(uint4 a)
1048 return max(max(a.x, a.y),max(a.z, a.w));
1051 MIRTKCU_API
inline float max(float2 a)
1053 return max(a.x,a.y);
1055 MIRTKCU_API
inline float max(float3 a)
1057 return max(a.x,max(a.y, a.z));
1059 MIRTKCU_API
inline float max(float4 a)
1061 return max(max(a.x, a.y),max(a.z, a.w));
1069 MIRTKCU_API
inline float lerp(
float a,
float b,
float t)
1073 MIRTKCU_API
inline float2 lerp(float2 a, float2 b,
float t)
1077 MIRTKCU_API
inline float3 lerp(float3 a, float3 b,
float t)
1081 MIRTKCU_API
inline float4 lerp(float4 a, float4 b,
float t)
1091 MIRTKCU_API
inline float clamp(
float f,
float a,
float b)
1093 return fmaxf(a, fminf(f, b));
1095 MIRTKCU_API
inline int clamp(
int f,
int a,
int b)
1097 return max(a, min(f, b));
1099 MIRTKCU_API
inline uint clamp(uint f, uint a, uint b)
1101 return max(a, min(f, b));
1104 MIRTKCU_API
inline float2 clamp(float2 v,
float a,
float b)
1106 return make_float2(clamp(v.x, a, b), clamp(v.y, a, b));
1108 MIRTKCU_API
inline float2 clamp(float2 v, float2 a, float2 b)
1110 return make_float2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
1112 MIRTKCU_API
inline float3 clamp(float3 v,
float a,
float b)
1114 return make_float3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
1116 MIRTKCU_API
inline float3 clamp(float3 v, float3 a, float3 b)
1118 return make_float3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
1120 MIRTKCU_API
inline float4 clamp(float4 v,
float a,
float b)
1122 return make_float4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
1124 MIRTKCU_API
inline float4 clamp(float4 v, float4 a, float4 b)
1126 return make_float4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w));
1129 MIRTKCU_API
inline int2 clamp(int2 v,
int a,
int b)
1131 return make_int2(clamp(v.x, a, b), clamp(v.y, a, b));
1133 MIRTKCU_API
inline int2 clamp(int2 v, int2 a, int2 b)
1135 return make_int2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
1137 MIRTKCU_API
inline int3 clamp(int3 v,
int a,
int b)
1139 return make_int3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
1141 MIRTKCU_API
inline int3 clamp(int3 v, int3 a, int3 b)
1143 return make_int3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
1145 MIRTKCU_API
inline int4 clamp(int4 v,
int a,
int b)
1147 return make_int4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
1149 MIRTKCU_API
inline int4 clamp(int4 v, int4 a, int4 b)
1151 return make_int4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w));
1154 MIRTKCU_API
inline uint2 clamp(uint2 v, uint a, uint b)
1156 return make_uint2(clamp(v.x, a, b), clamp(v.y, a, b));
1158 MIRTKCU_API
inline uint2 clamp(uint2 v, uint2 a, uint2 b)
1160 return make_uint2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
1162 MIRTKCU_API
inline uint3 clamp(uint3 v, uint a, uint b)
1164 return make_uint3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
1166 MIRTKCU_API
inline uint3 clamp(uint3 v, uint3 a, uint3 b)
1168 return make_uint3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
1170 MIRTKCU_API
inline uint4 clamp(uint4 v, uint a, uint b)
1172 return make_uint4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
1174 MIRTKCU_API
inline uint4 clamp(uint4 v, uint4 a, uint4 b)
1176 return make_uint4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w));
1183 MIRTKCU_API
inline float dot(float2 a, float2 b)
1185 return a.x * b.x + a.y * b.y;
1187 MIRTKCU_API
inline float dot(float3 a, float3 b)
1189 return a.x * b.x + a.y * b.y + a.z * b.z;
1191 MIRTKCU_API
inline float dot(float4 a, float4 b)
1193 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
1196 MIRTKCU_API
inline int dot(int2 a, int2 b)
1198 return a.x * b.x + a.y * b.y;
1200 MIRTKCU_API
inline int dot(int3 a, int3 b)
1202 return a.x * b.x + a.y * b.y + a.z * b.z;
1204 MIRTKCU_API
inline int dot(int4 a, int4 b)
1206 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
1209 MIRTKCU_API
inline uint dot(uint2 a, uint2 b)
1211 return a.x * b.x + a.y * b.y;
1213 MIRTKCU_API
inline uint dot(uint3 a, uint3 b)
1215 return a.x * b.x + a.y * b.y + a.z * b.z;
1217 MIRTKCU_API
inline uint dot(uint4 a, uint4 b)
1219 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
1226 MIRTKCU_API
inline float length(float2 v)
1228 return sqrtf(dot(v, v));
1230 MIRTKCU_API
inline float length(float3 v)
1232 return sqrtf(dot(v, v));
1234 MIRTKCU_API
inline float length(float4 v)
1236 return sqrtf(dot(v, v));
1243 MIRTKCU_API
inline float2 normalize(float2 v)
1245 float invLen = rsqrtf(dot(v, v));
1248 MIRTKCU_API
inline float3 normalize(float3 v)
1250 float invLen = rsqrtf(dot(v, v));
1253 MIRTKCU_API
inline float4 normalize(float4 v)
1255 float invLen = rsqrtf(dot(v, v));
1263 MIRTKCU_API
inline float2 floorf(float2 v)
1265 return make_float2(floorf(v.x), floorf(v.y));
1267 MIRTKCU_API
inline float3 floorf(float3 v)
1269 return make_float3(floorf(v.x), floorf(v.y), floorf(v.z));
1271 MIRTKCU_API
inline float4 floorf(float4 v)
1273 return make_float4(floorf(v.x), floorf(v.y), floorf(v.z), floorf(v.w));
1280 MIRTKCU_API
inline float fracf(
float v)
1282 return v - floorf(v);
1284 MIRTKCU_API
inline float2 fracf(float2 v)
1286 return make_float2(fracf(v.x), fracf(v.y));
1288 MIRTKCU_API
inline float3 fracf(float3 v)
1290 return make_float3(fracf(v.x), fracf(v.y), fracf(v.z));
1292 MIRTKCU_API
inline float4 fracf(float4 v)
1294 return make_float4(fracf(v.x), fracf(v.y), fracf(v.z), fracf(v.w));
1301 MIRTKCU_API
inline float2 fmodf(float2 a, float2 b)
1303 return make_float2(fmodf(a.x, b.x), fmodf(a.y, b.y));
1305 MIRTKCU_API
inline float3 fmodf(float3 a, float3 b)
1307 return make_float3(fmodf(a.x, b.x), fmodf(a.y, b.y), fmodf(a.z, b.z));
1309 MIRTKCU_API
inline float4 fmodf(float4 a, float4 b)
1311 return make_float4(fmodf(a.x, b.x), fmodf(a.y, b.y), fmodf(a.z, b.z), fmodf(a.w, b.w));
1318 MIRTKCU_API
inline float2 fabs(float2 v)
1320 return make_float2(fabs(v.x), fabs(v.y));
1322 MIRTKCU_API
inline float3 fabs(float3 v)
1324 return make_float3(fabs(v.x), fabs(v.y), fabs(v.z));
1326 MIRTKCU_API
inline float4 fabs(float4 v)
1328 return make_float4(fabs(v.x), fabs(v.y), fabs(v.z), fabs(v.w));
1331 MIRTKCU_API
inline int2 abs(int2 v)
1333 return make_int2(abs(v.x), abs(v.y));
1335 MIRTKCU_API
inline int3 abs(int3 v)
1337 return make_int3(abs(v.x), abs(v.y), abs(v.z));
1339 MIRTKCU_API
inline int4 abs(int4 v)
1341 return make_int4(abs(v.x), abs(v.y), abs(v.z), abs(v.w));
1350 MIRTKCU_API
inline float3 reflect(float3 i, float3 n)
1352 return i - 2.0f * n * dot(n,i);
1359 MIRTKCU_API
inline float3 cross(float3 a, float3 b)
1361 return make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
1371 MIRTKCU_API
inline float smoothstep(
float a,
float b,
float x)
1373 float y = clamp((x - a) / (b - a), 0.0f, 1.0f);
1374 return (y*y*(3.0f - (2.0f*y)));
1376 MIRTKCU_API
inline float2 smoothstep(float2 a, float2 b, float2 x)
1378 float2 y = clamp((x - a) / (b - a), 0.0f, 1.0f);
1379 return (y*y*(make_float2(3.0f) - (make_float2(2.0f)*y)));
1381 MIRTKCU_API
inline float3 smoothstep(float3 a, float3 b, float3 x)
1383 float3 y = clamp((x - a) / (b - a), 0.0f, 1.0f);
1384 return (y*y*(make_float3(3.0f) - (make_float3(2.0f)*y)));
1386 MIRTKCU_API
inline float4 smoothstep(float4 a, float4 b, float4 x)
1388 float4 y = clamp((x - a) / (b - a), 0.0f, 1.0f);
1389 return (y*y*(make_float4(3.0f) - (make_float4(2.0f)*y)));
1396 MIRTKCU_API
inline uint2 operator<<(uint2 a,
int b)
1398 return make_uint2(a.x << b, a.y << b);
1401 MIRTKCU_API
inline uint3 operator<<(uint3 a,
int b)
1403 return make_uint3(a.x << b, a.y << b, a.z << b);
1406 MIRTKCU_API
inline uint4 operator<<(uint4 a,
int b)
1408 return make_uint4(a.x << b, a.y << b, a.z << b, a.w << b);
1411 MIRTKCU_API
inline uint2 operator>>(uint2 a,
int b)
1413 return make_uint2(a.x >> b, a.y >> b);
1416 MIRTKCU_API
inline uint3 operator>>(uint3 a,
int b)
1418 return make_uint3(a.x >> b, a.y >> b, a.z >> b);
1421 MIRTKCU_API
inline uint4 operator>>(uint4 a,
int b)
1423 return make_uint4(a.x >> b, a.y >> b, a.z >> b, a.w >> b);
1428 MIRTKCU_API
inline int2 operator<<(int2 a,
int b)
1430 return make_int2(a.x << b, a.y << b);
1433 MIRTKCU_API
inline int3 operator<<(int3 a,
int b)
1435 return make_int3(a.x << b, a.y << b, a.z << b);
1438 MIRTKCU_API
inline int4 operator<<(int4 a,
int b)
1440 return make_int4(a.x << b, a.y << b, a.z << b, a.w << b);
1443 MIRTKCU_API
inline int2 operator>>(int2 a,
int b)
1445 return make_int2(a.x >> b, a.y >> b);
1448 MIRTKCU_API
inline int3 operator>>(int3 a,
int b)
1450 return make_int3(a.x >> b, a.y >> b, a.z >> b);
1453 MIRTKCU_API
inline int4 operator>>(int4 a,
int b)
1455 return make_int4(a.x >> b, a.y >> b, a.z >> b, a.w >> b);
1461 #endif // MIRTK_CutilMath_H