Easy3D 2.6.1
|
A matrix representation, which supports dynamic sizes. More...
#include <easy3d/core/matrix.h>
Public Member Functions | |
Matrix () | |
Matrix (const Matrix< FT > &A) | |
Matrix (int rows, int cols, const FT &x=FT(0)) | |
Matrix (int rows, int cols, const std::vector< FT > &array) | |
Matrix (int rows, int cols, const FT *array) | |
Matrix< FT > & | operator= (const Matrix< FT > &A) |
Assign A to this matrix. | |
Matrix< FT > & | operator= (const FT &x) |
Assign x to every entry of this matrix. | |
FT * | operator[] (int row) |
Return the row_th row as a 1D array. | |
const FT * | operator[] (int row) const |
Return the row_th row as a 1D array (const version). | |
FT & | operator() (int row, int col) |
Return the element at (row, col). | |
const FT & | operator() (int row, int col) const |
Return the element at (row, col) (const version). | |
void | set (int row, int col, FT v) |
Set the value of the element at (row, col). | |
const FT & | get (int row, int col) const |
Get the value of the element at (row, col). | |
FT * | data () |
const FT * | data () const |
int | rows () const |
Return the number of rows. | |
int | cols () const |
Return the number of columns. | |
Matrix< FT > & | resize (int rows, int cols) |
Change the size/dimension of the matrix. | |
std::vector< FT > | get_row (int row) const |
Get the matrix's row vector as a 1D array. | |
std::vector< FT > | get_column (int col) const |
Get the matrix's column vector as a 1D array. | |
void | set_row (const std::vector< FT > &v, int row) |
Set the matrix's row vector. | |
void | set_column (const std::vector< FT > &v, int col) |
Set the matrix's column vector. | |
void | load_zero () |
Set all elements to zero. | |
void | load_identity (FT v=FT(1)) |
void | load_random () |
Set all elements to a random value (in the range [0.0, 1.0]) | |
Matrix< FT > | transpose () const |
Return the transposed matrix. | |
Matrix< FT > | inverse () const |
Return the inverse of the matrix (for positive square matrices only) | |
FT | determinant () const |
Return the determinant of the matrix (for square matrices only) | |
FT | trace () const |
Matrix< FT > & | operator+= (const FT &v) |
computed assignment. Add each element by v | |
Matrix< FT > & | operator-= (const FT &v) |
computed assignment. Subtract each element by v | |
template<typename FT2> | |
Matrix< FT > & | operator*= (const FT2 &v) |
computed assignment. Multiply each element by v | |
template<typename FT2> | |
Matrix< FT > & | operator/= (const FT2 &v) |
computed assignment. Divide each element by v | |
Matrix< FT > & | operator+= (const Matrix< FT > &A) |
computed assignment. Add A to this matrix. | |
Matrix< FT > & | operator-= (const Matrix< FT > &) |
computed assignment. Subtract A from this matrix. | |
A matrix representation, which supports dynamic sizes.
Matrix | ( | ) |
Default constructor (that constructs an empty matrix).
constructors and destructor
Copy constructor (i.e., construct a matrix from another matrix). The new matrix will be the same as the input matrix.
A | Input matrix. |
Matrix | ( | int | rows, |
int | cols, | ||
const FT & | x = FT(0) ) |
Construct a matrix by specifying its dimension (i.e., number of rows and number of columns) and initialize all entries to zero.
rows | Number of rows |
cols | Number of columns. |
x | Default value of each element of the matrix. |
Matrix | ( | int | rows, |
int | cols, | ||
const std::vector< FT > & | array ) |
Construct a matrix by specifying its dimension (i.e., number of rows and number of columns) and initialize the matrix from an array. The first row of the matrix will be initialized by the first cols elements of the array. Then the second row will be initialized by the next cols elements of the array, and so on.
rows | Number of rows |
cols | Number of columns. |
array | An array containing at least (rows * cols) elements. |
Matrix | ( | int | rows, |
int | cols, | ||
const FT * | array ) |
This is an override of the above constructor. Construct a matrix by specifying its dimension (i.e., number of rows and number of columns) and initialize the matrix from an array. The first row of the matrix will be initialized by the first cols elements of the array. Then the second row will be initialized by the next cols elements of the array, and so on.
rows | Number of rows |
cols | Number of columns. |
array | The pointer to the first element of an array used to initialize the matrix. It must have at least (rows * cols) elements. |
|
inline |
Return the data of the matrix as a 1D array. Attention: Matrices are stored internally as row-major (i.e., the rows are concatenated in the returned array).
|
inline |
Return the data of the matrix as a 1D array (const version). Attention: Matrices are stored internally as row-major (i.e., the rows are concatenated in the returned array).
std::vector< FT > get_column | ( | int | col | ) | const |
Get the matrix's column vector as a 1D array.
get the matrix's column vector
std::vector< FT > get_row | ( | int | row | ) | const |
Get the matrix's row vector as a 1D array.
get the matrix's row vector
|
inline |
Make this matrix identity (i.e., all elements on the diagonal have a value of 1).
Sets the matrix to identity This sets all coefficients of this matrix to be equal to nROW x nCOL identity matrix.
|
inline |
Set all elements to zero.
Clears the matrix such that all values are set to 0 (zero)
computed assignment. Multiply each element by v
compound assignment operators *=
Matrix< FT > & operator+= | ( | const FT & | x | ) |
computed assignment. Add each element by v
compound assignment operators +=
Matrix< FT > & operator-= | ( | const FT & | x | ) |
computed assignment. Subtract each element by v
compound assignment operators -=
computed assignment. Divide each element by v
compound assignment operators /=
|
inline |
Assign x to every entry of this matrix.
overload evaluate operator = from scalar to matrix
Assign A to this matrix.
overload evaluate operator = from matrix to matrix
|
inline |
Return the row_th row as a 1D array.
overload operator [] for 0-offset access
Matrix< FT > & resize | ( | int | rows, |
int | cols ) |
Change the size/dimension of the matrix.
reallocate matrix's size
void set_column | ( | const std::vector< FT > & | v, |
int | col ) |
Set the matrix's column vector.
set the matrix's column vector
void set_row | ( | const std::vector< FT > & | v, |
int | row ) |
Set the matrix's row vector.
set the matrix's row vector
FT trace | ( | ) | const |
Return the trace of this matrix, i.e. the sum of the coefficients on the main diagonal.