InstantIO::Matrix4< T > Class Template Reference

Helper class for exchanging 4x4 transform matrices. More...

#include <InstantIO/Matrix4.h>

List of all members.

Public Types

enum  MatrixElementIndex {
  M_00 = 0, M_01 = 1, M_02 = 2, M_03 = 3,
  M_10 = 4, M_11 = 5, M_12 = 6, M_13 = 7,
  M_20 = 8, M_21 = 9, M_22 = 10, M_23 = 11,
  M_30 = 12, M_31 = 13, M_32 = 14, M_33 = 15
}
 

Defines symbolic indices for the elements of the matrix.


enum  QuaternionElementIndex { Q_X = 0, Q_Y = 1, Q_Z = 2, Q_W = 3 }
 

Defines symbolic indices for the elements of a quaternion.


enum  VectorElementIndex { V_X = 0, V_Y = 1, V_Z = 2 }
 

Defines symbolic indices for the elements of a vector.


Public Member Functions

 Matrix4 ()
 Creates a new Matrix4 object that contains an identity matrix.
 Matrix4 (const Matrix4 &obj)
 Creates a new Matrix4 object that is an exact copy of another Matrix4 object.
 Matrix4 (const T matrix[16], bool transposed=false)
 Creates a new Matrix4 object that gets initialized by a given 16 component float array representing a 4x4 matrix.
 Matrix4 (T tx, T ty, T tz, T qx, T qy, T qz, T qw)
 Creates a new Matrix4 object and initializes it with a given translation and rotation.
 Matrix4 (T tx, T ty, T tz, T qx, T qy, T qz, T qw, T sx, T sy, T sz)
 Creates a new Matrix4 object and initializes it with a given translation, rotation and scale.
const Matrix4operator= (const Matrix4 &obj)
 Assigns another Matrix4 to this Matrix4.
const T * operator= (const T matrix[16])
 Assigns the sixteen components of an float array to this Matrix4.
void setIdentity ()
 Sets the Matrix4 to identity.
void setTransform (T tx, T ty, T tz)
 Sets the Matrix4 from three components of a translation.
void setTransform (T qx, T qy, T qz, T qw)
 Sets the Matrix4 from four components of a quaternion.
void setTransform (T tx, T ty, T tz, T qx, T qy, T qz, T qw)
 Sets the Matrix4 from three components of a translation and four components of a quaternion.
void setTransform (T tx, T ty, T tz, T qx, T qy, T qz, T qw, T sx, T sy, T sz)
 Sets the Matrix4 from three components of a translation, four components of a quaternion and three elements of a scale vector.
template<class TranslationT , class QuaternionT , class ScaleT >
void setTransform (const TranslationT &t, const QuaternionT &q, const ScaleT &s)
 Sets the Matrix4 from a from a translation , a quaternion and a scale.
template<class TranslationT , class QuaternionT >
void setTransform (const TranslationT &t, const QuaternionT &q)
 Sets the Matrix4 from a translation and a quaternion.
template<class Vec3fT >
void setTranslationAxisAngle (const Vec3fT &translation, const Vec3fT &axis, T angle)
 Sets the Matrix4 from a translation, a rotation axis and a rotation angle.
template<class ArrayT >
void setMatrixFromArray (const ArrayT &array, bool transposed=false)
 Sets the Matrix4 elements from an array of 16 values.
template<class MatrixT >
void setMatrixFromMatrix (const MatrixT &matrix, bool transposed=false)
 Sets the Matrix4 elements from a matrix.
void setRotationFromQuaternion (T qx, T qy, T qz, T qw)
 Sets the value of the Matrix4 from a quaternion.
template<class QuaternionT >
void setRotationFromQuaternion (const QuaternionT &q)
 Sets the value of the Matrix4 from a quaternion.
template<class RotationMatrixT >
void setRotationFromRotationMatrix (const RotationMatrixT &r, bool transposed=false)
 Sets the value of the Matrix4 from a 3x3 rotation matrix.
template<class TranslationT >
void setTranslation (const TranslationT &translation)
 Sets the translation components of the Matrix4.
void setTranslation (T tx, T ty, T tz)
 Sets the translation components of the Matrix4.
template<class ScaleT >
void applyScale (const ScaleT &s)
 Scales the Matrix4.
void applyScale (T sx, T sy, T sz)
 Scales the Matrix4.
operator[] (MatrixElementIndex i) const
 Returns a component of the Matrix4.
T & operator[] (MatrixElementIndex i)
 Returns a component of the Matrix4.
const T * getValue () const
 Returns the components of the Matrix4 as an array of 16 float values.
