37 #ifndef INCLUDED_IMATHMATRIX_H
38 #define INCLUDED_IMATHMATRIX_H
58 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
60 #pragma warning(disable:4290)
285 const int c0,
const int c1)
const;
411 template <
typename R,
typename S>
417 template <
typename R>
418 struct isSameType<
R,
R>
654 T fastMinor (
const int r0,
const int r1,
const int r2,
655 const int c0,
const int c1,
const int c2)
const;
806 template <
typename R,
typename S>
812 template <
typename R>
813 struct isSameType<
R,
R>
825 std::ostream & operator << (std::ostream & s, const Matrix33<T> &
m);
828 std::ostream & operator << (std::ostream & s, const Matrix44<T> &
m);
835 template <
class S,
class T>
838 template <
class S,
class T>
841 template <
class S,
class T>
844 template <
class S,
class T>
847 template <
class S,
class T>
850 template <
class S,
class T>
853 template <
class S,
class T>
856 template <
class S,
class T>
891 memset (
x, 0,
sizeof (
x));
916 memcpy (
x, a,
sizeof (
x));
938 memcpy (
x, v.
x, sizeof (
x));
946 x[0][0] =
T (v.
x[0][0]);
947 x[0][1] =
T (v.
x[0][1]);
948 x[0][2] =
T (v.
x[0][2]);
949 x[1][0] =
T (v.
x[1][0]);
950 x[1][1] =
T (v.
x[1][1]);
951 x[1][2] =
T (v.
x[1][2]);
952 x[2][0] =
T (v.
x[2][0]);
953 x[2][1] =
T (v.
x[2][1]);
954 x[2][2] =
T (v.
x[2][2]);
961 memcpy (
x, v.
x, sizeof (
x));
985 return (
T *) &
x[0][0];
992 return (
const T *) &
x[0][0];
1002 memcpy (v.
x,
x, sizeof (
x));
1006 v.
x[0][0] =
x[0][0];
1007 v.
x[0][1] =
x[0][1];
1008 v.
x[0][2] =
x[0][2];
1009 v.
x[1][0] =
x[1][0];
1010 v.
x[1][1] =
x[1][1];
1011 v.
x[1][2] =
x[1][2];
1012 v.
x[2][0] =
x[2][0];
1013 v.
x[2][1] =
x[2][1];
1014 v.
x[2][2] =
x[2][2];
1025 memcpy (
x, v.
x, sizeof (
x));
1029 x[0][0] = v.
x[0][0];
1030 x[0][1] = v.
x[0][1];
1031 x[0][2] = v.
x[0][2];
1032 x[1][0] = v.
x[1][0];
1033 x[1][1] = v.
x[1][1];
1034 x[1][2] = v.
x[1][2];
1035 x[2][0] = v.
x[2][0];
1036 x[2][1] = v.
x[2][1];
1037 x[2][2] = v.
x[2][2];
1050 memcpy (
x, v.
x, sizeof (
x));
1054 x[0][0] = v.
x[0][0];
1055 x[0][1] = v.
x[0][1];
1056 x[0][2] = v.
x[0][2];
1057 x[1][0] = v.
x[1][0];
1058 x[1][1] = v.
x[1][1];
1059 x[1][2] = v.
x[1][2];
1060 x[2][0] = v.
x[2][0];
1061 x[2][1] = v.
x[2][1];
1062 x[2][2] = v.
x[2][2];
1072 memset (
x, 0,
sizeof (
x));
1082 return x[0][0] == v.
x[0][0] &&
1083 x[0][1] == v.
x[0][1] &&
1084 x[0][2] == v.
x[0][2] &&
1085 x[1][0] == v.
x[1][0] &&
1086 x[1][1] == v.
x[1][1] &&
1087 x[1][2] == v.
x[1][2] &&
1088 x[2][0] == v.
x[2][0] &&
1089 x[2][1] == v.
x[2][1] &&
1090 x[2][2] == v.
x[2][2];
1097 return x[0][0] != v.
x[0][0] ||
1098 x[0][1] != v.
x[0][1] ||
1099 x[0][2] != v.
x[0][2] ||
1100 x[1][0] != v.
x[1][0] ||
1101 x[1][1] != v.
x[1][1] ||
1102 x[1][2] != v.
x[1][2] ||
1103 x[2][0] != v.
x[2][0] ||
1104 x[2][1] != v.
x[2][1] ||
1105 x[2][2] != v.
x[2][2];
1112 for (
int i = 0; i < 3; i++)
1113 for (
int j = 0; j < 3; j++)
1124 for (
int i = 0; i < 3; i++)
1125 for (
int j = 0; j < 3; j++)
1136 x[0][0] += v.
x[0][0];
1137 x[0][1] += v.
x[0][1];
1138 x[0][2] += v.
x[0][2];
1139 x[1][0] += v.
x[1][0];
1140 x[1][1] += v.
x[1][1];
1141 x[1][2] += v.
x[1][2];
1142 x[2][0] += v.
x[2][0];
1143 x[2][1] += v.
x[2][1];
1144 x[2][2] += v.
x[2][2];
1171 x[0][1] + v.
x[0][1],
1172 x[0][2] + v.
x[0][2],
1173 x[1][0] + v.
x[1][0],
1174 x[1][1] + v.
x[1][1],
1175 x[1][2] + v.
x[1][2],
1176 x[2][0] + v.
x[2][0],
1177 x[2][1] + v.
x[2][1],
1178 x[2][2] + v.
x[2][2]);
1185 x[0][0] -= v.
x[0][0];
1186 x[0][1] -= v.
x[0][1];
1187 x[0][2] -= v.
x[0][2];
1188 x[1][0] -= v.
x[1][0];
1189 x[1][1] -= v.
x[1][1];
1190 x[1][2] -= v.
x[1][2];
1191 x[2][0] -= v.
x[2][0];
1192 x[2][1] -= v.
x[2][1];
1193 x[2][2] -= v.
x[2][2];
1220 x[0][1] - v.
x[0][1],
1221 x[0][2] - v.
x[0][2],
1222 x[1][0] - v.
x[1][0],
1223 x[1][1] - v.
x[1][1],
1224 x[1][2] - v.
x[1][2],
1225 x[2][0] - v.
x[2][0],
1226 x[2][1] - v.
x[2][1],
1227 x[2][2] - v.
x[2][2]);
1307 for (
int i = 0; i < 3; i++)
1308 for (
int j = 0; j < 3; j++)
1309 for (
int k = 0; k < 3; k++)
1310 tmp.
x[i][j] +=
x[i][k] * v.
x[k][j];
1322 for (
int i = 0; i < 3; i++)
1323 for (
int j = 0; j < 3; j++)
1324 for (
int k = 0; k < 3; k++)
1325 tmp.
x[i][j] +=
x[i][k] * v.
x[k][j];
1337 a = src[0] *
x[0][0] + src[1] *
x[1][0] +
x[2][0];
1338 b = src[0] * x[0][1] + src[1] * x[1][1] + x[2][1];
1339 w = src[0] * x[0][2] + src[1] * x[1][2] + x[2][2];
1352 a = src[0] *
x[0][0] + src[1] *
x[1][0];
1353 b = src[0] * x[0][1] + src[1] * x[1][1];
1427 *
this = gjInverse (singExc);
1441 for (i = 0; i < 2 ; i++)
1445 T pivotsize = t[i][i];
1448 pivotsize = -pivotsize;
1450 for (j = i + 1; j < 3; j++)
1457 if (tmp > pivotsize)
1467 throw ::IMATH_INTERNAL_NAMESPACE::SingMatrixExc (
"Cannot invert singular matrix.");
1474 for (j = 0; j < 3; j++)
1479 t[i][j] = t[
pivot][j];
1483 s[i][j] = s[
pivot][j];
1488 for (j = i + 1; j < 3; j++)
1490 T f = t[j][i] / t[i][i];
1492 for (k = 0; k < 3; k++)
1494 t[j][k] -= f * t[i][k];
1495 s[j][k] -= f * s[i][k];
1502 for (i = 2; i >= 0; --i)
1506 if ((f = t[i][i]) == 0)
1509 throw ::IMATH_INTERNAL_NAMESPACE::SingMatrixExc (
"Cannot invert singular matrix.");
1514 for (j = 0; j < 3; j++)
1520 for (j = 0; j < i; j++)
1524 for (k = 0; k < 3; k++)
1526 t[j][k] -= f * t[i][k];
1527 s[j][k] -= f * s[i][k];
1539 *
this = inverse (singExc);
1547 if (
x[0][2] != 0 ||
x[1][2] != 0 ||
x[2][2] != 1)
1550 x[2][1] * x[0][2] - x[0][1] * x[2][2],
1551 x[0][1] * x[1][2] - x[1][1] * x[0][2],
1553 x[2][0] * x[1][2] - x[1][0] * x[2][2],
1554 x[0][0] * x[2][2] - x[2][0] * x[0][2],
1555 x[1][0] * x[0][2] - x[0][0] * x[1][2],
1557 x[1][0] * x[2][1] - x[2][0] * x[1][1],
1558 x[2][0] * x[0][1] - x[0][0] * x[2][1],
1559 x[0][0] * x[1][1] - x[1][0] * x[0][1]);
1561 T r = x[0][0] * s[0][0] + x[0][1] * s[1][0] + x[0][2] * s[2][0];
1565 for (
int i = 0; i < 3; ++i)
1567 for (
int j = 0; j < 3; ++j)
1577 for (
int i = 0; i < 3; ++i)
1579 for (
int j = 0; j < 3; ++j)
1588 throw SingMatrixExc (
"Cannot invert "
1589 "singular matrix.");
1612 T r =
x[0][0] *
x[1][1] -
x[1][0] *
x[0][1];
1616 for (
int i = 0; i < 2; ++i)
1618 for (
int j = 0; j < 2; ++j)
1628 for (
int i = 0; i < 2; ++i)
1630 for (
int j = 0; j < 2; ++j)
1639 throw SingMatrixExc (
"Cannot invert "
1640 "singular matrix.");
1647 s[2][0] = -x[2][0] * s[0][0] - x[2][1] * s[1][0];
1648 s[2][1] = -x[2][0] * s[0][1] - x[2][1] * s[1][1];
1658 int r0 = 0 + (r < 1 ? 1 : 0);
1659 int r1 = 1 + (r < 2 ? 1 : 0);
1660 int c0 = 0 + (c < 1 ? 1 : 0);
1661 int c1 = 1 + (c < 2 ? 1 : 0);
1663 return x[r0][c0]*
x[r1][c1] -
x[r1][c0]*
x[r0][c1];
1669 const int c0,
const int c1)
const
1671 return x[r0][c0]*
x[r1][c1] -
x[r0][c1]*
x[r1][c0];
1678 return x[0][0]*(
x[1][1]*
x[2][2] -
x[1][2]*
x[2][1]) +
1679 x[0][1]*(
x[1][2]*
x[2][0] -
x[1][0]*
x[2][2]) +
1680 x[0][2]*(x[1][0]*x[2][1] - x[1][1]*x[2][0]);
1721 memset (
x, 0,
sizeof (
x));
1734 memset (
x, 0,
sizeof (
x));
1790 x[2][0] += t[0] *
x[0][0] + t[1] *
x[1][0];
1791 x[2][1] += t[0] * x[0][1] + t[1] * x[1][1];
1792 x[2][2] += t[0] * x[0][2] + t[1] * x[1][2];
1848 x[1][0] += xy *
x[0][0];
1849 x[1][1] += xy * x[0][1];
1850 x[1][2] += xy * x[0][2];
1862 x[0][0] = P[0][0] + h[1] * P[1][0];
1863 x[0][1] = P[0][1] + h[1] * P[1][1];
1864 x[0][2] = P[0][2] + h[1] * P[1][2];
1866 x[1][0] = P[1][0] + h[0] * P[0][0];
1867 x[1][1] = P[1][1] + h[0] * P[0][1];
1868 x[1][2] = P[1][2] + h[0] * P[0][2];
1896 memset (
x, 0,
sizeof (
x));
1929 memcpy (
x, a,
sizeof (
x));
1935 T i, T j, T k, T
l, T
m, T
n, T o, T
p)
1982 x[0][0] = v.
x[0][0];
1983 x[0][1] = v.
x[0][1];
1984 x[0][2] = v.
x[0][2];
1985 x[0][3] = v.
x[0][3];
1986 x[1][0] = v.
x[1][0];
1987 x[1][1] = v.
x[1][1];
1988 x[1][2] = v.
x[1][2];
1989 x[1][3] = v.
x[1][3];
1990 x[2][0] = v.
x[2][0];
1991 x[2][1] = v.
x[2][1];
1992 x[2][2] = v.
x[2][2];
1993 x[2][3] = v.
x[2][3];
1994 x[3][0] = v.
x[3][0];
1995 x[3][1] = v.
x[3][1];
1996 x[3][2] = v.
x[3][2];
1997 x[3][3] = v.
x[3][3];
2005 x[0][0] =
T (v.
x[0][0]);
2006 x[0][1] =
T (v.
x[0][1]);
2007 x[0][2] =
T (v.
x[0][2]);
2008 x[0][3] =
T (v.
x[0][3]);
2009 x[1][0] =
T (v.
x[1][0]);
2010 x[1][1] =
T (v.
x[1][1]);
2011 x[1][2] =
T (v.
x[1][2]);
2012 x[1][3] =
T (v.
x[1][3]);
2013 x[2][0] =
T (v.
x[2][0]);
2014 x[2][1] =
T (v.
x[2][1]);
2015 x[2][2] =
T (v.
x[2][2]);
2016 x[2][3] =
T (v.
x[2][3]);
2017 x[3][0] =
T (v.
x[3][0]);
2018 x[3][1] =
T (v.
x[3][1]);
2019 x[3][2] =
T (v.
x[3][2]);
2020 x[3][3] =
T (v.
x[3][3]);
2027 x[0][0] = v.
x[0][0];
2028 x[0][1] = v.
x[0][1];
2029 x[0][2] = v.
x[0][2];
2030 x[0][3] = v.
x[0][3];
2031 x[1][0] = v.
x[1][0];
2032 x[1][1] = v.
x[1][1];
2033 x[1][2] = v.
x[1][2];
2034 x[1][3] = v.
x[1][3];
2035 x[2][0] = v.
x[2][0];
2036 x[2][1] = v.
x[2][1];
2037 x[2][2] = v.
x[2][2];
2038 x[2][3] = v.
x[2][3];
2039 x[3][0] = v.
x[3][0];
2040 x[3][1] = v.
x[3][1];
2041 x[3][2] = v.
x[3][2];
2042 x[3][3] = v.
x[3][3];
2073 return (
T *) &
x[0][0];
2080 return (
const T *) &
x[0][0];
2090 memcpy (v.
x,
x, sizeof (
x));
2094 v.
x[0][0] =
x[0][0];
2095 v.
x[0][1] =
x[0][1];
2096 v.
x[0][2] =
x[0][2];
2097 v.
x[0][3] =
x[0][3];
2098 v.
x[1][0] =
x[1][0];
2099 v.
x[1][1] =
x[1][1];
2100 v.
x[1][2] =
x[1][2];
2101 v.
x[1][3] =
x[1][3];
2102 v.
x[2][0] =
x[2][0];
2103 v.
x[2][1] =
x[2][1];
2104 v.
x[2][2] =
x[2][2];
2105 v.
x[2][3] =
x[2][3];
2106 v.
x[3][0] =
x[3][0];
2107 v.
x[3][1] =
x[3][1];
2108 v.
x[3][2] =
x[3][2];
2109 v.
x[3][3] =
x[3][3];
2120 memcpy (
x, v.
x, sizeof (
x));
2124 x[0][0] = v.
x[0][0];
2125 x[0][1] = v.
x[0][1];
2126 x[0][2] = v.
x[0][2];
2127 x[0][3] = v.
x[0][3];
2128 x[1][0] = v.
x[1][0];
2129 x[1][1] = v.
x[1][1];
2130 x[1][2] = v.
x[1][2];
2131 x[1][3] = v.
x[1][3];
2132 x[2][0] = v.
x[2][0];
2133 x[2][1] = v.
x[2][1];
2134 x[2][2] = v.
x[2][2];
2135 x[2][3] = v.
x[2][3];
2136 x[3][0] = v.
x[3][0];
2137 x[3][1] = v.
x[3][1];
2138 x[3][2] = v.
x[3][2];
2139 x[3][3] = v.
x[3][3];
2152 memcpy (
x, v.
x, sizeof (
x));
2156 x[0][0] = v.
x[0][0];
2157 x[0][1] = v.
x[0][1];
2158 x[0][2] = v.
x[0][2];
2159 x[0][3] = v.
x[0][3];
2160 x[1][0] = v.
x[1][0];
2161 x[1][1] = v.
x[1][1];
2162 x[1][2] = v.
x[1][2];
2163 x[1][3] = v.
x[1][3];
2164 x[2][0] = v.
x[2][0];
2165 x[2][1] = v.
x[2][1];
2166 x[2][2] = v.
x[2][2];
2167 x[2][3] = v.
x[2][3];
2168 x[3][0] = v.
x[3][0];
2169 x[3][1] = v.
x[3][1];
2170 x[3][2] = v.
x[3][2];
2171 x[3][3] = v.
x[3][3];
2181 memset (
x, 0,
sizeof (
x));
2192 return x[0][0] == v.
x[0][0] &&
2193 x[0][1] == v.
x[0][1] &&
2194 x[0][2] == v.
x[0][2] &&
2195 x[0][3] == v.
x[0][3] &&
2196 x[1][0] == v.
x[1][0] &&
2197 x[1][1] == v.
x[1][1] &&
2198 x[1][2] == v.
x[1][2] &&
2199 x[1][3] == v.
x[1][3] &&
2200 x[2][0] == v.
x[2][0] &&
2201 x[2][1] == v.
x[2][1] &&
2202 x[2][2] == v.
x[2][2] &&
2203 x[2][3] == v.
x[2][3] &&
2204 x[3][0] == v.
x[3][0] &&
2205 x[3][1] == v.
x[3][1] &&
2206 x[3][2] == v.
x[3][2] &&
2207 x[3][3] == v.
x[3][3];
2214 return x[0][0] != v.
x[0][0] ||
2215 x[0][1] != v.
x[0][1] ||
2216 x[0][2] != v.
x[0][2] ||
2217 x[0][3] != v.
x[0][3] ||
2218 x[1][0] != v.
x[1][0] ||
2219 x[1][1] != v.
x[1][1] ||
2220 x[1][2] != v.
x[1][2] ||
2221 x[1][3] != v.
x[1][3] ||
2222 x[2][0] != v.
x[2][0] ||
2223 x[2][1] != v.
x[2][1] ||
2224 x[2][2] != v.
x[2][2] ||
2225 x[2][3] != v.
x[2][3] ||
2226 x[3][0] != v.
x[3][0] ||
2227 x[3][1] != v.
x[3][1] ||
2228 x[3][2] != v.
x[3][2] ||
2229 x[3][3] != v.
x[3][3];
2236 for (
int i = 0; i < 4; i++)
2237 for (
int j = 0; j < 4; j++)
2248 for (
int i = 0; i < 4; i++)
2249 for (
int j = 0; j < 4; j++)
2260 x[0][0] += v.
x[0][0];
2261 x[0][1] += v.
x[0][1];
2262 x[0][2] += v.
x[0][2];
2263 x[0][3] += v.
x[0][3];
2264 x[1][0] += v.
x[1][0];
2265 x[1][1] += v.
x[1][1];
2266 x[1][2] += v.
x[1][2];
2267 x[1][3] += v.
x[1][3];
2268 x[2][0] += v.
x[2][0];
2269 x[2][1] += v.
x[2][1];
2270 x[2][2] += v.
x[2][2];
2271 x[2][3] += v.
x[2][3];
2272 x[3][0] += v.
x[3][0];
2273 x[3][1] += v.
x[3][1];
2274 x[3][2] += v.
x[3][2];
2275 x[3][3] += v.
x[3][3];
2309 x[0][1] + v.
x[0][1],
2310 x[0][2] + v.
x[0][2],
2311 x[0][3] + v.
x[0][3],
2312 x[1][0] + v.
x[1][0],
2313 x[1][1] + v.
x[1][1],
2314 x[1][2] + v.
x[1][2],
2315 x[1][3] + v.
x[1][3],
2316 x[2][0] + v.
x[2][0],
2317 x[2][1] + v.
x[2][1],
2318 x[2][2] + v.
x[2][2],
2319 x[2][3] + v.
x[2][3],
2320 x[3][0] + v.
x[3][0],
2321 x[3][1] + v.
x[3][1],
2322 x[3][2] + v.
x[3][2],
2323 x[3][3] + v.
x[3][3]);
2330 x[0][0] -= v.
x[0][0];
2331 x[0][1] -= v.
x[0][1];
2332 x[0][2] -= v.
x[0][2];
2333 x[0][3] -= v.
x[0][3];
2334 x[1][0] -= v.
x[1][0];
2335 x[1][1] -= v.
x[1][1];
2336 x[1][2] -= v.
x[1][2];
2337 x[1][3] -= v.
x[1][3];
2338 x[2][0] -= v.
x[2][0];
2339 x[2][1] -= v.
x[2][1];
2340 x[2][2] -= v.
x[2][2];
2341 x[2][3] -= v.
x[2][3];
2342 x[3][0] -= v.
x[3][0];
2343 x[3][1] -= v.
x[3][1];
2344 x[3][2] -= v.
x[3][2];
2345 x[3][3] -= v.
x[3][3];
2379 x[0][1] - v.
x[0][1],
2380 x[0][2] - v.
x[0][2],
2381 x[0][3] - v.
x[0][3],
2382 x[1][0] - v.
x[1][0],
2383 x[1][1] - v.
x[1][1],
2384 x[1][2] - v.
x[1][2],
2385 x[1][3] - v.
x[1][3],
2386 x[2][0] - v.
x[2][0],
2387 x[2][1] - v.
x[2][1],
2388 x[2][2] - v.
x[2][2],
2389 x[2][3] - v.
x[2][3],
2390 x[3][0] - v.
x[3][0],
2391 x[3][1] - v.
x[3][1],
2392 x[3][2] - v.
x[3][2],
2393 x[3][3] - v.
x[3][3]);
2533 cp[0] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12];
2534 cp[1] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13];
2535 cp[2] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14];
2536 cp[3] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15];
2543 cp[4] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12];
2544 cp[5] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13];
2545 cp[6] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14];
2546 cp[7] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15];
2553 cp[8] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12];
2554 cp[9] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13];
2555 cp[10] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14];
2556 cp[11] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15];
2563 cp[12] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12];
2564 cp[13] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13];
2565 cp[14] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14];
2566 cp[15] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15];
2569 template <
class T>
template <
class S>
2575 a = src[0] *
x[0][0] + src[1] *
x[1][0] + src[2] *
x[2][0] +
x[3][0];
2576 b = src[0] * x[0][1] + src[1] * x[1][1] + src[2] * x[2][1] + x[3][1];
2577 c = src[0] * x[0][2] + src[1] * x[1][2] + src[2] * x[2][2] + x[3][2];
2578 w = src[0] * x[0][3] + src[1] * x[1][3] + src[2] * x[2][3] + x[3][3];
2585 template <
class T>
template <
class S>
2591 a = src[0] *
x[0][0] + src[1] *
x[1][0] + src[2] *
x[2][0];
2592 b = src[0] * x[0][1] + src[1] * x[1][1] + src[2] * x[2][1];
2593 c = src[0] * x[0][2] + src[1] * x[1][2] + src[2] * x[2][2];
2696 *
this = gjInverse (singExc);
2710 for (i = 0; i < 3 ; i++)
2714 T pivotsize = t[i][i];
2717 pivotsize = -pivotsize;
2719 for (j = i + 1; j < 4; j++)
2726 if (tmp > pivotsize)
2736 throw ::IMATH_INTERNAL_NAMESPACE::SingMatrixExc (
"Cannot invert singular matrix.");
2743 for (j = 0; j < 4; j++)
2748 t[i][j] = t[
pivot][j];
2752 s[i][j] = s[
pivot][j];
2757 for (j = i + 1; j < 4; j++)
2759 T f = t[j][i] / t[i][i];
2761 for (k = 0; k < 4; k++)
2763 t[j][k] -= f * t[i][k];
2764 s[j][k] -= f * s[i][k];
2771 for (i = 3; i >= 0; --i)
2775 if ((f = t[i][i]) == 0)
2778 throw ::IMATH_INTERNAL_NAMESPACE::SingMatrixExc (
"Cannot invert singular matrix.");
2783 for (j = 0; j < 4; j++)
2789 for (j = 0; j < i; j++)
2793 for (k = 0; k < 4; k++)
2795 t[j][k] -= f * t[i][k];
2796 s[j][k] -= f * s[i][k];
2808 *
this = inverse (singExc);
2816 if (
x[0][3] != 0 ||
x[1][3] != 0 ||
x[2][3] != 0 ||
x[3][3] != 1)
2817 return gjInverse(singExc);
2820 x[2][1] * x[0][2] - x[0][1] * x[2][2],
2821 x[0][1] * x[1][2] - x[1][1] * x[0][2],
2824 x[2][0] * x[1][2] - x[1][0] * x[2][2],
2825 x[0][0] * x[2][2] - x[2][0] * x[0][2],
2826 x[1][0] * x[0][2] - x[0][0] * x[1][2],
2829 x[1][0] * x[2][1] - x[2][0] * x[1][1],
2830 x[2][0] * x[0][1] - x[0][0] * x[2][1],
2831 x[0][0] * x[1][1] - x[1][0] * x[0][1],
2839 T r = x[0][0] * s[0][0] + x[0][1] * s[1][0] + x[0][2] * s[2][0];
2843 for (
int i = 0; i < 3; ++i)
2845 for (
int j = 0; j < 3; ++j)
2855 for (
int i = 0; i < 3; ++i)
2857 for (
int j = 0; j < 3; ++j)
2866 throw SingMatrixExc (
"Cannot invert singular matrix.");
2874 s[3][0] = -x[3][0] * s[0][0] - x[3][1] * s[1][0] - x[3][2] * s[2][0];
2875 s[3][1] = -x[3][0] * s[0][1] - x[3][1] * s[1][1] - x[3][2] * s[2][1];
2876 s[3][2] = -x[3][0] * s[0][2] - x[3][1] * s[1][2] - x[3][2] * s[2][2];
2884 const int c0,
const int c1,
const int c2)
const
2886 return x[r0][c0] * (
x[r1][c1]*
x[r2][c2] -
x[r1][c2]*
x[r2][c1])
2887 +
x[r0][c1] * (
x[r1][c2]*
x[r2][c0] -
x[r1][c0]*
x[r2][c2])
2888 +
x[r0][c2] * (
x[r1][c0]*
x[r2][c1] -
x[r1][c1]*
x[r2][c0]);
2895 int r0 = 0 + (r < 1 ? 1 : 0);
2896 int r1 = 1 + (r < 2 ? 1 : 0);
2897 int r2 = 2 + (r < 3 ? 1 : 0);
2898 int c0 = 0 + (c < 1 ? 1 : 0);
2899 int c1 = 1 + (c < 2 ? 1 : 0);
2900 int c2 = 2 + (c < 3 ? 1 : 0);
2903 x[r0][c1],
x[r1][c1],
x[r2][c1],
2904 x[r0][c2],
x[r1][c2],
x[r2][c2]);
2915 if (
x[0][3] != 0.) sum -=
x[0][3] * fastMinor(1,2,3,0,1,2);
2916 if (
x[1][3] != 0.) sum +=
x[1][3] * fastMinor(0,2,3,0,1,2);
2917 if (
x[2][3] != 0.) sum -=
x[2][3] * fastMinor(0,1,3,0,1,2);
2918 if (
x[3][3] != 0.) sum +=
x[3][3] * fastMinor(0,1,2,0,1,2);
2928 S cos_rz, sin_rz, cos_ry, sin_ry, cos_rx, sin_rx;
2938 x[0][0] = cos_rz * cos_ry;
2939 x[0][1] = sin_rz * cos_ry;
2943 x[1][0] = -sin_rz * cos_rx + cos_rz * sin_ry * sin_rx;
2944 x[1][1] = cos_rz * cos_rx + sin_rz * sin_ry * sin_rx;
2945 x[1][2] = cos_ry * sin_rx;
2948 x[2][0] = sin_rz * sin_rx + cos_rz * sin_ry * cos_rx;
2949 x[2][1] = -cos_rz * sin_rx + sin_rz * sin_ry * cos_rx;
2950 x[2][2] = cos_ry * cos_rx;
2970 x[0][0] =
unit[0] *
unit[0] * (1 - cosine) + cosine;
2971 x[0][1] =
unit[0] *
unit[1] * (1 - cosine) +
unit[2] * sine;
2972 x[0][2] =
unit[0] *
unit[2] * (1 - cosine) -
unit[1] * sine;
2975 x[1][0] =
unit[0] *
unit[1] * (1 - cosine) -
unit[2] * sine;
2976 x[1][1] =
unit[1] *
unit[1] * (1 - cosine) + cosine;
2977 x[1][2] =
unit[1] *
unit[2] * (1 - cosine) +
unit[0] * sine;
2980 x[2][0] =
unit[0] *
unit[2] * (1 - cosine) +
unit[1] * sine;
2981 x[2][1] =
unit[1] *
unit[2] * (1 - cosine) -
unit[0] * sine;
2982 x[2][2] =
unit[2] *
unit[2] * (1 - cosine) + cosine;
2998 S cos_rz, sin_rz, cos_ry, sin_ry, cos_rx, sin_rx;
3011 m00 = cos_rz * cos_ry;
3012 m01 = sin_rz * cos_ry;
3014 m10 = -sin_rz * cos_rx + cos_rz * sin_ry * sin_rx;
3015 m11 = cos_rz * cos_rx + sin_rz * sin_ry * sin_rx;
3016 m12 = cos_ry * sin_rx;
3017 m20 = -sin_rz * -sin_rx + cos_rz * sin_ry * cos_rx;
3018 m21 = cos_rz * -sin_rx + sin_rz * sin_ry * cos_rx;
3019 m22 = cos_ry * cos_rx;
3023 x[0][0] = P[0][0] * m00 + P[1][0] * m01 + P[2][0] * m02;
3024 x[0][1] = P[0][1] * m00 + P[1][1] * m01 + P[2][1] * m02;
3025 x[0][2] = P[0][2] * m00 + P[1][2] * m01 + P[2][2] * m02;
3026 x[0][3] = P[0][3] * m00 + P[1][3] * m01 + P[2][3] * m02;
3028 x[1][0] = P[0][0] * m10 + P[1][0] * m11 + P[2][0] * m12;
3029 x[1][1] = P[0][1] * m10 + P[1][1] * m11 + P[2][1] * m12;
3030 x[1][2] = P[0][2] * m10 + P[1][2] * m11 + P[2][2] * m12;
3031 x[1][3] = P[0][3] * m10 + P[1][3] * m11 + P[2][3] * m12;
3033 x[2][0] = P[0][0] * m20 + P[1][0] * m21 + P[2][0] * m22;
3034 x[2][1] = P[0][1] * m20 + P[1][1] * m21 + P[2][1] * m22;
3035 x[2][2] = P[0][2] * m20 + P[1][2] * m21 + P[2][2] * m22;
3036 x[2][3] = P[0][3] * m20 + P[1][3] * m21 + P[2][3] * m22;
3045 memset (
x, 0,
sizeof (
x));
3059 memset (
x, 0,
sizeof (
x));
3123 return Vec3<T> (
x[3][0], x[3][1], x[3][2]);
3131 x[3][0] += t[0] *
x[0][0] + t[1] *
x[1][0] + t[2] *
x[2][0];
3132 x[3][1] += t[0] * x[0][1] + t[1] * x[1][1] + t[2] * x[2][1];
3133 x[3][2] += t[0] * x[0][2] + t[1] * x[1][2] + t[2] * x[2][2];
3134 x[3][3] += t[0] * x[0][3] + t[1] * x[1][3] + t[2] * x[2][3];
3206 for (
int i=0; i < 4; i++)
3208 x[2][i] += h[1] *
x[0][i] + h[2] *
x[1][i];
3209 x[1][i] += h[0] * x[0][i];
3222 for (
int i=0; i < 4; i++)
3224 x[0][i] = P[0][i] + h.
yx * P[1][i] + h.
zx * P[2][i];
3225 x[1][i] = h.
xy * P[0][i] + P[1][i] + h.
zy * P[2][i];
3226 x[2][i] = h.
xz * P[0][i] + h.
yz * P[1][i] + P[2][i];
3239 operator << (std::ostream &s, const Matrix33<T> &
m)
3241 std::ios_base::fmtflags oldFlags =
s.flags();
3244 if (
s.flags() & std::ios_base::fixed)
3246 s.setf (std::ios_base::showpoint);
3247 width =
static_cast<int>(
s.precision()) + 5;
3251 s.setf (std::ios_base::scientific);
3252 s.setf (std::ios_base::showpoint);
3253 width =
static_cast<int>(
s.precision()) + 8;
3256 s <<
"(" << std::setw (width) <<
m[0][0] <<
3257 " " << std::setw (width) <<
m[0][1] <<
3258 " " << std::setw (width) <<
m[0][2] <<
"\n" <<
3260 " " << std::setw (width) <<
m[1][0] <<
3261 " " << std::setw (width) <<
m[1][1] <<
3262 " " << std::setw (width) <<
m[1][2] <<
"\n" <<
3264 " " << std::setw (width) <<
m[2][0] <<
3265 " " << std::setw (width) <<
m[2][1] <<
3266 " " << std::setw (width) <<
m[2][2] <<
")\n";
3274 operator << (std::ostream &s, const Matrix44<T> &
m)
3276 std::ios_base::fmtflags oldFlags =
s.flags();
3279 if (
s.flags() & std::ios_base::fixed)
3281 s.setf (std::ios_base::showpoint);
3282 width =
static_cast<int>(
s.precision()) + 5;
3286 s.setf (std::ios_base::scientific);
3287 s.setf (std::ios_base::showpoint);
3288 width =
static_cast<int>(
s.precision()) + 8;
3291 s <<
"(" << std::setw (width) <<
m[0][0] <<
3292 " " << std::setw (width) <<
m[0][1] <<
3293 " " << std::setw (width) <<
m[0][2] <<
3294 " " << std::setw (width) <<
m[0][3] <<
"\n" <<
3296 " " << std::setw (width) <<
m[1][0] <<
3297 " " << std::setw (width) <<
m[1][1] <<
3298 " " << std::setw (width) <<
m[1][2] <<
3299 " " << std::setw (width) <<
m[1][3] <<
"\n" <<
3301 " " << std::setw (width) <<
m[2][0] <<
3302 " " << std::setw (width) <<
m[2][1] <<
3303 " " << std::setw (width) <<
m[2][2] <<
3304 " " << std::setw (width) <<
m[2][3] <<
"\n" <<
3306 " " << std::setw (width) <<
m[3][0] <<
3307 " " << std::setw (width) <<
m[3][1] <<
3308 " " << std::setw (width) <<
m[3][2] <<
3309 " " << std::setw (width) <<
m[3][3] <<
")\n";
3320 template <
class S,
class T>
3324 S x =
S(v.
x * m[0][0] + v.
y * m[1][0] + m[2][0]);
3325 S y =
S(v.
x * m[0][1] + v.
y * m[1][1] + m[2][1]);
3326 S w =
S(v.
x * m[0][2] + v.
y * m[1][2] + m[2][2]);
3334 template <
class S,
class T>
3338 S x =
S(v.
x * m[0][0] + v.
y * m[1][0] + m[2][0]);
3339 S y =
S(v.
x * m[0][1] + v.
y * m[1][1] + m[2][1]);
3340 S w =
S(v.
x * m[0][2] + v.
y * m[1][2] + m[2][2]);
3346 template <
class S,
class T>
3350 S x =
S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0]);
3351 S y =
S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1]);
3352 S z =
S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2]);
3361 template <
class S,
class T>
3365 S x =
S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0]);
3366 S y =
S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1]);
3367 S z =
S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2]);
3373 template <
class S,
class T>
3377 S x =
S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0] + m[3][0]);
3378 S y =
S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1] + m[3][1]);
3379 S z =
S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2] + m[3][2]);
3380 S w =
S(v.
x * m[0][3] + v.
y * m[1][3] + v.
z * m[2][3] + m[3][3]);
3389 template <
class S,
class T>
3393 S x =
S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0] + m[3][0]);
3394 S y =
S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1] + m[3][1]);
3395 S z =
S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2] + m[3][2]);
3396 S w =
S(v.
x * m[0][3] + v.
y * m[1][3] + v.
z * m[2][3] + m[3][3]);
3402 template <
class S,
class T>
3406 S x =
S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0] + v.
w * m[3][0]);
3407 S y =
S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1] + v.
w * m[3][1]);
3408 S z =
S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2] + v.
w * m[3][2]);
3409 S w =
S(v.
x * m[0][3] + v.
y * m[1][3] + v.
z * m[2][3] + v.
w * m[3][3]);
3419 template <
class S,
class T>
3423 S x =
S(v.
x * m[0][0] + v.
y * m[1][0] + v.
z * m[2][0] + v.
w * m[3][0]);
3424 S y =
S(v.
x * m[0][1] + v.
y * m[1][1] + v.
z * m[2][1] + v.
w * m[3][1]);
3425 S z =
S(v.
x * m[0][2] + v.
y * m[1][2] + v.
z * m[2][2] + v.
w * m[3][2]);
3426 S w =
S(v.
x * m[0][3] + v.
y * m[1][3] + v.
z * m[2][3] + v.
w * m[3][3]);
3433 #endif // INCLUDED_IMATHMATRIX_H
#define IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
Matrix44 operator/(T a) const
const Matrix33 & setShear(const S &h)
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
const Matrix44 & operator+=(const Matrix44 &v)
GLboolean GLboolean GLboolean b
const Matrix44 & setAxisAngle(const Vec3< S > &ax, S ang)
const Matrix33 & setTranslation(const Vec2< S > &t)
const Matrix33 & operator=(const Matrix33 &v)
const Matrix33 & gjInvert(bool singExc=false)
#define IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
Matrix44 operator+(const Matrix44 &v) const
const Matrix44 & operator*=(T a)
const Matrix44 & setShear(const Vec3< S > &h)
static T baseTypeEpsilon()
const Matrix44 & operator-=(const Matrix44 &v)
static void multiply(const Matrix44 &a, const Matrix44 &b, Matrix44 &c)
bool equalWithRelError(T x1, T x2, T e)
const Matrix44 & operator/=(T a)
void multDirMatrix(const Vec3< S > &src, Vec3< S > &dst) const
Matrix44< T > inverse(bool singExc=false) const
const Matrix33 & scale(const Vec2< S > &s)
Matrix33 operator+(const Matrix33 &v) const
Matrix33 operator*(T a) const
const Matrix44 & setScale(T s)
const Matrix44 & transpose()
const Matrix33 & operator/=(T a)
T fastMinor(const int r0, const int r1, const int r2, const int c0, const int c1, const int c2) const
T fastMinor(const int r0, const int r1, const int c0, const int c1) const
const Matrix44 & operator=(const Matrix44 &v)
GLubyte GLubyte GLubyte GLubyte w
bool operator!=(const Matrix44 &v) const
const Matrix44 & translate(const Vec3< S > &t)
bool operator==(const Matrix33 &v) const
Vec2< T > translation() const
Vec3< T > & operator*=(Vec3< T > &_v, const Mat3< MT > &_m)
Multiply _v by _m and replace _v with the resulting vector.
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T abs(T a)
const Matrix33 & negate()
Matrix44 transposed() const
GLboolean GLboolean GLboolean GLboolean a
void multVecMatrix(const Vec3< S > &src, Vec3< S > &dst) const
Matrix33 & setValue(const Matrix33< S > &v)
Vec3< T > normalized() const
const Matrix33 & operator+=(const Matrix33 &v)
Matrix33 operator-() const
static T baseTypeSmallest()
bool operator==(const Matrix44 &v) const
const Matrix44 & shear(const Vec3< S > &h)
GLdouble GLdouble GLdouble z
png_const_structrp png_const_inforp int * unit
static T baseTypeSmallest()
static unsigned int dimensions()
bool equalWithRelError(const Matrix33< T > &v, T e) const
const Matrix33 & operator*=(T a)
const Matrix33 & translate(const Vec2< S > &t)
Matrix33 operator/(T a) const
bool operator!=(const Matrix33 &v) const
static T baseTypeEpsilon()
Matrix33< T > inverse(bool singExc=false) const
GLfloat GLfloat GLfloat GLfloat h
static unsigned int dimensions()
const Matrix33 & rotate(S r)
const Matrix44 & scale(const Vec3< S > &s)
const Matrix33 & shear(const S &xy)
Matrix44< T > gjInverse(bool singExc=false) const
const Matrix33 & setScale(T s)
void multVecMatrix(const Vec2< S > &src, Vec2< S > &dst) const
const Matrix33 & transpose()
Matrix33 transposed() const
bool equalWithAbsError(const Matrix44< T > &v, T e) const
GA_API const UT_StringHolder pivot
GLsizei const GLfloat * value
void multDirMatrix(const Vec2< S > &src, Vec2< S > &dst) const
T minorOf(const int r, const int c) const
Matrix44 & setTheMatrix(const Matrix44< S > &v)
const Matrix44 & rotate(const Vec3< S > &r)
Matrix33< T > gjInverse(bool singExc=false) const
const Matrix44 & negate()
Matrix44 operator-() const
bool equalWithRelError(const Matrix44< T > &v, T e) const
const Matrix44 & gjInvert(bool singExc=false)
const Matrix33 & invert(bool singExc=false)
const Matrix44 & setEulerAngles(const Vec3< S > &r)
const Matrix33 & operator-=(const Matrix33 &v)
const Matrix44 & invert(bool singExc=false)
const Matrix33 & setRotation(S r)
uint64_t multiply(uint64_t lhs, uint64_t rhs)
T minorOf(const int r, const int c) const
const Matrix44 & setTranslation(const Vec3< S > &t)
bool equalWithAbsError(const Matrix33< T > &v, T e) const
const Vec3< T > translation() const
Matrix33 & setTheMatrix(const Matrix33< S > &v)
bool equalWithAbsError(T x1, T x2, T e)
Matrix44 & setValue(const Matrix44< S > &v)
Matrix44 operator*(T a) const