8 #ifndef META_OCEAN_MATH_SQUARE_MATRIX_3_H
9 #define META_OCEAN_MATH_SQUARE_MATRIX_3_H
24 template <
typename T>
class EulerT;
26 template <
typename T>
class HomogenousMatrixT4;
28 template <
typename T>
class QuaternionT;
30 template <
typename T>
class RotationT;
32 template <
typename T>
class SquareMatrixT4;
35 template <
typename T>
class SquareMatrixT3;
117 template <
typename U>
163 template <
typename U>
178 template <
typename U>
212 explicit SquareMatrixT3(
const T& m00,
const T& m10,
const T& m20,
const T& m01,
const T& m11,
const T& m21,
const T& m02,
const T& m12,
const T& m22);
432 template <
typename U>
433 void copyElements(U* arrayValues,
const bool valuesRowAligned =
false)
const;
440 void copyElements(T* arrayValues,
const bool valuesRowAligned =
false)
const;
601 inline T
operator()(
const unsigned int row,
const unsigned int column)
const;
610 inline T&
operator()(
const unsigned int row,
const unsigned int column);
679 template <
typename U>
689 template <
typename U>
698 template <
typename T>
704 template <
typename T>
705 template <
typename U>
708 values_[0] = T(matrix.
values_[0]);
709 values_[1] = T(matrix.
values_[1]);
710 values_[2] = T(matrix.
values_[2]);
711 values_[3] = T(matrix.
values_[3]);
712 values_[4] = T(matrix.
values_[4]);
713 values_[5] = T(matrix.
values_[5]);
714 values_[6] = T(matrix.
values_[6]);
715 values_[7] = T(matrix.
values_[7]);
716 values_[8] = T(matrix.
values_[8]);
719 template <
typename T>
748 template <
typename T>
788 values_[0] = cy * cz + sx * sy * sz;
789 values_[1] = cx * sz;
790 values_[2] = -cz * sy + cy * sx * sz;
791 values_[3] = cz * sx * sy - cy * sz;
792 values_[4] = cx * cz;
793 values_[5] = cy * cz * sx + sy * sz;
794 values_[6] = cx * sy;
796 values_[8] = cx * cy;
801 template <
typename T>
806 ocean_assert(rotation.
isValid());
809 const T cosValue1 = T(1.0) - cosValue;
814 const T xx = axis.
x() * axis.
x() * cosValue1;
815 const T yy = axis.
y() * axis.
y() * cosValue1;
816 const T zz = axis.
z() * axis.
z() * cosValue1;
817 const T xy = axis.
x() * axis.
y() * cosValue1;
818 const T xz = axis.
x() * axis.
z() * cosValue1;
819 const T yz = axis.
y() * axis.
z() * cosValue1;
821 const T nx = axis.
x() * sinValue;
822 const T ny = axis.
y() * sinValue;
823 const T nz = axis.
z() * sinValue;
825 values_[0] = xx + cosValue;
826 values_[1] = xy + nz;
827 values_[2] = xz - ny;
829 values_[3] = xy - nz;
830 values_[4] = yy + cosValue;
831 values_[5] = yz + nx;
833 values_[6] = xz + ny;
834 values_[7] = yz - nx;
835 values_[8] = zz + cosValue;
840 template <
typename T>
843 ocean_assert(quaternion.
isValid());
845 const T xx = quaternion.
x() * quaternion.
x();
846 const T yy = quaternion.
y() * quaternion.
y();
847 const T zz = quaternion.
z() * quaternion.
z();
849 const T wx = quaternion.
w() * quaternion.
x();
850 const T wy = quaternion.
w() * quaternion.
y();
851 const T wz = quaternion.
w() * quaternion.
z();
852 const T xy = quaternion.
x() * quaternion.
y();
853 const T xz = quaternion.
x() * quaternion.
z();
854 const T yz = quaternion.
y() * quaternion.
z();
856 values_[0] = T(1.0) - T(2.0) * (yy + zz);
857 values_[1] = T(2.0) * (wz + xy);
858 values_[2] = T(2.0) * (xz - wy);
860 values_[3] = T(2.0) * (xy - wz);
861 values_[4] = T(1.0) - T(2.0) * (xx + zz);
862 values_[5] = T(2.0) * (wx + yz);
864 values_[6] = T(2.0) * (wy + xz);
865 values_[7] = T(2.0) * (yz - wx);
866 values_[8] = T(1.0) - T(2.0) * (xx + yy);
871 template <
typename T>
887 template <
typename T>
890 memcpy(values_, xAxis(),
sizeof(T) * 3);
891 memcpy(values_ + 3, yAxis(),
sizeof(T) * 3);
892 memcpy(values_ + 6, zAxis(),
sizeof(T) * 3);
895 template <
typename T>
898 values_[0] = diagonal[0];
902 values_[4] = diagonal[1];
906 values_[8] = diagonal[2];
909 template <
typename T>
910 template <
typename U>
913 ocean_assert(arrayValues);
915 for (
unsigned int n = 0u; n < 9u; ++n)
917 values_[n] = T(arrayValues[n]);
921 template <
typename T>
924 ocean_assert(arrayValues);
925 memcpy(values_, arrayValues,
sizeof(T) * 9);
928 template <
typename T>
929 template <
typename U>
932 ocean_assert(arrayValues);
934 if (valuesRowAligned)
936 values_[0] = T(arrayValues[0]);
937 values_[1] = T(arrayValues[3]);
938 values_[2] = T(arrayValues[6]);
939 values_[3] = T(arrayValues[1]);
940 values_[4] = T(arrayValues[4]);
941 values_[5] = T(arrayValues[7]);
942 values_[6] = T(arrayValues[2]);
943 values_[7] = T(arrayValues[5]);
944 values_[8] = T(arrayValues[8]);
949 for (
unsigned int n = 0u; n < 9u; ++n)
951 values_[n] = T(arrayValues[n]);
956 template <
typename T>
959 ocean_assert(arrayValues);
961 if (valuesRowAligned)
963 values_[0] = arrayValues[0];
964 values_[1] = arrayValues[3];
965 values_[2] = arrayValues[6];
966 values_[3] = arrayValues[1];
967 values_[4] = arrayValues[4];
968 values_[5] = arrayValues[7];
969 values_[6] = arrayValues[2];
970 values_[7] = arrayValues[5];
971 values_[8] = arrayValues[8];
975 memcpy(values_, arrayValues,
sizeof(T) * 9);
979 template <
typename T>
982 memcpy(values_, transformation(),
sizeof(T) * 3);
983 memcpy(values_ + 3, transformation() + 4,
sizeof(T) * 3);
984 memcpy(values_ + 6, transformation() + 8,
sizeof(T) * 3);
987 template <
typename T>
990 memcpy(values_, transformation(),
sizeof(T) * 3);
991 memcpy(values_ + 3, transformation() + 4,
sizeof(T) * 3);
992 memcpy(values_ + 6, transformation() + 8,
sizeof(T) * 3);
1013 const T d = determinant();
1017 const T d0 = b[0] * (values_[4] * values_[8] - values_[5] * values_[7]) + b[1] * (values_[5] * values_[6] - values_[3] * values_[8]) + b[2] * (values_[3] * values_[7] - values_[4] * values_[6]);
1018 const T d1 = values_[0] * ( b[1] * values_[8] - b[2] * values_[7]) + values_[1] * ( b[2] * values_[6] - b[0] * values_[8]) + values_[2] * ( b[0] * values_[7] - b[1] * values_[6]);
1019 const T d2 = values_[0] * (values_[4] * b[2] - values_[5] * b[1]) + values_[1] * (values_[5] * b[0] - values_[3] * b[2]) + values_[2] * (values_[3] * b[1] - values_[4] * b[0]);
1021 const T invD = T(1) / d;
1033 template<
typename T>
1039 template<
typename T>
1042 return (values_[0] + values_[1] + values_[2] + values_[3] + values_[4] + values_[5] + values_[6] + values_[7] + values_[8]);
1045 template <
typename T>
1051 template <
typename T>
1057 template <
typename T>
1060 return !(*
this == matrix);
1063 template <
typename T>
1066 *
this = *
this * matrix;
1070 template <
typename T>
1073 ocean_assert(index < 9u);
1074 return values_[index];
1077 template <
typename T>
1080 ocean_assert(index < 9u);
1081 return values_[index];
1084 template <
typename T>
1087 ocean_assert(row < 3u && column < 3u);
1088 return values_[column * 3 + row];
1091 template <
typename T>
1094 ocean_assert(row < 3u && column < 3u);
1095 return values_[column * 3 + row];
1098 template <
typename T>
1101 ocean_assert(index < 9u);
1102 return values_[index];
1105 template <
typename T>
1108 ocean_assert(index < 9u);
1109 return values_[index];
1112 template <
typename T>
1118 template <
typename T>
1124 template <
typename T>
1127 size_t seed = std::hash<T>{}(matrix.
values_[0]);
1129 for (
unsigned int n = 1u; n < 9u; ++n)
1131 seed ^= std::hash<T>{}(matrix.
values_[n]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1137 template <
typename T>
1143 template <
typename T>
1148 result.
values_[1] = values_[3];
1149 result.
values_[3] = values_[1];
1151 result.
values_[2] = values_[6];
1152 result.
values_[6] = values_[2];
1154 result.
values_[5] = values_[7];
1155 result.
values_[7] = values_[5];
1160 template <
typename T>
1175 template <
typename T>
1180 if (!invert(invertedMatrix))
1182 ocean_assert(
false &&
"Could not invert the matrix.");
1186 return invertedMatrix;
1189 template <
typename T>
1194 if (!invert(invertedMatrix))
1199 *
this = invertedMatrix;
1204 template <
typename T>
1208 const T v48 = values_[4] * values_[8];
1209 const T v57 = values_[5] * values_[7];
1210 const T v56 = values_[5] * values_[6];
1211 const T v38 = values_[3] * values_[8];
1212 const T v37 = values_[3] * values_[7];
1213 const T v46 = values_[4] * values_[6];
1215 const T v48_57 = v48 - v57;
1216 const T v56_38 = v56 - v38;
1217 const T v37_46 = v37 - v46;
1219 const T det = values_[0] * v48_57 + values_[1] * v56_38 + values_[2] * v37_46;
1226 const T factor = T(1.0) / det;
1228 invertedMatrix.
values_[0] = (v48_57) * factor;
1229 invertedMatrix.
values_[1] = (values_[2] * values_[7] - values_[1] * values_[8]) * factor;
1230 invertedMatrix.
values_[2] = (values_[1] * values_[5] - values_[2] * values_[4]) * factor;
1232 invertedMatrix.
values_[3] = (v56_38) * factor;
1233 invertedMatrix.
values_[4] = (values_[0] * values_[8] - values_[2] * values_[6]) * factor;
1234 invertedMatrix.
values_[5] = (values_[2] * values_[3] - values_[0] * values_[5]) * factor;
1236 invertedMatrix.
values_[6] = (v37_46) * factor;
1237 invertedMatrix.
values_[7] = (values_[1] * values_[6] - values_[0] * values_[7]) * factor;
1238 invertedMatrix.
values_[8] = (values_[0] * values_[4] - values_[1] * values_[3]) * factor;
1240 #ifdef OCEAN_INTENSIVE_DEBUG
1241 if (!std::is_same<T, float>::value)
1247 for (
unsigned int n = 0; n < 9u; ++n)
1256 T absolusteAverageEnergy = 0;
1257 for (
unsigned int n = 0u; n < 9u; ++n)
1262 absolusteAverageEnergy *= T(0.111111111111111111);
1266 if (absolusteAverageEnergy <= 1)
1268 ocean_assert_accuracy(!
"This should never happen!");
1272 const T adjustedDistance = distance / absolusteAverageEnergy;
1282 template <
typename T>
1285 return values_[0] * (values_[4] * values_[8] - values_[5] * values_[7])
1286 + values_[1] * (values_[5] * values_[6] - values_[3] * values_[8])
1287 + values_[2] * (values_[3] * values_[7] - values_[4] * values_[6]);
1290 template <
typename T>
1293 return values_[0] + values_[4] + values_[8];
1296 template <
typename T>
1299 values_[0] = T(1.0);
1300 values_[1] = T(0.0);
1301 values_[2] = T(0.0);
1302 values_[3] = T(0.0);
1303 values_[4] = T(1.0);
1304 values_[5] = T(0.0);
1305 values_[6] = T(0.0);
1306 values_[7] = T(0.0);
1307 values_[8] = T(1.0);
1310 template <
typename T>
1313 values_[0] = T(0.0);
1314 values_[1] = T(0.0);
1315 values_[2] = T(0.0);
1316 values_[3] = T(0.0);
1317 values_[4] = T(0.0);
1318 values_[5] = T(0.0);
1319 values_[6] = T(0.0);
1320 values_[7] = T(0.0);
1321 values_[8] = T(0.0);
1324 template <
typename T>
1332 template <
typename T>
1340 template <
typename T>
1346 template <
typename T>
1352 template <
typename T>
1358 template <
typename T>
1364 template <
typename T>
1367 ocean_assert(epsilon >= 0);
1377 template <
typename T>
1380 ocean_assert(epsilon >= T(0));
1385 template <
typename T>
1395 template <
typename T>
1401 template <
typename T>
1407 template <
typename T>
1413 template <
typename T>
1416 ocean_assert(!isSingular());
1423 const T xScale = xAxis.
length();
1428 const T xyShear = xAxis * yAxis;
1431 yAxis -= xAxis * xyShear;
1434 const T yScale = yAxis.
length();
1439 const T xzShear = xAxis * zAxis;
1441 zAxis -= xAxis * xzShear;
1444 const T yzShear = yAxis * zAxis;
1446 zAxis -= yAxis * yzShear;
1449 const T zScale = zAxis.
length();
1453 #ifdef OCEAN_INTENSIVE_DEBUG
1454 if (std::is_same<T, double>::value)
1466 template <
typename T>
1469 ocean_assert(eigenValues);
1493 const T a = values_[0];
1494 const T d = values_[1];
1495 const T g = values_[2];
1497 const T b = values_[3];
1498 const T e = values_[4];
1499 const T h = values_[5];
1501 const T c = values_[6];
1502 const T f = values_[7];
1503 const T i = values_[8];
1505 const T a1 = T(1.0);
1506 const T a2 = -(a + e + i);
1507 const T a3 = -(-a * e - a * i - e * i + g * c + h * f + d * b);
1508 const T a4 = -a * e * i - b * f * g - c * d * h + g * e * c + h * f * a + d * i * b;
1519 template <
typename T>
1522 ocean_assert(eigenValues !=
nullptr && eigenVectors !=
nullptr);
1545 const T a = values_[0];
1546 const T d = values_[1];
1547 const T g = values_[2];
1549 const T b = values_[3];
1550 const T e = values_[4];
1551 const T h = values_[5];
1553 const T c = values_[6];
1554 const T f = values_[7];
1555 const T i = values_[8];
1557 const T a1 = T(1.0);
1558 const T a2 = -(a + e + i);
1559 const T a3 = -(-a * e - a * i - e * i + g * c + h * f + d * b);
1560 const T a4 = -a * e * i - b * f * g - c * d * h + g * e * c + h * f * a + d * i * b;
1579 for (
unsigned int n = 0u; n < 3u; ++n)
1589 T sqrCandidate0(candidate0.
sqr());
1590 T sqrCandidate1(candidate1.
sqr());
1591 T sqrCandidate2(candidate2.
sqr());
1604 sqrCandidate0 = candidate0.
sqr();
1605 sqrCandidate1 = candidate1.
sqr();
1606 sqrCandidate2 = candidate2.
sqr();
1615 eigenVectors[n] = candidate0;
1624 template <
typename T>
1627 return VectorT3<T>(values_[0], values_[4], values_[8]);
1630 template <
typename T>
1631 template <
typename U>
1634 ocean_assert(arrayValues !=
nullptr);
1636 if (valuesRowAligned)
1641 arrayValues[0] = U(values_[0]);
1642 arrayValues[1] = U(values_[3]);
1643 arrayValues[2] = U(values_[6]);
1645 arrayValues[3] = U(values_[1]);
1646 arrayValues[4] = U(values_[4]);
1647 arrayValues[5] = U(values_[7]);
1649 arrayValues[6] = U(values_[2]);
1650 arrayValues[7] = U(values_[5]);
1651 arrayValues[8] = U(values_[8]);
1658 arrayValues[0] = U(values_[0]);
1659 arrayValues[1] = U(values_[1]);
1660 arrayValues[2] = U(values_[2]);
1661 arrayValues[3] = U(values_[3]);
1662 arrayValues[4] = U(values_[4]);
1663 arrayValues[5] = U(values_[5]);
1664 arrayValues[6] = U(values_[6]);
1665 arrayValues[7] = U(values_[7]);
1666 arrayValues[8] = U(values_[8]);
1670 template <
typename T>
1673 ocean_assert(arrayValues !=
nullptr);
1675 if (valuesRowAligned)
1680 arrayValues[0] = values_[0];
1681 arrayValues[1] = values_[3];
1682 arrayValues[2] = values_[6];
1684 arrayValues[3] = values_[1];
1685 arrayValues[4] = values_[4];
1686 arrayValues[5] = values_[7];
1688 arrayValues[6] = values_[2];
1689 arrayValues[7] = values_[5];
1690 arrayValues[8] = values_[8];
1697 memcpy(arrayValues, values_,
sizeof(T) * 9);
1701 template <
typename T>
1704 return SquareMatrixT3<T>(0, vector(2), -vector(1), -vector(2), 0, vector(0), vector(1), -vector(0), 0);
1707 template <
typename T>
1716 const T z = values_[2] * vector[0] + values_[5] * vector[1] + values_[8];
1720 const T factor = T(1) / z;
1722 result =
VectorT2<T>((values_[0] * vector[0] + values_[3] * vector[1] + values_[6]) * factor,
1723 (values_[1] * vector[0] + values_[4] * vector[1] + values_[7]) * factor);
1731 template <
typename T>
1746 #ifdef OCEAN_INTENSIVE_DEBUG
1748 ocean_assert(debugMatrix == result);
1754 template <
typename T>
1757 return isEqual(matrix);
1760 template <
typename T>
1778 template <
typename T>
1781 values_[0] += matrix.
values_[0];
1782 values_[1] += matrix.
values_[1];
1783 values_[2] += matrix.
values_[2];
1784 values_[3] += matrix.
values_[3];
1785 values_[4] += matrix.
values_[4];
1786 values_[5] += matrix.
values_[5];
1787 values_[6] += matrix.
values_[6];
1788 values_[7] += matrix.
values_[7];
1789 values_[8] += matrix.
values_[8];
1794 template <
typename T>
1812 template <
typename T>
1815 values_[0] -= matrix.
values_[0];
1816 values_[1] -= matrix.
values_[1];
1817 values_[2] -= matrix.
values_[2];
1818 values_[3] -= matrix.
values_[3];
1819 values_[4] -= matrix.
values_[4];
1820 values_[5] -= matrix.
values_[5];
1821 values_[6] -= matrix.
values_[6];
1822 values_[7] -= matrix.
values_[7];
1823 values_[8] -= matrix.
values_[8];
1828 template <
typename T>
1833 result.
values_[0] = -values_[0];
1834 result.
values_[1] = -values_[1];
1835 result.
values_[2] = -values_[2];
1836 result.
values_[3] = -values_[3];
1837 result.
values_[4] = -values_[4];
1838 result.
values_[5] = -values_[5];
1839 result.
values_[6] = -values_[6];
1840 result.
values_[7] = -values_[7];
1841 result.
values_[8] = -values_[8];
1846 template <
typename T>
1864 template <
typename T>
1873 const T z = values_[2] * vector[0] + values_[5] * vector[1] + values_[8];
1876 const T factor = T(1) / z;
1878 return VectorT2<T>((values_[0] * vector[0] + values_[3] * vector[1] + values_[6]) * factor,
1879 (values_[1] * vector[0] + values_[4] * vector[1] + values_[7]) * factor);
1882 template <
typename T>
1885 return VectorT3<T>(values_[0] * vector[0] + values_[3] * vector[1] + values_[6] * vector[2],
1886 values_[1] * vector[0] + values_[4] * vector[1] + values_[7] * vector[2],
1887 values_[2] * vector[0] + values_[5] * vector[1] + values_[8] * vector[2]);
1890 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 20
1914 const double*
const vectorValues = vector.
data();
1917 const __m128d v0 = _mm_load1_pd(vectorValues + 0);
1919 const __m128d c0 = _mm_loadu_pd(values_ + 0);
1922 const __m128d r0 = _mm_mul_pd(c0, v0);
1926 const __m128d v1 = _mm_load1_pd(vectorValues + 1);
1927 const __m128d c1 = _mm_loadu_pd(values_ + 3);
1928 const __m128d r1 = _mm_mul_pd(c1, v1);
1931 __m128d result_f64x2 = _mm_add_pd(r0, r1);
1935 const __m128d v2 = _mm_load1_pd(vectorValues + 2);
1936 const __m128d c2 = _mm_loadu_pd(values_ + 6);
1937 const __m128d r2 = _mm_mul_pd(c2, v2);
1940 result_f64x2 = _mm_add_pd(result_f64x2, r2);
1943 result[2] = values_[2] * vector[0] + values_[5] * vector[1] + values_[8] * vector[2];
1944 _mm_storeu_pd(result.
data(), result_f64x2);
1978 const __m128 v0 = _mm_load1_ps(vector.
data() + 0);
1981 const __m128 c0 = _mm_loadu_ps(values_ + 0);
1984 const __m128 r0 = _mm_mul_ps(c0, v0);
1988 const __m128 v1 = _mm_load1_ps(vector.
data() + 1);
1989 const __m128 c1 = _mm_loadu_ps(values_ + 3);
1990 const __m128 r1 = _mm_mul_ps(c1, v1);
1993 __m128 result_f32x4 = _mm_add_ps(r0, r1);
1997 const __m128 v2 = _mm_load1_ps(vector.
data() + 2);
1998 __m128 c2 = _mm_loadu_ps(values_ + 5);
1999 c2 = _mm_castsi128_ps(_mm_srli_si128(_mm_castps_si128(c2), 4));
2000 const __m128 r2 = _mm_mul_ps(c2, v2);
2003 result_f32x4 = _mm_add_ps(result_f32x4, r2);
2005 float resultValues[4];
2006 _mm_storeu_ps(resultValues, result_f32x4);
2014 template <
typename T>
2031 template <
typename T>
2034 values_[0] *= value;
2035 values_[1] *= value;
2036 values_[2] *= value;
2037 values_[3] *= value;
2038 values_[4] *= value;
2039 values_[5] *= value;
2040 values_[6] *= value;
2041 values_[7] *= value;
2042 values_[8] *= value;
2047 template <
typename T>
2050 ocean_assert((vectors && results) || number == 0);
2052 for (
size_t n = 0; n < number; ++n)
2054 results[n] = matrix * vectors[n];
2058 template <
typename T>
2061 ocean_assert((vectors && results) || number == 0);
2063 for (
size_t n = 0; n < number; ++n)
2065 results[n] = matrix * vectors[n];
2069 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 20
2089 const __m128 c0 = _mm_loadu_ps(matrix.
values_ + 0);
2090 const __m128 c1 = _mm_loadu_ps(matrix.
values_ + 3);
2091 __m128 c2 = _mm_loadu_ps(matrix.
values_ + 5);
2092 c2 = _mm_castsi128_ps(_mm_srli_si128(_mm_castps_si128(c2), 4));
2094 for (
size_t n = 0u; n < number - 1; ++n)
2096 const __m128 v0 = _mm_load1_ps(vectors[n].data() + 0);
2097 const __m128 v1 = _mm_load1_ps(vectors[n].data() + 1);
2098 const __m128 v2 = _mm_load1_ps(vectors[n].data() + 2);
2100 const __m128 r0 = _mm_mul_ps(c0, v0);
2101 const __m128 r1 = _mm_mul_ps(c1, v1);
2103 __m128 result_f32x4= _mm_add_ps(r0, r1);
2105 const __m128 r2 = _mm_mul_ps(c2, v2);
2107 result_f32x4 = _mm_add_ps(result_f32x4, r2);
2110 _mm_storeu_ps(results[n].data(), result_f32x4);
2115 const __m128 v0 = _mm_load1_ps(vectors[number - 1].data() + 0);
2116 const __m128 v1 = _mm_load1_ps(vectors[number - 1].data() + 1);
2117 const __m128 v2 = _mm_load1_ps(vectors[number - 1].data() + 2);
2119 const __m128 r0 = _mm_mul_ps(c0, v0);
2120 const __m128 r1 = _mm_mul_ps(c1, v1);
2122 __m128 result_f32x4 = _mm_add_ps(r0, r1);
2124 const __m128 r2 = _mm_mul_ps(c2, v2);
2126 result_f32x4 = _mm_add_ps(result_f32x4, r2);
2128 float resultValues[4];
2129 _mm_storeu_ps(resultValues, result_f32x4);
2136 template <
typename T>
2137 template <
typename U>
2141 result.reserve(matrices.size());
2145 result.emplace_back(matrix);
2165 template <
typename T>
2166 template <
typename U>
2169 std::vector< SquareMatrixT3<T> > result;
2170 result.reserve(size);
2172 for (
size_t n = 0; n < size; ++n)
2174 result.emplace_back(matrices[n]);
2180 template <
typename T>
2183 stream <<
"|" << matrix(0, 0) <<
", " << matrix(0, 1) <<
", " << matrix(0, 2) <<
"|" << std::endl;
2184 stream <<
"|" << matrix(1, 0) <<
", " << matrix(1, 1) <<
", " << matrix(1, 2) <<
"|" << std::endl;
2185 stream <<
"|" << matrix(2, 0) <<
", " << matrix(2, 1) <<
", " << matrix(2, 2) <<
"|";
2190 template <
bool tActive,
typename T>
2191 MessageObject<tActive>&
operator<<(MessageObject<tActive>& messageObject,
const SquareMatrixT3<T>& matrix)
2193 return messageObject <<
"|" << matrix(0, 0) <<
", " << matrix(0, 1) <<
", " << matrix(0, 2) <<
"|\n|"
2194 << matrix(1, 0) <<
", " << matrix(1, 1) <<
", " << matrix(1, 2) <<
"|\n|"
2195 << matrix(2, 0) <<
", " << matrix(2, 1) <<
", " << matrix(2, 2) <<
"|";
2198 template <
bool tActive,
typename T>
2199 MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const SquareMatrixT3<T>& matrix)
2201 return messageObject <<
"|" << matrix(0, 0) <<
", " << matrix(0, 1) <<
", " << matrix(0, 2) <<
"|\n|"
2202 << matrix(1, 0) <<
", " << matrix(1, 1) <<
", " << matrix(1, 2) <<
"|\n|"
2203 << matrix(2, 0) <<
", " << matrix(2, 1) <<
", " << matrix(2, 2) <<
"|";
This class provides several functions to solve equations with different degree using floating point v...
Definition: Equation.h:53
This class implements an euler rotation with angles: yaw, pitch and roll.
Definition: Euler.h:80
const T & yaw() const
Returns the yaw angle.
Definition: Euler.h:315
const T & roll() const
Returns the roll angle.
Definition: Euler.h:339
const T & pitch() const
Returns the pitch angle.
Definition: Euler.h:327
This class implements a 4x4 homogeneous transformation matrix using floating point values with the pr...
Definition: HomogenousMatrix4.h:110
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static T sin(const T value)
Returns the sine of a given value.
Definition: Numeric.h:1568
static T abs(const T value)
Returns the absolute value of a given value.
Definition: Numeric.h:1220
static T sqrt(const T value)
Returns the square root of a given value.
Definition: Numeric.h:1533
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition: Numeric.h:2386
static constexpr T sqr(const T value)
Returns the square of a given value.
Definition: Numeric.h:1495
static constexpr bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition: Numeric.h:2087
static T cos(const T value)
Returns the cosine of a given value.
Definition: Numeric.h:1584
static constexpr bool isNotEqualEps(const T value)
Returns whether a value is not smaller than or equal to a small epsilon.
Definition: Numeric.h:2237
This class implements a unit quaternion rotation.
Definition: Quaternion.h:100
const T & x() const
Returns the x value of the quaternion.
Definition: Quaternion.h:917
bool isValid() const
Returns whether this quaternion is a valid unit quaternion.
Definition: Quaternion.h:899
const T & w() const
Returns the w value of the quaternion.
Definition: Quaternion.h:905
const T & y() const
Returns the y value of the quaternion.
Definition: Quaternion.h:929
const T & z() const
Returns the z value of the quaternion.
Definition: Quaternion.h:941
This class implements a axis-angle rotation using floating point values.
Definition: Rotation.h:79
VectorT3< T > axis() const
Returns the axis of the rotation.
Definition: Rotation.h:740
T angle() const
Returns the angle of the rotation.
Definition: Rotation.h:746
bool isValid() const
Returns whether this rotation has valid parameters.
Definition: Rotation.h:665
size_t operator()(const SquareMatrixT3< T > &matrix) const
Hash function.
Definition: SquareMatrix3.h:1125
VectorT3< T > xAxis() const
Returns the x axis which is the first column of the matrix.
Definition: SquareMatrix3.h:1396
bool eigenValues(T *eigenValues) const
Determines the eigen values of this matrix.
Definition: SquareMatrix3.h:1467
T * operator()()
Access operator.
Definition: SquareMatrix3.h:1119
SquareMatrixT3< T > orthonormalMatrix() const
Returns the orthonormal matrix of this matrix by scaling the x-axis and adjusting y- and z-axis.
Definition: SquareMatrix3.h:1414
SquareMatrixT3(const SquareMatrixT3< U > &matrix)
Copy constructor for a matrix with difference element data type than T.
Definition: SquareMatrix3.h:706
OCEAN_FORCE_INLINE VectorT2< T > operator*(const VectorT2< T > &vector) const
Multiply operator for a 2D vector.
Definition: SquareMatrix3.h:1865
static SquareMatrixT3< T > skewSymmetricMatrix(const VectorT3< T > &vector)
Creates a skew symmetric 3x3 matrix for a specific vector.
Definition: SquareMatrix3.h:1702
T operator[](const unsigned int index) const
Element operator.
Definition: SquareMatrix3.h:1071
SquareMatrixT3(const U *arrayValues)
Creates a new SquareMatrixT3 object by nine elements of float type U.
Definition: SquareMatrix3.h:911
bool eigenSystem(T *eigenValues, VectorT3< T > *eigenVectors) const
Performs an eigen value analysis.
Definition: SquareMatrix3.h:1520
bool isEqual(const SquareMatrixT3< T > &matrix, const T eps=NumericT< T >::eps()) const
Returns whether two matrices are almost identical up to a specified epsilon.
Definition: SquareMatrix3.h:1386
bool invert()
Inverts this matrix in place.
Definition: SquareMatrix3.h:1190
T & operator()(const unsigned int index)
Element operator.
Definition: SquareMatrix3.h:1106
bool isNull() const
Returns whether this matrix is a zero matrix.
Definition: SquareMatrix3.h:1333
static size_t elements()
Returns the number of elements this matrix has.
Definition: SquareMatrix3.h:1138
SquareMatrixT3()
Creates a new SquareMatrixT3 object with undefined elements.
Definition: SquareMatrix3.h:699
bool isAffine() const
Returns true if this matrix is a affine transformation.
Definition: SquareMatrix3.h:1353
SquareMatrixT3< T > operator+(const SquareMatrixT3< T > &matrix) const
Adds two matrices.
Definition: SquareMatrix3.h:1761
SquareMatrixT3(const VectorT3< T > &xAxis, const VectorT3< T > &yAxis, const VectorT3< T > &zAxis)
Creates a new SquareMatrixT3 object by three axes.
Definition: SquareMatrix3.h:888
T values_[9]
The nine values of the matrix.
Definition: SquareMatrix3.h:695
SquareMatrixT3(const U *arrayValues, const bool valuesRowAligned)
Creates a new SquareMatrixT3 object by nine elements.
Definition: SquareMatrix3.h:930
SquareMatrixT3< T > transposedMultiply(const SquareMatrixT3< T > &right) const
Multiplies this transposed matrix with a second matrix.
Definition: SquareMatrix3.h:1732
static SquareMatricesT3< T > matrices2matrices(const SquareMatrixT3< U > *matrices, const size_t size)
Converts matrices with specific data type to matrices with different data type.
SquareMatrixT3(const T *arrayValues, const bool valuesRowAligned)
Creates a new SquareMatrixT3 object by nine elements.
Definition: SquareMatrix3.h:957
void transpose()
Transposes the matrix.
Definition: SquareMatrix3.h:1161
OCEAN_FORCE_INLINE SquareMatrixT3< T > operator*(const T value) const
Multiplies this matrix with a scalar value.
Definition: SquareMatrix3.h:2015
OCEAN_FORCE_INLINE VectorT3< T > operator*(const VectorT3< T > &vector) const
Multiply operator for a 3D vector.
Definition: SquareMatrix3.h:1883
SquareMatrixT3< T > transposed() const
Returns the transposed of this matrix.
Definition: SquareMatrix3.h:1144
static SquareMatricesT3< T > matrices2matrices(const SquareMatricesT3< U > &matrices)
Converts matrices with specific data type to matrices with different data type.
Definition: SquareMatrix3.h:2138
void copyElements(U *arrayValues, const bool valuesRowAligned=false) const
Copies the elements of this matrix to an array with floating point values of type U.
Definition: SquareMatrix3.h:1632
bool multiply(const VectorT2< T > &vector, VectorT2< T > &result) const
Multiplies a 2D vector with this matrix (from the right).
Definition: SquareMatrix3.h:1708
SquareMatrixT3(const SquareMatrixT3< T > &matrix)=default
Copy constructor.
T absSum() const
Calculates the sum of absolute value of elements.
Definition: SquareMatrix3.h:1034
T & operator[](const unsigned int index)
Element operator.
Definition: SquareMatrix3.h:1078
SquareMatrixT3< T > operator-() const
Returns the negative matrix of this matrix (all matrix elements are multiplied by -1).
Definition: SquareMatrix3.h:1829
friend class SquareMatrixT3
Definition: SquareMatrix3.h:89
OCEAN_FORCE_INLINE SquareMatrixT3< T > operator*(const SquareMatrixT3< T > &matrix) const
Multiplies two matrices.
Definition: SquareMatrix3.h:1847
SquareMatrixT3< T > & operator-=(const SquareMatrixT3< T > &matrix)
Subtracts and assigns two matrices.
Definition: SquareMatrix3.h:1813
static void multiply(const SquareMatrixT3< T > &matrix, const VectorT3< T > *vectors, VectorT3< T > *results, const size_t number)
Multiplies several 3D vectors with a given 3x3 matrix.
Definition: SquareMatrix3.h:2059
bool operator!=(const SquareMatrixT3< T > &matrix) const
Returns whether two matrices are not identical up to a small epsilon.
Definition: SquareMatrix3.h:1058
static void multiply(const SquareMatrixT3< T > &matrix, const VectorT2< T > *vectors, VectorT2< T > *results, const size_t number)
Multiplies several 2D vectors with a given 3x3 matrix.
Definition: SquareMatrix3.h:2048
SquareMatrixT3(const bool setToIdentity)
Creates a new SquareMatrixT3 object.
Definition: SquareMatrix3.h:720
SquareMatrixT3(const EulerT< T > &euler)
Creates a new SquareMatrixT3 rotation matrix by a given Euler rotation.
Definition: SquareMatrix3.h:749
SquareMatrixT3(const HomogenousMatrixT4< T > &transformation)
Creates a 3x3 rotation matrix by a given 4x4 homogeneous transformation.
Definition: SquareMatrix3.h:980
VectorT3< T > zAxis() const
Returns the z axis which is the last column of the matrix.
Definition: SquareMatrix3.h:1408
SquareMatrixT3(const RotationT< T > &rotation)
Creates a new 3x3 matrix object by a given angle-axis rotation.
Definition: SquareMatrix3.h:802
void toNull()
Sets the matrix to a zero matrix.
Definition: SquareMatrix3.h:1311
const T * data() const
Returns a pointer to the internal values.
Definition: SquareMatrix3.h:1046
T * data()
Returns a pointer to the internal values.
Definition: SquareMatrix3.h:1052
const T * operator()() const
Access operator.
Definition: SquareMatrix3.h:1113
void copyElements(T *arrayValues, const bool valuesRowAligned=false) const
Copies the elements of this matrix to an array with floating point values of type T.
Definition: SquareMatrix3.h:1671
SquareMatrixT3< T > & operator=(const SquareMatrixT3< T > &)=default
Default copy assignment operator.
bool isHomography() const
Returns true if this matrix is perspective transform/homography.
Definition: SquareMatrix3.h:1359
bool isSimilarity() const
Returns true if this matrix is a similarity transformation.
Definition: SquareMatrix3.h:1347
VectorT3< T > yAxis() const
Returns the y axis which is the middle column of the matrix.
Definition: SquareMatrix3.h:1402
void toIdentity()
Sets the matrix to the identity matrix.
Definition: SquareMatrix3.h:1297
bool solve(const VectorT3< T > &b, VectorT3< T > &x) const
Solve a simple 3x3 system of linear equations: Ax = b Beware: The system of linear equations is assum...
Definition: SquareMatrix3.h:996
SquareMatrixT3(const T &m00, const T &m10, const T &m20, const T &m01, const T &m11, const T &m21, const T &m02, const T &m12, const T &m22)
Creates a 3x3 rotation matrix by 9 given matrix elements.
Definition: SquareMatrix3.h:872
T operator()(const unsigned int index) const
Element operator.
Definition: SquareMatrix3.h:1099
T determinant() const
Returns the determinant of the matrix.
Definition: SquareMatrix3.h:1283
SquareMatrixT3< T > operator-(const SquareMatrixT3< T > &matrix) const
Subtracts two matrices.
Definition: SquareMatrix3.h:1795
SquareMatrixT3< T > & operator+=(const SquareMatrixT3< T > &matrix)
Adds and assigns two matrices.
Definition: SquareMatrix3.h:1779
SquareMatrixT3(const T *arrayValues)
Creates a new SquareMatrixT3 object by nine elements.
Definition: SquareMatrix3.h:922
bool invert(SquareMatrixT3< T > &invertedMatrix) const
Inverts the matrix and returns the result as parameter.
Definition: SquareMatrix3.h:1205
SquareMatrixT3(const SquareMatrixT4< T > &transformation)
Creates a 3x3 square matrix by a given 4x4 square transformation.
Definition: SquareMatrix3.h:988
T sum() const
Calculates the sum of elements.
Definition: SquareMatrix3.h:1040
T Type
Definition of the used data type.
Definition: SquareMatrix3.h:96
SquareMatrixT3< T > & operator*=(const T value)
Multiplies and assigns this matrix with a scalar value.
Definition: SquareMatrix3.h:2032
bool isIdentity() const
Returns whether this matrix is an identity matrix.
Definition: SquareMatrix3.h:1325
VectorT3< T > diagonal() const
Returns a 3d vector with values of the matrix diagonal.
Definition: SquareMatrix3.h:1625
SquareMatrixT3(const VectorT3< T > &diagonal)
Creates a new SquareMatrixT3 object by a given diagonal vector.
Definition: SquareMatrix3.h:896
OCEAN_FORCE_INLINE SquareMatrixT3< T > & operator*=(const SquareMatrixT3< T > &matrix)
Multiplies and assigns two matrices.
Definition: SquareMatrix3.h:1064
SquareMatrixT3< T > inverted() const
Returns the inverted matrix of this matrix.
Definition: SquareMatrix3.h:1176
bool isOrthonormal(const T epsilon=NumericT< T >::eps()) const
Returns whether this matrix is an orthonormal matrix.
Definition: SquareMatrix3.h:1365
bool isSymmetric(const T epsilon=NumericT< T >::eps()) const
Returns whether this matrix is symmetric.
Definition: SquareMatrix3.h:1378
bool operator==(const SquareMatrixT3< T > &matrix) const
Returns whether two matrices are identical up to a small epsilon.
Definition: SquareMatrix3.h:1755
T & operator()(const unsigned int row, const unsigned int column)
Element operator.
Definition: SquareMatrix3.h:1092
bool isSingular() const
Returns whether this matrix is singular (and thus cannot be inverted).
Definition: SquareMatrix3.h:1341
T trace() const
Returns the trace of the matrix which is the sum of the diagonal elements.
Definition: SquareMatrix3.h:1291
SquareMatrixT3(const QuaternionT< T > &quaternion)
Creates a new 3x3 matrix object by a given quaternion rotation.
Definition: SquareMatrix3.h:841
T operator()(const unsigned int row, const unsigned int column) const
Element operator.
Definition: SquareMatrix3.h:1085
This class implements a 4x4 square matrix.
Definition: SquareMatrix4.h:85
static void sortHighestToFront3(T &value0, T &value1, T &value2)
Sorts three values so that the highest value will finally be the first value.
Definition: base/Utilities.h:700
This class implements a vector with two elements.
Definition: Vector2.h:96
This class implements a vector with three elements.
Definition: Vector3.h:97
VectorT3< T > perpendicular() const
Returns a vector that is perpendicular to this vector.
Definition: Vector3.h:756
const T & y() const noexcept
Returns the y value.
Definition: Vector3.h:812
bool normalize()
Normalizes this vector.
Definition: Vector3.h:647
VectorT3< T > cross(const VectorT3< T > &vector) const
Returns the cross product of two vectors.
Definition: Vector3.h:597
const T & x() const noexcept
Returns the x value.
Definition: Vector3.h:800
const T & z() const noexcept
Returns the z value.
Definition: Vector3.h:824
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition: Vector3.h:842
T length() const
Returns the length of the vector.
Definition: Vector3.h:664
T sqr() const
Returns the square of the vector length.
Definition: Vector3.h:670
unsigned int sqrDistance(const char first, const char second)
Returns the square distance between two values.
Definition: base/Utilities.h:1089
SquareMatrixT3< Scalar > SquareMatrix3
Definition of the SquareMatrix3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with ...
Definition: SquareMatrix3.h:35
std::vector< SquareMatrixT3< T > > SquareMatricesT3
Definition of a typename alias for vectors with SquareMatrixT3 objects.
Definition: SquareMatrix3.h:64
std::vector< SquareMatrix3 > SquareMatrices3
Definition of a vector holding SquareMatrix3 objects.
Definition: SquareMatrix3.h:71
SquareMatrixT3< double > SquareMatrixD3
Instantiation of the SquareMatrixT3 template class using a double precision float data type.
Definition: SquareMatrix3.h:49
SquareMatrixT3< float > SquareMatrixF3
Instantiation of the SquareMatrixT3 template class using a single precision float data type.
Definition: SquareMatrix3.h:56
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15
std::ostream & operator<<(std::ostream &stream, const HighPerformanceStatistic &highPerformanceStatistic)
Definition: HighPerformanceTimer.h:963