vmmlib  1.13.0
Templatized C++ vector and matrix math library
vmml::Matrix< R, C, T > Class Template Reference

Matrix with R rows and C columns of element type T. More...

#include <matrix.hpp>

+ Collaboration diagram for vmml::Matrix< R, C, T >:

Public Member Functions

 Matrix ()
 Construct a zero-initialized matrix. More...
 
 Matrix (const T *begin, const T *end)
 Construct a matrix with default values. More...
 
 Matrix (const std::vector< T > &data)
 Construct a matrix with default values. More...
 
template<size_t P, size_t Q>
 Matrix (const Matrix< P, Q, T > &source)
 Copy-construct a matrix. More...
 
template<size_t S>
 Matrix (const Quaternion< T > &rotation, const vector< S, T > &translation, typename std::enable_if< R==S+1 &&C==S+1 &&S==3 >::type *=0)
 Construct a new 4x4 transformation matrix from a rotation quaternion and a translation vector.
 
template<size_t S>
 Matrix (const vector< S, T > &eye, const vector< S, T > &lookat, const vector< S, T > &up, typename std::enable_if< R==S+1 &&C==S+1 &&S==3 >::type *=0)
 Construct a new transformation matrix from an eye position, lookat position and up vector, following convention from gluLookAt().
 
matrix-matrix operations
bool operator== (const Matrix &other) const
 
bool operator!= (const Matrix &other) const
 
bool equals (const Matrix &other, T tolerance=std::numeric_limits< T >::epsilon()) const
 
template<size_t P>
Matrix< R, C, T > & multiply (const Matrix< R, P, T > &left, const Matrix< P, C, T > &right)
 Set this to the product of the two matrices (left_RxP * right_PxC)
 
template<size_t P>
Matrix< R, P, T > operator* (const Matrix< C, P, T > &other) const
 
template<size_t O, size_t P, typename = typename std::enable_if< R == C && O == P && R == O>::type>
Matrix< R, C, T > & operator*= (const Matrix< O, P, T > &right)
 Multiply two square matrices.
 
Matrix operator+ (const Matrix &other) const
 Element-wise addition of two matrices.
 
Matrix operator- (const Matrix &other) const
 Element-wise substraction of two matrices.
 
void operator+= (const Matrix &other)
 Element-wise addition of two matrices.
 
void operator-= (const Matrix &other)
 Element-wise substraction of two matrices.
 
matrix-vector operations
vector< R, T > operator* (const vector< C, T > &other) const
 Transform column vector by matrix ( res = matrix * vec )
 
Data access
T & operator() (size_t rowIndex, size_t colIndex)
 
operator() (size_t rowIndex, size_t colIndex) const
 
const T * data () const
 
template<size_t O, size_t P>
Matrix< O, P, T > getSubMatrix (size_t rowOffset, size_t colOffset, typename std::enable_if< O<=R &&P<=C >::type *=0) const
 
template<size_t O, size_t P>
std::enable_if< O<=R &&P<=C >::type *setSubMatrix(const Matrix< O, P, T > &sub_matrix, size_t rowOffset, size_t colOffset);const Matrix &operator=(const Matrix< R, C, T > &source_);template< size_t P, size_t Q > const Matrix &operator=(const Matrix< P, Q, T > &source_);void operator=(const std::vector< T > &data);Matrix< R, C, T > operator-() const ;vector< R, T > getColumn(size_t columnIndex) const ;void setColumn(size_t index, const vector< R, T > &column);vector< C, T > getRow(size_t index) const ;void setRow(size_t index, const vector< C, T > &row);vector< C-1, T > getTranslation() const ;Matrix< R, C, T > &setTranslation(const vector< C-1, T > &t);template< size_t S > void getLookAt(vector< S, T > &eye, vector< S, T > &lookAt, vector< S, T > &up, typename std::enable_if< R==S+1 &&C==S+1 &&S==3 >::type *=0) const ;Matrix< R, C, T > inverse() const ;template< size_t O, size_t P > typename std::enable_if< O==P &&R==C &&O==R &&R >=2 >::type *getAdjugate(Matrix< O, P, T > &adjugate) const ;template< size_t O, size_t P > typename std::enable_if< O==P &&R==C &&O==R &&R >=2 >::type * getCofactors (Matrix< O, P, T > &cofactors) const
 Set the sub matrix of size OxP at the given start indices. More...
 
