4#ifndef OPENVDB_MATH_MAT3_H_HAS_BEEN_INCLUDED
5#define OPENVDB_MATH_MAT3_H_HAS_BEEN_INCLUDED
21template<
typename T>
class Vec3;
22template<
typename T>
class Mat4;
23template<
typename T>
class Quat;
53 template<
typename Source>
54 Mat3(Source a, Source b, Source c,
55 Source d, Source e, Source f,
56 Source g, Source h, Source i)
71 template<
typename Source>
85 template<
typename Source>
100 template<
typename Source>
103 for (
int i=0; i<3; ++i) {
104 for (
int j=0; j<3; ++j) {
105 MyBase::mm[i*3 + j] =
static_cast<T
>(m[i][j]);
113 for (
int i=0; i<3; ++i) {
114 for (
int j=0; j<3; ++j) {
155 return Vec3<T>((*
this)(i,0), (*
this)(i,1), (*
this)(i,2));
171 return Vec3<T>((*
this)(0,j), (*
this)(1,j), (*
this)(2,j));
240 vdiag[0], vtri[0], vtri[1],
241 vtri[0], vdiag[1], vtri[2],
242 vtri[1], vtri[2], vdiag[2]
290 template<
typename Source>
301 bool eq(
const Mat3 &m, T eps=1.0e-8)
const
330 template <
typename S>
346 template <
typename S>
364 template <
typename S>
382 template <
typename S>
389 MyBase::mm[0] =
static_cast<T
>(s0[0] * s1[0] +
392 MyBase::mm[1] =
static_cast<T
>(s0[0] * s1[1] +
395 MyBase::mm[2] =
static_cast<T
>(s0[0] * s1[2] +
399 MyBase::mm[3] =
static_cast<T
>(s0[3] * s1[0] +
402 MyBase::mm[4] =
static_cast<T
>(s0[3] * s1[1] +
405 MyBase::mm[5] =
static_cast<T
>(s0[3] * s1[2] +
409 MyBase::mm[6] =
static_cast<T
>(s0[6] * s1[0] +
412 MyBase::mm[7] =
static_cast<T
>(s0[6] * s1[1] +
415 MyBase::mm[8] =
static_cast<T
>(s0[6] * s1[2] +
475 return inv * (T(1)/
det);
504 template<
typename T0>
507 return static_cast< Vec3<T0> >(v * *
this);
512 template<
typename T0>
515 return static_cast< Vec3<T0> >(*
this * v);
525 ret.
mm[0] *= diag(0);
526 ret.
mm[1] *= diag(1);
527 ret.
mm[2] *= diag(2);
528 ret.
mm[3] *= diag(0);
529 ret.
mm[4] *= diag(1);
530 ret.
mm[5] *= diag(2);
531 ret.
mm[6] *= diag(0);
532 ret.
mm[7] *= diag(1);
533 ret.
mm[8] *= diag(2);
541template <
typename T0,
typename T1>
547 for (
int i=0; i<9; ++i) {
555template <
typename T0,
typename T1>
560template <
typename S,
typename T>
566template <
typename S,
typename T>
576template <
typename T0,
typename T1>
586template <
typename T0,
typename T1>
596template <
typename T0,
typename T1>
606template<
typename T,
typename MT>
607inline Vec3<typename promote<T, MT>::type>
612 _v[0]*m[0] + _v[1]*m[1] + _v[2]*m[2],
613 _v[0]*m[3] + _v[1]*m[4] + _v[2]*m[5],
614 _v[0]*m[6] + _v[1]*m[7] + _v[2]*m[8]);
619template<
typename T,
typename MT>
625 _v[0]*m[0] + _v[1]*m[3] + _v[2]*m[6],
626 _v[0]*m[1] + _v[1]*m[4] + _v[2]*m[7],
627 _v[0]*m[2] + _v[1]*m[5] + _v[2]*m[8]);
632template<
typename T,
typename MT>
645 return Mat3<T>(v1[0]*v2[0], v1[0]*v2[1], v1[0]*v2[2],
646 v1[1]*v2[0], v1[1]*v2[1], v1[1]*v2[2],
647 v1[2]*v2[0], v1[2]*v2[1], v1[2]*v2[2]);
654template<
typename T,
typename T0>
673 double cotan_of_2_theta;
675 double cosin_of_theta;
681 double Sjj_minus_Sii = D[j] - D[i];
684 tan_of_theta = Sij / Sjj_minus_Sii;
687 cotan_of_2_theta = 0.5*Sjj_minus_Sii / Sij ;
689 if (cotan_of_2_theta < 0.) {
691 -1./(sqrt(1. + cotan_of_2_theta*cotan_of_2_theta) - cotan_of_2_theta);
694 1./(sqrt(1. + cotan_of_2_theta*cotan_of_2_theta) + cotan_of_2_theta);
698 cosin_of_theta = 1./sqrt( 1. + tan_of_theta * tan_of_theta);
699 sin_of_theta = cosin_of_theta * tan_of_theta;
700 z = tan_of_theta * Sij;
704 for (
int k = 0; k < i; ++k) {
706 S(k,i) = cosin_of_theta * temp - sin_of_theta * S(k,j);
707 S(k,j)= sin_of_theta * temp + cosin_of_theta * S(k,j);
709 for (
int k = i+1; k < j; ++k) {
711 S(i,k) = cosin_of_theta * temp - sin_of_theta * S(k,j);
712 S(k,j) = sin_of_theta * temp + cosin_of_theta * S(k,j);
714 for (
int k = j+1; k < n; ++k) {
716 S(i,k) = cosin_of_theta * temp - sin_of_theta * S(j,k);
717 S(j,k) = sin_of_theta * temp + cosin_of_theta * S(j,k);
719 for (
int k = 0; k < n; ++k)
722 Q(k,i) = cosin_of_theta * temp - sin_of_theta*Q(k,j);
723 Q(k,j) = sin_of_theta * temp + cosin_of_theta*Q(k,j);
738 unsigned int MAX_ITERATIONS=250)
748 for (
int i = 0; i < n; ++i) {
752 unsigned int iterations(0);
759 for (
int i = 0; i < n; ++i) {
760 for (
int j = i+1; j < n; ++j) {
773 for (
int i = 0; i < n; ++i) {
774 for (
int j = i+1; j < n; ++j){
780 if (fabs(S(i,j)) > max_element) {
781 max_element = fabs(S(i,j));
788 }
while (iterations < MAX_ITERATIONS);
800 for (
unsigned i = 0; i < 9; ++i, ++op, ++ip) *op =
math::Abs(*ip);
804template<
typename Type1,
typename Type2>
811 for (
unsigned i = 0; i < 9; ++i, ++op, ++ip) {
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
#define OPENVDB_IS_POD(Type)
Definition Math.h:56
Definition Exceptions.h:56
3x3 matrix class.
Definition Mat3.h:29
Mat3(Source *a)
Definition Mat3.h:86
Mat3(const Mat4< T > &m)
Conversion from Mat4 (copies top left)
Definition Mat3.h:111
const Mat3< T > & operator-=(const Mat3< S > &m1)
Subtract each element of the given matrix from the corresponding element of this matrix.
Definition Mat3.h:365
void setRows(const Vec3< Real > &v1, const Vec3< Real > &v2, const Vec3< Real > &v3)
Definition Mat3.h:195
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.
Definition Mat3.h:561
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition Mat3.h:556
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
Definition Mat3.h:577
Mat3< typename promote< S, T >::type > operator*(const Mat3< T > &m, S scalar)
Multiply each element of the given matrix by scalar and return the result.
Definition Mat3.h:567
void setIdentity()
Set this matrix to identity.
Definition Mat3.h:276
Mat3(Source a, Source b, Source c, Source d, Source e, Source f, Source g, Source h, Source i)
Constructor given array of elements, the ordering is in row major form:
Definition Mat3.h:54
Mat3(const Mat3< Source > &m)
Conversion constructor.
Definition Mat3.h:101
void setToRotation(const Vec3< T > &axis, T angle)
Set this matrix to the rotation specified by axis and angle.
Definition Mat3.h:258
void setZero()
Set this matrix to zero.
Definition Mat3.h:262
const Mat3 & operator=(const Mat3< Source > &m)
Assignment operator.
Definition Mat3.h:291
Mat3(const Quat< T > &q)
Definition Mat3.h:43
const Mat3< T > & operator+=(const Mat3< S > &m1)
Add each element of the given matrix to the corresponding element of this matrix.
Definition Mat3.h:347
Vec3< T0 > pretransform(const Vec3< T0 > &v) const
Definition Mat3.h:513
bool eq(const Mat3 &m, T eps=1.0e-8) const
Return true if this matrix is equivalent to m within a tolerance of eps.
Definition Mat3.h:301
void setToRotation(const Quat< Real > &q)
Definition Mat3.h:253
Mat3 inverse(T tolerance=0) const
Definition Mat3.h:465
T trace() const
Trace of matrix.
Definition Mat3.h:488
Mat3< T > operator-() const
Negation operator, for e.g. m1 = -m2;.
Definition Mat3.h:315
void setCol(int j, const Vec3< T > &v)
Set jth column to vector v.
Definition Mat3.h:159
Mat3 adjoint() const
Return the adjoint of this matrix, i.e., the transpose of its cofactor.
Definition Mat3.h:438
void setSkew(const Vec3< T > &v)
Set the matrix as cross product of the given vector.
Definition Mat3.h:247
const Mat3< T > & operator*=(S scalar)
Multiplication operator, e.g. M = scalar * M;.
Definition Mat3.h:331
Mat< 3, Real > MyBase
Definition Mat3.h:34
Vec3< typename promote< T, MT >::type > operator*(const Mat3< MT > &_m, const Vec3< T > &_v)
Multiply _m by _v and return the resulting vector.
Definition Mat3.h:608
Mat3 snapBasis(Axis axis, const Vec3< T > &direction)
Definition Mat3.h:497
Mat3 transpose() const
returns transpose of this
Definition Mat3.h:454
Mat3 timesDiagonal(const Vec3< T > &diag) const
Treat diag as a diagonal matrix and return the product of this matrix with diag (from the right).
Definition Mat3.h:521
Real det() const
Definition Mat3.h:479
static const Mat3< T > & zero()
Predefined constant for zero matrix.
Definition Mat3.h:131
Vec3< T > col(int j) const
Get jth column, e.g. Vec3d v = m.col(0);.
Definition Mat3.h:168
T & operator()(int i, int j)
Definition Mat3.h:177
static Mat3 symmetric(const Vec3< T > &vdiag, const Vec3< T > &vtri)
Return a matrix with the prescribed diagonal and symmetric triangular components.
Definition Mat3.h:237
Vec3< T0 > transform(const Vec3< T0 > &v) const
Definition Mat3.h:505
static const Mat3< T > & identity()
Predefined constant for identity matrix.
Definition Mat3.h:121
T operator()(int i, int j) const
Definition Mat3.h:187
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition Mat3.h:542
const Mat3< T > & operator*=(const Mat3< S > &m1)
Multiply this matrix by the given matrix.
Definition Mat3.h:383
Vec3< T > row(int i) const
Get ith row, e.g. Vec3d v = m.row(1);.
Definition Mat3.h:152
void setRow(int i, const Vec3< T > &v)
Set ith row to vector v.
Definition Mat3.h:141
Vec3< typename promote< T, MT >::type > operator*(const Vec3< T > &_v, const Mat3< MT > &_m)
Multiply _v by _m and return the resulting vector.
Definition Mat3.h:621
Real ValueType
Definition Mat3.h:33
void setColumns(const Vec3< Real > &v1, const Vec3< Real > &v2, const Vec3< Real > &v3)
Definition Mat3.h:209
Mat3 cofactor() const
Return the cofactor matrix of this matrix.
Definition Mat3.h:423
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
Definition Mat3.h:587
Mat3(const Vec3< Source > &v1, const Vec3< Source > &v2, const Vec3< Source > &v3, bool rows=true)
Definition Mat3.h:72
void setSymmetric(const Vec3< T > &vdiag, const Vec3< T > &vtri)
Set diagonal and symmetric triangular components.
Definition Mat3.h:223
Real value_type
Definition Mat3.h:32
4x4 -matrix class.
Definition Mat4.h:31
T mm[SIZE *SIZE]
Definition Mat.h:160
T * asPointer()
Direct access to the internal data.
Definition Mat.h:101
@ size
Definition Mat.h:31
static unsigned numElements()
Definition Mat.h:41
void pivot(int i, int j, Mat3< T > &S, Vec3< T > &D, Mat3< T > &Q)
Definition Mat3.h:668
MatType snapMatBasis(const MatType &source, Axis axis, const Vec3< typename MatType::value_type > &direction)
This function snaps a specific axis to a specific direction, preserving scaling.
Definition Mat.h:751
bool diagonalizeSymmetricMatrix(const Mat3< T > &input, Mat3< T > &Q, Vec3< T > &D, unsigned int MAX_ITERATIONS=250)
Use Jacobi iterations to decompose a symmetric 3x3 matrix (diagonalize and compute eigenvectors)
Definition Mat3.h:737
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Definition Mat3.h:597
Mat3< double > Mat3d
Definition Mat3.h:834
bool cwiseLessThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
Definition Mat.h:1015
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition Math.h:406
Mat3< float > Mat3s
Definition Mat3.h:833
MatType rotation(const Quat< typename MatType::value_type > &q, typename MatType::value_type eps=static_cast< typename MatType::value_type >(1.0e-8))
Return the rotation matrix specified by the given quaternion.
Definition Mat.h:172
Mat3< T > powLerp(const Mat3< T0 > &m1, const Mat3< T0 > &m2, T t)
Definition Mat3.h:655
Mat3d Mat3f
Definition Mat3.h:835
auto cwiseAdd(const math::Vec3< math::half > &v, const float s)
Definition Types.h:694
Coord Abs(const Coord &xyz)
Definition Coord.h:518
Mat3< T > outerProduct(const Vec3< T > &v1, const Vec3< T > &v2)
Definition Mat3.h:643
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition Vec2.h:446
void powSolve(const MatType &aA, MatType &aB, double aPower, double aTol=0.01)
Definition Mat.h:822
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:443
MatType skew(const Vec3< typename MatType::value_type > &skew)
Return a matrix as the cross product of the given vector.
Definition Mat.h:708
Axis
Definition Math.h:901
bool cwiseGreaterThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
Definition Mat.h:1029
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:70
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
static T value()
Definition Math.h:148
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218