Easy3D 2.5.3
Mat< N, M, T > Class Template Reference

Base class for matrix types. More...

#include <easy3d/core/mat.h>

Public Member Functions

 Mat ()=default
 Default constructor. More...
 
 Mat (T s)
 Initialized with diagonal as s and others zeros.
 
template<size_t rN, size_t rM>
 Mat (const Mat< rN, rM, T > &rhs)
 Copy constructor for rN >= N, rM >= M. For smaller incoming matrices (i.e, rN < N, rM < M ) specialization is required in order to fill the remaining elements with appropriate values (usually 0 or 1). rN: Number of rows in rhs. rM: Number of columns in rhs. rhs: rN by rM matrix of type T to copy. NOTE: This is explicit to prevent 'accidental' assignment of differently-sized matrices. TODO: Can this ever actually get called? A templated constructor for a templated class seems dodgy!
 
 Mat (const T *m)
 Initialize elements from an array of type T.
 
size_t num_rows () const
 Return the number of rows.
 
size_t num_columns () const
 Return the number of columns.
 
Vec< M, T > row (size_t r) const
 Return row r as a vector.
 
Vec< N, T > col (size_t c) const
 Return col c as a vector.
 
const T & operator() (size_t r, size_t c) const
 Const row/column access to elements.
 
T & operator() (size_t r, size_t c)
 Non-const row/column access to elements.
 
 operator const T * () const
 const array/low-level access to elements.
 
 operator T* ()
 Non-const array/low-level access to elements.
 
void load_zero ()
 Set all elements 0.
 
void load_identity (T s=T(1))
 Set diagonal elements s and others 0.
 
template<size_t vN>
void set_row (size_t r, const Vec< vN, T > &v)
 Set row r from vector v. This copies the first M components from v, so vN must be >= M. vN: Dimension (number of components) of v.
 
template<size_t vN>
void set_col (size_t c, const Vec< vN, T > &v)
 Set col c from vector v. This copies the first N components from v, so vN must be >= N. vN: Dimension (number of components) in v.
 
void swap_rows (size_t a, size_t b)
 Swaps row a with row b.
 
void swap_cols (size_t a, size_t b)
 Swaps col a with col b.
 
bool operator== (const Mat< N, M, T > &rhs) const
 Equality test.
 
bool operator!= (const Mat< N, M, T > &rhs) const
 Inequality test.
 
template<size_t rM>
Mat< N, rM, T > operator* (const Mat< M, rM, T > &rhs) const
 Matrix-matrix multiplication. rhs must have the same number of rows as this matrix has columns. rM: Columns in rhs. return Matrix of dimensions N x rM.
 
Mat< N, M, T > operator+ (const Mat< N, M, T > &rhs) const
 Component-wise matrix-matrix addition.
 
Mat< N, M, T > operator- (const Mat< N, M, T > &rhs) const
 Component-wise matrix-matrix subtraction.
 
Mat< N, M, T > operator- () const
 Component-wise matrix negation.
 
Vec< N, T > operator* (const Vec< M, T > &rhs) const
 Matrix-vector multiplication. rhs must have the same number of elements as this matrix has columns. return vec of size N.
 
Mat< N, M, T > operator* (T rhs) const
 Component-wise matrix-scalar multiplication.
 
Mat< N, M, T > operator/ (T rhs) const
 Component-wise matrix-scalar division.
 
Mat< N, M, T > & operator*= (const Mat< N, M, T > &rhs)
 Matrix-matrix multiplication/assignment.
 
Mat< N, M, T > & operator+= (const Mat< N, M, T > &rhs)
 Component-wise matrix-matrix addition/assignment.
 
Mat< N, M, T > & operator-= (const Mat< N, M, T > &rhs)
 Component-wise matrix-matrix subtraction/assignment.
 
Mat< N, M, T > & operator*= (T rhs)
 Component-wise matrix-scalar multiplication/assignment.
 
Mat< N, M, T > & operator/= (T rhs)
 Component-wise matrix-scalar division/assignment.
 
Mat< N, M, T > & operator+= (T rhs)
 Component-wise matrix-scalar addition/assignment.
 
Mat< N, M, T > & operator-= (T rhs)
 Component-wise matrix-scalar subtraction/assignment.
 

Static Public Member Functions

static Mat< N, M, T > identity ()
 Static constructor return an N x M identity matrix. see also load_identity()
 

Detailed Description

template<size_t N, size_t M, typename T>
class easy3d::Mat< N, M, T >

Base class for matrix types.

Mat is a base matrix class that provides generic functionality for N by M matrices.

Template Parameters
NThe number of rows in this matrix.
MThe number of columns in this matrix.
TThe scalar type for matrix elements.
Note
: Matrices are stored internally as column-major unless MATRIX_ROW_MAJOR is defined.
Todo:
Add a transform() method or overload operator* so as to allow matrices to transform vectors that are M-1 in size, as vectors in homogeneous space.
See also
Mat2, Mat3, and Mat4
Examples
Tutorial_207_RealCamera.

Constructor & Destructor Documentation

◆ Mat()

Mat ( )
default

Default constructor.

Note
The matrix elements are intentionally not initialized. This is efficient if the user assigns their values from subsequent computations. Use Mat(T s) to initialize the elements during construction.

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