template<size_t O, size_t P>
getMinor (Matrix< O, P, T > &minor_, size_t row_to_cut, size_t col_to_cut, typename std::enable_if< O==R-1 &&P==C-1 &&R==C &&R >=2 >::type *=0) const
 
Transformations on 4*4 matrices
template<typename TT >
Matrix< R, C, T > & rotate_x (TT angle, typename std::enable_if< R==C &&R==4, TT >::type *=0)
 
template<typename TT >
Matrix< R, C, T > & rotate_y (TT angle, typename std::enable_if< R==C &&R==4, TT >::type *=0)
 
template<typename TT >
Matrix< R, C, T > & rotate_z (TT angle, typename std::enable_if< R==C &&R==4, TT >::type *=0)
 
template<typename TT >
Matrix< R, C, T > & pre_rotate_x (TT angle, typename std::enable_if< R==C &&R==4, TT >::type *=0)
 
template<typename TT >
Matrix< R, C, T > & pre_rotate_y (TT angle, typename std::enable_if< R==C &&R==4, TT >::type *=0)
 
template<typename TT >
Matrix< R, C, T > & pre_rotate_z (TT angle, typename std::enable_if< R==C &&R==4, TT >::type *=0)
 
template<typename TT >
Matrix< R, C, T > & scale (const vector< 3, TT > &scale_, typename std::enable_if< R==C &&R==4, TT >::type *=0)
 
template<typename TT >
Matrix< R, C, T > & scaleTranslation (const vector< 3, TT > &scale_, typename std::enable_if< R==C &&R==4, TT >::type *=0)
 

Public Attributes

array [R *C]
 column by column storage
 

Friends

std::ostream & operator<< (std::ostream &os, const Matrix< R, C, T > &matrix)
 

Detailed Description

template<size_t R, size_t C, typename T>
class vmml::Matrix< R, C, T >

Matrix with R rows and C columns of element type T.

Definition at line 52 of file matrix.hpp.

Constructor & Destructor Documentation

template<size_t R, size_t C, typename T >
vmml::Matrix< R, C, T >::Matrix ( )

Construct a zero-initialized matrix.

Square matrices are initialized as identity.

Definition at line 487 of file matrix.hpp.

template<size_t R, size_t C, typename T >
vmml::Matrix< R, C, T >::Matrix ( const T *  begin,
const T *  end 
)

Construct a matrix with default values.

Missing data is zero-initialized. Additional data is ignored.

Definition at line 496 of file matrix.hpp.

References vmml::Matrix< R, C, T >::array.

template<size_t R, size_t C, typename T >
vmml::Matrix< R, C, T >::Matrix ( const std::vector< T > &  data)
explicit

Construct a matrix with default values.

Missing data is zero-initialized. Additional data is ignored.

Definition at line 504 of file matrix.hpp.

template<size_t R, size_t C, typename T >
template<size_t P, size_t Q>
vmml::Matrix< R, C, T >::Matrix ( const Matrix< P, Q, T > &  source)

Copy-construct a matrix.

Missing data is zero-initialized. Additional data is ignored.

Definition at line 511 of file matrix.hpp.

Member Function Documentation

template<size_t R, size_t C, typename T>
const T* vmml::Matrix< R, C, T >::data ( ) const
inline
Returns
the pointer to the data storage in column-major order.

Definition at line 153 of file matrix.hpp.

References vmml::Matrix< R, C, T >::array, vmml::Matrix< R, C, T >::getCofactors(), vmml::Matrix< R, C, T >::getSubMatrix(), and vmml::Matrix< R, C, T >::operator-().

+ Here is the call graph for this function:

template<size_t R, size_t C, typename T >
bool vmml::Matrix< R, C, T >::equals ( const Matrix< R, C, T > &  other,
tolerance = std::numeric_limits<T>::epsilon() 
) const
Returns
true if both matrices are equal within the given tolerance.

