Fawkes API Fawkes Development Version
|
A general matrix class. More...
#include <>>
Public Member Functions | |
Matrix (unsigned int num_rows=0, unsigned int num_cols=0, float *data=0, bool manage_own_memory=true) | |
Constructor. | |
Matrix (const Matrix &tbc) | |
Copy-constructor. | |
~Matrix () | |
Destructor. | |
void | size (unsigned int &num_rows, unsigned int &num_cols) const |
Determines the dimensions of the matrix. | |
unsigned int | num_rows () const |
Return the number of rows in the Matrix. | |
unsigned int | num_cols () const |
Return the number of columns in the Matrix. | |
Matrix & | id () |
Sets the diagonal elements to 1.0 and all other to 0.0. | |
Matrix & | transpose () |
Transposes the matrix. | |
Matrix | get_transpose () const |
Computes a matrix that is the transposed of this matrix. | |
Matrix & | invert () |
Inverts the matrix. | |
Matrix | get_inverse () const |
Computes a matrix that is the inverse of this matrix. | |
float | det () const |
Computes the determinant of the matrix. | |
const float * | get_data () const |
Returns the const data pointer. | |
float * | get_data () |
Returns the data pointer. | |
Matrix | get_submatrix (unsigned int row, unsigned int col, unsigned int num_rows, unsigned int num_cols) const |
Returns a submatrix of the matrix. | |
void | overlay (unsigned int row, unsigned int col, const Matrix &m) |
Overlays another matrix over this matrix. | |
float | operator() (unsigned int row, unsigned int col) const |
(Read-only) Access-operator. | |
float & | operator() (unsigned int row, unsigned int col) |
(RW) Access operator. | |
Matrix & | operator= (const Matrix &rhs) |
Assignment operator. | |
Matrix | operator* (const Matrix &rhs) const |
Matrix multiplication operator. | |
Matrix & | operator*= (const Matrix &rhs) |
Combined matrix-multipliation and assignement operator. | |
Vector | operator* (const Vector &cv) const |
Multiply the matrix with given vector. | |
Matrix | operator* (const float &f) const |
Mulitply every element of the matrix with the given scalar. | |
Matrix & | operator*= (const float &f) |
Combined scalar multiplication and assignment operator. | |
Matrix | operator/ (const float &f) const |
Divide every element of the matrix with the given scalar. | |
Matrix & | operator/= (const float &f) |
Combined scalar division and assignment operator. | |
Matrix | operator+ (const Matrix &rhs) const |
Addition operator. | |
Matrix & | operator+= (const Matrix &rhs) |
Add-assign operator. | |
Matrix | operator- (const Matrix &rhs) const |
Subtraction operator. | |
Matrix & | operator-= (const Matrix &rhs) |
Subtract-assign operator. | |
bool | operator== (const Matrix &rhs) const |
Comparison operator. | |
void | print_info (const char *name=0, const char *col_sep=0, const char *row_sep=0) const |
Print matrix to standard out. | |
Static Public Member Functions | |
static Matrix | get_id (unsigned int size, float *data_buffer=0) |
Creates a quadratic matrix with dimension size and sets the diagonal elements to 1.0. | |
static Matrix | get_diag (unsigned int size, float value, float *data_buffer=0) |
Creates a quadratic matrix with dimension size and sets the diagonal elements to value. |
A general matrix class.
It provides all the operations that are commonly used with a matrix, but has been optimized with typical robotic applications in mind. That meas especially that the chose data type is single-precision float and the class has been optimized for small matrices (up to about 10x10).
fawkes::Matrix::Matrix | ( | unsigned int | num_rows = 0 , |
unsigned int | num_cols = 0 , |
||
float * | data = 0 , |
||
bool | manage_own_memory = true |
||
) |
Constructor.
num_rows | number of rows |
num_cols | number of columns |
data | array containing elements of the matrix in row-by-row-order |
manage_own_memory | if true, the Matrix will manage its memory on its own, else it will not allocate new memory but works with the provided array |
Definition at line 103 of file matrix.cpp.
References num_cols(), and num_rows().
Referenced by firevision::CCDCalibration::CCDCalibration().
fawkes::Matrix::Matrix | ( | const Matrix & | tbc | ) |
fawkes::Matrix::~Matrix | ( | ) |
Destructor.
Definition at line 152 of file matrix.cpp.
float fawkes::Matrix::det | ( | ) | const |
Computes the determinant of the matrix.
Definition at line 375 of file matrix.cpp.
const float * fawkes::Matrix::get_data | ( | ) | const [inline] |
Returns the const data pointer.
Definition at line 57 of file matrix.h.
Referenced by get_submatrix(), get_transpose(), operator*(), operator+(), operator+=(), operator-(), operator-=(), operator/(), and operator==().
float * fawkes::Matrix::get_data | ( | ) | [inline] |
Matrix fawkes::Matrix::get_diag | ( | unsigned int | size, |
float | value, | ||
float * | data_buffer = 0 |
||
) | [static] |
Creates a quadratic matrix with dimension size and sets the diagonal elements to value.
All other elements are set to 0.0.
size | dimension of the matrix |
value | of the elements of the main diagonal |
data_buffer | if != NULL the given float array will be used as data internal data store (the object will not perform any memory management in this case) |
Definition at line 208 of file matrix.cpp.
References size().
Referenced by get_id().
Matrix fawkes::Matrix::get_id | ( | unsigned int | size, |
float * | data_buffer = 0 |
||
) | [static] |
Creates a quadratic matrix with dimension size and sets the diagonal elements to 1.0.
All other elements are set to 0.0.
size | dimension of the matrix |
data_buffer | if != NULL the given float array will be used as data internal data store (the object will not perform any memory management in this case) |
Definition at line 194 of file matrix.cpp.
References get_diag().
Referenced by invert().
Matrix fawkes::Matrix::get_inverse | ( | ) | const |
Computes a matrix that is the inverse of this matrix.
Definition at line 363 of file matrix.cpp.
References invert().
Matrix fawkes::Matrix::get_submatrix | ( | unsigned int | row, |
unsigned int | col, | ||
unsigned int | num_rows, | ||
unsigned int | num_cols | ||
) | const |
Returns a submatrix of the matrix.
row | the row in the original matrix of the top-left element in the submatrix |
col | the column in the original matrix of the top-left element in the submatrix |
num_rows | the number of rows of the submatrix |
num_cols | the number of columns of the submatrix |
Definition at line 416 of file matrix.cpp.
References get_data(), num_cols(), and num_rows().
Referenced by firevision::ProjectiveCam::get_GPA_p(), firevision::Calibration::K(), and firevision::ProjectiveCam::set_location().
Matrix fawkes::Matrix::get_transpose | ( | ) | const |
Computes a matrix that is the transposed of this matrix.
Definition at line 295 of file matrix.cpp.
References get_data().
Matrix & fawkes::Matrix::id | ( | ) |
Sets the diagonal elements to 1.0 and all other to 0.0.
Definition at line 173 of file matrix.cpp.
References num_cols(), and num_rows().
Referenced by firevision::Calibration::Calibration(), and firevision::Calibration::K().
Matrix & fawkes::Matrix::invert | ( | ) |
Inverts the matrix.
The algorithm that is implemented for computing the inverse of the matrix is the Gauss-Jordan-Algorithm. Hereby, the block- matrix (A|I) consisting of the matrix to be inverted (A) and the identity matrix (I) is transformed into (I|A^(-1)).
Definition at line 318 of file matrix.cpp.
References get_id(), and overlay().
Referenced by get_inverse(), and firevision::ProjectiveCam::set_location().
unsigned int fawkes::Matrix::num_cols | ( | ) | const [inline] |
Return the number of columns in the Matrix.
Definition at line 43 of file matrix.h.
Referenced by get_submatrix(), id(), Matrix(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator==(), print_info(), and size().
unsigned int fawkes::Matrix::num_rows | ( | ) | const [inline] |
Return the number of rows in the Matrix.
Definition at line 42 of file matrix.h.
Referenced by get_submatrix(), id(), Matrix(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator==(), print_info(), and size().
float fawkes::Matrix::operator() | ( | unsigned int | row, |
unsigned int | col | ||
) | const |
(Read-only) Access-operator.
With this operator it is possible to access a specific element of the matrix. (First element is at (0, 0)
row | the row of the element |
col | the column of the element |
Definition at line 473 of file matrix.cpp.
float & fawkes::Matrix::operator() | ( | unsigned int | row, |
unsigned int | col | ||
) |
(RW) Access operator.
see the read-only access operator for operational details
row | the row of the element |
col | the column of the element |
Definition at line 490 of file matrix.cpp.
Matrix multiplication operator.
(Matrix)a.operator*((Matrix)b) computes a * b; i.e., the 2nd matrix is right-multiplied to the 1st matrix
rhs | the right-hand-side matrix |
Definition at line 536 of file matrix.cpp.
References num_cols(), and num_rows().
Multiply the matrix with given vector.
v | a vector |
Definition at line 628 of file matrix.cpp.
References fawkes::Vector::data_ptr(), num_cols(), num_rows(), and fawkes::Vector::size().
Matrix fawkes::Matrix::operator* | ( | const float & | f | ) | const |
Mulitply every element of the matrix with the given scalar.
f | a scalar |
Definition at line 660 of file matrix.cpp.
References get_data().
Combined matrix-multipliation and assignement operator.
rhs | the right-hand-side Matrix |
Definition at line 573 of file matrix.cpp.
References num_cols(), and num_rows().
Matrix & fawkes::Matrix::operator*= | ( | const float & | f | ) |
Combined scalar multiplication and assignment operator.
f | a scalar |
Definition at line 678 of file matrix.cpp.
Addition operator.
Adds the corresponding elements of the two matrices.
rhs | the right-hand-side matrix |
Definition at line 727 of file matrix.cpp.
References get_data(), num_cols(), and num_rows().
Add-assign operator.
rhs | the right-hand-side matrix |
Definition at line 752 of file matrix.cpp.
References get_data(), num_cols(), and num_rows().
Subtraction operator.
Subtracts the corresponding elements of the two matrices.
rhs | the right-hand-side matrix |
Definition at line 776 of file matrix.cpp.
References get_data(), num_cols(), and num_rows().
Subtract-assign operator.
rhs | the right-hand-side matrix |
Definition at line 802 of file matrix.cpp.
References get_data(), num_cols(), and num_rows().
Matrix fawkes::Matrix::operator/ | ( | const float & | f | ) | const |
Divide every element of the matrix with the given scalar.
f | a scalar |
Definition at line 693 of file matrix.cpp.
References get_data().
Matrix & fawkes::Matrix::operator/= | ( | const float & | f | ) |
Combined scalar division and assignment operator.
f | a scalar |
Definition at line 711 of file matrix.cpp.
bool fawkes::Matrix::operator== | ( | const Matrix & | rhs | ) | const |
Comparison operator.
rhs | the right-hand-side Matrix |
Definition at line 826 of file matrix.cpp.
References get_data(), num_cols(), and num_rows().
void fawkes::Matrix::overlay | ( | unsigned int | row, |
unsigned int | col, | ||
const Matrix & | over | ||
) |
Overlays another matrix over this matrix.
row | the top-most row from which onwards the the elements are exchanged for corresponding elements in the given matrix |
col | the left-most column from which onwards the the elements are exchanged for corresponding elements in the given matrix |
over | the matrix to be overlaid |
Definition at line 446 of file matrix.cpp.
Referenced by firevision::ProjectiveCam::get_GPA_p(), invert(), firevision::Calibration::K(), and firevision::ProjectiveCam::set_location().
void fawkes::Matrix::print_info | ( | const char * | name = 0 , |
const char * | col_sep = 0 , |
||
const char * | row_sep = 0 |
||
) | const |
Print matrix to standard out.
name | a name that is printed before the content of the matrix (not required) |
col_sep | a string used to separate columns (defaults to '\t') |
row_sep | a string used to separate rows (defaults to '\n') |
Definition at line 891 of file matrix.cpp.
References num_cols(), and num_rows().
Referenced by firevision::ProjectiveCam::print_info().
void fawkes::Matrix::size | ( | unsigned int & | num_rows, |
unsigned int & | num_cols | ||
) | const |
Determines the dimensions of the matrix.
num_cols | pointer to an unsigned int to where the number of columns is copied to |
num_rows | pointer to an unsigned int to where the number of rows is copied to |
Definition at line 162 of file matrix.cpp.
References num_cols(), and num_rows().
Referenced by get_diag(), and firevision::Calibration::K().
Matrix & fawkes::Matrix::transpose | ( | ) |
Transposes the matrix.
Definition at line 234 of file matrix.cpp.