10#ifndef MI_MATH_MATRIX_H
11#define MI_MATH_MATRIX_H
88template <
typename T, Size ROW, Size COL>
278template <
typename T,
class Matrix,
bool specialized>
279struct Matrix_struct_get_base_pointer
282 static inline const T* get_base_ptr(
const Matrix& m) {
return m.elements; }
287template <
typename T,
class Matrix>
288struct Matrix_struct_get_base_pointer<T,Matrix,true>
290 static inline T* get_base_ptr( Matrix& m) {
return &m.xx; }
291 static inline const T* get_base_ptr(
const Matrix& m) {
return &m.xx; }
296template <
typename T, Size ROW, Size COL>
299 return Matrix_struct_get_base_pointer<T,Matrix_struct<T,ROW,COL>,
300 (ROW<=4 && COL<=4)>::get_base_ptr( mat);
304template <
typename T, Size ROW, Size COL>
307 return Matrix_struct_get_base_pointer<T,Matrix_struct<T,ROW,COL>,
308 (ROW<=4 && COL<=4)>::get_base_ptr( mat);
365template <
typename T, Size ROW, Size COL>
454 constexpr Size MIN_DIM = (ROW < COL) ? ROW : COL;
455 for(
Size k(0u); k <
MIN_DIM; ++k)
456 begin()[k * COL + k] = diag;
472 template <
typename Iterator>
475 for(
Size i(0u); i <
SIZE; ++i, ++p)
491 template <
typename T2>
495 begin()[i] = array[i];
500 template <
typename T2>
509 template <
typename T2>
521 for(
Size i(0u); i < ROW; ++i)
522 for(
Size j(0u); j < COL; ++j)
523 begin()[i * COL + j] = other.
begin()[j * ROW + i];
529 template <
typename T2>
534 for(
Size i(0u); i < ROW; ++i)
535 for(
Size j(0u); j < COL; ++j)
536 begin()[i * COL + j] = T(other.
begin()[j * ROW + i]);
625 inline Matrix( T m0, T m1, T m2, T m3, T m4, T m5)
635 inline Matrix( T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7)
645 inline Matrix( T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7, T m8)
657 T m0, T m1, T m2, T m3,
658 T m4, T m5, T m6, T m7,
659 T m8, T m9, T m10, T m11)
671 T m0, T m1, T m2, T m3,
672 T m4, T m5, T m6, T m7,
673 T m8, T m9, T m10, T m11,
674 T m12, T m13, T m14, T m15)
697 return begin()[row * COL + col];
707 return begin()[row * COL + col];
726 return begin()[row * COL + col];
747 begin()[row * COL + col] = value;
756 return this->xx * this->yy * this->zz
757 + this->xy * this->yz * this->zx
758 + this->xz * this->yx * this->zy
759 - this->xx * this->zy * this->yz
760 - this->xy * this->zz * this->yx
761 - this->xz * this->zx * this->yy;
777 for(
Size i=0; i < ROW-1; ++i) {
778 for(
Size j=i+1; j < COL; ++j) {
801 this->wx += T( vector.x);
802 this->wy += T( vector.y);
803 this->wz += T( vector.z);
811 this->wx += T( vector.x);
812 this->wy += T( vector.y);
813 this->wz += T( vector.z);
831 this->wx = T( vector.x);
832 this->wy = T( vector.y);
833 this->wz = T( vector.z);
841 this->wx = T( vector.x);
842 this->wy = T( vector.y);
843 this->wz = T( vector.z);
850 inline void rotate( T xangle, T yangle, T zangle)
864 tmp.
set_rotation( T( angles.x), T( angles.y), T( angles.z));
875 tmp.
set_rotation( T( angles.x), T( angles.y), T( angles.z));
893 set_rotation( T( angles.x), T( angles.y), T( angles.z));
903 set_rotation( T( angles.x), T( angles.y), T( angles.z));
946template <
typename T, Size ROW, Size COL>
955template <
typename T, Size ROW, Size COL>
966template <
typename T, Size ROW, Size COL>
977template <
typename T, Size ROW, Size COL>
988template <
typename T, Size ROW, Size COL>
999template <
typename T, Size ROW, Size COL>
1010template <
typename T, Size ROW, Size COL>
1011Matrix<T,ROW,COL>&
operator+=( Matrix<T,ROW,COL>& lhs,
const Matrix<T,ROW,COL>& rhs);
1014template <
typename T, Size ROW, Size COL>
1015Matrix<T,ROW,COL>&
operator-=( Matrix<T,ROW,COL>& lhs,
const Matrix<T,ROW,COL>& rhs);
1018template <
typename T, Size ROW, Size COL>
1029template <
typename T, Size ROW, Size COL>
1040template <
typename T, Size ROW, Size COL>
1045 for(
Size i(0u); i < ROW*COL; ++i)
1056template <
typename T, Size ROW, Size COL>
1064 for(
Size rrow = 0; rrow < ROW; ++rrow) {
1065 for(
Size rcol = 0; rcol < COL; ++rcol) {
1066 lhs( rrow, rcol) = T(0);
1067 for(
Size k = 0; k < COL; ++k)
1068 lhs( rrow, rcol) += old( rrow, k) * rhs( k, rcol);
1079template <
typename T, Size ROW1, Size COL1, Size ROW2, Size COL2>
1088 for(
Size rrow = 0; rrow < ROW1; ++rrow) {
1089 for(
Size rcol = 0; rcol < COL2; ++rcol) {
1090 result( rrow, rcol) = T(0);
1091 for(
Size k = 0; k < COL1; ++k)
1092 result( rrow, rcol) += lhs( rrow, k) * rhs( k, rcol);
1105template <
typename T, Size ROW, Size COL, Size DIM>
1112 for(
Size row = 0; row < ROW; ++row) {
1114 for(
Size col = 0; col < COL; ++col)
1115 result[row] += mat( row, col) * vec[col];
1126template <Size DIM,
typename T, Size ROW, Size COL>
1133 for(
Size col = 0; col < COL; ++col) {
1135 for(
Size row = 0; row < ROW; ++row)
1136 result[col] += mat( row, col) * vec[row];
1143template <
typename T, Size ROW, Size COL>
1146 for(
Size i=0; i < ROW*COL; ++i)
1147 mat.
begin()[i] *= factor;
1152template <
typename T, Size ROW, Size COL>
1161template <
typename T, Size ROW, Size COL>
1175template <Size
NEW_ROW, Size
NEW_COL,
typename T, Size ROW, Size COL>
1182 for(
Size i=0; i <
NEW_ROW; ++i)
1183 for(
Size j=0; j <
NEW_COL; ++j)
1184 result( i, j) = mat( i, j);
1191template <
typename T, Size ROW, Size COL>
1196 for(
Size i=0; i < ROW; ++i)
1197 for(
Size j=0; j < COL; ++j)
1198 result( j, i) = mat( i, j);
1207template <
typename T,
typename U>
1212 const T w = T(mat.xw * point + mat.ww);
1213 if( w == T(0) || w == T(1))
1214 return U(mat.xx * point + mat.wx);
1216 return U((mat.xx * point + mat.wx) / w);
1224template <
typename T,
typename U>
1229 T w = T(mat.xw * point.x + mat.yw * point.y + mat.ww);
1230 if( w == T(0) || w == T(1))
1232 U(mat.xx * point.x + mat.yx * point.y + mat.wx),
1233 U(mat.xy * point.x + mat.yy * point.y + mat.wy));
1237 U((mat.xx * point.x + mat.yx * point.y + mat.wx) * w),
1238 U((mat.xy * point.x + mat.yy * point.y + mat.wy) * w));
1247template <
typename T,
typename U>
1253 U(mat.xx * point.x + mat.yx * point.y + mat.zx * point.z + mat.wx),
1254 U(mat.xy * point.x + mat.yy * point.y + mat.zy * point.z + mat.wy),
1255 U(mat.xz * point.x + mat.yz * point.y + mat.zz * point.z + mat.wz));
1263template <
typename T,
typename U>
1268 T w = T(mat.xw * point.x + mat.yw * point.y + mat.zw * point.z + mat.ww);
1269 if( w == T(0) || w == T(1))
1271 U(mat.xx * point.x + mat.yx * point.y + mat.zx * point.z + mat.wx),
1272 U(mat.xy * point.x + mat.yy * point.y + mat.zy * point.z + mat.wy),
1273 U(mat.xz * point.x + mat.yz * point.y + mat.zz * point.z + mat.wz));
1277 U((mat.xx * point.x + mat.yx * point.y + mat.zx * point.z + mat.wx) * w),
1278 U((mat.xy * point.x + mat.yy * point.y + mat.zy * point.z + mat.wy) * w),
1279 U((mat.xz * point.x + mat.yz * point.y + mat.zz * point.z + mat.wz) * w));
1288template <
typename T,
typename U>
1294 U(mat.xx * point.x + mat.yx * point.y + mat.zx * point.z + mat.wx * point.w),
1295 U(mat.xy * point.x + mat.yy * point.y + mat.zy * point.z + mat.wy * point.w),
1296 U(mat.xz * point.x + mat.yz * point.y + mat.zz * point.z + mat.wz * point.w),
1297 U(mat.xw * point.x + mat.yw * point.y + mat.zw * point.z + mat.ww * point.w));
1305template <
typename T,
typename U>
1310 return U(mat.xx * vector);
1318template <
typename T,
typename U>
1324 U(mat.xx * vector.x + mat.yx * vector.y),
1325 U(mat.xy * vector.x + mat.yy * vector.y));
1333template <
typename T,
typename U>
1339 U(mat.xx * vector.x + mat.yx * vector.y + mat.zx * vector.z),
1340 U(mat.xy * vector.x + mat.yy * vector.y + mat.zy * vector.z),
1341 U(mat.xz * vector.x + mat.yz * vector.y + mat.zz * vector.z));
1349template <
typename T,
typename U>
1355 U(mat.xx * vector.x + mat.yx * vector.y + mat.zx * vector.z),
1356 U(mat.xy * vector.x + mat.yy * vector.y + mat.zy * vector.z),
1357 U(mat.xz * vector.x + mat.yz * vector.y + mat.zz * vector.z));
1365template <
typename T,
typename U>
1371 U(mat.xx * vector.x + mat.yx * vector.y + mat.zx * vector.z),
1372 U(mat.xy * vector.x + mat.yy * vector.y + mat.zy * vector.z),
1373 U(mat.xz * vector.x + mat.yz * vector.y + mat.zz * vector.z));
1387template <
typename T,
typename U>
1393 U(inv_mat.xx * normal.x + inv_mat.xy * normal.y + inv_mat.xz * normal.z),
1394 U(inv_mat.yx * normal.x + inv_mat.yy * normal.y + inv_mat.yz * normal.z),
1395 U(inv_mat.zx * normal.x + inv_mat.zy * normal.y + inv_mat.zz * normal.z));
1409template <
typename T,
typename U>
1415 U(inv_mat.xx * normal.x + inv_mat.xy * normal.y + inv_mat.xz * normal.z),
1416 U(inv_mat.yx * normal.x + inv_mat.yy * normal.y + inv_mat.yz * normal.z),
1417 U(inv_mat.zx * normal.x + inv_mat.zy * normal.y + inv_mat.zz * normal.z));
1433template <
typename T,
typename U>
1439 mat.yx, mat.yy, mat.yz,
1440 mat.zx, mat.zy, mat.zz);
1441 bool inverted = sub_mat.
invert();
1445 U(sub_mat.xx * normal.x + sub_mat.xy * normal.y + sub_mat.xz * normal.z),
1446 U(sub_mat.yx * normal.x + sub_mat.yy * normal.y + sub_mat.yz * normal.z),
1447 U(sub_mat.zx * normal.x + sub_mat.zy * normal.y + sub_mat.zz * normal.z));
1453template <
typename T, Size ROW, Size COL>
1458 for(
Size i=0; i < ROW*COL; ++i)
1463template <
typename T, Size ROW, Size COL>
1468 for(
Size i=0; i < ROW*COL; ++i)
1473#ifndef MI_FOR_DOXYGEN_ONLY
1475template <
typename T, Size ROW, Size COL>
1482 const T min_angle = T(0.00024f);
1484 if(
abs( xangle) > min_angle) {
1491 if(
abs( yangle) > min_angle) {
1498 if(
abs(zangle) > min_angle) {
1505 this->xx = tcy * tcz;
1506 this->xy = tcy * tsz;
1510 this->yx = tmp * tcz - tcx * tsz;
1511 this->yy = tmp * tsz + tcx * tcz;
1512 this->yz = tsx * tcy;
1515 this->zx = tmp * tcz + tsx * tsz;
1516 this->zy = tmp * tsz - tsx * tcz;
1517 this->zz = tcx * tcy;
1520template <
typename T, Size ROW, Size COL>
1524 Vector<T,3> axis( axis_v);
1525 const T min_angle = T(0.00024f);
1527 if(
abs( T(angle)) < min_angle) {
1528 T xa = axis.x * T(angle);
1529 T ya = axis.y * T(angle);
1530 T za = axis.z * T(angle);
1547 T s =
sin( T(angle));
1548 T c =
cos( T(angle));
1552 tmp = t * T(axis.x);
1553 this->xx = tmp * T(axis.x) + c;
1554 this->xy = tmp * T(axis.y) + s * T(axis.z);
1555 this->xz = tmp * T(axis.z) - s * T(axis.y);
1558 tmp = t * T(axis.y);
1559 this->yx = tmp * T(axis.x) - s * T(axis.z);
1560 this->yy = tmp * T(axis.y) + c;
1561 this->yz = tmp * T(axis.z) + s * T(axis.x);
1564 tmp = t * T(axis.z);
1565 this->zx = tmp * T(axis.x) + s * T(axis.y);
1566 this->zy = tmp * T(axis.y) - s * T(axis.x);
1567 this->zz = tmp * T(axis.z) + c;
1570 this->wx = this->wy = this->wz = T(0);
1574template <
typename T, Size ROW, Size COL>
1578 Vector<T,3> axis( axis_v);
1579 constexpr T min_angle = T(0.00024f);
1581 if(
abs(T(angle)) < min_angle) {
1582 T xa = axis.x * T(angle);
1583 T ya = axis.y * T(angle);
1584 T za = axis.z * T(angle);
1601 T s =
sin( T(angle));
1602 T c =
cos( T(angle));
1606 tmp = t * T(axis.x);
1607 this->xx = tmp * T(axis.x) + c;
1608 this->xy = tmp * T(axis.y) + s * T(axis.z);
1609 this->xz = tmp * T(axis.z) - s * T(axis.y);
1612 tmp = t * T(axis.y);
1613 this->yx = tmp * T(axis.x) - s * T(axis.z);
1614 this->yy = tmp * T(axis.y) + c;
1615 this->yz = tmp * T(axis.z) + s * T(axis.x);
1618 tmp = t * T(axis.z);
1619 this->zx = tmp * T(axis.x) + s * T(axis.y);
1620 this->zy = tmp * T(axis.y) - s * T(axis.x);
1621 this->zz = tmp * T(axis.z) + c;
1624 this->wx = this->wy = this->wz = T(0);
1628template <
typename T, Size ROW, Size COL>
1630 const Vector<Float32,3>& position,
1631 const Vector<Float32,3>& target,
1632 const Vector<Float32,3>& up)
1635 Vector<Float32,3> xaxis, yaxis, zaxis;
1638 zaxis = position - target;
1642 xaxis =
cross( up, zaxis);
1646 yaxis =
cross( zaxis, xaxis);
1651 T(xaxis.x), T(yaxis.x), T(zaxis.x), T(0),
1652 T(xaxis.y), T(yaxis.y), T(zaxis.y), T(0),
1653 T(xaxis.z), T(yaxis.z), T(zaxis.z), T(0),
1654 T(0), T(0), T(0), T(1));
1657 Matrix<T,4,4> trans(
1658 T(1), T(0), T(0), T(0),
1659 T(0), T(1), T(0), T(0),
1660 T(0), T(0), T(1), T(0),
1661 T(-position.x), T(-position.y), T(-position.z), T(1));
1663 *
this = trans * rot;
1666template <
typename T, Size ROW, Size COL>
1668 const Vector<Float64,3>& position,
1669 const Vector<Float64,3>& target,
1670 const Vector<Float64,3>& up)
1673 Vector<Float64,3> xaxis, yaxis, zaxis;
1676 zaxis = position - target;
1680 xaxis =
cross( up, zaxis);
1684 yaxis =
cross( zaxis, xaxis);
1689 T(xaxis.x), T(yaxis.x), T(zaxis.x), T(0),
1690 T(xaxis.y), T(yaxis.y), T(zaxis.y), T(0),
1691 T(xaxis.z), T(yaxis.z), T(zaxis.z), T(0),
1692 T(0), T(0), T(0), T(1));
1695 Matrix<T,4,4> trans(
1696 T(1), T(0), T(0), T(0),
1697 T(0), T(1), T(0), T(0),
1698 T(0), T(0), T(1), T(0),
1699 T(-position.x), T(-position.y), T(-position.z), T(1));
1701 *
this = trans * rot;
1708template <
class T, Size ROW, Size COL>
1709class Matrix_inverter
1712 using Matrix = math::Matrix<T, ROW, COL>;
1717 static inline bool invert( Matrix& ) {
return false; }
1721template <
class T, Size DIM>
1722class Matrix_inverter<T,DIM,DIM>
1725 using Matrix = math::Matrix<T, DIM, DIM>;
1726 using Value_vector = math::Vector<T, DIM>;
1727 using Index_vector = math::Vector<Size, DIM>;
1733 static bool lu_decomposition(
1735 Index_vector& indx);
1739 static void lu_backsubstitution(
1741 const Index_vector& indx,
1744 static bool invert( Matrix& mat);
1747template <
class T, Size DIM>
1748bool Matrix_inverter<T,DIM,DIM>::lu_decomposition(
1754 for(
Size i = 0; i < DIM; i++) {
1756 for(
Size j = 0; j < DIM; j++) {
1757 T temp =
abs(lu.get(i,j));
1769 for(
Size j = 0; j < DIM; j++) {
1770 for(
Size i = 0; i < j; i++) {
1771 T sum = lu.get(i,j);
1772 for(
Size k = 0; k < i; k++)
1773 sum -= lu.get(i,k) * lu.get(k,j);
1777 for(
Size i = j; i < DIM; i++) {
1778 T sum = lu.get(i,j);
1779 for(
Size k = 0; k < j; k++)
1780 sum -= lu.get(i,k) * lu.get(k,j);
1782 T dum = vv[i] *
abs(sum);
1789 for(
Size k = 0; k < DIM; k++) {
1790 T dum = lu.get(imax,k);
1791 lu.set(imax, k, lu.get(j,k));
1797 if( lu.get(j,j) == 0)
1800 T dum = T(1) / lu.get(j,j);
1801 for(
Size i = j + 1; i < DIM; i++)
1802 lu.set(i, j, lu.get(i,j) * dum);
1808template <
class T, Size DIM>
1809void Matrix_inverter<T,DIM,DIM>::lu_backsubstitution(
1811 const Index_vector& indx,
1816 for(
Size i = 0; i < DIM; i++) {
1821 for(
Size j = ii; j < i; j++) {
1822 sum -= lu.get(i,j) * b[j];
1831 for(
Size i2 = DIM; i2 > 0;) {
1834 for(
Size j = i2+1; j < DIM; j++)
1835 sum -= lu.get(i2,j) * b[j];
1836 b[i2] = sum / lu.get(i2,i2);
1840template <
class T, Size DIM>
1841bool Matrix_inverter<T,DIM,DIM>::invert( Matrix& mat)
1847 if( !lu_decomposition(lu, indx))
1851 for(
Size j = 0; j < DIM; ++j) {
1852 Value_vector col(T(0));
1854 lu_backsubstitution( lu, indx, col);
1855 for(
Size i = 0; i < DIM; ++i) {
1856 mat.set( i, j, col[i]);
1864class Matrix_inverter<T,1,1>
1867 using Matrix = math::Matrix<T, 1, 1>;
1869 static inline bool invert( Matrix& mat)
1871 T s = mat.get( 0, 0);
1874 mat.set( 0, 0, T(1) / s);
1881class Matrix_inverter<T,2,2>
1884 using Matrix = math::Matrix<T, 2, 2>;
1886 static inline bool invert( Matrix& mat)
1888 T a = mat.get( 0, 0);
1889 T b = mat.get( 0, 1);
1890 T c = mat.get( 1, 0);
1891 T d = mat.get( 1, 1);
1895 T rdet = T(1) / det;
1896 mat.set( 0, 0, d * rdet);
1897 mat.set( 0, 1,-b * rdet);
1898 mat.set( 1, 0,-c * rdet);
1899 mat.set( 1, 1, a * rdet);
1904template <
typename T, Size ROW, Size COL>
1907 return Matrix_inverter<T,ROW,COL>::invert( *
this);
1915template <
typename T>
1918 const Matrix<T,4,4>& rhs)
1920 Matrix<T,4,4> old( lhs);
1922 lhs.xx = old.xx * rhs.xx + old.xy * rhs.yx + old.xz * rhs.zx + old.xw * rhs.wx;
1923 lhs.xy = old.xx * rhs.xy + old.xy * rhs.yy + old.xz * rhs.zy + old.xw * rhs.wy;
1924 lhs.xz = old.xx * rhs.xz + old.xy * rhs.yz + old.xz * rhs.zz + old.xw * rhs.wz;
1925 lhs.xw = old.xx * rhs.xw + old.xy * rhs.yw + old.xz * rhs.zw + old.xw * rhs.ww;
1927 lhs.yx = old.yx * rhs.xx + old.yy * rhs.yx + old.yz * rhs.zx + old.yw * rhs.wx;
1928 lhs.yy = old.yx * rhs.xy + old.yy * rhs.yy + old.yz * rhs.zy + old.yw * rhs.wy;
1929 lhs.yz = old.yx * rhs.xz + old.yy * rhs.yz + old.yz * rhs.zz + old.yw * rhs.wz;
1930 lhs.yw = old.yx * rhs.xw + old.yy * rhs.yw + old.yz * rhs.zw + old.yw * rhs.ww;
1932 lhs.zx = old.zx * rhs.xx + old.zy * rhs.yx + old.zz * rhs.zx + old.zw * rhs.wx;
1933 lhs.zy = old.zx * rhs.xy + old.zy * rhs.yy + old.zz * rhs.zy + old.zw * rhs.wy;
1934 lhs.zz = old.zx * rhs.xz + old.zy * rhs.yz + old.zz * rhs.zz + old.zw * rhs.wz;
1935 lhs.zw = old.zx * rhs.xw + old.zy * rhs.yw + old.zz * rhs.zw + old.zw * rhs.ww;
1937 lhs.wx = old.wx * rhs.xx + old.wy * rhs.yx + old.wz * rhs.zx + old.ww * rhs.wx;
1938 lhs.wy = old.wx * rhs.xy + old.wy * rhs.yy + old.wz * rhs.zy + old.ww * rhs.wy;
1939 lhs.wz = old.wx * rhs.xz + old.wy * rhs.yz + old.wz * rhs.zz + old.ww * rhs.wz;
1940 lhs.ww = old.wx * rhs.xw + old.wy * rhs.yw + old.wz * rhs.zw + old.ww * rhs.ww;
1946template <
typename T>
1948 const Matrix<T,4,4>& lhs,
1949 const Matrix<T,4,4>& rhs)
1951 Matrix<T,4,4> temp( lhs);
NxM-dimensional matrix class template of fixed dimensions.
Definition: matrix.h:367
Fixed-size math vector class template with generic operations.
Definition: vector.h:286
Math functions and function templates on simple types or generic container and vector concepts.
#define mi_static_assert(expr)
Compile time assertion that raises a compilation error if the constant expression expr evaluates to f...
Definition: assert.h:58
double Float64
64-bit float.
Definition: types.h:52
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
Sint64 Difference
Signed integral type that is large enough to hold the difference of two pointers.
Definition: types.h:122
bool lexicographically_less(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically less than vector rhs, and false otherwise.
Definition: function.h:1114
bool lexicographically_less_or_equal(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically less than or equal to vector rhs, and false otherwise...
Definition: function.h:1130
bool lexicographically_greater_or_equal(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically greater than or equal to vector rhs,...
Definition: function.h:1162
bool is_not_equal(const V &lhs, const V &rhs)
Returns true if vector lhs is elementwise not equal to vector rhs, and false otherwise.
Definition: function.h:1101
bool lexicographically_greater(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically greater than vector rhs, and false otherwise.
Definition: function.h:1146
bool is_equal(const V &lhs, const V &rhs)
Returns true if vector lhs is elementwise equal to vector rhs, and false otherwise.
Definition: function.h:1090
#define mi_math_assert_msg(expr, msg)
Math API assertion macro (with message).
Definition: assert.h:80
bool operator>=(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically greater than or equal to rhs.
Definition: bbox.h:650
Bbox<T, DIM> operator+(const Bbox<T, DIM> &bbox, T value)
Returns a bounding box that is the bbox increased by a constant value at each face,...
Definition: bbox.h:468
bool operator<(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically less than rhs.
Definition: bbox.h:605
Bbox<T, DIM> & operator*=(Bbox<T, DIM> &bbox, T factor)
Scales bbox by factor, i.e., bbox.max and bbox.min are multiplied by factor.
Definition: bbox.h:562
Bbox<T, DIM> & operator+=(Bbox<T, DIM> &bbox, T value)
Increases bbox by a constant value at each face, i.e., value is added to bbox.max and subtracted from...
Definition: bbox.h:533
bool operator==(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is elementwise equal to rhs.
Definition: bbox.h:589
bool operator>(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically greater than rhs.
Definition: bbox.h:635
bool operator!=(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is elementwise not equal to rhs.
Definition: bbox.h:596
bool operator<=(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically less than or equal to rhs.
Definition: bbox.h:620
Bbox<T, 3> transform_vector(const Matrix<TT, 4, 4> &mat, const Bbox<T, 3> &bbox)
Returns the 3D bounding box transformed by a matrix.
Definition: bbox.h:843
Bbox<T, DIM> & operator-=(Bbox<T, DIM> &bbox, T value)
Shrinks bbox by a constant value at each face, i.e., value is subtracted from bbox....
Definition: bbox.h:548
Bbox<T, 3> transform_point(const Matrix<TT, 4, 4> &mat, const Bbox<T, 3> &bbox)
Returns the 3D bounding box transformed by a matrix.
Definition: bbox.h:780
Bbox<T, DIM> operator-(const Bbox<T, DIM> &bbox, T value)
Returns a bounding box that is the bbox shrunk by a constant value at each face, i....
Definition: bbox.h:484
Bbox<T, DIM> operator*(const Bbox<T, DIM> &bbox, T factor)
Returns a bounding box that is a version of bbox scaled by factor, i.e., bbox.max and bbox....
Definition: bbox.h:500
Color abs(const Color &c)
Returns a color with the elementwise absolute values of the color c.
Definition: color.h:459
Color sin(const Color &c)
Returns a color with the elementwise sine of the color c.
Definition: color.h:749
Color cos(const Color &c)
Returns a color with the elementwise cosine of the color c.
Definition: color.h:546
T * begin()
Returns the pointer to the first matrix element.
Definition: matrix.h:405
const T & const_reference
Const reference to element.
Definition: matrix.h:378
T yw
yw-element.
Definition: matrix.h:263
static constexpr Size size()
Constant size of the vector.
Definition: matrix.h:391
T yx
yx-element.
Definition: matrix.h:156
Matrix(T2 const (&array)[SIZE])
Constructor initializes the matrix elements from an array of dimension ROW times COL.
Definition: matrix.h:492
T zz
zz-element.
Definition: matrix.h:208
T yx
yx-element.
Definition: matrix.h:203
void set_rotation(const Vector<Float32, 3> &angles)
Stores an absolute rotation in the upper left 3x3 rotation matrix (Euler angles, by vector).
Definition: matrix.h:891
void lookat(const Vector<Float64, 3> &position, const Vector<Float64, 3> &target, const Vector<Float64, 3> &up)
Sets a transformation matrix based on a given center, a reference point, and a direction.
T xy
xy-element.
Definition: matrix.h:176
T xy
xy-element.
Definition: matrix.h:240
bool invert()
Inverts this matrix and returns success or failure.
T & reference
Mutable reference to element.
Definition: matrix.h:377
T yy
yy-element.
Definition: matrix.h:261
T xz
xz-element.
Definition: matrix.h:219
T yw
yw-element.
Definition: matrix.h:233
T get(Size i) const
Accesses the i-th matrix element, indexed in the order of the row-major memory layout.
Definition: matrix.h:713
T wy
wy-element.
Definition: matrix.h:269
Matrix(const Matrix_struct<T2, ROW, COL> &other)
Template constructor that allows explicit conversions from underlying storage type with assignment co...
Definition: matrix.h:510
T xx
xx-element.
Definition: matrix.h:110
Matrix(Transposed_copy_tag, const Matrix<T, COL, ROW> &other)
Constructor that initializes the matrix with the transpose matrix of other.
Definition: matrix.h:517
T xx
xx-element.
Definition: matrix.h:226
T const * end() const
Returns the past-the-end pointer.
Definition: matrix.h:418
T xx
xx-element.
Definition: matrix.h:256
T xx
xx-element.
Definition: matrix.h:127
T yz
yz-element.
Definition: matrix.h:232
T zy
zy-element.
Definition: matrix.h:265
T xw
xw-element.
Definition: matrix.h:242
T wx
wx-element.
Definition: matrix.h:209
T * end()
Returns the past-the-end pointer.
Definition: matrix.h:413
Matrix & operator=(const Matrix &other)
Assignment.
Definition: matrix.h:684
Matrix(T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7)
8-element constructor, must be a 2x4 or 4x2 matrix.
Definition: matrix.h:635
T xw
xw-element.
Definition: matrix.h:220
void translate(const Vector<Float32, 3> &vector)
Adds a relative translation to the matrix (by vector).
Definition: matrix.h:799
T xy
xy-element.
Definition: matrix.h:227
Matrix(T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7, T m8, T m9, T m10, T m11)
12-element constructor, must be a 3x4 or 4x3 matrix.
Definition: matrix.h:656
T xw
xw-element.
Definition: matrix.h:259
T * pointer
Mutable pointer to element.
Definition: matrix.h:375
void set_translation(T dx, T dy, T dz)
Stores an absolute translation in the matrix (by component).
Definition: matrix.h:819
T yz
yz-element.
Definition: matrix.h:191
T yx
yx-element.
Definition: matrix.h:260
T yx
yx-element.
Definition: matrix.h:243
T const * begin() const
Returns the pointer to the first matrix element.
Definition: matrix.h:408
Matrix(Transposed_copy_tag, const Matrix<T2, COL, ROW> &other)
Template constructor that initializes the matrix with the transpose matrix of other that allows the e...
Definition: matrix.h:530
T xx
xx-element.
Definition: matrix.h:103
T zx
zx-element.
Definition: matrix.h:264
T xz
xz-element.
Definition: matrix.h:228
T yy
yy-element.
Definition: matrix.h:231
Matrix(T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7, T m8)
9-element constructor, must be a 3x3 matrix.
Definition: matrix.h:645
T zz
zz-element.
Definition: matrix.h:194
T zw
zw-element.
Definition: matrix.h:267
Row_vector & operator[](Size row)
Accesses the row-th row vector, 0 <= row < ROW.
Definition: matrix.h:421
Matrix(T m0, T m1, T m2, T m3, T m4, T m5)
6-element constructor, must be a 2x3 or 3x2 matrix.
Definition: matrix.h:625
T yy
yy-element.
Definition: matrix.h:244
T yy
yy-element.
Definition: matrix.h:146
static constexpr Size max_size()
Constant maximum size of the vector.
Definition: matrix.h:394
T yx
yx-element.
Definition: matrix.h:230
T yy
yy-element.
Definition: matrix.h:190
T yx
yx-element.
Definition: matrix.h:104
Matrix(T m0, T m1, T m2, T m3)
4-element constructor, must be a 1x4, 2x2, or 4x1 matrix.
Definition: matrix.h:616
T xx
xx-element.
Definition: matrix.h:200
T yz
yz-element.
Definition: matrix.h:245
void set_translation(const Vector<Float64, 3> &vector)
Stores an absolute translation in the matrix (by vector).
Definition: matrix.h:839
const T & operator()(Size row, Size col) const
Accesses the (row, col)-th matrix element.
Definition: matrix.h:703
void set_translation(const Vector<Float32, 3> &vector)
Stores an absolute translation in the matrix (by vector).
Definition: matrix.h:829
T yx
yx-element.
Definition: matrix.h:136
T xz
xz-element.
Definition: matrix.h:188
T wy
wy-element.
Definition: matrix.h:161
Matrix(const Row_vector &v0, const Row_vector &v1, const Row_vector &v2, const Row_vector &v3)
Dedicated constructor, for ROW==4 only, that initializes matrix from four row vectors (v0,...
Definition: matrix.h:582
T xz
xz-element.
Definition: matrix.h:258
T zw
zw-element.
Definition: matrix.h:250
void rotate(const Vector<Float32, 3> &angles)
Adds a relative rotation to the matrix (Euler angles, by vector).
Definition: matrix.h:861
T xy
xy-element.
Definition: matrix.h:144
T xx
xx-element.
Definition: matrix.h:217
void translate(const Vector<Float64, 3> &vector)
Adds a relative translation to the matrix (by vector).
Definition: matrix.h:809
void rotate(const Vector<Float64, 3> &angles)
Adds a relative rotation to the matrix (Euler angles, by vector).
Definition: matrix.h:872
T xy
xy-element.
Definition: matrix.h:168
T xx
xx-element.
Definition: matrix.h:134
Matrix(T m0, T m1)
2-element constructor, must be a 1x2 or 2x1 matrix.
Definition: matrix.h:598
const T * const_pointer
Const pointer to element.
Definition: matrix.h:376
T yx
yx-element.
Definition: matrix.h:178
static constexpr Size ROWS
Constant number of rows of the matrix.
Definition: matrix.h:386
T xy
xy-element.
Definition: matrix.h:257
T xx
xx-element.
Definition: matrix.h:97
Size size_type
Size type, unsigned.
Definition: matrix.h:373
T zx
zx-element.
Definition: matrix.h:192
T yz
yz-element.
Definition: matrix.h:205
Matrix< T, NEW_ROW, NEW_COL > sub_matrix(const Matrix<T, ROW, COL> &mat)
Returns the upper-left sub-matrix of size NEW_ROW times NEW_COL.
Definition: matrix.h:1176
T xx
xx-element.
Definition: matrix.h:118
void set_rotation(const Vector<Float64, 3> &angles)
Stores an absolute rotation in the upper left 3x3 rotation matrix (Euler angles, by vector).
Definition: matrix.h:901
T zy
zy-element.
Definition: matrix.h:207
T yx
yx-element.
Definition: matrix.h:111
T zy
zy-element.
Definition: matrix.h:193
T wx
wx-element.
Definition: matrix.h:268
T yx
yx-element.
Definition: matrix.h:145
T elements[ROW *COL]
general case matrix elements.
Definition: matrix.h:91
T yy
yy-element.
Definition: matrix.h:157
Matrix(T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7, T m8, T m9, T m10, T m11, T m12, T m13, T m14, T m15)
16-element constructor, must be a 4x4 matrix.
Definition: matrix.h:670
T get(Size row, Size col) const
Accesses the (row, col)-th matrix element.
Definition: matrix.h:722
Matrix(From_iterator_tag, Iterator p)
Constructor requires the mi::math::FROM_ITERATOR tag as first argument and initializes the matrix ele...
Definition: matrix.h:473
T xy
xy-element.
Definition: matrix.h:135
Vector<U, 3> transform_normal_inv(const Matrix<T, 3, 3> &inv_mat, const Vector<U, 3> &normal)
Returns an inverse transformed 3D normal vector by applying the 3x3 transposed linear transformation ...
Definition: matrix.h:1388
void transpose()
Transposes this matrix by exchanging rows and columns.
Definition: matrix.h:774
static constexpr Size COLUMNS
Constant number of columns of the matrix.
Definition: matrix.h:387
void lookat(const Vector<Float32, 3> &position, const Vector<Float32, 3> &target, const Vector<Float32, 3> &up)
Sets a transformation matrix based on a given center, a reference point, and a direction.
T yy
yy-element.
Definition: matrix.h:179
T zy
zy-element.
Definition: matrix.h:148
T wz
wz-element.
Definition: matrix.h:211
void set_rotation(const Vector<Float32, 3> &axis, Float64 angle)
Stores an absolute rotation (by axis and angle).
Matrix(T diag)
Constructor initializes all matrix elements to zero and the diagonal elements to diag.
Definition: matrix.h:450
Matrix(const Row_vector &v0, const Row_vector &v1, const Row_vector &v2)
Dedicated constructor, for ROW==3 only, that initializes matrix from three row vectors (v0,...
Definition: matrix.h:567
T det33() const
Returns the determinant of the upper-left 3x3 sub-matrix.
Definition: matrix.h:753
T yx
yx-element.
Definition: matrix.h:119
T wz
wz-element.
Definition: matrix.h:270
constexpr Matrix()=default
The default constructor leaves the vector elements uninitialized.
static constexpr Size SIZE
Constant size of the matrix.
Definition: matrix.h:388
T xx
xx-element.
Definition: matrix.h:175
Matrix(const Matrix<T2, ROW, COL> &other)
Template constructor that allows explicit conversions from other matrices with assignment compatible ...
Definition: matrix.h:501
Matrix(const Row_vector &v0, const Row_vector &v1)
Dedicated constructor, for ROW==2 only, that initializes matrix from two row vectors (v0,...
Definition: matrix.h:554
T xw
xw-element.
Definition: matrix.h:229
void set(Size row, Size col, T value)
Sets the i-th matrix element to value, indexed in the order of the row-major memory layout.
Definition: matrix.h:743
void set_rotation(T x_angle, T y_angle, T z_angle)
Stores an absolute rotation in the upper left 3x3 rotation matrix (Euler angles, by component).
T & operator()(Size row, Size col)
Accesses the (row,col)-th matrix element.
Definition: matrix.h:693
T zx
zx-element.
Definition: matrix.h:158
T wx
wx-element.
Definition: matrix.h:160
T yz
yz-element.
Definition: matrix.h:180
T xy
xy-element.
Definition: matrix.h:187
void set(Size i, T value)
Sets the i-th matrix element to value, indexed in the order of the row-major memory layout.
Definition: matrix.h:733
T xx
xx-element.
Definition: matrix.h:154
T xy
xy-element.
Definition: matrix.h:128
T ww
ww-element.
Definition: matrix.h:271
T zx
zx-element.
Definition: matrix.h:206
T zx
zx-element.
Definition: matrix.h:112
T xz
xz-element.
Definition: matrix.h:169
Matrix(const Matrix<T, ROW, COL> &other)=default
Default copy constructor.
T zx
zx-element.
Definition: matrix.h:120
T xx
xx-element.
Definition: matrix.h:186
T xy
xy-element.
Definition: matrix.h:155
Vector<U, 3> transform_normal(const Matrix<T, 4, 4> &mat, const Vector<U, 3> &normal)
Returns a transformed 3D normal vector by applying the 3x3 transposed linear sub-transformation in th...
Definition: matrix.h:1434
void translate(T x, T y, T z)
Adds a relative translation to the matrix (by components).
Definition: matrix.h:789
T wx
wx-element.
Definition: matrix.h:121
T zz
zz-element.
Definition: matrix.h:249
T xy
xy-element.
Definition: matrix.h:218
T zx
zx-element.
Definition: matrix.h:147
T xz
xz-element.
Definition: matrix.h:202
T yz
yz-element.
Definition: matrix.h:262
Difference difference_type
Difference type, signed.
Definition: matrix.h:374
T xz
xz-element.
Definition: matrix.h:177
Matrix(T m0, T m1, T m2)
3-element constructor, must be a 1x3 or 3x1 matrix.
Definition: matrix.h:607
T value_type
Element type.
Definition: matrix.h:372
T wy
wy-element.
Definition: matrix.h:210
T xy
xy-element.
Definition: matrix.h:201
T yx
yx-element.
Definition: matrix.h:189
T zy
zy-element.
Definition: matrix.h:159
T yy
yy-element.
Definition: matrix.h:137
T zz
zz-element.
Definition: matrix.h:266
T yw
yw-element.
Definition: matrix.h:246
T zx
zx-element.
Definition: matrix.h:247
void rotate(T xangle, T yangle, T zangle)
Adds a relative rotation to the matrix (Euler angles, by component).
Definition: matrix.h:850
T xx
xx-element.
Definition: matrix.h:143
T xx
xx-element.
Definition: matrix.h:167
T xz
xz-element.
Definition: matrix.h:241
Matrix<T, COL, ROW> transpose(const Matrix<T, ROW, COL> &mat)
Returns the transpose of the matrix mat by exchanging rows and columns.
Definition: matrix.h:1192
T zy
zy-element.
Definition: matrix.h:248
Matrix(const Row_vector &v0)
Dedicated constructor, for ROW==1 only, that initializes matrix from one row vector v0.
Definition: matrix.h:543
Matrix(const Matrix_struct<T, ROW, COL> &other)
Constructor from underlying storage type.
Definition: matrix.h:441
void set_rotation(const Vector<Float64, 3> &axis, Float64 angle)
Stores an absolute rotation (by axis and angle).
T xx
xx-element.
Definition: matrix.h:239
T yy
yy-element.
Definition: matrix.h:204
Transposed_copy_tag
Enum type used to tag a special copy constructor that transposes the matrix while copying.
Definition: matrix.h:398
T * matrix_base_ptr(Matrix_struct<T, ROW, COL> &mat)
Returns the base pointer to the matrix data.
Definition: matrix.h:297
@ TRANSPOSED_COPY_TAG
Enum value used to call a special copy constructor that transposes the matrix while copying.
Definition: matrix.h:401
T cross(const Vector_struct<T, 2> &lhs, const Vector_struct<T, 2> &rhs)
Returns the two-times-two determinant result for the two vectors lhs and rhs.
Definition: vector.h:1921
From_iterator_tag
Enum used for initializing a vector from an iterator.
Definition: vector.h:36
Assertions and compile-time assertions.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: example_derivatives.dox:5
Storage class for a NxM-dimensional matrix class template of fixed dimensions.
Definition: matrix.h:90
Math vector class template of fixed dimension with arithmetic operators and generic functions.