Definition at line 588 of file matrix.hpp.

References vmml::Matrix< R, C, T >::array.

template<size_t R, size_t C, typename T>
template<size_t O, size_t P>
std::enable_if<O <= R && P <= C>::type* setSubMatrix( const Matrix<O, P, T>& sub_matrix, size_t rowOffset, size_t colOffset); const Matrix& operator=(const Matrix<R, C, T>& source_); template <size_t P, size_t Q> const Matrix& operator=(const Matrix<P, Q, T>& source_); void operator=(const std::vector<T>& data); Matrix<R, C, T> operator-() const; vector<R, T> getColumn(size_t columnIndex) const; void setColumn(size_t index, const vector<R, T>& column); vector<C, T> getRow(size_t index) const; void setRow(size_t index, const vector<C, T>& row); vector<C - 1, T> getTranslation() const; Matrix<R, C, T>& setTranslation(const vector<C - 1, T>& t); template <size_t S> void getLookAt(vector<S, T>& eye, vector<S, T>& lookAt, vector<S, T>& up, typename std::enable_if<R == S + 1 && C == S + 1 && S == 3>::type* = 0) const; Matrix<R, C, T> inverse() const; template <size_t O, size_t P> typename std::enable_if<O == P && R == C && O == R && R >= 2>::type* getAdjugate(Matrix<O, P, T>& adjugate) const; template <size_t O, size_t P> typename std::enable_if<O == P && R == C && O == R && R >= 2>::type* vmml::Matrix< R, C, T >::getCofactors ( Matrix< O, P, T > &  cofactors) const

Set the sub matrix of size OxP at the given start indices.

Referenced by vmml::Matrix< R, C, T >::data(), and vmml::Matrix< R, C, T >::getSubMatrix().

+ Here is the caller graph for this function:

template<size_t R, size_t C, typename T >
template<size_t O, size_t P>
Matrix< O, P, T > vmml::Matrix< R, C, T >::getSubMatrix ( size_t  rowOffset,
size_t  colOffset 
) const
Returns
the sub matrix of size OxP at the given start indices.

Definition at line 775 of file matrix.hpp.

References vmml::Matrix< R, C, T >::array, and vmml::Matrix< R, C, T >::getCofactors().

Referenced by vmml::Matrix< R, C, T >::data().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<size_t R, size_t C, typename T >
bool vmml::Matrix< R, C, T >::operator!= ( const Matrix< R, C, T > &  other) const
Returns
true if both matrices are not equal.

Definition at line 582 of file matrix.hpp.

References vmml::Matrix< R, C, T >::operator==().

+ Here is the call graph for this function:

template<size_t R, size_t C, typename T >
T & vmml::Matrix< R, C, T >::operator() ( size_t  rowIndex,
size_t  colIndex 
)
inline
Returns
the element at the given row and column.

Definition at line 557 of file matrix.hpp.

References vmml::Matrix< R, C, T >::array.

template<size_t R, size_t C, typename T >
T vmml::Matrix< R, C, T >::operator() ( size_t  rowIndex,
size_t  colIndex 
) const
inline
Returns
the element at the given row and column.

Definition at line 565 of file matrix.hpp.

References vmml::Matrix< R, C, T >::array.

template<size_t R, size_t C, typename T >
template<size_t P>
Matrix< R, P, T > vmml::Matrix< R, C, T >::operator* ( const Matrix< C, P, T > &  other) const
Returns
matrix_RxP = (this) matrix * other matrix_CxP;

Definition at line 661 of file matrix.hpp.

References vmml::Matrix< R, C, T >::multiply().

+ Here is the call graph for this function:

template<size_t R, size_t C, typename T >
bool vmml::Matrix< R, C, T >::operator== ( const Matrix< R, C, T > &  other) const
Returns
true if both matrices are equal.

Definition at line 573 of file matrix.hpp.

References vmml::Matrix< R, C, T >::array.

Referenced by vmml::Matrix< R, C, T >::operator!=().

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: