Matrix< M, N, T > Class Template Reference

A Matrix is templated to store M rows and N columns of data of type T. If left off, T will default to a "real_t" data type. Also, if N is not specified, the template will default to a square MxM matrix. More...

#include <Matrix.h>

List of all members.

Public Member Functions

Constructors
 Matrix (const T *srcData)
 Expects arguments in row-major order.
 Matrix ()
 Constructs a zero Matrix.
 Matrix (const Matrix< M, N, T > &m)
 Copy Constructor.
Accessor Operators
const Vector< N, T > & operator[] (const unsigned rowIndex) const
Vector< N, T > & operator[] (const unsigned rowIndex)
const T * operator* () const
T * operator* ()
Equality Operators
bool operator== (const Matrix< M, N, T > &m) const
bool operator!= (const Matrix< M, N, T > &m) const
Mutator Operators
Matrix< M, N, T > & operator= (const Matrix< M, N, T > &m)
Matrix< M, N, T > & operator+= (const Matrix< M, N, T > &rhs)
Matrix< M, N, T > & operator-= (const Matrix< M, N, T > &rhs)
Matrix< M, N, T > & operator*= (const Matrix< M, N, T > &rhs)
Scalar Mutator Operators
Matrix< M, N, T > & operator*= (const T &scale)
Matrix< M, N, T > & operator/= (const T &scale)
Arithmetic Operators
Matrix< M, N, T > operator+ (const Matrix< M, N, T > &rhs) const
Matrix< M, N, T > operator- (const Matrix< M, N, T > &rhs) const
Matrix< M, N, T > operator* (const Matrix< M, N, T > &rhs) const
 MxN (square) matrix * MxN (square) matrix yields an MxN (square) matrix.
Point< M, T > operator* (const Point< N, T > &rhs) const
Vector< M, T > operator* (const Vector< N, T > &rhs) const
Vector< M-1, T > operator* (const Vector< N-1, T > &rhs) const
Scalar Arithmetic Operators
Matrix< M, N, T > operator* (const T &scale) const
Matrix< M, N, T > operator/ (const T &scale) const
More Complex Functionality
bool isDiagonal () const
Vector< N, T > & row (unsigned index)
Vector< N, T > row (unsigned index) const
Vector< M, T > col (unsigned index) const
Matrix< M, N, T > & setCol (unsigned index, const Vector< M, T > &vec)
 Sets the index'th column of this matrix to the given Vector.
