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>
437#if (__cplusplus >= 201103L)
456 const Size MIN_DIM = (ROW < COL) ? ROW : COL;
457 for(
Size k(0u); k <
MIN_DIM; ++k)
458 begin()[k * COL + k] = diag;
474 template <
typename Iterator>
477 for(
Size i(0u); i <
SIZE; ++i, ++p)
493 template <
typename T2>
497 begin()[i] = array[i];
502 template <
typename T2>
511 template <
typename T2>
523 for(
Size i(0u); i < ROW; ++i)
524 for(
Size j(0u); j < COL; ++j)
525 begin()[i * COL + j] = other.
begin()[j * ROW + i];
531 template <
typename T2>
536 for(
Size i(0u); i < ROW; ++i)
537 for(
Size j(0u); j < COL; ++j)
538 begin()[i * COL + j] = T(other.
begin()[j * ROW + i]);
627 inline Matrix( T m0, T m1, T m2, T m3, T m4, T m5)
637 inline Matrix( T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7)
647 inline Matrix( T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7, T m8)
659 T m0, T m1, T m2, T m3,
660 T m4, T m5, T m6, T m7,
661 T m8, T m9, T m10, T m11)
673 T m0, T m1, T m2, T m3,
674 T m4, T m5, T m6, T m7,
675 T m8, T m9, T m10, T m11,
676 T m12, T m13, T m14, T m15)
699 return begin()[row * COL + col];
709 return begin()[row * COL + col];
728 return begin()[row * COL + col];
749 begin()[row * COL + col] = value;
758 return this->xx * this->yy * this->zz
759 + this->xy * this->yz * this->zx
760 + this->xz * this->yx * this->zy
761 - this->xx * this->zy * this->yz
762 - this->xy * this->zz * this->yx
763 - this->xz * this->zx * this->yy;
779 for(
Size i=0; i < ROW-1; ++i) {
780 for(
Size j=i+1; j < COL; ++j) {
803 this->wx += T( vector.x);
804 this->wy += T( vector.y);
805 this->wz += T( vector.z);
813 this->wx += T( vector.x);
814 this->wy += T( vector.y);
815 this->wz += T( vector.z);
833 this->wx = T( vector.x);
834 this->wy = T( vector.y);
835 this->wz = T( vector.z);
843 this->wx = T( vector.x);
844 this->wy = T( vector.y);
845 this->wz = T( vector.z);
852 inline void rotate( T xangle, T yangle, T zangle)
866 tmp.
set_rotation( T( angles.x), T( angles.y), T( angles.z));
877 tmp.
set_rotation( T( angles.x), T( angles.y), T( angles.z));
895 set_rotation( T( angles.x), T( angles.y), T( angles.z));
905 set_rotation( T( angles.x), T( angles.y), T( angles.z));
948template <
typename T, Size ROW, Size COL>
957template <
typename T, Size ROW, Size COL>
968template <
typename T, Size ROW, Size COL>
979template <
typename T, Size ROW, Size COL>
990template <
typename T, Size ROW, Size COL>
1001template <
typename T, Size ROW, Size COL>
1012template <
typename T, Size ROW, Size COL>
1013Matrix<T,ROW,COL>&
operator+=( Matrix<T,ROW,COL>& lhs,
const Matrix<T,ROW,COL>& rhs);
1016template <
typename T, Size ROW, Size COL>
1017Matrix<T,ROW,COL>&
operator-=( Matrix<T,ROW,COL>& lhs,
const Matrix<T,ROW,COL>& rhs);
1020template <
typename T, Size ROW, Size COL>
1031template <
typename T, Size ROW, Size COL>
1042template <
typename T, Size ROW, Size COL>
1047 for(
Size i(0u); i < ROW*COL; ++i)
1058template <
typename T, Size ROW, Size COL>
1066 for(
Size rrow = 0; rrow < ROW; ++rrow) {
1067 for(
Size rcol = 0; rcol < COL; ++rcol) {
1068 lhs( rrow, rcol) = T(0);
1069 for(
Size k = 0; k < COL; ++k)
1070 lhs( rrow, rcol) += old( rrow, k) * rhs( k, rcol);
1081template <
typename T, Size ROW1, Size COL1, Size ROW2, Size COL2>
1090 for(
Size rrow = 0; rrow < ROW1; ++rrow) {
1091 for(
Size rcol = 0; rcol < COL2; ++rcol) {
1092 result( rrow, rcol) = T(0);
1093 for(
Size k = 0; k < COL1; ++k)
1094 result( rrow, rcol) += lhs( rrow, k) * rhs( k, rcol);
1107template <
typename T, Size ROW, Size COL, Size DIM>
1114 for(
Size row = 0; row < ROW; ++row) {
1116 for(
Size col = 0; col < COL; ++col)
1117 result[row] += mat( row, col) * vec[col];
1128template <Size DIM,
typename T, Size ROW, Size COL>
1135 for(
Size col = 0; col < COL; ++col) {
1137 for(
Size row = 0; row < ROW; ++row)
1138 result[col] += mat( row, col) * vec[row];
1145template <
typename T, Size ROW, Size COL>
1148 for(
Size i=0; i < ROW*COL; ++i)
1149 mat.
begin()[i] *= factor;
1154template <
typename T, Size ROW, Size COL>
1163template <
typename T, Size ROW, Size COL>
1177template <Size
NEW_ROW, Size
NEW_COL,
typename T, Size ROW, Size COL>
1184 for(
Size i=0; i <
NEW_ROW; ++i)
1185 for(
Size j=0; j <
NEW_COL; ++j)
1186 result( i, j) = mat( i, j);
1193template <
typename T, Size ROW, Size COL>
1198 for(
Size i=0; i < ROW; ++i)
1199 for(
Size j=0; j < COL; ++j)
1200 result( j, i) = mat( i, j);
1209template <
typename T,
typename U>
1214 const T w = T(mat.xw * point + mat.ww);
1215 if( w == T(0) || w == T(1))
1216 return U(mat.xx * point + mat.wx);
1218 return U((mat.xx * point + mat.wx) / w);
1226template <
typename T,
typename U>
1231 T w = T(mat.xw * point.x + mat.yw * point.y + mat.ww);
1232 if( w == T(0) || w == T(1))
1234 U(mat.xx * point.x + mat.yx * point.y + mat.wx),
1235 U(mat.xy * point.x + mat.yy * point.y + mat.wy));
1239 U((mat.xx * point.x + mat.yx * point.y + mat.wx) * w),
1240 U((mat.xy * point.x + mat.yy * point.y + mat.wy) * w));
1249template <
typename T,
typename U>
1255 U(mat.xx * point.x + mat.yx * point.y + mat.zx * point.z + mat.wx),
1256 U(mat.xy * point.x + mat.yy * point.y + mat.zy * point.z + mat.wy),
1257 U(mat.xz * point.x + mat.yz * point.y + mat.zz * point.z + mat.wz));
1265template <
typename T,
typename U>
1270 T w = T(mat.xw * point.x + mat.yw * point.y + mat.zw * point.z + mat.ww);
1271 if( w == T(0) || w == T(1))
1273 U(mat.xx * point.x + mat.yx * point.y + mat.zx * point.z + mat.wx),
1274 U(mat.xy * point.x + mat.yy * point.y + mat.zy * point.z + mat.wy),
1275 U(mat.xz * point.x + mat.yz * point.y + mat.zz * point.z + mat.wz));
1279 U((mat.xx * point.x + mat.yx * point.y + mat.zx * point.z + mat.wx) * w),
1280 U((mat.xy * point.x + mat.yy * point.y + mat.zy * point.z + mat.wy) * w),
1281 U((mat.xz * point.x + mat.yz * point.y + mat.zz * point.z + mat.wz) * w));
1290template <
typename T,
typename U>
1296 U(mat.xx * point.x + mat.yx * point.y + mat.zx * point.z + mat.wx * point.w),
1297 U(mat.xy * point.x + mat.yy * point.y + mat.zy * point.z + mat.wy * point.w),
1298 U(mat.xz * point.x + mat.yz * point.y + mat.zz * point.z + mat.wz * point.w),
1299 U(mat.xw * point.x + mat.yw * point.y + mat.zw * point.z + mat.ww * point.w));
1307template <
typename T,
typename U>
1312 return U(mat.xx * vector);
1320template <
typename T,
typename U>
1326 U(mat.xx * vector.x + mat.yx * vector.y),
1327 U(mat.xy * vector.x + mat.yy * vector.y));
1335template <
typename T,
typename U>
1341 U(mat.xx * vector.x + mat.yx * vector.y + mat.zx * vector.z),
1342 U(mat.xy * vector.x + mat.yy * vector.y + mat.zy * vector.z),
1343 U(mat.xz * vector.x + mat.yz * vector.y + mat.zz * vector.z));
1351template <
typename T,
typename U>
1357 U(mat.xx * vector.x + mat.yx * vector.y + mat.zx * vector.z),
1358 U(mat.xy * vector.x + mat.yy * vector.y + mat.zy * vector.z),
1359 U(mat.xz * vector.x + mat.yz * vector.y + mat.zz * vector.z));
1367template <
typename T,
typename U>
1373 U(mat.xx * vector.x + mat.yx * vector.y + mat.zx * vector.z),
1374 U(mat.xy * vector.x + mat.yy * vector.y + mat.zy * vector.z),
1375 U(mat.xz * vector.x + mat.yz * vector.y + mat.zz * vector.z));
1389template <
typename T,
typename U>
1395 U(inv_mat.xx * normal.x + inv_mat.xy * normal.y + inv_mat.xz * normal.z),
1396 U(inv_mat.yx * normal.x + inv_mat.yy * normal.y + inv_mat.yz * normal.z),
1397 U(inv_mat.zx * normal.x + inv_mat.zy * normal.y + inv_mat.zz * normal.z));
1411template <
typename T,
typename U>
1417 U(inv_mat.xx * normal.x + inv_mat.xy * normal.y + inv_mat.xz * normal.z),
1418 U(inv_mat.yx * normal.x + inv_mat.yy * normal.y + inv_mat.yz * normal.z),
1419 U(inv_mat.zx * normal.x + inv_mat.zy * normal.y + inv_mat.zz * normal.z));
1435template <
typename T,
typename U>
1441 mat.yx, mat.yy, mat.yz,
1442 mat.zx, mat.zy, mat.zz);
1443 bool inverted = sub_mat.
invert();
1447 U(sub_mat.xx * normal.x + sub_mat.xy * normal.y + sub_mat.xz * normal.z),
1448 U(sub_mat.yx * normal.x + sub_mat.yy * normal.y + sub_mat.yz * normal.z),
1449 U(sub_mat.zx * normal.x + sub_mat.zy * normal.y + sub_mat.zz * normal.z));
1455template <
typename T, Size ROW, Size COL>
1460 for(
Size i=0; i < ROW*COL; ++i)
1465template <
typename T, Size ROW, Size COL>
1470 for(
Size i=0; i < ROW*COL; ++i)
1475#ifndef MI_FOR_DOXYGEN_ONLY
1477template <
typename T, Size ROW, Size COL>
1484 const T min_angle = T(0.00024f);
1486 if(
abs( xangle) > min_angle) {
1493 if(
abs( yangle) > min_angle) {
1500 if(
abs(zangle) > min_angle) {
1507 this->xx = tcy * tcz;
1508 this->xy = tcy * tsz;
1512 this->yx = tmp * tcz - tcx * tsz;
1513 this->yy = tmp * tsz + tcx * tcz;
1514 this->yz = tsx * tcy;
1517 this->zx = tmp * tcz + tsx * tsz;
1518 this->zy = tmp * tsz - tsx * tcz;
1519 this->zz = tcx * tcy;
1522template <
typename T, Size ROW, Size COL>
1526 Vector<T,3> axis( axis_v);
1527 const T min_angle = T(0.00024f);
1529 if(
abs( T(angle)) < min_angle) {
1530 T xa = axis.x * T(angle);
1531 T ya = axis.y * T(angle);
1532 T za = axis.z * T(angle);
1549 T s =
sin( T(angle));
1550 T c =
cos( T(angle));
1554 tmp = t * T(axis.x);
1555 this->xx = tmp * T(axis.x) + c;
1556 this->xy = tmp * T(axis.y) + s * T(axis.z);
1557 this->xz = tmp * T(axis.z) - s * T(axis.y);
1560 tmp = t * T(axis.y);
1561 this->yx = tmp * T(axis.x) - s * T(axis.z);
1562 this->yy = tmp * T(axis.y) + c;
1563 this->yz = tmp * T(axis.z) + s * T(axis.x);
1566 tmp = t * T(axis.z);
1567 this->zx = tmp * T(axis.x) + s * T(axis.y);
1568 this->zy = tmp * T(axis.y) - s * T(axis.x);
1569 this->zz = tmp * T(axis.z) + c;
1572 this->wx = this->wy = this->wz = T(0);
1576template <
typename T, Size ROW, Size COL>
1580 Vector<T,3> axis( axis_v);
1581 const T min_angle = T(0.00024f);
1583 if(
abs(T(angle)) < min_angle) {
1584 T xa = axis.x * T(angle);
1585 T ya = axis.y * T(angle);
1586 T za = axis.z * T(angle);
1603 T s =
sin( T(angle));
1604 T c =
cos( T(angle));
1608 tmp = t * T(axis.x);
1609 this->xx = tmp * T(axis.x) + c;
1610 this->xy = tmp * T(axis.y) + s * T(axis.z);
1611 this->xz = tmp * T(axis.z) - s * T(axis.y);
1614 tmp = t * T(axis.y);
1615 this->yx = tmp * T(axis.x) - s * T(axis.z);
1616 this->yy = tmp * T(axis.y) + c;
1617 this->yz = tmp * T(axis.z) + s * T(axis.x);
1620 tmp = t * T(axis.z);
1621 this->zx = tmp * T(axis.x) + s * T(axis.y);
1622 this->zy = tmp * T(axis.y) - s * T(axis.x);
1623 this->zz = tmp * T(axis.z) + c;
1626 this->wx = this->wy = this->wz = T(0);
1630template <
typename T, Size ROW, Size COL>
1632 const Vector<Float32,3>& position,
1633 const Vector<Float32,3>& target,
1634 const Vector<Float32,3>& up)
1637 Vector<Float32,3> xaxis, yaxis, zaxis;
1640 zaxis = position - target;
1644 xaxis =
cross( up, zaxis);
1648 yaxis =
cross( zaxis, xaxis);
1653 T(xaxis.x), T(yaxis.x), T(zaxis.x), T(0),
1654 T(xaxis.y), T(yaxis.y), T(zaxis.y), T(0),
1655 T(xaxis.z), T(yaxis.z), T(zaxis.z), T(0),
1656 T(0), T(0), T(0), T(1));
1659 Matrix<T,4,4> trans(
1660 T(1), T(0), T(0), T(0),
1661 T(0), T(1), T(0), T(0),
1662 T(0), T(0), T(1), T(0),
1663 T(-position.x), T(-position.y), T(-position.z), T(1));
1665 *
this = trans * rot;
1668template <
typename T, Size ROW, Size COL>
1670 const Vector<Float64,3>& position,
1671 const Vector<Float64,3>& target,
1672 const Vector<Float64,3>& up)
1675 Vector<Float64,3> xaxis, yaxis, zaxis;
1678 zaxis = position - target;
1682 xaxis =
cross( up, zaxis);
1686 yaxis =
cross( zaxis, xaxis);
1691 T(xaxis.x), T(yaxis.x), T(zaxis.x), T(0),
1692 T(xaxis.y), T(yaxis.y), T(zaxis.y), T(0),
1693 T(xaxis.z), T(yaxis.z), T(zaxis.z), T(0),
1694 T(0), T(0), T(0), T(1));
1697 Matrix<T,4,4> trans(
1698 T(1), T(0), T(0), T(0),
1699 T(0), T(1), T(0), T(0),
1700 T(0), T(0), T(1), T(0),
1701 T(-position.x), T(-position.y), T(-position.z), T(1));
1703 *
this = trans * rot;
1710template <
class T, Size ROW, Size COL>
1711class Matrix_inverter
1714 typedef math::Matrix<T,ROW,COL> Matrix;
1719 static inline bool invert( Matrix& ) {
return false; }
1723template <
class T, Size DIM>
1724class Matrix_inverter<T,DIM,DIM>
1727 typedef math::Matrix<T,DIM,DIM> Matrix;
1728 typedef math::Vector<T,DIM> Value_vector;
1729 typedef math::Vector<Size,DIM> Index_vector;
1735 static bool lu_decomposition(
1737 Index_vector& indx);
1741 static void lu_backsubstitution(
1743 const Index_vector& indx,
1746 static bool invert( Matrix& mat);
1749template <
class T, Size DIM>
1750bool Matrix_inverter<T,DIM,DIM>::lu_decomposition(
1756 for(
Size i = 0; i < DIM; i++) {
1758 for(
Size j = 0; j < DIM; j++) {
1759 T temp =
abs(lu.get(i,j));
1771 for(
Size j = 0; j < DIM; j++) {
1772 for(
Size i = 0; i < j; i++) {
1773 T sum = lu.get(i,j);
1774 for(
Size k = 0; k < i; k++)
1775 sum -= lu.get(i,k) * lu.get(k,j);
1779 for(
Size i = j; i < DIM; i++) {
1780 T sum = lu.get(i,j);
1781 for(
Size k = 0; k < j; k++)
1782 sum -= lu.get(i,k) * lu.get(k,j);
1784 T dum = vv[i] *
abs(sum);
1791 for(
Size k = 0; k < DIM; k++) {
1792 T dum = lu.get(imax,k);
1793 lu.set(imax, k, lu.get(j,k));
1799 if( lu.get(j,j) == 0)
1802 T dum = T(1) / lu.get(j,j);
1803 for(
Size i = j + 1; i < DIM; i++)
1804 lu.set(i, j, lu.get(i,j) * dum);
1810template <
class T, Size DIM>
1811void Matrix_inverter<T,DIM,DIM>::lu_backsubstitution(
1813 const Index_vector& indx,
1818 for(
Size i = 0; i < DIM; i++) {
1823 for(
Size j = ii; j < i; j++) {
1824 sum -= lu.get(i,j) * b[j];
1833 for(
Size i2 = DIM; i2 > 0;) {
1836 for(
Size j = i2+1; j < DIM; j++)
1837 sum -= lu.get(i2,j) * b[j];
1838 b[i2] = sum / lu.get(i2,i2);
1842template <
class T, Size DIM>
1843bool Matrix_inverter<T,DIM,DIM>::invert( Matrix& mat)
1849 if( !lu_decomposition(lu, indx))
1853 for(
Size j = 0; j < DIM; ++j) {
1854 Value_vector col(T(0));
1856 lu_backsubstitution( lu, indx, col);
1857 for(
Size i = 0; i < DIM; ++i) {
1858 mat.set( i, j, col[i]);
1866class Matrix_inverter<T,1,1>
1869 typedef math::Matrix<T,1,1> Matrix;
1871 static inline bool invert( Matrix& mat)
1873 T s = mat.get( 0, 0);
1876 mat.set( 0, 0, T(1) / s);
1883class Matrix_inverter<T,2,2>
1886 typedef math::Matrix<T,2,2> Matrix;
1888 static inline bool invert( Matrix& mat)
1890 T a = mat.get( 0, 0);
1891 T b = mat.get( 0, 1);
1892 T c = mat.get( 1, 0);
1893 T d = mat.get( 1, 1);
1897 T rdet = T(1) / det;
1898 mat.set( 0, 0, d * rdet);
1899 mat.set( 0, 1,-b * rdet);
1900 mat.set( 1, 0,-c * rdet);
1901 mat.set( 1, 1, a * rdet);
1906template <
typename T, Size ROW, Size COL>
1909 return Matrix_inverter<T,ROW,COL>::invert( *
this);
1917template <
typename T>
1920 const Matrix<T,4,4>& rhs)
1922 Matrix<T,4,4> old( lhs);
1924 lhs.xx = old.xx * rhs.xx + old.xy * rhs.yx + old.xz * rhs.zx + old.xw * rhs.wx;
1925 lhs.xy = old.xx * rhs.xy + old.xy * rhs.yy + old.xz * rhs.zy + old.xw * rhs.wy;
1926 lhs.xz = old.xx * rhs.xz + old.xy * rhs.yz + old.xz * rhs.zz + old.xw * rhs.wz;
1927 lhs.xw = old.xx * rhs.xw + old.xy * rhs.yw + old.xz * rhs.zw + old.xw * rhs.ww;
1929 lhs.yx = old.yx * rhs.xx + old.yy * rhs.yx + old.yz * rhs.zx + old.yw * rhs.wx;
1930 lhs.yy = old.yx * rhs.xy + old.yy * rhs.yy + old.yz * rhs.zy + old.yw * rhs.wy;
1931 lhs.yz = old.yx * rhs.xz + old.yy * rhs.yz + old.yz * rhs.zz + old.yw * rhs.wz;
1932 lhs.yw = old.yx * rhs.xw + old.yy * rhs.yw + old.yz * rhs.zw + old.yw * rhs.ww;
1934 lhs.zx = old.zx * rhs.xx + old.zy * rhs.yx + old.zz * rhs.zx + old.zw * rhs.wx;
1935 lhs.zy = old.zx * rhs.xy + old.zy * rhs.yy + old.zz * rhs.zy + old.zw * rhs.wy;
1936 lhs.zz = old.zx * rhs.xz + old.zy * rhs.yz + old.zz * rhs.zz + old.zw * rhs.wz;
1937 lhs.zw = old.zx * rhs.xw + old.zy * rhs.yw + old.zz * rhs.zw + old.zw * rhs.ww;
1939 lhs.wx = old.wx * rhs.xx + old.wy * rhs.yx + old.wz * rhs.zx + old.ww * rhs.wx;
1940 lhs.wy = old.wx * rhs.xy + old.wy * rhs.yy + old.wz * rhs.zy + old.ww * rhs.wy;
1941 lhs.wz = old.wx * rhs.xz + old.wy * rhs.yz + old.wz * rhs.zz + old.ww * rhs.wz;
1942 lhs.ww = old.wx * rhs.xw + old.wy * rhs.yw + old.wz * rhs.zw + old.ww * rhs.ww;
1948template <
typename T>
1950 const Matrix<T,4,4>& lhs,
1951 const Matrix<T,4,4>& rhs)
1953 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:65
Sint64 Difference
Signed integral type that is large enough to hold the difference of two pointers.
Definition: types.h:122
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
double Float64
64-bit float.
Definition: types.h:52
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:1181
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:1197
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:1229
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:1168
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:1213
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:1157
#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:652
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:470
bool operator<(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically less than rhs.
Definition: bbox.h:607
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:564
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:535
bool operator==(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is elementwise equal to rhs.
Definition: bbox.h:591
bool operator>(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically greater than rhs.
Definition: bbox.h:637
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:598
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:622
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:845
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:550
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:782
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:486
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:502
Color abs(const Color &c)
Returns a color with the elementwise absolute values of the color c.
Definition: color.h:474
Color sin(const Color &c)
Returns a color with the elementwise sine of the color c.
Definition: color.h:764
Color cos(const Color &c)
Returns a color with the elementwise cosine of the color c.
Definition: color.h:561
T * begin()
Returns the pointer to the first matrix element.
Definition: matrix.h:405
T yw
yw-element.
Definition: matrix.h:263
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:494
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:893
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 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:715
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:512
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:519
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
Vector<T, ROW> Column_vector
Associated column vector of dimension ROW.
Definition: matrix.h:384
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:686
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:637
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:801
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:658
T xw
xw-element.
Definition: matrix.h:259
void set_translation(T dx, T dy, T dz)
Stores an absolute translation in the matrix (by component).
Definition: matrix.h:821
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:532
static const Size ROWS
Constant number of rows of the matrix.
Definition: matrix.h:386
T xx
xx-element.
Definition: matrix.h:103
T value_type
Element type.
Definition: matrix.h:372
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:647
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:627
T yy
yy-element.
Definition: matrix.h:244
T yy
yy-element.
Definition: matrix.h:146
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_struct<T, ROW, COL> Pod_type
POD class corresponding to this matrix.
Definition: matrix.h:369
Matrix(T m0, T m1, T m2, T m3)
4-element constructor, must be a 1x4, 2x2, or 4x1 matrix.
Definition: matrix.h:618
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:841
const T & operator()(Size row, Size col) const
Accesses the (row, col)-th matrix element.
Definition: matrix.h:705
void set_translation(const Vector<Float32, 3> &vector)
Stores an absolute translation in the matrix (by vector).
Definition: matrix.h:831
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:584
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:863
T xy
xy-element.
Definition: matrix.h:144
T xx
xx-element.
Definition: matrix.h:217
Difference difference_type
Difference type, signed.
Definition: matrix.h:374
void translate(const Vector<Float64, 3> &vector)
Adds a relative translation to the matrix (by vector).
Definition: matrix.h:811
void rotate(const Vector<Float64, 3> &angles)
Adds a relative rotation to the matrix (Euler angles, by vector).
Definition: matrix.h:874
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:600
T yx
yx-element.
Definition: matrix.h:178
const T * const_pointer
Const pointer to element.
Definition: matrix.h:376
T xy
xy-element.
Definition: matrix.h:257
T xx
xx-element.
Definition: matrix.h:97
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:1178
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:903
T zy
zy-element.
Definition: matrix.h:207
T yx
yx-element.
Definition: matrix.h:111
T & reference
Mutable reference to element.
Definition: matrix.h:377
T zy
zy-element.
Definition: matrix.h:193
T wx
wx-element.
Definition: matrix.h:268
static const Size COLUMNS
Constant number of columns of the matrix.
Definition: matrix.h:387
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:672
T get(Size row, Size col) const
Accesses the (row, col)-th matrix element.
Definition: matrix.h:724
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:475
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:1390
void transpose()
Transposes this matrix by exchanging rows and columns.
Definition: matrix.h:776
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:452
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:569
T det33() const
Returns the determinant of the upper-left 3x3 sub-matrix.
Definition: matrix.h:755
T yx
yx-element.
Definition: matrix.h:119
T wz
wz-element.
Definition: matrix.h:270
static Size max_size()
Constant maximum size of the vector.
Definition: matrix.h:394
Size size_type
Size type, unsigned.
Definition: matrix.h:373
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:503
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:556
Matrix_struct<T, ROW, COL> storage_type
Storage class used by this matrix.
Definition: matrix.h:370
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:745
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:695
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:735
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 * pointer
Mutable pointer to element.
Definition: matrix.h:375
T zx
zx-element.
Definition: matrix.h:112
T xz
xz-element.
Definition: matrix.h:169
Matrix()
The default constructor leaves the vector elements uninitialized.
Definition: matrix.h:435
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:1436
void translate(T x, T y, T z)
Adds a relative translation to the matrix (by components).
Definition: matrix.h:791
T wx
wx-element.
Definition: matrix.h:121
T zz
zz-element.
Definition: matrix.h:249
const T & const_reference
Const reference to element.
Definition: matrix.h:378
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
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:609
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:852
T xx
xx-element.
Definition: matrix.h:143
static Size size()
Constant size of the vector.
Definition: matrix.h:391
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:1194
T zy
zy-element.
Definition: matrix.h:248
static const Size SIZE
Constant size of the matrix.
Definition: matrix.h:388
Matrix(const Row_vector &v0)
Dedicated constructor, for ROW==1 only, that initializes matrix from one row vector v0.
Definition: matrix.h:545
Matrix(const Matrix_struct<T, ROW, COL> &other)
Constructor from underlying storage type.
Definition: matrix.h:443
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
Vector<T, COL> Row_vector
Associated row vector of dimension COL.
Definition: matrix.h:381
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:1705
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: dice.h:89
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.