GitHub link
Polygon Mesh Processing Library
Matrix< Scalar, M, N > Class Template Reference

Base class for MxN matrix. More...

#include <pmp/MatVec.h>

Public Types

using value_type = Scalar
 the scalar type of the vector More...
 

Public Member Functions

 Matrix ()=default
 default constructor More...
 
 Matrix (Scalar s)
 construct with all entries being a given scalar (matrix and vector) More...
 
 Matrix (const std::initializer_list< Scalar > &&values)
 constructor with row-wise initializer list of M*N entries More...
 
 Matrix (const std::initializer_list< Matrix< Scalar, M, 1 > > &&columns)
 constructor with N column vectors of dimension M More...
 
 Matrix (Scalar x, Scalar y)
 constructor for 2D vectors More...
 
 Matrix (Scalar x, Scalar y, Scalar z)
 constructor for 3D vectors More...
 
 Matrix (Scalar x, Scalar y, Scalar z, Scalar w)
 constructor for 4D vectors More...
 
 Matrix (Matrix< Scalar, 3, 1 > xyz, Scalar w)
 constructor for 4D vectors More...
 
 Matrix (Matrix< Scalar, 3, 1 > c0, Matrix< Scalar, 3, 1 > c1, Matrix< Scalar, 3, 1 > c2)
 construct 3x3 matrix from 3 column vectors More...
 
 Matrix (Matrix< Scalar, 4, 1 > c0, Matrix< Scalar, 4, 1 > c1, Matrix< Scalar, 4, 1 > c2, Matrix< Scalar, 4, 1 > c3)
 construct 4x4 matrix from 4 column vectors More...
 
 Matrix (Scalar m00, Scalar m01, Scalar m02, Scalar m03, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m20, Scalar m21, Scalar m22, Scalar m23, Scalar m30, Scalar m31, Scalar m32, Scalar m33)
 construct 4x4 matrix from 16 (row-wise) entries More...
 
template<typename Derived >
 Matrix (const Eigen::MatrixBase< Derived > &m)
 construct from Eigen More...
 
template<typename OtherScalarType >
 Matrix (const Matrix< OtherScalarType, M, N > &m)
 copy constructor from other scalar type is also invoked for type-casting More...
 
template<typename Derived >
Matrix< Scalar, M, N > & operator= (const Eigen::MatrixBase< Derived > &m)
 assign from Eigen More...
 
template<typename OtherScalar >
 operator Eigen::Matrix< OtherScalar, M, N > () const
 cast to Eigen More...
 
Scalaroperator() (unsigned int i, unsigned int j)
 access entry at row i and column j More...
 
const Scalaroperator() (unsigned int i, unsigned int j) const
 const-access entry at row i and column j More...
 
Scalaroperator[] (unsigned int i)
 access i'th entry (use for vectors) More...
 
Scalar operator[] (unsigned int i) const
 const-access i'th entry (use for vectors) More...
 
const Scalardata () const
 const-access as scalar array More...
 
Scalardata ()
 access as scalar array More...
 
void normalize ()
 normalize matrix/vector by dividing through Frobenius/Euclidean norm More...
 
Matrix< Scalar, M, N > & operator/= (const Scalar s)
 divide matrix by scalar More...
 
Matrix< Scalar, M, N > & operator*= (const Scalar s)
 multply matrix by scalar More...
 
Matrix< Scalar, M, N > & operator-= (const Matrix< Scalar, M, N > &m)
 subtract other matrix from this matrix More...
 
bool operator== (const Matrix< Scalar, M, N > &other) const
 component-wise comparison More...
 
bool operator!= (const Matrix< Scalar, M, N > &other) const
 component-wise comparison More...
 
bool allFinite () const
 

Static Public Member Functions

static constexpr int rows ()
 returns number of rows of the matrix More...
 
static constexpr int cols ()
 returns number of columns of the matrix More...
 
static constexpr int size ()
 returns the dimension of the vector (or size of the matrix, rows*cols) More...
 
static Matrix< Scalar, M, N > identity ()
 return identity matrix (only for square matrices, N==M) More...
 

Detailed Description

template<typename Scalar, int M, int N>
class pmp::Matrix< Scalar, M, N >

Base class for MxN matrix.

Member Typedef Documentation

◆ value_type

using value_type = Scalar

the scalar type of the vector

Constructor & Destructor Documentation

◆ Matrix() [1/13]

Matrix ( )
default

default constructor

◆ Matrix() [2/13]

Matrix ( Scalar  s)
inlineexplicit

construct with all entries being a given scalar (matrix and vector)

◆ Matrix() [3/13]

Matrix ( const std::initializer_list< Scalar > &&  values)
inlineexplicit

