Fawkes API  Fawkes Development Version
fawkes::Matrix Class Reference

A general matrix class. More...

#include <>>

Inheritance diagram for fawkes::Matrix:

Public Member Functions

 Matrix (unsigned int num_rows=0, unsigned int num_cols=0, float *data=0, bool manage_own_memory=true)
 Constructor. More...
 
 Matrix (const Matrix &tbc)
 Copy-constructor. More...
 
 ~Matrix ()
 Destructor. More...
 
void size (unsigned int &num_rows, unsigned int &num_cols) const
 Determines the dimensions of the matrix. More...
 
unsigned int num_rows () const
 Return the number of rows in the Matrix. More...
 
unsigned int num_cols () const
 Return the number of columns in the Matrix. More...
 
Matrixid ()
 Sets the diagonal elements to 1.0 and all other to 0.0. More...
 
Matrixtranspose ()
 Transposes the matrix. More...
 
Matrix get_transpose () const
 Computes a matrix that is the transposed of this matrix. More...
 
Matrixinvert ()
 Inverts the matrix. More...
 
Matrix get_inverse () const
 Computes a matrix that is the inverse of this matrix. More...
 
float det () const
 Computes the determinant of the matrix. More...
 
const float * get_data () const
 Returns the const data pointer. More...
 
float * get_data ()
 Returns the data pointer. More...
 
Matrix get_submatrix (unsigned int row, unsigned int col, unsigned int num_rows, unsigned int num_cols) const
 Returns a submatrix of the matrix. More...
 
void overlay (unsigned int row, unsigned int col, const Matrix &m)
 Overlays another matrix over this matrix. More...
 
float operator() (unsigned int row, unsigned int col) const
 (Read-only) Access-operator. More...
 
float & operator() (unsigned int row, unsigned int col)
 (RW) Access operator. More...
 
Matrixoperator= (const Matrix &rhs)
 Assignment operator. More...
 
Matrix operator* (const Matrix &rhs) const
 Matrix multiplication operator. More...
 
Matrixoperator*= (const Matrix &rhs)
 Combined matrix-multipliation and assignement operator. More...
 
Vector operator* (const Vector &cv) const
 Multiply the matrix with given vector. More...
 
Matrix operator* (const float &f) const
 Mulitply every element of the matrix with the given scalar. More...
 
Matrixoperator*= (const float &f)
 Combined scalar multiplication and assignment operator. More...
 
Matrix operator/ (const float &f) const
 Divide every element of the matrix with the given scalar. More...
 
Matrixoperator/= (const float &f)
 Combined scalar division and assignment operator. More...
 
Matrix operator+ (const Matrix &rhs) const
 Addition operator. More...
 
Matrixoperator+= (const Matrix &rhs)
 Add-assign operator. More...
 
Matrix operator- (const Matrix &rhs) const
 Subtraction operator. More...
 
Matrixoperator-= (const Matrix &rhs)
 Subtract-assign operator. More...
 
bool operator== (const Matrix &rhs) const
 Comparison operator. More...
 
void print_info (const char *name=0, const char *col_sep=0, const char *row_sep=0) const
 Print matrix to standard out. More...
 

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. More...
 
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. More...
 

Detailed Description

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).

Author
Daniel Beck
Masrur Doostdar
Christof Rath

Definition at line 33 of file matrix.h.

Constructor & Destructor Documentation

fawkes::Matrix::Matrix ( unsigned int  num_rows = 0,
unsigned int  num_cols = 0,
float *  data = 0,
bool  manage_own_memory = true 
)

Constructor.

Parameters
num_rowsnumber of rows
num_colsnumber of columns
dataarray containing elements of the matrix in row-by-row-order
manage_own_memoryif 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 102 of file matrix.cpp.

References num_cols(), and num_rows().

Referenced by firevision::CCDCalibration::CCDCalibration().

fawkes::Matrix::Matrix ( const Matrix tbc)

Copy-constructor.

Parameters
tbcmatrix to be copied

Definition at line 138 of file matrix.cpp.

fawkes::Matrix::~Matrix ( )

Destructor.

Definition at line 151 of file matrix.cpp.

Member Function Documentation

float fawkes::Matrix::det ( ) const

Computes the determinant of the matrix.

Returns
the determinant

Definition at line 374 of file matrix.cpp.

Referenced by num_cols().

const float * fawkes::Matrix::get_data ( ) const
inline