T * getValue ()
 Returns the components of the Matrix4 as an array of 16 float values.
void getTransform (T &tx, T &ty, T &tz, T &qx, T &qy, T &qz, T &qw, T &sx, T &sy, T &sz) const
 Returns the transformation stored in the Matrix4 as a translation, a quaternion, and a scale.
void getTransform (T &tx, T &ty, T &tz, T &qx, T &qy, T &qz, T &qw) const
 Returns the transformation stored in the Matrix4 as a translation and a quaternion.
template<class TranslationT , class QuaternionT , class ScaleT >
void getTransform (TranslationT &t, QuaternionT &q, ScaleT &s) const
 Returns the transformation stored in the Matrix4 as a translation, a quaternion, and a scale.
template<class TranslationT , class QuaternionT >
void getTransform (TranslationT &t, QuaternionT &q) const
 Returns the transformation stored in the Matrix4 as a translation and a quaternion.
template<class ArrayT >
void getMatrixAsArray (ArrayT &matrix, bool transposed=false) const
 Returns the components of the Matrix4 in an array of 16 values.
template<class MatrixT >
void getMatrixAsMatrix (MatrixT &matrix, bool transposed=false) const
 Returns the components of the Matrix4 in a matrix.
 operator T * ()
 Transforms the Matrix4 to an array of 16 float values.
 operator const T * () const
 Transforms the Matrix4 to an array of 16 float values.
void scale (T s)
 Scales the Matrix4 elements.
void add (const Matrix4 &m)
 Adds a matrix.
void addScaled (const Matrix4 &m, T s)
 Adds a scaled Matrix4.
void negate ()
 Negates the Matrix4.
void multLeft (const Matrix4 &m)
 Multiplies the matrix with another matrix.
void mult (const Matrix4 &m)
 Multiplies the matrix with another matrix.
template<class Vec3fT >
void multVec (Vec3fT &v)
 Multiplies a vector with the matrix.
template<class Vec3fT >
void multPnt (Vec3fT &v)
 Multiplies a point with the matrix.
normInfinity ()
 Returns the infinity norm of the Matrix4.
det () const
 Returns the determinat of the whole 4x4 matrix.
bool getInverse (Matrix4 &result) const
 Stores the inverse of the matrix into result.
bool sqrt ()
 Sets this matrix to its square root, assumes det > 0.
void setExpOf (const Matrix4 &m)
 Sets this matrix to the exponential of the given matrix.
bool setLogOf (const Matrix4 &matrix)
 Sets this Matrix4 to the logarithm of the given matrix, assumes det > 0.
void print (std::ostream &target)
 Prints the matrix to an output stream.

Static Public Attributes

static const T epsilon = static_cast<T>(0.000001)
 Epsilon value used for comparisons.

Detailed Description

template<class T>
class InstantIO::Matrix4< T >

Helper class for exchanging 4x4 transform matrices.

Matrix4 is a basic helper class for exchanging transformations between different software components. It does not contain any means for matrix arithmetics, only methods for setting and getting the transformation. It is not meant to be used directly by software components for matrix representation. Instead, software components should use their own, appropriate classes for handling matrices. Only when sending matrices to an OutSlot, or when receiving matrices from an InSlot, the internal representation of matrices should be converted to Matrix4's. This ensures the interoperability between different software components that use different internal representations for matrices.

Matrices are internally stored as 4x4 matrices. You can access these matrices directly, or you can use methods that convert a translation vector, a quaternion axis and a scale vector to a Matrix4.

Author:
Helmut Seibert

Constructor & Destructor Documentation

template<class T >
InstantIO::Matrix4< T >::Matrix4 ( const Matrix4< T > &  obj  )  [inline]

Creates a new Matrix4 object that is an exact copy of another Matrix4 object.

Parameters:
obj The other Matrix4 object
template<class T >
InstantIO::Matrix4< T >::Matrix4 ( const T  matrix[16],
bool  transposed = false 
) [inline]

Creates a new Matrix4 object that gets initialized by a given 16 component float array representing a 4x4 matrix.

Parameters:
matrix The sixteen components of the matrix
transposed Flags that must be set to true when the array needs to be transposed when copying it into the Matrix4 object
template<class T >
InstantIO::Matrix4< T >::Matrix4 ( tx,
ty,
tz,
qx,
qy,
qz,
qw 
) [inline]

Creates a new Matrix4 object and initializes it with a given translation and rotation.

