Math API nvidia_logo_transpbg.gif Up
mi::math::Matrix<T, ROW, COL> Class Template Reference

NxM-dimensional matrix class template of fixed dimensions. More...

#include <matrix.h>

Inheritance diagram for mi::math::Matrix<T, ROW, COL>:

Public Types

enum  Transposed_copy_tag { TRANSPOSED_COPY_TAG }
 Enum type used to tag a special copy constructor that transposes the matrix while copying. More...
 
typedef Matrix_struct<T, ROW, COL> Pod_type
 POD class corresponding to this matrix. More...
 
typedef Matrix_struct<T, ROW, COL> storage_type
 Storage class used by this matrix. More...
 
typedef T value_type
 Element type. More...
 
typedef Size size_type
 Size type, unsigned. More...
 
typedef Difference difference_type
 Difference type, signed. More...
 
typedef T * pointer
 Mutable pointer to element. More...
 
typedef const T * const_pointer
 Const pointer to element. More...
 
typedef T & reference
 Mutable reference to element. More...
 
typedef const T & const_reference
 Const reference to element. More...
 
typedef Vector<T, COL> Row_vector
 Associated row vector of dimension COL. More...
 
typedef Vector<T, ROW> Column_vector
 Associated column vector of dimension ROW. More...
 

Public Member Functions

T * begin ()
 Returns the pointer to the first matrix element. More...
 
T const * begin () const
 Returns the pointer to the first matrix element. More...
 
T * end ()
 Returns the past-the-end pointer. More...
 
T const * end () const
 Returns the past-the-end pointer. More...
 
Row_vectoroperator[] (Size row)
 Accesses the row-th row vector, 0 <= row < ROW. More...
 
const Row_vectoroperator[] (Size row) const
 Accesses the row-th row vector, 0 <= row < ROW. More...
 
 Matrix ()
 The default constructor leaves the vector elements uninitialized. More...
 
 Matrix (const Matrix<T, ROW, COL> &other)=default
 Default copy constructor. More...
 
 Matrix (const Matrix_struct<T, ROW, COL> &other)
 Constructor from underlying storage type. More...
 
 Matrix (T diag)
 Constructor initializes all matrix elements to zero and the diagonal elements to diag. More...
 
template<typename Iterator>
 Matrix (From_iterator_tag, Iterator p)
 Constructor requires the mi::math::FROM_ITERATOR tag as first argument and initializes the matrix elements with the first ROW times COL elements from the sequence starting at the iterator p. More...
 
template<typename T2>
 Matrix (T2 const (&array)[SIZE])
 Constructor initializes the matrix elements from an array of dimension ROW times COL. More...
 
template<typename T2>
 Matrix (const Matrix<T2, ROW, COL> &other)
 Template constructor that allows explicit conversions from other matrices with assignment compatible element value type. More...
 
template<typename T2>
 Matrix (const Matrix_struct<T2, ROW, COL> &other)
 Template constructor that allows explicit conversions from underlying storage type with assignment compatible element value type. More...
 
 Matrix (Transposed_copy_tag, const Matrix<T, COL, ROW> &other)
 Constructor that initializes the matrix with the transpose matrix of other. More...
 
template<typename T2>
 Matrix (Transposed_copy_tag, const Matrix<T2, COL, ROW> &other)
 Template constructor that initializes the matrix with the transpose matrix of other that allows the explicit conversions from other matrices with assignment compatible element value type. More...
 
 Matrix (const Row_vector &v0)
 Dedicated constructor, for ROW==1 only, that initializes matrix from one row vector v0. More...
 
 Matrix (const Row_vector &v0, const Row_vector &v1)
 Dedicated constructor, for ROW==2 only, that initializes matrix from two row vectors (v0,v1). More...
 
 Matrix (const Row_vector &v0, const Row_vector &v1, const Row_vector &v2)
 Dedicated constructor, for ROW==3 only, that initializes matrix from three row vectors (v0,v1,v2). More...
 
 Matrix (const Row_vector &v0, const Row_vector &v1, const Row_vector &v2, const Row_vector &v3)
 Dedicated constructor, for ROW==4 only, that initializes matrix from four row vectors (v0,v1,v2,v3). More...
 
 Matrix (T m0, T m1)
 2-element constructor, must be a 1x2 or 2x1 matrix. More...
 
 Matrix (T m0, T m1, T m2)
 3-element constructor, must be a 1x3 or 3x1 matrix. More...
 
 Matrix (T m0, T m1, T m2, T m3)
 4-element constructor, must be a 1x4, 2x2, or 4x1 matrix. More...
 
 Matrix (T m0, T m1, T m2, T m3, T m4, T m5)
 6-element constructor, must be a 2x3 or 3x2 matrix. More...
 
 Matrix (T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7)
 8-element constructor, must be a 2x4 or 4x2 matrix. More...
 
 Matrix (T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7, T m8)
 9-element constructor, must be a 3x3 matrix. More...
 
 Matrix (T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7, T m8, T m9, T m10, T m11)
 12-element constructor, must be a 3x4 or 4x3 matrix. More...
 
 Matrix (T m0, T m1, T m2, T m3, T m4, T m5, T m6, T m7, T m8, T m9, T m10, T m11, T m12, T m13, T m14, T m15)
 16-element constructor, must be a 4x4 matrix. More...
 
Matrixoperator= (const Matrix &other)
 Assignment. More...
 
T & operator() (Size row, Size col)
 Accesses the (row,col)-th matrix element. More...
 
const T & operator() (Size row, Size col) const
 Accesses the (row, col)-th matrix element. More...
 