const Matrix< M, N, T > getTranspose () const
void fillGLMatrix (T *bufferToFill) const
bool isUpperTriangular () const
bool isLowerTriangular () const
Matrix< M, N, T > getInverse () const
getDeterminant () const
void cleanup ()
 Cleans up a matrix (0's out entries that are less than epsilon).
 Matrix (const T &v0, const T &v1=0, const T &v2=0, const T &v3=0, const T &v4=0, const T &v5=0, const T &v6=0, const T &v7=0, const T &v8=0, const T &v9=0, const T &v10=0, const T &v11=0, const T &v12=0, const T &v13=0, const T &v14=0, const T &v15=0)
 Convenience Constructor.

Static Public Member Functions

Static convenience constructors to generate common matrices
static Matrix zero ()
 Generates a matrix full of zeroes.
static Matrix identity ()
 Generates an identity matrix.
static Matrix diagonal (T diagonalValue)
 Generates a diagonal matrix with the value specified.

Public Attributes

Vector< N, T > rows [M]
 Underlying data, where each row is stored in a separate Vector.


Detailed Description

template<unsigned M, unsigned N = M, typename T = real_t>
class Matrix< M, N, T >

A Matrix is templated to store M rows and N columns of data of type T. If left off, T will default to a "real_t" data type. Also, if N is not specified, the template will default to a square MxM matrix.

Provides basic functionality for a templated, arbitrarily-sized matrix.

Included in this definition are typedefs for the most commonly used matrices (4x4, 3x3, etc), and these can be thought of as shortcuts to reference their associated Matrix templates. For example, Matrix4x4 can be used to refer to Matrix<4, 4, real_t>.

A Matrix stores each of its M rows internally as an N-length Vector.

Author:
Travis Fischer (fisch0920@gmail.com)
Date:
Fall 2008
A Matrix is templated to store M rows and N columns of data of type T. If left off, T will default to a "real_t" data type. Also, if N is not specified, the template will default to a square MxM matrix.

Included in this definition are typedefs for the most commonly used matrices (4x4, 3x3, etc), and these can be thought of as shortcuts to reference their associated Matrix templates. For example, Matrix4x4 can be used to refer to Matrix<4, 4, real_t>.

A Matrix stores each of its M rows internally as an N-length Vector called rows which has been defined as:

Vector<N, T> rows[M];

Definition at line 48 of file Matrix.h.


Constructor & Destructor Documentation

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T >::Matrix ( const T *  srcData  )  [inline]

Expects arguments in row-major order.

Definition at line 37 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T >::Matrix (  )  [inline]

Constructs a zero Matrix.

Definition at line 43 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T >::Matrix ( const Matrix< M, N, T > &  m  )  [inline]

Copy Constructor.

Definition at line 49 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T >::Matrix ( const T &  v0,
const T &  v1 = 0,
const T &  v2 = 0,
const T &  v3 = 0,
const T &  v4 = 0,
const T &  v5 = 0,
const T &  v6 = 0,
const T &  v7 = 0,
const T &  v8 = 0,
const T &  v9 = 0,
const T &  v10 = 0,
const T &  v11 = 0,
const T &  v12 = 0,
const T &  v13 = 0,
const T &  v14 = 0,
const T &  v15 = 0 
) [inline, explicit]

Convenience Constructor.

Definition at line 586 of file Matrix.inl.


Member Function Documentation

template<unsigned M, unsigned N = M, typename T = real_t>
static Matrix Matrix< M, N, T >::zero (  )  [inline, static]

Generates a matrix full of zeroes.

Definition at line 72 of file Matrix.h.

template<unsigned M, unsigned N = M, typename T = real_t>
static Matrix Matrix< M, N, T >::identity (  )  [inline, static]

Generates an identity matrix.

Definition at line 77 of file Matrix.h.

template<unsigned M, unsigned N = M, typename T = real_t>
static Matrix Matrix< M, N, T >::diagonal ( diagonalValue  )  [inline, static]

Generates a diagonal matrix with the value specified.

Definition at line 82 of file Matrix.h.

template<unsigned M, unsigned N, typename T>
const Vector< N, T > & Matrix< M, N, T >::operator[] ( const unsigned  rowIndex  )  const [inline]

Returns:
a const reference to the row at the given index

Definition at line 59 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Vector< N, T > & Matrix< M, N, T >::operator[] ( const unsigned  rowIndex  )  [inline]

Returns:
a reference to the row at the given index
Note:
changes to the returned vector will affect this matrix

Definition at line 68 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
const T * Matrix< M, N, T >::operator* (  )  const [inline]

Returns:
a const pointer to the raw, underlying data (row-major, M*N-length array of type T)

Definition at line 77 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
T * Matrix< M, N, T >::operator* (  )  [inline]

Returns:
a pointer to the raw, underlying data (row-major, M*N-length array of type T)

Definition at line 84 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
bool Matrix< M, N, T >::operator== ( const Matrix< M, N, T > &  m  )  const [inline]

Definition at line 101 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
bool Matrix< M, N, T >::operator!= ( const Matrix< M, N, T > &  m  )  const [inline]

Definition at line 113 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > & Matrix< M, N, T >::operator= ( const Matrix< M, N, T > &  m  )  [inline]

Definition at line 125 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > & Matrix< M, N, T >::operator+= ( const Matrix< M, N, T > &  rhs  )  [inline]

Definition at line 133 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > & Matrix< M, N, T >::operator-= ( const Matrix< M, N, T > &  rhs  )  [inline]

Definition at line 142 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > & Matrix< M, N, T >::operator*= ( const Matrix< M, N, T > &  rhs  )  [inline]

Definition at line 151 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > & Matrix< M, N, T >::operator*= ( const T &  scale  )  [inline]

Definition at line 165 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > & Matrix< M, N, T >::operator/= ( const T &  scale  )  [inline]

Definition at line 174 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > Matrix< M, N, T >::operator+ ( const Matrix< M, N, T > &  rhs  )  const [inline]

Definition at line 188 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > Matrix< M, N, T >::operator- ( const Matrix< M, N, T > &  rhs  )  const [inline]

Definition at line 199 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > Matrix< M, N, T >::operator* ( const Matrix< M, N, T > &  rhs  )  const [inline]

MxN (square) matrix * MxN (square) matrix yields an MxN (square) matrix.

Definition at line 211 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Point< M, T > Matrix< M, N, T >::operator* ( const Point< N, T > &  rhs  )  const [inline]

MxN matrix * N-length column vector yields an M-length vector

Note:
this method returns an M-length Vector. Make sure you understand why.

Definition at line 222 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Vector< M, T > Matrix< M, N, T >::operator* ( const Vector< N, T > &  rhs  )  const [inline]

Definition at line 237 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Vector< M-1, T > Matrix< M, N, T >::operator* ( const Vector< N-1, T > &  rhs  )  const [inline]

Definition at line 248 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > Matrix< M, N, T >::operator* ( const T &  scale  )  const [inline]

Definition at line 262 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > Matrix< M, N, T >::operator/ ( const T &  scale  )  const [inline]

Definition at line 273 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
bool Matrix< M, N, T >::isDiagonal (  )  const [inline]

Returns:
whether or not this Matrix is diagonal

Definition at line 290 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Vector< N, T > & Matrix< M, N, T >::row ( unsigned  index  )  [inline]

Returns:
a Vector containing the index'th row of this matrix
Note:
Modifying the Vector returned will directly affect this Matrix's data

Definition at line 302 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Vector< N, T > Matrix< M, N, T >::row ( unsigned  index  )  const [inline]

Returns:
a Vector containing the index'th row of this matrix
Note:
Modifying the Vector returned will Not affect this Matrix's data

Definition at line 311 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Vector< M, T > Matrix< M, N, T >::col ( unsigned  index  )  const [inline]

Returns:
a Vector containing the index'th column of this matrix
Note:
Modifying the Vector returned will Not affect this Matrix's data

Definition at line 320 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > & Matrix< M, N, T >::setCol ( unsigned  index,
const Vector< M, T > &  vec 
) [inline]

Sets the index'th column of this matrix to the given Vector.

Definition at line 332 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
const Matrix< M, N, T > Matrix< M, N, T >::getTranspose (  )  const [inline]

Returns:
the transpose of this matrix

Definition at line 383 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
void Matrix< M, N, T >::fillGLMatrix ( T *  bufferToFill  )  const [inline]

Fills the data provided with the transpose of this matrix (since OpenGL matrices are stored in column-major format).

Definition at line 399 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
bool Matrix< M, N, T >::isUpperTriangular (  )  const [inline]

Returns:
true if this matrix is strictly upper-triangular. An upper- triangular matrix contains only zeros below its diagonal (but may contain non-zero values on and above its diagonal).
Example 4x4 upper triangular matrix: [ 1 2 3 4 ] [ 0 5 6 7 ] [ 0 0 0 8 ] [ 0 0 0 9 ]

Example 4x4 non upper triangular matrix: [ 1 2 3 4 ] [ 0 5 6 7 ] [ 8 0 0 9 ] [ 0 0 0 0 ]

Definition at line 425 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
bool Matrix< M, N, T >::isLowerTriangular (  )  const [inline]

Returns:
true if this matrix is strictly lower-triangular. An lower- triangular matrix contains only zeros above its diagonal (but may contain non-zero values on and below its diagonal).
Example 4x4 triangular matrix: [ 1 0 0 0 ] [ 2 3 0 0 ] [ 4 5 0 0 ] [ 6 7 8 9 ]

Example 4x4 non upper triangular matrix: [ 1 0 0 2 ] [ 3 4 0 5 ] [ 6 7 8 0 ] [ 0 0 0 0 ]

Definition at line 452 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
Matrix< M, N, T > Matrix< M, N, T >::getInverse (  )  const [inline]

Returns:
the inverse of this matrix, assuming it exists

Definition at line 463 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
T Matrix< M, N, T >::getDeterminant (  )  const [inline]

Returns:
the determinant of this matrix

Definition at line 538 of file Matrix.inl.

template<unsigned M, unsigned N, typename T>
void Matrix< M, N, T >::cleanup (  )  [inline]

Cleans up a matrix (0's out entries that are less than epsilon).

Definition at line 579 of file Matrix.inl.


Member Data Documentation

template<unsigned M, unsigned N = M, typename T = real_t>
Vector<N, T> Matrix< M, N, T >::rows[M]

Underlying data, where each row is stored in a separate Vector.

Definition at line 51 of file Matrix.h.


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

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6