Parameters:
tx The first component of the translation
ty The second component of the translation
tz The third component of the translation
qx The first component of the quaternion
qy The second component of the quaternion
qz The third component of the quaternion
qw The fourth component of the quaternion
template<class T >
InstantIO::Matrix4< T >::Matrix4 ( tx,
ty,
tz,
qx,
qy,
qz,
qw,
sx,
sy,
sz 
) [inline]

Creates a new Matrix4 object and initializes it with a given translation, rotation and scale.

Parameters:
tx The first component of the translation
ty The second component of the translation
tz The third component of the translation
qx The first component of the quaternion
qy The second component of the quaternion
qz The third component of the quaternion
qw The fourth component of the quaternion
sx The first component of the scale
sy The second component of the scale
sz The third component of the scale

Member Function Documentation

template<class T >
const Matrix4& InstantIO::Matrix4< T >::operator= ( const Matrix4< T > &  obj  )  [inline]

Assigns another Matrix4 to this Matrix4.

Parameters:
obj The other Matrix4 object
Returns:
The other Matrix4 object
template<class T >
const T* InstantIO::Matrix4< T >::operator= ( const T  matrix[16]  )  [inline]

Assigns the sixteen components of an float array to this Matrix4.

Parameters:
matrix The sixteen components of the matrix
Returns:
The sixteen components of the matrix
template<class T >
void InstantIO::Matrix4< T >::setTransform ( tx,
ty,
tz 
) [inline]

Sets the Matrix4 from three components of a translation.

Parameters:
tx The first component of the translation
ty The second component of the translation
tz The third component of the translation
template<class T >
void InstantIO::Matrix4< T >::setTransform ( qx,
qy,
qz,
qw 
) [inline]

Sets the Matrix4 from four components of a quaternion.

Parameters:
qx The first component of the quaternion
qy The second component of the quaternion
qz The third component of the quaternion
qw The fourth component of the quaternion
template<class T >
void InstantIO::Matrix4< T >::setTransform ( tx,
ty,
tz,
qx,
qy,
qz,
qw 
) [inline]

Sets the Matrix4 from three components of a translation and four components of a quaternion.

Parameters:
tx The first component of the translation
ty The second component of the translation
tz The third component of the translation
qx The first component of the quaternion
qy The second component of the quaternion
qz The third component of the quaternion
qw The fourth component of the quaternion
template<class T >
void InstantIO::Matrix4< T >::setTransform ( tx,
ty,
tz,
qx,
qy,
qz,
qw,
sx,
sy,
sz 
) [inline]

Sets the Matrix4 from three components of a translation, four components of a quaternion and three elements of a scale vector.

Parameters:
tx The first component of the translation
ty The second component of the translation
tz The third component of the translation
qx The first component of the quaternion
qy The second component of the quaternion
qz The third component of the quaternion
qw The fourth component of the quaternion
sx The first component of the scale
sy The second component of the scale
sz The third component of the scale
template<class T >
template<class TranslationT , class QuaternionT , class ScaleT >
void InstantIO::Matrix4< T >::setTransform ( const TranslationT &  t,
const QuaternionT &  q,
const ScaleT &  s 
) [inline]

Sets the Matrix4 from a from a translation , a quaternion and a scale.

Parameters:
t The translation (arb. 3 component vector)
q The rotation as quatenion (arb. 4 component vector)
s The scale (arb. 3 component vector)
template<class T >
template<class TranslationT , class QuaternionT >
void InstantIO::Matrix4< T >::setTransform ( const TranslationT &  t,
const QuaternionT &  q 
) [inline]

Sets the Matrix4 from a translation and a quaternion.

Parameters:
t The translation (arb. 3 component vector)
q The rotation as quatenion (arb. 4 component vector)
template<class T >
template<class Vec3fT >
void InstantIO::Matrix4< T >::setTranslationAxisAngle ( const Vec3fT &  translation,
const Vec3fT &  axis,
angle 
) [inline]

Sets the Matrix4 from a translation, a rotation axis and a rotation angle.

Parameters:
translation The translation (arb. 3 component vector)
axis The rotation axis (arb. 3 component vector)
angle The rotation angle (in radians)
template<class T >
template<class ArrayT >
void InstantIO::Matrix4< T >::setMatrixFromArray ( const ArrayT &  array,
bool  transposed = false 
) [inline]

Sets the Matrix4 elements from an array of 16 values.

Parameters:
array An arb. 16 component array for the matrix elements
transposed Flags that must be set to true when the array needs to be transposed when copying it into the Matrix4 object
template<class T >
template<class MatrixT >
void InstantIO::Matrix4< T >::setMatrixFromMatrix ( const MatrixT &  matrix,
bool  transposed = false 
) [inline]