constructor with row-wise initializer list of M*N entries

◆ Matrix() [4/13]

Matrix ( const std::initializer_list< Matrix< Scalar, M, 1 > > &&  columns)
inlineexplicit

constructor with N column vectors of dimension M

◆ Matrix() [5/13]

Matrix ( Scalar  x,
Scalar  y 
)
inlineexplicit

constructor for 2D vectors

◆ Matrix() [6/13]

Matrix ( Scalar  x,
Scalar  y,
Scalar  z 
)
inlineexplicit

constructor for 3D vectors

◆ Matrix() [7/13]

Matrix ( Scalar  x,
Scalar  y,
Scalar  z,
Scalar  w 
)
inlineexplicit

constructor for 4D vectors

◆ Matrix() [8/13]

Matrix ( Matrix< Scalar, 3, 1 >  xyz,
Scalar  w 
)
inlineexplicit

constructor for 4D vectors

◆ Matrix() [9/13]

Matrix ( Matrix< Scalar, 3, 1 >  c0,
Matrix< Scalar, 3, 1 >  c1,
Matrix< Scalar, 3, 1 >  c2 
)
inline

construct 3x3 matrix from 3 column vectors

◆ Matrix() [10/13]

Matrix ( Matrix< Scalar, 4, 1 >  c0,
Matrix< Scalar, 4, 1 >  c1,
Matrix< Scalar, 4, 1 >  c2,
Matrix< Scalar, 4, 1 >  c3 
)
inline

construct 4x4 matrix from 4 column vectors

◆ Matrix() [11/13]

Matrix ( Scalar  m00,
Scalar  m01,
Scalar  m02,
Scalar  m03,
Scalar  m10,
Scalar  m11,
Scalar  m12,
Scalar  m13,
Scalar  m20,
Scalar  m21,
Scalar  m22,
Scalar  m23,
Scalar  m30,
Scalar  m31,
Scalar  m32,
Scalar  m33 
)
inline

construct 4x4 matrix from 16 (row-wise) entries

◆ Matrix() [12/13]

Matrix ( const Eigen::MatrixBase< Derived > &  m)
inline

construct from Eigen

◆ Matrix() [13/13]

Matrix ( const Matrix< OtherScalarType, M, N > &  m)
inlineexplicit

copy constructor from other scalar type is also invoked for type-casting

Member Function Documentation

◆ allFinite()

bool allFinite ( ) const
inline
Returns
true if all elements are finite, i.e. not NaN or +/- inf

◆ cols()

static constexpr int cols ( )
inlinestaticconstexpr

returns number of columns of the matrix

◆ data() [1/2]

Scalar * data ( )
inline

access as scalar array

◆ data() [2/2]

const Scalar * data ( ) const
inline

const-access as scalar array

◆ normalize()

void normalize ( )
inline

normalize matrix/vector by dividing through Frobenius/Euclidean norm

◆ operator Eigen::Matrix< OtherScalar, M, N >()

operator Eigen::Matrix< OtherScalar, M, N > ( ) const
inline

cast to Eigen

◆ operator!=()

bool operator!= ( const Matrix< Scalar, M, N > &  other) const
inline

component-wise comparison

◆ operator()() [1/2]

Scalar & operator() ( unsigned int  i,
unsigned int  j 
)
inline

access entry at row i and column j

◆ operator()() [2/2]

const Scalar & operator() ( unsigned int  i,
unsigned int  j 
) const
inline

const-access entry at row i and column j

◆ operator*=()

Matrix< Scalar, M, N > & operator*= ( const Scalar  s)
inline

multply matrix by scalar

◆ operator-=()

Matrix< Scalar, M, N > & operator-= ( const Matrix< Scalar, M, N > &  m)
inline

subtract other matrix from this matrix

◆ operator/=()

Matrix< Scalar, M, N > & operator/= ( const Scalar  s)
inline

divide matrix by scalar

◆ operator=()

Matrix< Scalar, M, N > & operator= ( const Eigen::MatrixBase< Derived > &  m)
inline

assign from Eigen

◆ operator==()

bool operator== ( const Matrix< Scalar, M, N > &  other) const
inline

component-wise comparison

◆ operator[]() [1/2]

Scalar & operator[] ( unsigned int  i)
inline

access i'th entry (use for vectors)

◆ operator[]() [2/2]

Scalar operator[] ( unsigned int  i) const
inline

const-access i'th entry (use for vectors)

◆ rows()

static constexpr int rows ( )
inlinestaticconstexpr

returns number of rows of the matrix

◆ size()

static constexpr int size ( )
inlinestaticconstexpr

returns the dimension of the vector (or size of the matrix, rows*cols)