Returns the const data pointer.

Returns
the 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

Returns the data pointer.

Returns
the data pointer

Definition at line 58 of file matrix.h.

References get_submatrix(), operator()(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator=(), operator==(), overlay(), and print_info().

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.

Parameters
sizedimension of the matrix
valueof the elements of the main diagonal
data_bufferif != NULL the given float array will be used as data internal data store (the object will not perform any memory management in this case)
Returns
the diag matrix object

Definition at line 207 of file matrix.cpp.

References size().

Referenced by get_id(), and num_cols().

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.

Parameters
sizedimension of the matrix
data_bufferif != NULL the given float array will be used as data internal data store (the object will not perform any memory management in this case)
Returns
the id matrix object

Definition at line 193 of file matrix.cpp.

References get_diag().

Referenced by invert(), and num_cols().

Matrix fawkes::Matrix::get_inverse ( ) const

Computes a matrix that is the inverse of this matrix.

Returns
a matrix that is the inverse of this matrix

Definition at line 362 of file matrix.cpp.

References invert().

Referenced by num_cols().

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.

Parameters
rowthe row in the original matrix of the top-left element in the submatrix
colthe column in the original matrix of the top-left element in the submatrix
num_rowsthe number of rows of the submatrix
num_colsthe number of columns of the submatrix
Returns
the submatrix

Definition at line 415 of file matrix.cpp.

References get_data(), num_cols(), and num_rows().

Referenced by get_data(), firevision::ProjectiveCam::get_GPA_p(), fawkes::HomTransform::invert(), firevision::Calibration::K(), and firevision::ProjectiveCam::set_location().

Matrix fawkes::Matrix::get_transpose ( ) const

Computes a matrix that is the transposed of this matrix.

Returns
a matrix that is the transposed of this matrix

Definition at line 294 of file matrix.cpp.

References get_data().

Referenced by num_cols().

Matrix & fawkes::Matrix::id ( )

Sets the diagonal elements to 1.0 and all other to 0.0.

Returns
a reference to the matrix object

Definition at line 172 of file matrix.cpp.

References num_cols(), and num_rows().

Referenced by firevision::Calibration::Calibration(), fawkes::HomTransform::HomTransform(), firevision::Calibration::K(), num_cols(), and fawkes::HomTransform::reset().

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)).

Returns
a reference to the matrix object which contains now the inverted matrix

Definition at line 317 of file matrix.cpp.

References get_id(), and overlay().

Referenced by get_inverse(), num_cols(), and firevision::ProjectiveCam::set_location().

unsigned int fawkes::Matrix::num_cols ( ) const
inline

Return the number of columns in the Matrix.

Returns
the number of columns

Definition at line 43 of file matrix.h.

References det(), get_diag(), get_id(), get_inverse(), get_transpose(), id(), invert(), and transpose().

Referenced by get_submatrix(), fawkes::HomTransform::HomTransform(), 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.

Returns
the number of rows

Definition at line 42 of file matrix.h.

Referenced by get_submatrix(), fawkes::HomTransform::HomTransform(), 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)

Parameters
rowthe row of the element
colthe column of the element
Returns
the value of the specified element

Definition at line 472 of file matrix.cpp.

Referenced by get_data().

float & fawkes::Matrix::operator() ( unsigned int  row,
unsigned int  col 
)

(RW) Access operator.

see the read-only access operator for operational details

Parameters
rowthe row of the element
colthe column of the element
Returns
a reference to the specified element

Definition at line 489 of file matrix.cpp.

Matrix fawkes::Matrix::operator* ( const Matrix rhs) const

Matrix multiplication operator.

(Matrix)a.operator*((Matrix)b) computes a * b; i.e., the 2nd matrix is right-multiplied to the 1st matrix

Parameters
rhsthe right-hand-side matrix
Returns
the product of the two matrices (a * b)

Definition at line 535 of file matrix.cpp.

References num_cols(), and num_rows().

Referenced by get_data().

Vector fawkes::Matrix::operator* ( const Vector v) const

Multiply the matrix with given vector.

Parameters
va vector
Returns
the result of the matrix-vector multiplication

Definition at line 627 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.

Parameters
fa scalar
Returns
the result of the multiplication

Definition at line 659 of file matrix.cpp.

References get_data().

Matrix & fawkes::Matrix::operator*= ( const Matrix rhs)