Sets the Matrix4 elements from a matrix.

Parameters:
matrix An arb. 4x4 component matrix for the matrix elements
transposed Flags that must be set to true when the matrix needs to be transposed when copying it into the Matrix4 object
template<class T >
void InstantIO::Matrix4< T >::setRotationFromQuaternion ( qx,
qy,
qz,
qw 
) [inline]

Sets the value of the Matrix4 from a quaternion.

Parameters:
qx The first component of the quaternion
qy The second component of the quaternion
qz The third component of the quaternion
qw The fourth component of the quaternion
template<class T >
template<class QuaternionT >
void InstantIO::Matrix4< T >::setRotationFromQuaternion ( const QuaternionT &  q  )  [inline]

Sets the value of the Matrix4 from a quaternion.

Parameters:
q The rotation as quatenion (arb. 4 component vector)
template<class T >
template<class RotationMatrixT >
void InstantIO::Matrix4< T >::setRotationFromRotationMatrix ( const RotationMatrixT &  r,
bool  transposed = false 
) [inline]

Sets the value of the Matrix4 from a 3x3 rotation matrix.

Parameters:
r The rotation as matrix (matrix type with double indexed access e.g. float[3][3])
transposed Flags that must be set to true when the matrix needs to be transposed when copying it into the Matrix4 object
template<class T >
template<class TranslationT >
void InstantIO::Matrix4< T >::setTranslation ( const TranslationT &  translation  )  [inline]

Sets the translation components of the Matrix4.

Parameters:
translation The translation (arb. 3 component vector)
template<class T >
void InstantIO::Matrix4< T >::setTranslation ( tx,
ty,
tz 
) [inline]

Sets the translation components of the Matrix4.

Parameters:
tx The first component of the translation
ty The second component of the translation
tz The third component of the translation
template<class T >
template<class ScaleT >
void InstantIO::Matrix4< T >::applyScale ( const ScaleT &  s  )  [inline]

Scales the Matrix4.

Parameters:
s The scale (arb. 3 component vector)
template<class T >
void InstantIO::Matrix4< T >::applyScale ( sx,
sy,
sz 
) [inline]

Scales the Matrix4.

Parameters:
sx The x scale
sy The y scale
sz The z scale
template<class T >
T InstantIO::Matrix4< T >::operator[] ( MatrixElementIndex  i  )  const [inline]

Returns a component of the Matrix4.

Parameters:
i The index of the component
Returns:
The component
template<class T >
T& InstantIO::Matrix4< T >::operator[] ( MatrixElementIndex  i  )  [inline]

Returns a component of the Matrix4.

Parameters:
i The index of the component
Returns:
The component
template<class T >
const T* InstantIO::Matrix4< T >::getValue (  )  const [inline]

Returns the components of the Matrix4 as an array of 16 float values.

Returns:
The components of the Matrix4
template<class T >
T* InstantIO::Matrix4< T >::getValue (  )  [inline]

Returns the components of the Matrix4 as an array of 16 float values.

Returns:
The components of the Matrix4
template<class T >
void InstantIO::Matrix4< T >::getTransform ( T &  tx,
T &  ty,
T &  tz,
T &  qx,
T &  qy,
T &  qz,
T &  qw,
T &  sx,
T &  sy,
T &  sz 
) const [inline]

Returns the transformation stored in the Matrix4 as a translation, a quaternion, and a scale.

Parameters:
tx The first component of the translation
ty The second component of the translation
tz The third component of the translation
qx The first component of the quaternion
qy The second component of the quaternion
qz The third component of the quaternion
qw The fourth component of the quaternion
sx The first component of the scale
sy The second component of the scale
sz The third component of the scale
template<class T >
void InstantIO::Matrix4< T >::getTransform ( T &  tx,
T &  ty,
T &  tz,
T &  qx,
T &  qy,
T &  qz,
T &  qw 
) const [inline]

Returns the transformation stored in the Matrix4 as a translation and a quaternion.

Parameters:
tx The first component of the translation
ty The second component of the translation
tz The third component of the translation
qx The first component of the quaternion
qy The second component of the quaternion
qz The third component of the quaternion
qw The fourth component of the quaternion
template<class T >
template<class TranslationT , class QuaternionT , class ScaleT >
void InstantIO::Matrix4< T >::getTransform ( TranslationT &  t,
QuaternionT &  q,
ScaleT &  s 
) const [inline]

Returns the transformation stored in the Matrix4 as a translation, a quaternion, and a scale.

