23 #include "mirtk/CommonExport.h" 25 #include "mirtk/Config.h" 26 #include "mirtk/Stream.h" 27 #include "mirtk/CutilMath.h" 44 MIRTK_Common_EXPORT
extern const double inf;
47 MIRTK_Common_EXPORT
extern const double nan;
48 MIRTK_Common_EXPORT
extern const double NaN;
51 MIRTK_Common_EXPORT
extern const double pi;
54 MIRTK_Common_EXPORT
extern const double two_pi;
57 MIRTK_Common_EXPORT
extern const double pi_half;
60 MIRTK_Common_EXPORT
extern const double rad_per_deg;
63 MIRTK_Common_EXPORT
extern const double deg_per_rad;
82 using std::numeric_limits;
91 MIRTKCU_API
inline bool IsNaN(
double x)
94 return (_isnan(x) != 0);
103 MIRTKCU_API
inline bool IsInf(
double x)
115 MIRTKCU_API
inline bool AreEqual(
double a,
double b,
double tol = 1e-12)
117 return abs(a - b) < tol;
122 MIRTKCU_API
inline bool AreEqualOrNaN(
double a,
double b,
double tol = 1e-12)
131 MIRTKCU_API
inline bool IsZero(
double a,
double tol = 1e-12)
138 MIRTKCU_API
inline bool fequal(
double a,
double b,
double tol = 1e-12)
145 template <
typename T>
146 MIRTKCU_API
int sgn(T val)
148 return (T(0) < val) - (val < T(0));
156 return static_cast<int>(floor(x));
164 return static_cast<int>(ceil(x));
172 return static_cast<int>(round(x));
178 MIRTKCU_API
inline double finc(
double f)
181 double m = frexp(f, &e);
182 return ::ldexp(m + numeric_limits<double>::epsilon(), e);
188 MIRTKCU_API
inline double fdec(
double f)
191 double m = frexp(f, &e);
192 return ::ldexp(m - numeric_limits<double>::epsilon(), e);
204 MIRTKCU_API
inline double finc(
double f,
double df)
206 if (df == 0)
return f;
209 if (df < 0) s =
fdec(f);
224 MIRTKCU_API
inline double fdec(
double f,
double df)
226 if (df == 0)
return f;
229 if (df < 0) s =
finc(f);
244 }
else if (x <= .5 * (a + b)) {
245 const double t = (x - a) / (b - a);
248 const double t = (x - b) / (b - a);
249 return 1. - 2. * t * t;
267 MIRTKCU_API
float2x2 &operator =(
float s)
269 a.x = a.y = b.x = b.y = s;
275 a = rhs.a, b = rhs.b;
289 MIRTKCU_API
float3x3 &operator =(
float s)
291 a.x = a.y = a.z = b.x = b.y = b.z = c.x = c.y = c.z = s;
297 a = rhs.a, b = rhs.b, c = rhs.c;
312 MIRTKCU_API
float4x4 &operator =(
float s)
314 a.x = a.y = a.z = a.w = b.x = b.y = b.z = b.w = c.x = c.y = c.z = c.w = d.x = d.y = d.z = d.w = s;
320 a = rhs.a, b = rhs.b, c = rhs.c, d = rhs.d;
334 MIRTKCU_API
float3x4 &operator =(
float s)
336 a.x = a.y = a.z = a.w = b.x = b.y = b.z = b.w = c.x = c.y = c.z = c.w = s;
342 a = rhs.a, b = rhs.b, c = rhs.c;
359 MIRTKCU_API
double2x2 &operator =(
double s)
361 a.x = a.y = b.x = b.y = s;
367 a = rhs.a, b = rhs.b;
380 MIRTKCU_API
double3x3 &operator =(
double s)
382 a.x = a.y = a.z = b.x = b.y = b.z = c.x = c.y = c.z = s;
388 a = rhs.a, b = rhs.b, c = rhs.c;
402 MIRTKCU_API
double4x4 &operator =(
double s)
404 a.x = a.y = a.z = a.w = b.x = b.y = b.z = b.w = c.x = c.y = c.z = c.w = d.x = d.y = d.z = d.w = s;
410 a = rhs.a, b = rhs.b, c = rhs.c, d = rhs.d;
423 MIRTKCU_API
double3x4 &operator =(
double s)
425 a.x = a.y = a.z = a.w = b.x = b.y = b.z = b.w = c.x = c.y = c.z = c.w = s;
431 a = rhs.a, b = rhs.b, c = rhs.c;
446 MIRTKCU_API
inline int4 make_int4(double4 a)
448 return make_int4(
int(a.x),
int(a.y),
int(a.z),
int(a.w));
457 MIRTKCU_API
inline float1 make_float1(
double x)
459 return make_float1(
float(x));
464 MIRTKCU_API
inline float1 make_float1(double1 d)
466 return make_float1(d.x);
471 MIRTKCU_API
inline float2 make_float2(
double x,
double y)
473 return make_float2(
float(x),
float(y));
478 MIRTKCU_API
inline float2 make_float2(double2 d)
480 return make_float2(d.x, d.y);
485 MIRTKCU_API
inline float3 make_float3(
double x,
double y,
double z)
487 return make_float3(
float(x),
float(y),
float(z));
492 MIRTKCU_API
inline float3 make_float3(double3 d)
494 return make_float3(d.x, d.y, d.z);
499 MIRTKCU_API
inline float4 make_float4(
double x,
double y,
double z,
double w)
501 return make_float4(
float(x),
float(y),
float(z),
float(w));
506 MIRTKCU_API
inline float4 make_float4(double4 d)
508 return make_float4(d.x, d.y, d.z, d.w);
513 MIRTKCU_API
inline float3x3 make_float3x3(
float s)
516 m.a = make_float3(s);
517 m.b = make_float3(s);
518 m.c = make_float3(s);
524 MIRTKCU_API
inline float3x3 make_float3x3(float3x4 m)
527 d.a = make_float3(m.a.x, m.a.y, m.a.z);
528 d.b = make_float3(m.b.x, m.b.y, m.b.z);
529 d.c = make_float3(m.c.x, m.c.y, m.c.z);
535 MIRTKCU_API
inline float3x3 make_float3x3(double3x3 m)
538 d.a = make_float3(m.a.x, m.a.y, m.a.z);
539 d.b = make_float3(m.b.x, m.b.y, m.b.z);
540 d.c = make_float3(m.c.x, m.c.y, m.c.z);
546 template <
class VoxelType>
547 MIRTKCU_HOST_API
float *
to_float(
const VoxelType *in,
unsigned int N)
549 float *out =
new float[N];
550 for (
unsigned int i = 0; i < N; i++) out[i] =
float(in[i]);
560 MIRTKCU_API
inline double1 make_double1(float1 f)
562 return make_double1(f.x);
567 MIRTKCU_API
inline double2 make_double2(
double s)
569 return make_double2(s, s);
574 MIRTKCU_API
inline double2 make_double2(float2 f)
576 return make_double2(f.x, f.y);
581 MIRTKCU_API
inline double2 make_double2(int2 i)
583 return make_double2(
double(i.x),
double(i.y));
588 MIRTKCU_API
inline double2 make_double2(uint2 i)
590 return make_double2(
double(i.x),
double(i.y));
595 MIRTKCU_API
inline double3 make_double3(
double s)
597 return make_double3(s, s, s);
602 MIRTKCU_API
inline double3 make_double3(int3 i)
604 return make_double3(
double(i.x),
double(i.y),
double(i.z));
609 MIRTKCU_API
inline double3 make_double3(uint3 i)
611 return make_double3(
double(i.x),
double(i.y),
double(i.z));
616 MIRTKCU_API
inline double3 make_double3(float3 f)
618 return make_double3(f.x, f.y, f.z);
623 MIRTKCU_API
inline double4 make_double4(
double s)
625 return make_double4(s, s, s, s);
630 MIRTKCU_API
inline double4 make_double4(int4 i)
632 return make_double4(
double(i.x),
double(i.y),
double(i.z),
double(i.w));
637 MIRTKCU_API
inline double4 make_double4(float4 f)
639 return make_double4(f.x, f.y, f.z, f.w);
644 MIRTKCU_API
inline double3x3 make_double3x3(
double s)
647 d.a = make_double3(s);
648 d.b = make_double3(s);
649 d.c = make_double3(s);
655 MIRTKCU_API
inline double3x3 make_double3x3(float3x3 m)
658 d.a = make_double3(m.a.x, m.a.y, m.a.z);
659 d.b = make_double3(m.b.x, m.b.y, m.b.z);
660 d.c = make_double3(m.c.x, m.c.y, m.c.z);
666 MIRTKCU_API
inline double3x3 make_double3x3(double3x4 m)
669 d.a = make_double3(m.a.x, m.a.y, m.a.z);
670 d.b = make_double3(m.b.x, m.b.y, m.b.z);
671 d.c = make_double3(m.c.x, m.c.y, m.c.z);
684 t.a = make_float2(m.a.x, m.b.x);
685 t.b = make_float2(m.a.y, m.b.y);
694 t.a = make_float3(m.a.x, m.b.x, m.c.x);
695 t.b = make_float3(m.a.y, m.b.y, m.c.y);
696 t.c = make_float3(m.a.z, m.b.z, m.c.z);
705 t.a = make_double2(m.a.x, m.b.x);
706 t.b = make_double2(m.a.y, m.b.y);
715 t.a = make_double3(m.a.x, m.b.x, m.c.x);
716 t.b = make_double3(m.a.y, m.b.y, m.c.y);
717 t.c = make_double3(m.a.z, m.b.z, m.c.z);
731 MIRTKCU_API
inline bool operator ==(
const float1 &a,
const float1 &b)
738 MIRTKCU_API
inline bool operator ==(
const float2 &a,
const float2 &b)
740 return (a.x == b.x && a.y == b.y);
745 MIRTKCU_API
inline bool operator ==(
const float3 &a,
const float3 &b)
747 return (a.x == b.x && a.y == b.y && a.z == b.z);
752 MIRTKCU_API
inline bool operator ==(
const float4 &a,
const float4 &b)
754 return (a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w);
759 MIRTKCU_API
inline bool operator ==(
const float3x3 &a,
const float3x3 &b)
761 return (a.a == b.a && a.b == b.b && a.c == b.c);
766 MIRTKCU_API
inline bool operator ==(
const float3x4 &a,
const float3x4 &b)
768 return (a.a == b.a && a.b == b.b && a.c == b.c);
773 MIRTKCU_API
inline bool operator ==(
const float4x4 &a,
const float4x4 &b)
775 return (a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d);
780 MIRTKCU_API
inline bool operator ==(
const double1 &a,
const double1 &b)
787 MIRTKCU_API
inline bool operator ==(
const double2 &a,
const double2 &b)
789 return (a.x == b.x && a.y == b.y);
794 MIRTKCU_API
inline bool operator ==(
const double3 &a,
const double3 &b)
796 return (a.x == b.x && a.y == b.y && a.z == b.z);
801 MIRTKCU_API
inline bool operator ==(
const double4 &a,
const double4 &b)
803 return (a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w);
808 MIRTKCU_API
inline bool operator ==(
const double3x3 &a,
const double3x3 &b)
810 return (a.a == b.a && a.b == b.b && a.c == b.c);
815 MIRTKCU_API
inline bool operator ==(
const double3x4 &a,
const double3x4 &b)
817 return (a.a == b.a && a.b == b.b && a.c == b.c);
822 MIRTKCU_API
inline bool operator ==(
const double4x4 &a,
const double4x4 &b)
824 return (a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d);
833 MIRTKCU_API
inline bool operator <(
const float1 &a,
const float1 &b)
840 MIRTKCU_API
inline bool operator <(
const float2 &a,
const float2 &b)
842 return (a.x < b.x || (a.x == b.x && a.y < b.y));
847 MIRTKCU_API
inline bool operator <(
const float3 &a,
const float3 &b)
849 return (a.x < b.x || (a.x == b.x && (a.y < b.y || (a.y == b.y && a.z < b.z))));
854 MIRTKCU_API
inline bool operator <(
const float4 &a,
const float4 &b)
856 return (a.x < b.x || (a.x == b.x && (a.y < b.y || (a.y == b.y && (a.z < b.z || (a.z == b.z && a.w < b.w))))));
861 MIRTKCU_API
inline bool operator <(
const double1 &a,
const double1 &b)
868 MIRTKCU_API
inline bool operator <(
const double2 &a,
const double2 &b)
870 return (a.x < b.x || (a.x == b.x && a.y < b.y));
875 MIRTKCU_API
inline bool operator <(
const double3 &a,
const double3 &b)
877 return (a.x < b.x || (a.x == b.x && (a.y < b.y || (a.y == b.y && a.z < b.z))));
882 MIRTKCU_API
inline bool operator <(
const double4 &a,
const double4 &b)
884 return (a.x < b.x || (a.x == b.x && (a.y < b.y || (a.y == b.y && (a.z < b.z || (a.z == b.z && a.w < b.w))))));
891 #define __other_comp(T) \ 892 MIRTKCU_API inline bool operator !=(const T &a, const T &b) { return !(a == b); } \ 893 MIRTKCU_API inline bool operator <=(const T &a, const T &b) { return !(b < a); } \ 894 MIRTKCU_API inline bool operator > (const T &a, const T &b) { return (b < a); } \ 895 MIRTKCU_API inline bool operator >=(const T &a, const T &b) { return !(a < b); } 898 __other_comp(float1);
899 __other_comp(float2);
900 __other_comp(float3);
901 __other_comp(float4);
904 __other_comp(double1);
905 __other_comp(double2);
906 __other_comp(double3);
907 __other_comp(double4);
910 MIRTKCU_API
inline bool operator !=(
const float3x3 &a,
const float3x3 &b) {
return !(a == b); }
911 MIRTKCU_API
inline bool operator !=(
const float3x4 &a,
const float3x4 &b) {
return !(a == b); }
912 MIRTKCU_API
inline bool operator !=(
const float4x4 &a,
const float4x4 &b) {
return !(a == b); }
915 MIRTKCU_API
inline bool operator !=(
const double3x3 &a,
const double3x3 &b) {
return !(a == b); }
916 MIRTKCU_API
inline bool operator !=(
const double3x4 &a,
const double3x4 &b) {
return !(a == b); }
917 MIRTKCU_API
inline bool operator !=(
const double4x4 &a,
const double4x4 &b) {
return !(a == b); }
927 MIRTKCU_API
inline double clamp(
double f,
double a,
double b)
929 return max(a, min(f, b));
940 return p.x == s && p.y == s && p.z == s;
947 return p.x < dim.x || p.y < dim.y || p.z < dim.z;
952 MIRTKCU_API
inline bool operator >(uint3 p, uint3 dim)
954 return p.x > dim.x || p.y > dim.y || p.z > dim.z;
959 MIRTKCU_API
inline bool operator >=(uint3 p, uint3 dim)
961 return p.x >= dim.x || p.y >= dim.y || p.z >= dim.z;
974 MIRTKCU_API
inline uint3 operator *(uint3 idx, dim3 dim)
976 return make_uint3(idx.x * dim.x, idx.y * dim.y, idx.z * dim.z);
981 MIRTKCU_API
inline uint3 operator *(dim3 dim, uint3 idx)
992 MIRTKCU_API
inline void operator +=(float1 &a, float1 b)
1005 MIRTKCU_API
inline void operator +=(float2x2 &m,
float s)
1012 MIRTKCU_API
inline void operator +=(float3x3 &m,
float s)
1014 m.a += s, m.b += s, m.c += s;
1019 MIRTKCU_API
inline void operator +=(float3x4 &m,
float s)
1021 m.a += s, m.b += s, m.c += s;
1026 MIRTKCU_API
inline void operator +=(float4x4 &m,
float s)
1028 m.a += s, m.b += s, m.c += s, m.d += s;
1033 MIRTKCU_API
inline void operator +=(float2x2 &a, float2x2 b)
1035 a.a += b.a, a.b += b.b;
1040 MIRTKCU_API
inline void operator +=(float3x3 &a, float3x3 b)
1042 a.a += b.a, a.b += b.b, a.c += b.c;
1047 MIRTKCU_API
inline void operator +=(float3x4 &a, float3x4 b)
1049 a.a += b.a, a.b += b.b, a.c += b.c;
1054 MIRTKCU_API
inline void operator +=(float4x4 &a, float4x4 b)
1056 a.a += b.a, a.b += b.b, a.c += b.c, a.d += b.d;
1061 MIRTKCU_API
inline float1 operator +(float1 a, float1 b)
1063 return make_float1(a.x + b.x);
1074 MIRTKCU_API
inline float2x2 operator +(float2x2 m,
float s)
1083 MIRTKCU_API
inline float3x3 operator +(float3x3 m,
float s)
1092 MIRTKCU_API
inline float3x4 operator +(float3x4 m,
float s)
1101 MIRTKCU_API
inline float4x4 operator +(float4x4 m,
float s)
1110 MIRTKCU_API
inline float2x2 operator +(float2x2 a, float2x2 b)
1120 MIRTKCU_API
inline float3x3 operator +(float3x3 a, float3x3 b)
1131 MIRTKCU_API
inline float3x4 operator +(float3x4 a, float3x4 b)
1142 MIRTKCU_API
inline float4x4 operator +(float4x4 a, float4x4 b)
1154 MIRTKCU_API
inline void operator -=(float1 &a, float1 b)
1167 MIRTKCU_API
inline void operator -=(float2x2 &m,
float s)
1174 MIRTKCU_API
inline void operator -=(float3x3 &m,
float s)
1176 m.a -= s, m.b -= s, m.c -= s;
1181 MIRTKCU_API
inline void operator -=(float3x4 &m,
float s)
1183 m.a -= s, m.b -= s, m.c -= s;
1188 MIRTKCU_API
inline void operator -=(float4x4 &m,
float s)
1190 m.a -= s, m.b -= s, m.c -= s, m.d -= s;
1195 MIRTKCU_API
inline void operator -=(float2x2 &a, float2x2 b)
1197 a.a -= b.a, a.b -= b.b;
1202 MIRTKCU_API
inline void operator -=(float3x3 &a, float3x3 b)
1204 a.a -= b.a, a.b -= b.b, a.c -= b.c;
1209 MIRTKCU_API
inline void operator -=(float3x4 &a, float3x4 b)
1211 a.a -= b.a, a.b -= b.b, a.c -= b.c;
1216 MIRTKCU_API
inline void operator -=(float4x4 &a, float4x4 b)
1218 a.a -= b.a, a.b -= b.b, a.c -= b.c, a.d -= b.d;
1223 MIRTKCU_API
inline float1 operator -(float1 a, float1 b)
1225 return make_float1(a.x - b.x);
1236 MIRTKCU_API
inline float2x2 operator -(float2x2 m,
float s)
1245 MIRTKCU_API
inline float3x3 operator -(float3x3 m,
float s)
1254 MIRTKCU_API
inline float3x4 operator -(float3x4 m,
float s)
1263 MIRTKCU_API
inline float4x4 operator -(float4x4 m,
float s)
1272 MIRTKCU_API
inline float2x2 operator -(float2x2 a, float2x2 b)
1282 MIRTKCU_API
inline float3x3 operator -(float3x3 a, float3x3 b)
1293 MIRTKCU_API
inline float3x4 operator -(float3x4 a, float3x4 b)
1304 MIRTKCU_API
inline float4x4 operator -(float4x4 a, float4x4 b)
1316 MIRTKCU_API
inline float1 operator *(float1 v,
float s)
1318 return make_float1(v.x * s);
1329 MIRTKCU_API
inline void operator *=(float2x2 &m,
float s)
1336 MIRTKCU_API
inline void operator *=(float3x3 &m,
float s)
1338 m.a *= s, m.b *= s, m.c *= s;
1343 MIRTKCU_API
inline void operator *=(float3x4 &m,
float s)
1345 m.a *= s, m.b *= s, m.c *= s;
1350 MIRTKCU_API
inline void operator *=(float4x4 &m,
float s)
1352 m.a *= s, m.b *= s, m.c *= s, m.d *= s;
1357 MIRTKCU_API
inline float2x2 operator *(float2x2 m,
float s)
1360 o.a = make_float2(m.a.x * s, m.a.y * s);
1361 o.b = make_float2(m.b.x * s, m.b.y * s);
1367 MIRTKCU_API
inline float2x2 operator *(
float s, float2x2 m)
1374 MIRTKCU_API
inline float2 operator *(float2x2 m, float2 p)
1377 o.x = m.a.x * p.x + m.a.y * p.y;
1378 o.y = m.b.x * p.x + m.b.y * p.y;
1384 MIRTKCU_API
inline float2 operator *(float2 p, float2x2 m)
1387 o.x = p.x * m.a.x + p.y * m.b.x;
1388 o.y = p.x * m.a.y + p.y * m.b.y;
1394 MIRTKCU_API
inline float3x3 operator *(float3x3 m,
float s)
1397 o.a = make_float3(m.a.x * s, m.a.y * s, m.a.z * s);
1398 o.b = make_float3(m.b.x * s, m.b.y * s, m.b.z * s);
1399 o.c = make_float3(m.c.x * s, m.c.y * s, m.c.z * s);
1405 MIRTKCU_API
inline float3x3 operator *(
float s, float3x3 m)
1412 MIRTKCU_API
inline float3 operator *(float3x3 m, float3 p)
1415 o.x = m.a.x * p.x + m.a.y * p.y + m.a.z * p.z;
1416 o.y = m.b.x * p.x + m.b.y * p.y + m.b.z * p.z;
1417 o.z = m.c.x * p.x + m.c.y * p.y + m.c.z * p.z;
1423 MIRTKCU_API
inline float3 operator *(float3 p, float3x3 m)
1426 o.x = p.x * m.a.x + p.y * m.b.x + p.z * m.c.x;
1427 o.y = p.x * m.a.y + p.y * m.b.y + p.z * m.c.y;
1428 o.z = p.x * m.a.z + p.y * m.b.z + p.z * m.c.z;
1434 MIRTKCU_API
inline float3x4 operator *(float3x4 m,
float s)
1445 MIRTKCU_API
inline float3x4 operator *(
float s, float3x4 m)
1452 MIRTKCU_API
inline float2 operator *(float3x4 m, float2 p)
1455 o.x = m.a.x * p.x + m.a.y * p.y + m.a.w;
1456 o.y = m.b.x * p.x + m.b.y * p.y + m.b.w;
1462 MIRTKCU_API
inline float2 operator *(float3x4 m, int2 p)
1464 return m * make_float2(p);
1469 MIRTKCU_API
inline float2 operator *(float3x4 m, uint2 p)
1471 return m * make_float2(p);
1476 MIRTKCU_API
inline float3 operator *(float3x4 m, float3 p)
1479 o.x = m.a.x * p.x + m.a.y * p.y + m.a.z * p.z + m.a.w;
1480 o.y = m.b.x * p.x + m.b.y * p.y + m.b.z * p.z + m.b.w;
1481 o.z = m.c.x * p.x + m.c.y * p.y + m.c.z * p.z + m.c.w;
1487 MIRTKCU_API
inline float3 operator *(float3x4 m, int3 p)
1489 return m * make_float3(p);
1494 MIRTKCU_API
inline float3 operator *(float3x4 m, uint3 p)
1496 return m * make_float3(p);
1501 MIRTKCU_API
inline float4x4 operator *(float4x4 m,
float s)
1513 MIRTKCU_API
inline float4x4 operator *(
float s, float4x4 m)
1520 MIRTKCU_API
inline float2x2 operator *(float2x2 m, float2x2 n)
1523 o.a.x = m.a.x * n.a.x + m.a.y * n.b.x;
1524 o.a.y = m.a.x * n.a.y + m.a.y * n.b.y;
1525 o.b.x = m.b.x * n.a.x + m.b.y * n.b.x;
1526 o.b.y = m.b.x * n.a.y + m.b.y * n.b.y;
1532 MIRTKCU_API
inline float3x3 operator *(float3x3 m, float3x3 n)
1535 o.a.x = m.a.x * n.a.x + m.a.y * n.b.x + m.a.z * n.c.x;
1536 o.a.y = m.a.x * n.a.y + m.a.y * n.b.y + m.a.z * n.c.y;
1537 o.a.z = m.a.x * n.a.z + m.a.y * n.b.z + m.a.z * n.c.z;
1538 o.b.x = m.b.x * n.a.x + m.b.y * n.b.x + m.b.z * n.c.x;
1539 o.b.y = m.b.x * n.a.y + m.b.y * n.b.y + m.b.z * n.c.y;
1540 o.b.z = m.b.x * n.a.z + m.b.y * n.b.z + m.b.z * n.c.z;
1541 o.c.x = m.c.x * n.a.x + m.c.y * n.b.x + m.c.z * n.c.x;
1542 o.c.y = m.c.x * n.a.y + m.c.y * n.b.y + m.c.z * n.c.y;
1543 o.c.z = m.c.x * n.a.z + m.c.y * n.b.z + m.c.z * n.c.z;
1549 MIRTKCU_API
inline void operator *=(float2x2 &m, float2x2 n)
1556 MIRTKCU_API
inline void operator *=(float3x3 &m, float3x3 n)
1563 MIRTKCU_API
inline void operator /=(float2x2 &m,
float s)
1570 MIRTKCU_API
inline void operator /=(float3x3 &m,
float s)
1572 m.a /= s, m.b /= s, m.c /= s;
1577 MIRTKCU_API
inline void operator /=(float3x4 &m,
float s)
1579 m.a /= s, m.b /= s, m.c /= s;
1584 MIRTKCU_API
inline void operator /=(float4x4 &m,
float s)
1586 m.a /= s, m.b /= s, m.c /= s, m.d /= s;
1591 MIRTKCU_API
inline float2x2 operator /(float2x2 m,
float s)
1599 MIRTKCU_API
inline float3x3 operator /(float3x3 m,
float s)
1607 MIRTKCU_API
inline float3x4 operator /(float3x4 m,
float s)
1615 MIRTKCU_API
inline float4x4 operator /(float4x4 m,
float s)
1627 MIRTKCU_API
inline void operator +=(double1 &a,
double s)
1634 MIRTKCU_API
inline void operator +=(double2 &a,
double s)
1641 MIRTKCU_API
inline void operator +=(double3 &a,
double s)
1643 a.x += s, a.y += s, a.z += s;
1648 MIRTKCU_API
inline void operator +=(double4 &a,
double s)
1650 a.x += s, a.y += s, a.z += s, a.w += s;
1655 MIRTKCU_API
inline void operator +=(double2x2 &m,
double s)
1662 MIRTKCU_API
inline void operator +=(double3x3 &m,
double s)
1664 m.a += s, m.b += s, m.c += s;
1669 MIRTKCU_API
inline void operator +=(double3x4 &m,
double s)
1671 m.a += s, m.b += s, m.c += s;
1676 MIRTKCU_API
inline void operator +=(double4x4 &m,
double s)
1678 m.a += s, m.b += s, m.c += s, m.d += s;
1683 MIRTKCU_API
inline double1 operator +(double1 a,
double s)
1692 MIRTKCU_API
inline double1 operator +(
double s, double1 a)
1699 MIRTKCU_API
inline double2 operator +(double2 a,
double s)
1709 MIRTKCU_API
inline double2 operator +(
double s, double2 a)
1716 MIRTKCU_API
inline double3 operator +(double3 a,
double s)
1727 MIRTKCU_API
inline double3 operator +(
double s, double3 a)
1734 MIRTKCU_API
inline double4 operator +(double4 a,
double s)
1746 MIRTKCU_API
inline double4 operator +(
double s, double4 a)
1753 MIRTKCU_API
inline double2x2 operator +(double2x2 m,
double s)
1762 MIRTKCU_API
inline double3x3 operator +(double3x3 m,
double s)
1771 MIRTKCU_API
inline double3x4 operator +(double3x4 m,
double s)
1780 MIRTKCU_API
inline double4x4 operator +(double4x4 m,
double s)
1789 MIRTKCU_API
inline void operator +=(double1 &a, double1 b)
1796 MIRTKCU_API
inline void operator +=(double2 &a, double2 b)
1798 a.x += b.x, a.y += b.y;
1803 MIRTKCU_API
inline void operator +=(double3 &a, double3 b)
1805 a.x += b.x, a.y += b.y, a.z += b.z;
1810 MIRTKCU_API
inline void operator +=(double4 &a, double4 b)
1812 a.x += b.x, a.y += b.y, a.z += b.z, a.w += b.w;
1817 MIRTKCU_API
inline void operator +=(double2x2 &a, double2x2 b)
1819 a.a += b.a, a.b += b.b;
1824 MIRTKCU_API
inline void operator +=(double3x3 &a, double3x3 b)
1826 a.a += b.a, a.b += b.b, a.c += b.c;
1831 MIRTKCU_API
inline void operator +=(double3x4 &a, double3x4 b)
1833 a.a += b.a, a.b += b.b, a.c += b.c;
1838 MIRTKCU_API
inline void operator +=(double4x4 &a, double4x4 b)
1840 a.a += b.a, a.b += b.b, a.c += b.c, a.d += b.d;
1845 MIRTKCU_API
inline double1 operator +(double1 a, double1 b)
1847 return make_double1(a.x + b.x);
1852 MIRTKCU_API
inline double2 operator +(double2 a, double2 b)
1854 return make_double2(a.x + b.x, a.y + b.y);
1859 MIRTKCU_API
inline double3 operator +(double3 a, double3 b)
1861 return make_double3(a.x + b.x, a.y + b.y, a.z + b.z);
1866 MIRTKCU_API
inline double4 operator +(double4 a, double4 b)
1868 return make_double4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
1873 MIRTKCU_API
inline double2x2 operator +(double2x2 a, double2x2 b)
1883 MIRTKCU_API
inline double3x3 operator +(double3x3 a, double3x3 b)
1894 MIRTKCU_API
inline double3x4 operator +(double3x4 a, double3x4 b)
1905 MIRTKCU_API
inline double4x4 operator +(double4x4 a, double4x4 b)
1917 MIRTKCU_API
inline void operator -=(double1 &a,
double s)
1924 MIRTKCU_API
inline void operator -=(double2 &a,
double s)
1931 MIRTKCU_API
inline void operator -=(double3 &a,
double s)
1933 a.x -= s, a.y -= s, a.z -= s;
1938 MIRTKCU_API
inline void operator -=(double4 &a,
double s)
1940 a.x -= s, a.y -= s, a.z -= s, a.w -= s;
1945 MIRTKCU_API
inline void operator -=(double2x2 &m,
double s)
1952 MIRTKCU_API
inline void operator -=(double3x3 &m,
double s)
1954 m.a -= s, m.b -= s, m.c -= s;
1959 MIRTKCU_API
inline void operator -=(double3x4 &m,
double s)
1961 m.a -= s, m.b -= s, m.c -= s;
1966 MIRTKCU_API
inline void operator -=(double4x4 &m,
double s)
1968 m.a -= s, m.b -= s, m.c -= s, m.d -= s;
1973 MIRTKCU_API
inline double1 operator -(double1 a,
double s)
1982 MIRTKCU_API
inline double1 operator -(
double s, double1 a)
1989 MIRTKCU_API
inline double2 operator -(double2 a,
double s)
1999 MIRTKCU_API
inline double2 operator -(
double s, double2 a)
2006 MIRTKCU_API
inline double3 operator -(double3 a,
double s)
2017 MIRTKCU_API
inline double3 operator -(
double s, double3 a)
2024 MIRTKCU_API
inline double4 operator -(double4 a,
double s)
2036 MIRTKCU_API
inline double4 operator -(
double s, double4 a)
2043 MIRTKCU_API
inline double2x2 operator -(double2x2 m,
double s)
2052 MIRTKCU_API
inline double3x3 operator -(double3x3 m,
double s)
2061 MIRTKCU_API
inline double3x4 operator -(double3x4 m,
double s)
2070 MIRTKCU_API
inline double4x4 operator -(double4x4 m,
double s)
2079 MIRTKCU_API
inline void operator -=(double1 &a, double1 b)
2086 MIRTKCU_API
inline void operator -=(double2 &a, double2 b)
2088 a.x -= b.x, a.y -= b.y;
2093 MIRTKCU_API
inline void operator -=(double3 &a, double3 b)
2095 a.x -= b.x, a.y -= b.y, a.z -= b.z;
2100 MIRTKCU_API
inline void operator -=(double4 &a, double4 b)
2102 a.x -= b.x, a.y -= b.y, a.z -= b.z, a.w -= b.w;
2107 MIRTKCU_API
inline void operator -=(double2x2 &a, double2x2 b)
2109 a.a -= b.a, a.b -= b.b;
2114 MIRTKCU_API
inline void operator -=(double3x3 &a, double3x3 b)
2116 a.a -= b.a, a.b -= b.b, a.c -= b.c;
2121 MIRTKCU_API
inline void operator -=(double3x4 &a, double3x4 b)
2123 a.a -= b.a, a.b -= b.b, a.c -= b.c;
2128 MIRTKCU_API
inline void operator -=(double4x4 &a, double4x4 b)
2130 a.a -= b.a, a.b -= b.b, a.c -= b.c, a.d -= b.d;
2135 MIRTKCU_API
inline double1 operator -(double1 a, double1 b)
2137 return make_double1(a.x - b.x);
2142 MIRTKCU_API
inline double2 operator -(double2 a, double2 b)
2144 return make_double2(a.x - b.x, a.y - b.y);
2149 MIRTKCU_API
inline double3 operator -(double3 a, double3 b)
2151 return make_double3(a.x - b.x, a.y - b.y, a.z - b.z);
2156 MIRTKCU_API
inline double4 operator -(double4 a, double4 b)
2158 return make_double4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
2163 MIRTKCU_API
inline double2x2 operator -(double2x2 a, double2x2 b)
2173 MIRTKCU_API
inline double3x3 operator -(double3x3 a, double3x3 b)
2184 MIRTKCU_API
inline double3x4 operator -(double3x4 a, double3x4 b)
2195 MIRTKCU_API
inline double4x4 operator -(double4x4 a, double4x4 b)
2207 MIRTKCU_API
inline void operator *=(double1 &a,
double s)
2214 MIRTKCU_API
inline void operator *=(double2 &a,
double s)
2221 MIRTKCU_API
inline void operator *=(double3 &a,
double s)
2223 a.x *= s, a.y *= s, a.z *= s;
2228 MIRTKCU_API
inline void operator *=(double4 &a,
double s)
2230 a.x *= s, a.y *= s, a.z *= s, a.w *= s;
2235 MIRTKCU_API
inline double1 operator *(double1 v,
double s)
2237 return make_double1(v.x * s);
2242 MIRTKCU_API
inline double1 operator *(
double s, double1 a)
2249 MIRTKCU_API
inline double2 operator *(double2 v,
double s)
2251 return make_double2(v.x * s, v.y * s);
2256 MIRTKCU_API
inline double2 operator *(
double s, double2 a)
2263 MIRTKCU_API
inline double3 operator *(double3 v,
double s)
2265 return make_double3(v.x * s, v.y * s, v.z * s);
2270 MIRTKCU_API
inline double3 operator *(
double s, double3 a)
2277 MIRTKCU_API
inline double4 operator *(double4 v,
double s)
2279 return make_double4(v.x * s, v.y * s, v.z * s, v.w * s);
2284 MIRTKCU_API
inline double4 operator *(
double s, double4 a)
2291 MIRTKCU_API
inline void operator *=(double1 &a, double1 b)
2298 MIRTKCU_API
inline void operator *=(double2 &a, double2 b)
2300 a.x *= b.x, a.y *= b.y;
2305 MIRTKCU_API
inline void operator *=(double3 &a, double3 b)
2307 a.x *= b.x, a.y *= b.y, a.z *= b.z;
2312 MIRTKCU_API
inline void operator *=(double4 &a, double4 b)
2314 a.x *= b.x, a.y *= b.y, a.z *= b.z, a.w *= b.w;
2319 MIRTKCU_API
inline double1 operator *(double1 a, double1 b)
2321 return make_double1(a.x * b.x);
2326 MIRTKCU_API
inline double2 operator *(double2 a, double2 b)
2328 return make_double2(a.x * b.x, a.y * b.y);
2333 MIRTKCU_API
inline double3 operator *(double3 a, double3 b)
2335 return make_double3(a.x * b.x, a.y * b.y, a.z * b.z);
2340 MIRTKCU_API
inline double4 operator *(double4 a, double4 b)
2342 return make_double4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
2347 MIRTKCU_API
inline void operator /=(double1 &a,
double s)
2354 MIRTKCU_API
inline void operator /=(double2 &a,
double s)
2361 MIRTKCU_API
inline void operator /=(double3 &a,
double s)
2363 a.x /= s, a.y /= s, a.z /= s;
2368 MIRTKCU_API
inline void operator /=(double4 &a,
double s)
2370 a.x /= s, a.y /= s, a.z /= s, a.w /= s;
2375 MIRTKCU_API
inline void operator /=(double2x2 &m,
double s)
2382 MIRTKCU_API
inline void operator /=(double3x3 &m,
double s)
2384 m.a /= s, m.b /= s, m.c /= s;
2389 MIRTKCU_API
inline void operator /=(double3x4 &m,
double s)
2391 m.a /= s, m.b /= s, m.c /= s;
2396 MIRTKCU_API
inline void operator /=(double4x4 &m,
double s)
2398 m.a /= s, m.b /= s, m.c /= s, m.d /= s;
2403 MIRTKCU_API
inline double1 operator /(double1 v,
double s)
2405 return make_double1(v.x / s);
2410 MIRTKCU_API
inline double2 operator /(double2 v,
double s)
2412 return make_double2(v.x / s, v.y / s);
2417 MIRTKCU_API
inline double3 operator /(double3 v,
double s)
2419 return make_double3(v.x / s, v.y / s, v.z / s);
2424 MIRTKCU_API
inline double4 operator /(double4 v,
double s)
2426 return make_double4(v.x / s, v.y / s, v.z / s, v.w / s);
2431 MIRTKCU_API
inline double2x2 operator /(double2x2 m,
double s)
2439 MIRTKCU_API
inline double3x3 operator /(double3x3 m,
double s)
2447 MIRTKCU_API
inline double3x4 operator /(double3x4 m,
double s)
2455 MIRTKCU_API
inline double4x4 operator /(double4x4 m,
double s)
2463 MIRTKCU_API
inline void operator /=(double1 &a, double1 b)
2470 MIRTKCU_API
inline void operator /=(double2 &a, double2 b)
2472 a.x /= b.x, a.y /= b.y;
2477 MIRTKCU_API
inline void operator /=(double3 &a, double3 b)
2479 a.x /= b.x, a.y /= b.y, a.z /= b.z;
2484 MIRTKCU_API
inline void operator /=(double4 &a, double4 b)
2486 a.x /= b.x, a.y /= b.y, a.z /= b.z, a.w /= b.w;
2491 MIRTKCU_API
inline double1 operator /(double1 a, double1 b)
2493 return make_double1(a.x / b.x);
2498 MIRTKCU_API
inline double2 operator /(double2 a, double2 b)
2500 return make_double2(a.x / b.x, a.y / b.y);
2505 MIRTKCU_API
inline double3 operator /(double3 a, double3 b)
2507 return make_double3(a.x / b.x, a.y / b.y, a.z / b.z);
2512 MIRTKCU_API
inline double4 operator /(double4 a, double4 b)
2514 return make_double4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
2519 MIRTKCU_API
inline void operator *=(double2x2 &m,
double s)
2526 MIRTKCU_API
inline void operator *=(double3x3 &m,
double s)
2528 m.a *= s, m.b *= s, m.c *= s;
2533 MIRTKCU_API
inline void operator *=(double3x4 &m,
double s)
2535 m.a *= s, m.b *= s, m.c *= s;
2540 MIRTKCU_API
inline void operator *=(double4x4 &m,
double s)
2542 m.a *= s, m.b *= s, m.c *= s, m.d *= s;
2547 MIRTKCU_API
inline double2x2 operator *(double2x2 m,
double s)
2550 o.a = make_double2(m.a.x * s, m.a.y * s);
2551 o.b = make_double2(m.b.x * s, m.b.y * s);
2557 MIRTKCU_API
inline double2x2 operator *(
double s, double2x2 m)
2564 MIRTKCU_API
inline double2 operator *(double2x2 m, double2 p)
2567 o.x = m.a.x * p.x + m.a.y * p.y;
2568 o.y = m.b.x * p.x + m.b.y * p.y;
2574 MIRTKCU_API
inline double2 operator *(double2 p, double2x2 m)
2577 o.x = p.x * m.a.x + p.y * m.b.x;
2578 o.y = p.x * m.a.y + p.y * m.b.y;
2584 MIRTKCU_API
inline double3x3 operator *(double3x3 m,
double s)
2587 o.a = make_double3(m.a.x * s, m.a.y * s, m.a.z * s);
2588 o.b = make_double3(m.b.x * s, m.b.y * s, m.b.z * s);
2589 o.c = make_double3(m.c.x * s, m.c.y * s, m.c.z * s);
2595 MIRTKCU_API
inline double3x3 operator *(
double s, double3x3 m)
2602 MIRTKCU_API
inline double3 operator *(double3x3 m, double3 p)
2605 o.x = m.a.x * p.x + m.a.y * p.y + m.a.z * p.z;
2606 o.y = m.b.x * p.x + m.b.y * p.y + m.b.z * p.z;
2607 o.z = m.c.x * p.x + m.c.y * p.y + m.c.z * p.z;
2613 MIRTKCU_API
inline double3 operator *(double3 p, double3x3 m)
2616 o.x = p.x * m.a.x + p.y * m.b.x + p.z * m.c.x;
2617 o.y = p.x * m.a.y + p.y * m.b.y + p.z * m.c.y;
2618 o.z = p.x * m.a.z + p.y * m.b.z + p.z * m.c.z;
2624 MIRTKCU_API
inline double3x4 operator *(double3x4 m,
double s)
2635 MIRTKCU_API
inline double3x4 operator *(
double s, double3x4 m)
2642 MIRTKCU_API
inline double4x4 operator *(double4x4 m,
double s)
2653 MIRTKCU_API
inline double4x4 operator *(
double s, double4x4 m)
2660 MIRTKCU_API
inline double2 operator *(double3x4 m, double2 p)
2663 o.x = m.a.x * p.x + m.a.y * p.y + m.a.w;
2664 o.y = m.b.x * p.x + m.b.y * p.y + m.b.w;
2670 MIRTKCU_API
inline double2 operator *(double3x4 m, int2 p)
2672 return m * make_double2(p);
2677 MIRTKCU_API
inline double2 operator *(double3x4 m, uint2 p)
2679 return m * make_double2(p);
2684 MIRTKCU_API
inline double3 operator *(double3x4 m, double3 p)
2687 o.x = m.a.x * p.x + m.a.y * p.y + m.a.z * p.z + m.a.w;
2688 o.y = m.b.x * p.x + m.b.y * p.y + m.b.z * p.z + m.b.w;
2689 o.z = m.c.x * p.x + m.c.y * p.y + m.c.z * p.z + m.c.w;
2695 MIRTKCU_API
inline double3 operator *(double3x4 m, int3 p)
2697 return m * make_double3(p);
2702 MIRTKCU_API
inline double3 operator *(double3x4 m, uint3 p)
2704 return m * make_double3(p);
2709 MIRTKCU_API
inline double2x2 operator *(double2x2 m, double2x2 n)
2712 o.a.x = m.a.x * n.a.x + m.a.y * n.b.x;
2713 o.a.y = m.a.x * n.a.y + m.a.y * n.b.y;
2714 o.b.x = m.b.x * n.a.x + m.b.y * n.b.x;
2715 o.b.y = m.b.x * n.a.y + m.b.y * n.b.y;
2721 MIRTKCU_API
inline double3x3 operator *(double3x3 m, double3x3 n)
2724 o.a.x = m.a.x * n.a.x + m.a.y * n.b.x + m.a.z * n.c.x;
2725 o.a.y = m.a.x * n.a.y + m.a.y * n.b.y + m.a.z * n.c.y;
2726 o.a.z = m.a.x * n.a.z + m.a.y * n.b.z + m.a.z * n.c.z;
2727 o.b.x = m.b.x * n.a.x + m.b.y * n.b.x + m.b.z * n.c.x;
2728 o.b.y = m.b.x * n.a.y + m.b.y * n.b.y + m.b.z * n.c.y;
2729 o.b.z = m.b.x * n.a.z + m.b.y * n.b.z + m.b.z * n.c.z;
2730 o.c.x = m.c.x * n.a.x + m.c.y * n.b.x + m.c.z * n.c.x;
2731 o.c.y = m.c.x * n.a.y + m.c.y * n.b.y + m.c.z * n.c.y;
2732 o.c.z = m.c.x * n.a.z + m.c.y * n.b.z + m.c.z * n.c.z;
2738 MIRTKCU_API
inline void operator *=(double2x2 &m, double2x2 n)
2745 MIRTKCU_API
inline void operator *=(double3x3 &m, double3x3 n)
2759 MIRTKCU_API
inline float1 floor(float1 v)
2761 return make_float1(floorf(v.x));
2765 MIRTKCU_API
inline float2 floor(float2 v)
2767 return make_float2(floorf(v.x), floorf(v.y));
2771 MIRTKCU_API
inline float3 floor(float3 v)
2773 return make_float3(floorf(v.x), floorf(v.y), floorf(v.z));
2777 MIRTKCU_API
inline float4 floor(float4 v)
2779 return make_float4(floorf(v.x), floorf(v.y), floorf(v.z), floorf(v.w));
2783 MIRTKCU_API
inline float1 ceil(float1 v)
2785 return make_float1(ceilf(v.x));
2789 MIRTKCU_API
inline float2 ceil(float2 v)
2791 return make_float2(ceilf(v.x), ceilf(v.y));
2795 MIRTKCU_API
inline float3 ceil(float3 v)
2797 return make_float3(ceilf(v.x), ceilf(v.y), ceilf(v.z));
2801 MIRTKCU_API
inline float4 ceil(float4 v)
2803 return make_float4(ceilf(v.x), ceilf(v.y), ceilf(v.z), ceilf(v.w));
2807 MIRTKCU_API
inline float1 round(float1 v)
2809 return make_float1(round(v.x));
2813 MIRTKCU_API
inline float2 round(float2 v)
2815 return make_float2(round(v.x), round(v.y));
2819 MIRTKCU_API
inline float3 round(float3 v)
2821 return make_float3(
float(round(v.x)),
float(round(v.y)),
float(round(v.z)));
2825 MIRTKCU_API
inline float4 round(float4 v)
2827 return make_float4(
float(round(v.x)),
float(round(v.y)),
float(round(v.z)),
float(round(v.w)));
2835 MIRTKCU_API
inline double1 floor(double1 v)
2837 return make_double1(floor(v.x));
2841 MIRTKCU_API
inline double2 floor(double2 v)
2843 return make_double2(floor(v.x), floor(v.y));
2847 MIRTKCU_API
inline double3 floor(double3 v)
2849 return make_double3(floor(v.x), floor(v.y), floor(v.z));
2853 MIRTKCU_API
inline double4 floor(double4 v)
2855 return make_double4(floor(v.x), floor(v.y), floor(v.z), floor(v.w));
2859 MIRTKCU_API
inline double1 ceil(double1 v)
2861 return make_double1(ceil(v.x));
2865 MIRTKCU_API
inline double2 ceil(double2 v)
2867 return make_double2(ceil(v.x), ceil(v.y));
2871 MIRTKCU_API
inline double3 ceil(double3 v)
2873 return make_double3(ceil(v.x), ceil(v.y), ceil(v.z));
2877 MIRTKCU_API
inline double4 ceil(double4 v)
2879 return make_double4(ceil(v.x), ceil(v.y), ceil(v.z), ceil(v.w));
2883 MIRTKCU_API
inline double1 round(double1 v)
2885 return make_double1(
double(round(v.x)));
2889 MIRTKCU_API
inline double2 round(double2 v)
2891 return make_double2(
double(round(v.x)),
double(round(v.y)));
2895 MIRTKCU_API
inline double3 round(double3 v)
2897 return make_double3(
double(round(v.x)),
double(round(v.y)),
double(round(v.z)));
2901 MIRTKCU_API
inline double4 round(double4 v)
2903 return make_double4(
double(round(v.x)),
double(round(v.y)),
double(round(v.z)),
double(round(v.w)));
2915 MIRTKCU_API
inline float frac(
float v)
2917 return v - floorf(v);
2921 MIRTKCU_API
inline float2 frac(float2 v)
2923 return make_float2(frac(v.x), frac(v.y));
2927 MIRTKCU_API
inline float3 frac(float3 v)
2929 return make_float3(frac(v.x), frac(v.y), frac(v.z));
2933 MIRTKCU_API
inline float4 frac(float4 v)
2935 return make_float4(frac(v.x), frac(v.y), frac(v.z), frac(v.w));
2943 MIRTKCU_API
inline double frac(
double v)
2945 return v - floor(v);
2949 MIRTKCU_API
inline double2 frac(double2 v)
2951 return make_double2(frac(v.x), frac(v.y));
2955 MIRTKCU_API
inline double3 frac(double3 v)
2957 return make_double3(frac(v.x), frac(v.y), frac(v.z));
2961 MIRTKCU_API
inline double4 frac(double4 v)
2963 return make_double4(frac(v.x), frac(v.y), frac(v.z), frac(v.w));
2975 MIRTKCU_API
inline double min(double2 a)
2977 return min(a.x, a.y);
2981 MIRTKCU_API
inline double min(double3 a)
2983 return min(a.x, min(a.y, a.z));
2987 MIRTKCU_API
inline double min(double4 a)
2989 return min(min(a.x, a.y), min(a.z, a.w));
2993 MIRTKCU_API
inline double max(double2 a)
2995 return max(a.x, a.y);
2999 MIRTKCU_API
inline double max(double3 a)
3001 return max(a.x, max(a.y, a.z));
3005 MIRTKCU_API
inline double max(double4 a)
3007 return max(max(a.x, a.y), max(a.z, a.w));
3019 MIRTKCU_API
inline double2 fabs(double2 v)
3021 return make_double2(fabs(v.x), fabs(v.y));
3025 MIRTKCU_API
inline double3 fabs(double3 v)
3027 return make_double3(fabs(v.x), fabs(v.y), fabs(v.z));
3031 MIRTKCU_API
inline double4 fabs(double4 v)
3033 return make_double4(fabs(v.x), fabs(v.y), fabs(v.z), fabs(v.w));
3045 MIRTKCU_API
inline float1 pow(float1 v,
int e)
3047 return make_float1(pow(v.x, e));
3051 MIRTKCU_API
inline float2 pow(float2 v,
int e)
3053 return make_float2(pow(v.x, e), pow(v.y, e));
3057 MIRTKCU_API
inline float3 pow(float3 v,
int e)
3059 return make_float3(pow(v.x, e), pow(v.y, e), pow(v.z, e));
3063 MIRTKCU_API
inline float4 pow(float4 v,
int e)
3065 return make_float4(pow(v.x, e), pow(v.y, e), pow(v.z, e), pow(v.w, e));
3069 MIRTKCU_API
inline float1 pow(float1 v,
float e)
3071 return make_float1(pow(v.x, e));
3075 MIRTKCU_API
inline float2 pow(float2 v,
float e)
3077 return make_float2(pow(v.x, e), pow(v.y, e));
3081 MIRTKCU_API
inline float3 pow(float3 v,
float e)
3083 return make_float3(pow(v.x, e), pow(v.y, e), pow(v.z, e));
3087 MIRTKCU_API
inline float4 pow(float4 v,
float e)
3089 return make_float4(pow(v.x, e), pow(v.y, e), pow(v.z, e), pow(v.w, e));
3093 MIRTKCU_API
inline float1 sqrt(float1 v)
3095 return make_float1(sqrt(v.x));
3099 MIRTKCU_API
inline float2 sqrt(float2 v)
3101 return make_float2(sqrt(v.x), sqrt(v.y));
3105 MIRTKCU_API
inline float3 sqrt(float3 v)
3107 return make_float3(sqrt(v.x), sqrt(v.y), sqrt(v.z));
3111 MIRTKCU_API
inline float4 sqrt(float4 v)
3113 return make_float4(sqrt(v.x), sqrt(v.y), sqrt(v.z), sqrt(v.w));
3121 MIRTKCU_API
inline double1 pow(double1 v,
int e)
3123 return make_double1(pow(v.x, e));
3127 MIRTKCU_API
inline double2 pow(double2 v,
int e)
3129 return make_double2(pow(v.x, e), pow(v.y, e));
3133 MIRTKCU_API
inline double3 pow(double3 v,
int e)
3135 return make_double3(pow(v.x, e), pow(v.y, e), pow(v.z, e));
3139 MIRTKCU_API
inline double4 pow(double4 v,
int e)
3141 return make_double4(pow(v.x, e), pow(v.y, e), pow(v.z, e), pow(v.w, e));
3145 MIRTKCU_API
inline double1 pow(double1 v,
double e)
3147 return make_double1(pow(v.x, e));
3151 MIRTKCU_API
inline double2 pow(double2 v,
double e)
3153 return make_double2(pow(v.x, e), pow(v.y, e));
3157 MIRTKCU_API
inline double3 pow(double3 v,
double e)
3159 return make_double3(pow(v.x, e), pow(v.y, e), pow(v.z, e));
3163 MIRTKCU_API
inline double4 pow(double4 v,
double e)
3165 return make_double4(pow(v.x, e), pow(v.y, e), pow(v.z, e), pow(v.w, e));
3169 MIRTKCU_API
inline double1 sqrt(double1 v)
3171 return make_double1(sqrt(v.x));
3175 MIRTKCU_API
inline double2 sqrt(double2 v)
3177 return make_double2(sqrt(v.x), sqrt(v.y));
3181 MIRTKCU_API
inline double3 sqrt(double3 v)
3183 return make_double3(sqrt(v.x), sqrt(v.y), sqrt(v.z));
3187 MIRTKCU_API
inline double4 sqrt(double4 v)
3189 return make_double4(sqrt(v.x), sqrt(v.y), sqrt(v.z), sqrt(v.w));
3201 MIRTKCU_API
inline float get(
const float &v,
int n)
3206 cerr <<
"Invalid vector element index: " << n << endl;
3207 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3213 MIRTKCU_API
inline float get(
const float1 &v,
int n)
3218 cerr <<
"Invalid vector element index: " << n << endl;
3219 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3225 MIRTKCU_API
inline float get(
const float2 &v,
int n)
3231 cerr <<
"Invalid vector element index: " << n << endl;
3232 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3238 MIRTKCU_API
inline float get(
const float3 &v,
int n)
3245 cerr <<
"Invalid vector element index: " << n << endl;
3246 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3252 MIRTKCU_API
inline float get(
const float4 &v,
int n)
3260 cerr <<
"Invalid vector element index: " << n << endl;
3261 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3267 MIRTKCU_API
inline float get(
const float2x2 &m,
int n)
3270 case 0:
return m.a.x;
3271 case 1:
return m.a.y;
3272 case 2:
return m.b.x;
3273 case 3:
return m.b.y;
3275 cerr <<
"Invalid matrix element index: " << n << endl;
3276 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3282 MIRTKCU_API
inline float get(
const float3x3 &m,
int n)
3285 case 0:
return m.a.x;
3286 case 1:
return m.a.y;
3287 case 2:
return m.a.z;
3288 case 3:
return m.b.x;
3289 case 4:
return m.b.y;
3290 case 5:
return m.b.z;
3291 case 6:
return m.c.x;
3292 case 7:
return m.c.y;
3293 case 8:
return m.c.z;
3295 cerr <<
"Invalid matrix element index: " << n << endl;
3296 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3302 MIRTKCU_API
inline float get(
const float3x4 &m,
int n)
3305 case 0:
return m.a.x;
3306 case 1:
return m.a.y;
3307 case 2:
return m.a.z;
3308 case 3:
return m.a.w;
3309 case 4:
return m.b.x;
3310 case 5:
return m.b.y;
3311 case 6:
return m.b.z;
3312 case 7:
return m.b.w;
3313 case 8:
return m.c.x;
3314 case 9:
return m.c.y;
3315 case 10:
return m.c.z;
3316 case 11:
return m.c.w;
3318 cerr <<
"Invalid matrix element index: " << n << endl;
3319 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3325 MIRTKCU_API
inline float get(
const float4x4 &m,
int n)
3328 case 0:
return m.a.x;
3329 case 1:
return m.a.y;
3330 case 2:
return m.a.z;
3331 case 3:
return m.a.w;
3332 case 4:
return m.b.x;
3333 case 5:
return m.b.y;
3334 case 6:
return m.b.z;
3335 case 7:
return m.b.w;
3336 case 8:
return m.c.x;
3337 case 9:
return m.c.y;
3338 case 10:
return m.c.z;
3339 case 11:
return m.c.w;
3340 case 12:
return m.d.x;
3341 case 13:
return m.d.y;
3342 case 14:
return m.d.z;
3343 case 15:
return m.d.w;
3345 cerr <<
"Invalid matrix element index: " << n << endl;
3346 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3352 MIRTKCU_API
inline void put(
float &v,
int n,
float s)
3357 cerr <<
"Invalid vector element index: " << n << endl;
3358 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3364 MIRTKCU_API
inline void put(float1 &v,
int n,
float s)
3369 cerr <<
"Invalid vector element index: " << n << endl;
3370 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3376 MIRTKCU_API
inline void put(float2 &v,
int n,
float s)
3382 cerr <<
"Invalid vector element index: " << n << endl;
3383 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3389 MIRTKCU_API
inline void put(float3 &v,
int n,
float s)
3396 cerr <<
"Invalid vector element index: " << n << endl;
3397 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3403 MIRTKCU_API
inline void put(float4 &v,
int n,
float s)
3411 cerr <<
"Invalid vector element index: " << n << endl;
3412 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3418 MIRTKCU_API
inline void put(float2x2 &m,
int n,
float s)
3426 cerr <<
"Invalid matrix element index: " << n << endl;
3427 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3433 MIRTKCU_API
inline void put(float3x3 &m,
int n,
float s)
3446 cerr <<
"Invalid matrix element index: " << n << endl;
3447 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3453 MIRTKCU_API
inline void put(float3x4 &m,
int n,
float s)
3469 cerr <<
"Invalid matrix element index: " << n << endl;
3470 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3476 MIRTKCU_API
inline void put(float4x4 &m,
int n,
float s)
3496 cerr <<
"Invalid matrix element index: " << n << endl;
3497 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3507 MIRTKCU_API
inline double get(
const double &v,
int n)
3512 cerr <<
"Invalid vector element index: " << n << endl;
3513 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3519 MIRTKCU_API
inline double get(
const double1 &v,
int n)
3524 cerr <<
"Invalid vector element index: " << n << endl;
3525 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3531 MIRTKCU_API
inline double get(
const double2 &v,
int n)
3537 cerr <<
"Invalid vector element index: " << n << endl;
3538 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3544 MIRTKCU_API
inline double get(
const double3 &v,
int n)
3551 cerr <<
"Invalid vector element index: " << n << endl;
3552 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3558 MIRTKCU_API
inline double get(
const double4 &v,
int n)
3566 cerr <<
"Invalid vector element index: " << n << endl;
3567 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3573 MIRTKCU_API
inline double get(
const double2x2 &m,
int n)
3576 case 0:
return m.a.x;
3577 case 1:
return m.a.y;
3578 case 2:
return m.b.x;
3579 case 3:
return m.b.y;
3581 cerr <<
"Invalid matrix element index: " << n << endl;
3582 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3588 MIRTKCU_API
inline double get(
const double3x3 &m,
int n)
3591 case 0:
return m.a.x;
3592 case 1:
return m.a.y;
3593 case 2:
return m.a.z;
3594 case 3:
return m.b.x;
3595 case 4:
return m.b.y;
3596 case 5:
return m.b.z;
3597 case 6:
return m.c.x;
3598 case 7:
return m.c.y;
3599 case 8:
return m.c.z;
3601 cerr <<
"Invalid matrix element index: " << n << endl;
3602 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3608 MIRTKCU_API
inline double get(
const double3x4 &m,
int n)
3611 case 0:
return m.a.x;
3612 case 1:
return m.a.y;
3613 case 2:
return m.a.z;
3614 case 3:
return m.a.w;
3615 case 4:
return m.b.x;
3616 case 5:
return m.b.y;
3617 case 6:
return m.b.z;
3618 case 7:
return m.b.w;
3619 case 8:
return m.c.x;
3620 case 9:
return m.c.y;
3621 case 10:
return m.c.z;
3622 case 11:
return m.c.w;
3624 cerr <<
"Invalid matrix element index: " << n << endl;
3625 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3631 MIRTKCU_API
inline double get(
const double4x4 &m,
int n)
3634 case 0:
return m.a.x;
3635 case 1:
return m.a.y;
3636 case 2:
return m.a.z;
3637 case 3:
return m.a.w;
3638 case 4:
return m.b.x;
3639 case 5:
return m.b.y;
3640 case 6:
return m.b.z;
3641 case 7:
return m.b.w;
3642 case 8:
return m.c.x;
3643 case 9:
return m.c.y;
3644 case 10:
return m.c.z;
3645 case 11:
return m.c.w;
3646 case 12:
return m.d.x;
3647 case 13:
return m.d.y;
3648 case 14:
return m.d.z;
3649 case 15:
return m.d.w;
3651 cerr <<
"Invalid matrix element index: " << n << endl;
3652 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3658 MIRTKCU_API
inline void put(
double &v,
int n,
double s)
3663 cerr <<
"Invalid vector element index: " << n << endl;
3664 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3670 MIRTKCU_API
inline void put(double1 &v,
int n,
double s)
3675 cerr <<
"Invalid vector element index: " << n << endl;
3676 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3682 MIRTKCU_API
inline void put(double2 &v,
int n,
double s)
3688 cerr <<
"Invalid vector element index: " << n << endl;
3689 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3695 MIRTKCU_API
inline void put(double3 &v,
int n,
double s)
3702 cerr <<
"Invalid vector element index: " << n << endl;
3703 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3709 MIRTKCU_API
inline void put(double4 &v,
int n,
double s)
3717 cerr <<
"Invalid vector element index: " << n << endl;
3718 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3724 MIRTKCU_API
inline void put(double2x2 &m,
int n,
double s)
3732 cerr <<
"Invalid matrix element index: " << n << endl;
3733 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3739 MIRTKCU_API
inline void put(double3x3 &m,
int n,
double s)
3752 cerr <<
"Invalid matrix element index: " << n << endl;
3753 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3759 MIRTKCU_API
inline void put(double3x4 &m,
int n,
double s)
3775 cerr <<
"Invalid matrix element index: " << n << endl;
3776 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3782 MIRTKCU_API
inline void put(double4x4 &m,
int n,
double s)
3802 cerr <<
"Invalid matrix element index: " << n << endl;
3803 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
3812 #if MIRTK_USE_FLOAT_BY_DEFAULT // (i.e., use float) 3813 typedef float realt;
3814 typedef float1 real1;
3815 typedef float2 real2;
3816 typedef float3 real3;
3817 typedef float4 real4;
3822 #define make_real1 make_float1 3823 #define make_real2 make_float2 3824 #define make_real3 make_float3 3825 #define make_real4 make_float4 3826 #define make_real3x3 make_float3x3 3827 #define make_real3x4 make_float3x4 3828 #define make_real4x4 make_float4x4 3829 #else // MIRTK_USE_FLOAT_BY_DEFAULT (i.e., use double) 3830 typedef double realt;
3831 typedef double1 real1;
3832 typedef double2 real2;
3833 typedef double3 real3;
3834 typedef double4 real4;
3835 typedef double2x2 real2x2;
3836 typedef double3x3 real3x3;
3837 typedef double3x4 real3x4;
3838 typedef double4x4 real4x4;
3839 #define make_real1 make_double1 3840 #define make_real2 make_double2 3841 #define make_real3 make_double3 3842 #define make_real4 make_double4 3843 #define make_real3x3 make_double3x3 3844 #define make_real3x4 make_double3x4 3845 #define make_real4x4 make_double4x4 3846 #endif // MIRTK_USE_FLOAT_BY_DEFAULT 3851 #endif // MIRTK_Math_H 2x2 single-precision matrix
MIRTK_Common_EXPORT const double nan
Not A Number (NaN)
MIRTKCU_API int sgn(T val)
Sign function - https://en.wikipedia.org/wiki/Sign_function.
MIRTKCU_HOST_API float * to_float(const VoxelType *in, unsigned int N)
Copy and cast image to single-precision floating point.
MIRTK_Common_EXPORT const double pi_half
Constant value of .
3x4 single-precision coordinate transformation matrix
4x4 single-precision matrix
MIRTKCU_API bool IsZero(double a, double tol=1e-12)
Determine equality of a floating point number with zero.
MIRTKCU_API bool operator<(const float1 &a, const float1 &b)
Check if 1D vector is lexicographically less than another.
MIRTKCU_API int iceil(T x)
Round floating-point value to next greater integer and cast to int.
MIRTKCU_API bool IsNaN(double x)
Check if floating point value is not a number (NaN)
3x3 double-precision matrix
MIRTK_Common_EXPORT const double two_pi
Constant value of .
MIRTK_Common_EXPORT const double pi
Constant value of .
3x3 single-precision matrix
MIRTKCU_API int ifloor(T x)
Round floating-point value to next smaller integer and cast to int.
MIRTKCU_API double finc(double f)
MIRTKCU_API bool fequal(double a, double b, double tol=1e-12)
MIRTKCU_API bool AreEqualOrNaN(double a, double b, double tol=1e-12)
Determine equality of two floating point numbers including check if both are NaN. ...
MIRTKCU_API double fdec(double f)
3x4 double-precision coordinate transformation matrix
4x4 double-precision matrix
MIRTKCU_API bool IsInf(double x)
Check if floating point value represents infinity.
2x2 double-precision matrix
MIRTKCU_API bool operator==(const float1 &a, const float1 &b)
Check two 1D vectors for equality.
MIRTKCU_API float2x2 transpose(float2x2 m)
Transpose 2x2 matrix.
double SShapedMembershipFunction(double x, double a, double b)
MIRTKCU_API bool AreEqual(double a, double b, double tol=1e-12)
Determine equality of two floating point numbers.
MIRTKCU_API int iround(T x)
Round floating-point value and cast to int.
MIRTK_Common_EXPORT const double deg_per_rad
Degree per radian, i.e., .
MIRTK_Common_EXPORT const double inf
Positive infinity.
MIRTK_Common_EXPORT const double rad_per_deg
Radians per degree, i.e., .