get (Size i) const
 Accesses the i-th matrix element, indexed in the order of the row-major memory layout. More...
 
get (Size row, Size col) const
 Accesses the (row, col)-th matrix element. More...
 
void set (Size i, T value)
 Sets the i-th matrix element to value, indexed in the order of the row-major memory layout. More...
 
void set (Size row, Size col, T value)
 Sets the i-th matrix element to value, indexed in the order of the row-major memory layout. More...
 
det33 () const
 Returns the determinant of the upper-left 3x3 sub-matrix. More...
 
bool invert ()
 Inverts this matrix and returns success or failure. More...
 
void transpose ()
 Transposes this matrix by exchanging rows and columns. More...
 
void translate (T x, T y, T z)
 Adds a relative translation to the matrix (by components). More...
 
void translate (const Vector< Float32, 3 > &vector)
 Adds a relative translation to the matrix (by vector). More...
 
void translate (const Vector< Float64, 3 > &vector)
 Adds a relative translation to the matrix (by vector). More...
 
void set_translation (T dx, T dy, T dz)
 Stores an absolute translation in the matrix (by component). More...
 
void set_translation (const Vector< Float32, 3 > &vector)
 Stores an absolute translation in the matrix (by vector). More...
 
void set_translation (const Vector< Float64, 3 > &vector)
 Stores an absolute translation in the matrix (by vector). More...
 
void rotate (T xangle, T yangle, T zangle)
 Adds a relative rotation to the matrix (Euler angles, by component). More...
 
void rotate (const Vector< Float32, 3 > &angles)
 Adds a relative rotation to the matrix (Euler angles, by vector). More...
 
void rotate (const Vector< Float64, 3 > &angles)
 Adds a relative rotation to the matrix (Euler angles, by vector). More...
 
void set_rotation (T x_angle, T y_angle, T z_angle)
 Stores an absolute rotation in the upper left 3x3 rotation matrix (Euler angles, by component). More...
 
void set_rotation (const Vector< Float32, 3 > &angles)
 Stores an absolute rotation in the upper left 3x3 rotation matrix (Euler angles, by vector). More...
 
void set_rotation (const Vector< Float64, 3 > &angles)
 Stores an absolute rotation in the upper left 3x3 rotation matrix (Euler angles, by vector). More...
 
void set_rotation (const Vector< Float32, 3 > &axis, Float64 angle)
 Stores an absolute rotation (by axis and angle). More...
 
void set_rotation (const Vector< Float64, 3 > &axis, Float64 angle)
 Stores an absolute rotation (by axis and angle). More...
 
void lookat (const Vector< Float32, 3 > &position, const Vector< Float32, 3 > &target, const Vector< Float32, 3 > &up)
 Sets a transformation matrix based on a given center, a reference point, and a direction. More...
 
void lookat (const Vector< Float64, 3 > &position, const Vector< Float64, 3 > &target, const Vector< Float64, 3 > &up)
 Sets a transformation matrix based on a given center, a reference point, and a direction. More...
 

Static Public Member Functions

static Size size ()
 Constant size of the vector. More...
 
static Size max_size ()
 Constant maximum size of the vector. More...
 

Public Attributes

elements [ROW *COL]
 general case matrix elements. More...
 

Static Public Attributes

static const Size ROWS = ROW
 Constant number of rows of the matrix. More...
 
static const Size COLUMNS = COL
 Constant number of columns of the matrix. More...
 
static const Size SIZE = ROW*COL
 Constant size of the matrix. More...
 

Detailed Description

template<typename T, Size ROW, Size COL>
class mi::math::Matrix<T, ROW, COL>

NxM-dimensional matrix class template of fixed dimensions.

This class template provides array-like storage for ROW times COL many values of a (arithmetic) type T. Several functions and arithmetic operators support the work with matrices.

The template parameters have the following requirements:

  • T: an arithmetic type supporting + - * / == != < > <= >= sqrt() .
  • ROW: a value > 0 of type mi::Size that defines the fixed number of rows in the matrix.
  • COL: a value > 0 of type mi::Size that defines the fixed number of columns in the matrix.

An instantiation of the matrix class template is a model of the STL container concept. It provides random access to its elements and corresponding random access iterators.

Depending on the dimensions ROW and COL, the mi::math::Matrix class template offers element access through the conventional data members named xx, xy, xz, xw, yx, yy, ..., wx, wy, wz, ww. The first letter denotes the row, the second letter the column. The following example, which, for the sake of illustration, defines a transformation matrix with a factor two scaling transformation:

mat.xx = 2.0;
mat.yy = 2.0;
mat.zz = 2.0;
mat.ww = 1.0;
NxM-dimensional matrix class template of fixed dimensions.
Definition: matrix.h:367
Memory layout:
Matrices are stored in row-major order, which says that the memory layout of a 4x4 matrix will be sequentially in memory xx, xy, xz, xw, yx, yy, ..., wx, wy, wz, ww.
Note
The matrix interpretation as a transformation is done by mi::math::transform_point(const Matrix<T,4,4>&,const Vector<U,4>&) and related functions. The convention if vectors are row vectors and multiplied from the left with matrices, or column vectors and multiplied from the right with matrices, determines where the different parameters of a transformation are actually stored in the matrix.
The matrix iterators access the matrix elements, however, the access operator[] accesses row vectors, which follows the interpretation of the matrix as a vector of row vectors in accordance with its underlying row-major memory layout.
See also
For the free functions and operators available for matrices see Matrix Class.
The underlying POD type mi::math::Matrix_struct.