Parameters:
t The translation (arb. 3 component vector)
q The rotation as quatenion (arb. 4 component vector)
s The scale (arb. 3 component vector)
template<class T >
template<class TranslationT , class QuaternionT >
void InstantIO::Matrix4< T >::getTransform ( TranslationT &  t,
QuaternionT &  q 
) const [inline]

Returns the transformation stored in the Matrix4 as a translation and a quaternion.

Parameters:
t The translation (arb. 3 component vector)
q The rotation as quatenion (arb. 4 component vector)
template<class T >
template<class ArrayT >
void InstantIO::Matrix4< T >::getMatrixAsArray ( ArrayT &  matrix,
bool  transposed = false 
) const [inline]

Returns the components of the Matrix4 in an array of 16 values.

Parameters:
matrix An arb. 16 component array for the matrix elements
transposed Flags that must be set to true when the Matrix4 components need to be transposed when copying them into the array
template<class T >
template<class MatrixT >
void InstantIO::Matrix4< T >::getMatrixAsMatrix ( MatrixT &  matrix,
bool  transposed = false 
) const [inline]

Returns the components of the Matrix4 in a matrix.

Parameters:
matrix An arb. 16 component array for the matrix elements
transposed Flags that must be set to true when the Matrix4 components need to be transposed when copying them into the array
template<class T >
InstantIO::Matrix4< T >::operator T * (  )  [inline]

Transforms the Matrix4 to an array of 16 float values.

Returns:
The array of 16 float values.
template<class T >
InstantIO::Matrix4< T >::operator const T * (  )  const [inline]

Transforms the Matrix4 to an array of 16 float values.

Returns:
The array of 16 float values.
template<class T >
void InstantIO::Matrix4< T >::scale ( s  )  [inline]

Scales the Matrix4 elements.

Parameters:
s The scale factor.
template<class T >
void InstantIO::Matrix4< T >::add ( const Matrix4< T > &  m  )  [inline]

Adds a matrix.

Parameters:
m A Matrix4 object.
template<class T >
void InstantIO::Matrix4< T >::addScaled ( const Matrix4< T > &  m,
s 
) [inline]

Adds a scaled Matrix4.

Parameters:
m A Matrix4 object.
scale A scale factor.
template<class T >
void InstantIO::Matrix4< T >::multLeft ( const Matrix4< T > &  m  )  [inline]

Multiplies the matrix with another matrix.

Parameters:
matrix A Matrix4 object
template<class T >
void InstantIO::Matrix4< T >::mult ( const Matrix4< T > &  m  )  [inline]

Multiplies the matrix with another matrix.

Parameters:
matrix A Matrix4 object
template<class T >
template<class Vec3fT >
void InstantIO::Matrix4< T >::multVec ( Vec3fT &  v  )  [inline]

Multiplies a vector with the matrix.

Parameters:
v The vector.
template<class T >
template<class Vec3fT >
void InstantIO::Matrix4< T >::multPnt ( Vec3fT &  v  )  [inline]

Multiplies a point with the matrix.

Parameters:
v The point.
template<class T >
T InstantIO::Matrix4< T >::normInfinity (  )  [inline]

Returns the infinity norm of the Matrix4.

Returns:
The infinity norm.
template<class T >
T InstantIO::Matrix4< T >::det (  )  const [inline]

Returns the determinat of the whole 4x4 matrix.

Returns:
The determinant.
template<class T >
bool InstantIO::Matrix4< T >::getInverse ( Matrix4< T > &  result  )  const [inline]

Stores the inverse of the matrix into result.

Parameters:
result Gets filled with the inverse of this matrix.
Returns:
true if the matrix is not singular.
template<class T >
bool InstantIO::Matrix4< T >::sqrt (  )  [inline]

Sets this matrix to its square root, assumes det > 0.

Source taken from OSGMatrix.

Returns:
Always true.
template<class T >
void InstantIO::Matrix4< T >::setExpOf ( const Matrix4< T > &  m  )  [inline]

Sets this matrix to the exponential of the given matrix.

Source taken from OSGMatrix.

Parameters:
m The given matrix.
template<class T >
bool InstantIO::Matrix4< T >::setLogOf ( const Matrix4< T > &  matrix  )  [inline]

Sets this Matrix4 to the logarithm of the given matrix, assumes det > 0.

Parameters:
matrix The given matrix.
template<class T >
void InstantIO::Matrix4< T >::print ( std::ostream &  target  )  [inline]

Prints the matrix to an output stream.

Parameters:
target The output stream.

The documentation for this class was generated from the following file:
Generated on Thu Jul 31 17:17:32 2014 by  doxygen 1.6.3