7#ifndef BALL_MATHS_MATRIX44_H
8#define BALL_MATHS_MATRIX44_H
10#ifndef BALL_COMMON_EXCEPTION_H
18#ifndef BALL_MATHS_ANGLE_H
22#ifndef BALL_MATHS_VECTOR3_H
26#ifndef BALL_MATHS_VECTOR4_H
126 (const T&
m11, const T&
m12, const T&
m13, const T&
m14,
164 void set(
const T ptr[4][4]);
185 (
const T&
m11,
const T&
m12,
const T&
m13,
const T&
m14,
188 const T&
m41,
const T&
m42,
const T&
m43,
const T&
m44);
222 void get(T ptr[4][4])
const;
286 void set(
const T& t = (T)1);
492 void scale(
const T& x_scale,
const T& y_scale,
const T& z_scale);
509 void setScale(
const T& x_scale,
const T& y_scale,
const T& z_scale);
664 void dump(std::ostream& s = std::cout,
Size depth = 0)
const;
722 void initializeComponentPointers_()
724 T **ptr = (T **)comp_ptr_;
726 *ptr++ = &
m11; *ptr++ = &
m12; *ptr++ = &
m13; *ptr++ = &
m14;
727 *ptr++ = &
m21; *ptr++ = &
m22; *ptr++ = &
m23; *ptr++ = &
m24;
728 *ptr++ = &
m31; *ptr++ = &
m32; *ptr++ = &
m33; *ptr++ = &
m34;
729 *ptr++ = &
m41; *ptr++ = &
m42; *ptr++ = &
m43; *ptr = &
m44;
737 template <
typename T>
744 initializeComponentPointers_();
747 template <
typename T>
760 initializeComponentPointers_();
763 template <
typename T>
771 const T *ptr = *array_ptr;
778 initializeComponentPointers_();
781 template <
typename T>
788 initializeComponentPointers_();
792 template <
typename T>
801 initializeComponentPointers_();
804 template <
typename T>
806 (
const T&
m11,
const T&
m12,
const T&
m13,
const T&
m14,
815 initializeComponentPointers_();
818 template <
typename T>
824 template <
typename T>
838 template <
typename T>
846 const T *ptr = *array_ptr;
854 template <
typename T>
863 template <
typename T>
874 template <
typename T>
876 (
const T& c11,
const T& c12,
const T& c13,
const T& c14,
877 const T& c21,
const T& c22,
const T& c23,
const T& c24,
878 const T& c31,
const T& c32,
const T& c33,
const T& c34,
879 const T& c41,
const T& c42,
const T& c43,
const T& c44)
887 template <
typename T>
895 template <
typename T>
903 template <
typename T>
911 template <
typename T>
925 template <
typename T>
941 template <
typename T>
947 template <
typename T>
958 template <
typename T>
960 (T& c11, T& c12, T& c13, T& c14,
961 T& c21, T& c22, T& c23, T& c24,
962 T& c31, T& c32, T& c33, T& c34,
963 T& c41, T& c42, T& c43, T& c44)
const
971 template <
typename T>
978 template <
typename T>
992 template <
typename T>
999 template <
typename T>
1012 template <
typename T>
1022 template <
typename T>
1043 template <
typename T>
1071 template <
typename T>
1080 const T* ptr = comp_ptr_[4 * row];
1081 return TVector4<T> (ptr[0], ptr[1], ptr[2], ptr[3]);
1084 template <
typename T>
1092 const T* ptr = comp_ptr_[col];
1094 return TVector4<T> (ptr[0], ptr[4], ptr[8], ptr[12]);
1098 template <
typename T>
1107 T* ptr = comp_ptr_[4 * row];
1109 ptr[0] = row_value.
x;
1110 ptr[1] = row_value.
y;
1111 ptr[2] = row_value.
z;
1112 ptr[3] = row_value.
h;
1115 template <
typename T>
1124 T* ptr = comp_ptr_[col];
1126 ptr[0] = col_value.
x;
1127 ptr[4] = col_value.
y;
1128 ptr[8] = col_value.
z;
1129 ptr[12] = col_value.
h;
1132 template <
typename T>
1148 template <
typename T>
1154 template <
typename T>
1158 if ((row > 3) || (col > 3))
1163 return *comp_ptr_[4 * row + col];
1166 template <
typename T>
1170 if ((row > 3) || (col > 3))
1175 return *comp_ptr_[4 * row + col];
1178 template <
typename T>
1186 return *comp_ptr_[position];
1189 template <
typename T>
1197 return *comp_ptr_[position];
1200 template <
typename T>
1207 template <
typename T>
1218 template <
typename T>
1228 template <
typename T>
1251 template <
typename T>
1261 template <
typename T>
1284 template <
typename T>
1288 (
m11 * scalar,
m12 * scalar,
m13 * scalar,
m14 * scalar,
1289 m21 * scalar,
m22 * scalar,
m23 * scalar,
m24 * scalar,
1290 m31 * scalar,
m32 * scalar,
m33 * scalar,
m34 * scalar,
1291 m41 * scalar,
m42 * scalar,
m43 * scalar,
m44 * scalar);
1294 template <
typename T>
1298 (scalar * m.
m11, scalar * m.
m12, scalar * m.
m13, scalar * m.
m14,
1299 scalar * m.
m21, scalar * m.
m22, scalar * m.
m23, scalar * m.
m24,
1300 scalar * m.
m31, scalar * m.
m32, scalar * m.
m33, scalar * m.
m34,
1301 scalar * m.
m41, scalar * m.
m42, scalar * m.
m43, scalar * m.
m44);
1304 template <
typename T>
1327 template <
typename T>
1331 (matrix.
m11 * vector.x + matrix.
m12 * vector.y + matrix.
m13 * vector.z + matrix.
m14,
1332 matrix.
m21 * vector.x + matrix.
m22 * vector.y + matrix.
m23 * vector.z + matrix.
m24,
1333 matrix.
m31 * vector.x + matrix.
m32 * vector.y + matrix.
m33 * vector.z + matrix.
m34);
1336 template <
typename T>
1345 return (*
this * ((T)1 / scalar));
1348 template <
typename T>
1357 return (*
this *= (T)1 / scalar);
1360 template <
typename T>
1385 template <
typename T>
1411 template <
typename T>
1421 template <
typename T>
1442 T
scale, sum_of_squares, sigma, tau;
1459 sum_of_squares = (T)0;
1461 sum_of_squares += a[i][k]*a[i][k];
1464 sigma = (a[k][k] >= 0) ? sqrt(sum_of_squares) : -sqrt(sum_of_squares);
1467 c[k] = sigma*a[k][k];
1468 d[k] = -
scale*sigma;
1470 for (j = k+1; j<4; j++)
1473 sum_of_squares = (T)0;
1474 for (i = k; i<4; i++)
1475 sum_of_squares += a[i][k] * a[i][j];
1477 tau = sum_of_squares / c[k];
1481 a[i][j] -= tau*a[i][k];
1499 result[0][0] = 1; result[0][1] = 0; result[0][2] = 0; result[0][3] = 0;
1500 result[1][0] = 0; result[1][1] = 1; result[1][2] = 0; result[1][3] = 0;
1501 result[2][0] = 0; result[2][1] = 0; result[2][2] = 1; result[2][3] = 0;
1502 result[3][0] = 0; result[3][1] = 0; result[3][2] = 0; result[3][3] = 1;
1509 sum_of_squares = (T)0;
1511 sum_of_squares += a[i][j]*result[i][k];
1513 tau = sum_of_squares / c[j];
1516 result[i][k] -= tau*a[i][j];
1520 result[3][k] /= d[3];
1521 for (i=2; i>=0; i--)
1523 sum_of_squares = (T)0;
1524 for (j=i+1; j<4; j++)
1525 sum_of_squares += a[i][j] * result[j][k];
1527 result[i][k] = (result[i][k] - sum_of_squares) / d[i];
1532 inverse.
m11 = *k_ptr++;
1533 inverse.
m12 = *k_ptr++;
1534 inverse.
m13 = *k_ptr++;
1535 inverse.
m14 = *k_ptr++;
1536 inverse.
m21 = *k_ptr++;
1537 inverse.
m22 = *k_ptr++;
1538 inverse.
m23 = *k_ptr++;
1539 inverse.
m24 = *k_ptr++;
1540 inverse.
m31 = *k_ptr++;
1541 inverse.
m32 = *k_ptr++;
1542 inverse.
m33 = *k_ptr++;
1543 inverse.
m34 = *k_ptr++;
1544 inverse.
m41 = *k_ptr++;
1545 inverse.
m42 = *k_ptr++;
1546 inverse.
m43 = *k_ptr++;
1547 inverse.
m44 = *k_ptr;
1552 template <
typename T>
1558 template <
typename T>
1574 for (i = 0; i < 4; i++)
1576 for (j = 0; j < 3; j++)
1578 for (k = 0; k < 3; k++)
1581 matrix[j + 1][(k < i) ? k : k + 1];
1585 determinant += matrix[0][i] * (T)(i / 2.0 == (i >> 1) ? 1 : -1)
1586 * (submatrix[0][0] * submatrix[1][1] * submatrix[2][2]
1587 + submatrix[0][1] * submatrix[1][2] * submatrix[2][0]
1588 + submatrix[0][2] * submatrix[1][0] * submatrix[2][1]
1589 - submatrix[0][2] * submatrix[1][1] * submatrix[2][0]
1590 - submatrix[0][0] * submatrix[1][2] * submatrix[2][1]
1591 - submatrix[0][1] * submatrix[1][0] * submatrix[2][2]);
1597 template <
typename T>
1606 template <
typename T>
1615 template <
typename T>
1630 template <
typename T>
1645 template <
typename T>
1664 template <
typename T>
1683 template <
typename T>
1702 template <
typename T>
1716 template <
typename T>
1730 template <
typename T>
1744 template <
typename T>
1754 template <
typename T>
1769 template <
typename T>
1779 template <
typename T>
1794 template <
typename T>
1804 template <
typename T>
1816 template <
typename T>
1823 template <
typename T>
1886 template <
typename T>
1889 T xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c;
1894 double sin_angle = sin(phi);
1895 double cos_angle = cos(phi);
1901 T mag = sqrt(xx + yy + zz);
1923 xs = (T) (x * sin_angle);
1924 ys = (T) (y * sin_angle);
1925 zs = (T) (z * sin_angle);
1926 one_c = (T) (1 - cos_angle);
1928 m11 = (T)( (one_c * xx) + cos_angle );
1929 m12 = (one_c * xy) - zs;
1930 m13 = (one_c * zx) + ys;
1933 m21 = (one_c * xy) + zs;
1934 m22 = (T) ((one_c * yy) + cos_angle);
1935 m23 = (one_c * yz) - xs;
1938 m31 = (one_c * zx) - ys;
1939 m32 = (one_c * yz) + xs;
1940 m33 = (T) ((one_c * zz) + cos_angle);
1949 template <
typename T>
1957 template <
typename T>
1966 template <
typename T>
1975 template <
typename T>
1997 template <
typename T>
2019 template <
typename T>
2041 template <
typename T>
2048 template <
typename T>
2055 template <
typename T>
2063 template <
typename T>
2066 return (
m12 == (T)0
2074 template <
typename T>
2077 return (
m21 == (T)0
2085 template <
typename T>
2089 return (
m12 == (T)0
2103 template <
typename T>
2106 T **ptr = (T **)comp_ptr_;
2108 return ( *ptr++ == &
m11
2126 template <
typename T>
2139 template <
typename T>
2142 s <<
'/' << std::setw(14) << m.
m11 <<
' ' << std::setw(14) << m.
m12 <<
' ' << std::setw(14) << m.
m13 <<
' ' << std::setw(14) << m.
m14 <<
" \\" << std::endl
2143 <<
'|' << std::setw(14) << m.
m21 <<
' ' << std::setw(14) << m.
m22 <<
' ' << std::setw(14) << m.
m23 <<
' ' << std::setw(14) << m.
m24 <<
" |" << std::endl
2144 <<
'|' << std::setw(14) << m.
m31 <<
' ' << std::setw(14) << m.
m32 <<
' ' << std::setw(14) << m.
m33 <<
' ' << std::setw(14) << m.
m34 <<
" |" << std::endl
2145 <<
'\\' << std::setw(14) << m.
m41 <<
' ' << std::setw(14) << m.
m42 <<
' ' << std::setw(14) << m.
m43 <<
' ' << std::setw(14) << m.
m44 <<
" /" << std::endl;
2150 template <
typename T>
2158 s <<
m11 <<
" " <<
m12 <<
" " <<
m13 <<
" " <<
m14 << std::endl;
2161 s <<
m21 <<
" " <<
m22 <<
" " <<
m23 <<
" " <<
m24 << std::endl;
2164 s <<
m31 <<
" " <<
m32 <<
" " <<
m33 <<
" " <<
m34 << std::endl;
2167 s <<
m41 <<
" " <<
m42 <<
" " <<
m43 <<
" " <<
m44 << std::endl;
2173 template <
typename T>
2177 template <
typename T>
TMatrix4x4 operator+() const
void get(TVector4< T > &col1, TVector4< T > &col2, TVector4< T > &col3, TVector4< T > &col4) const
TMatrix4x4 & operator=(const T *ptr)
void setRotation(const TAngle< T > &phi, const TVector3< T > &axis)
void setTranslation(const T &x, const T &y, const T &z)
void setRotationY(const TAngle< T > &phi)
static const TMatrix4x4 & getZero()
TVector4< T > getColumn(Position col) const
bool operator==(const TMatrix4x4 &m) const
TMatrix4x4 operator*(const T &scalar) const
void setRotationZ(const TAngle< T > &phi)
void translate(const T &x, const T &y, const T &z)
void set(const T &m11, const T &m12, const T &m13, const T &m14, const T &m21, const T &m22, const T &m23, const T &m24, const T &m31, const T &m32, const T &m33, const T &m34, const T &m41, const T &m42, const T &m43, const T &m44)
void setScale(const T &x_scale, const T &y_scale, const T &z_scale)
void setColumn(Position col, const TVector4< T > &col_value)
void rotateY(const TAngle< T > &phi)
void translate(const TVector3< T > &v)
static const TMatrix4x4 & getIdentity()
void get(TMatrix4x4 &m) const
TVector4< T > getRow(Position row) const
T & operator()(Position row, Position col)
void set(const T ptr[4][4])
void rotate(const TAngle< T > &phi, const TVector3< T > &axis)
bool invert(TMatrix4x4 &inverse) const
void rotate(const TAngle< T > &phi, const TVector4< T > &axis)
bool isEqual(const TMatrix4x4 &m) const
void setScale(const T &scale)
void set(const TVector4< T > &col1, const TVector4< T > &col2, const TVector4< T > &col3, const TVector4< T > &col4)
void setTranslation(const TVector3< T > &v)
bool operator!=(const TMatrix4x4 &m) const
TMatrix4x4 operator-() const
void get(T ptr[4][4]) const
void scale(const T &scale)
void rotateX(const TAngle< T > &phi)
void setRotation(const TAngle< T > &phi, const T &axis_x, const T &axis_y, const T &axis_z)
TVector4< T > getDiagonal() const
void dump(std::ostream &s=std::cout, Size depth=0) const
void set(const TMatrix4x4 &m)
void setScale(const TVector3< T > &v)
TMatrix4x4 & operator/=(const T &scalar)
TMatrix4x4 operator/(const T &scalar) const
void get(T &m11, T &m12, T &m13, T &m14, T &m21, T &m22, T &m23, T &m24, T &m31, T &m32, T &m33, T &m34, T &m41, T &m42, T &m43, T &m44) const
void scale(const T &x_scale, const T &y_scale, const T &z_scale)
bool isLowerTriangular() const
void rotate(const TAngle< T > &phi, const T &axis_x, const T &axis_y, const T &axis_z)
void setRotation(const TAngle< T > &phi, const TVector4< T > &axis)
void rotateZ(const TAngle< T > &phi)
TMatrix4x4 & operator*=(const T &scalar)
const T & operator[](Position position) const
TMatrix4x4 & operator-=(const TMatrix4x4 &m)
void setRow(Position row, const TVector4< T > &row_value)
bool isUpperTriangular() const
void scale(const TVector3< T > &v)
void set(const T &t=(T) 1)
void setRotationX(const TAngle< T > &phi)
TMatrix4x4 & operator+=(const TMatrix4x4 &m)
#define BALL_CREATE(name)
TMatrix4x4< float > Matrix4x4
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
#define BALL_DUMP_STREAM_PREFIX(os)
#define BALL_DUMP_STREAM_SUFFIX(os)
#define BALL_DUMP_DEPTH(os, depth)
#define BALL_DUMP_HEADER(os, cl, ob)
T max(const T &a, const T &b)
bool isEqual(const T1 &a, const T2 &b)
BALL_INLINE TAngle< T > operator*(const T &val, const TAngle< T > &angle)
T getDeterminant(const T *m, Size dim)
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.