Combined matrix-multipliation and assignement operator.

Parameters
rhsthe right-hand-side Matrix
Returns
a reference to the Matrix that contains the result of the multiplication

Definition at line 572 of file matrix.cpp.

References num_cols(), and num_rows().

Referenced by get_data().

Matrix & fawkes::Matrix::operator*= ( const float &  f)

Combined scalar multiplication and assignment operator.

Parameters
fa scalar
Returns
reference to the result

Definition at line 677 of file matrix.cpp.

Matrix fawkes::Matrix::operator+ ( const Matrix rhs) const

Addition operator.

Adds the corresponding elements of the two matrices.

Parameters
rhsthe right-hand-side matrix
Returns
the resulting matrix

Definition at line 726 of file matrix.cpp.

References get_data(), num_cols(), and num_rows().

Referenced by get_data().

Matrix & fawkes::Matrix::operator+= ( const Matrix rhs)

Add-assign operator.

Parameters
rhsthe right-hand-side matrix
Returns
a reference to the resulting matrix (this)

Definition at line 751 of file matrix.cpp.

References get_data(), num_cols(), and num_rows().

Referenced by get_data().

Matrix fawkes::Matrix::operator- ( const Matrix rhs) const

Subtraction operator.

Subtracts the corresponding elements of the two matrices.

Parameters
rhsthe right-hand-side matrix
Returns
the resulting matrix

Definition at line 775 of file matrix.cpp.

References get_data(), num_cols(), and num_rows().

Referenced by get_data().

Matrix & fawkes::Matrix::operator-= ( const Matrix rhs)

Subtract-assign operator.

Parameters
rhsthe right-hand-side matrix
Returns
a reference to the resulting matrix (this)

Definition at line 801 of file matrix.cpp.

References get_data(), num_cols(), and num_rows().

Referenced by get_data().

Matrix fawkes::Matrix::operator/ ( const float &  f) const

Divide every element of the matrix with the given scalar.

Parameters
fa scalar
Returns
the result of the divison

Definition at line 692 of file matrix.cpp.

References get_data().

Referenced by get_data().

Matrix & fawkes::Matrix::operator/= ( const float &  f)

Combined scalar division and assignment operator.

Parameters
fa scalar
Returns
reference to the result

Definition at line 710 of file matrix.cpp.

Referenced by get_data().

Matrix & fawkes::Matrix::operator= ( const Matrix m)

Assignment operator.

Copies the data form the rhs Matrix to the lhs Matrix.

Parameters
mthe rhs Matrix
Returns
a reference to this Matrix

Definition at line 506 of file matrix.cpp.

Referenced by get_data().

bool fawkes::Matrix::operator== ( const Matrix rhs) const

Comparison operator.

Parameters
rhsthe right-hand-side Matrix
Returns
true if every element of this matrix is equal to the corresponding element of the other matrix

Definition at line 825 of file matrix.cpp.

References get_data(), num_cols(), and num_rows().

Referenced by get_data().

void fawkes::Matrix::overlay ( unsigned int  row,
unsigned int  col,
const Matrix over 
)

Overlays another matrix over this matrix.

Parameters
rowthe top-most row from which onwards the the elements are exchanged for corresponding elements in the given matrix
colthe left-most column from which onwards the the elements are exchanged for corresponding elements in the given matrix
overthe matrix to be overlaid

Definition at line 445 of file matrix.cpp.

Referenced by get_data(), firevision::ProjectiveCam::get_GPA_p(), fawkes::HomTransform::invert(), 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.

Parameters
namea name that is printed before the content of the matrix (not required)
col_sepa string used to separate columns (defaults to '\t')
row_sepa string used to separate rows (defaults to '\n')

Definition at line 890 of file matrix.cpp.

References num_cols(), and num_rows().

Referenced by get_data(), fawkes::HomTransform::print_info(), and firevision::ProjectiveCam::print_info().

void fawkes::Matrix::size ( unsigned int &  num_rows,
unsigned int &  num_cols 
) const

Determines the dimensions of the matrix.

Parameters
num_colspointer to an unsigned int to where the number of columns is copied to
num_rowspointer to an unsigned int to where the number of rows is copied to

Definition at line 161 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.

Returns
a reference to the matrix object now containing the transposed matrix

Definition at line 233 of file matrix.cpp.

Referenced by fawkes::HomTransform::invert(), and num_cols().


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