last update 20 Sep 2009 |
#include <cvrMatrix.h>
Public Types | |
Internal classes and types | |
typedef genericMatrix< T > ::value_type | value_type |
typedef genericMatrix< T > ::size_type | size_type |
typedef vector< T > | row_type |
typedef genericMatrix< T > ::iterator | iterator |
typedef genericMatrix< T > ::const_iterator | const_iterator |
Public Member Functions | |
matrix () | |
matrix (const int rows, const int cols) | |
matrix (const size_type &size) | |
matrix (const int rows, const int cols, const T &iniValue) | |
matrix (const size_type &size, const T &iniValue) | |
matrix (const int rows, const int cols, const T data[]) | |
matrix (const size_type &dim, const T data[]) | |
matrix (const int rows, const int cols, T data[], const eConstantReference constRef) | |
matrix (const size_type &theSize, T data[], const eConstantReference constRef) | |
matrix (const genericMatrix< T > &other) | |
matrix (const genericMatrix< T > &other, const int fromRow, const int fromCol, const int toRow=container::MaxIndex, const int toCol=container::MaxIndex) | |
matrix (const genericMatrix< T > &other, const size_type &from, const size_type &to) | |
matrix (const genericMatrix< T > &other, const genericVector< int > &rows) | |
virtual | ~matrix () |
row_type & | getRow (const int row) |
const row_type & | getRow (const int row) const |
row_type & | operator[] (const int row) |
const row_type & | operator[] (const int row) const |
row_type | getRowCopy (const int row) const |
void | getRowCopy (const int row, row_type &theRow) const |
row_type | getColumnCopy (const int col) const |
void | getColumnCopy (const int col, row_type &theCol) const |
row_type | getDiagonal () const |
void | getDiagonal (row_type &diag) const |
void | setIdentity (const T scale=T(1)) |
matrix< T > & | copy (const genericMatrix< T > &other) |
matrix< T > & | copy (const genericMatrix< T > &other, const int fromRow, const int fromCol, const int toRow=container::MaxIndex, const int toCol=container::MaxIndex) |
matrix< T > & | copy (const genericMatrix< T > &other, const size_type &from, const size_type &to) |
matrix< T > & | copy (const genericMatrix< T > &other, const irectangle &window) |
matrix< T > & | copyRows (const genericMatrix< T > &other, const genericVector< int > &idx) |
matrix< T > & | copyColumns (const genericMatrix< T > &other, const genericVector< int > &idx) |
template<typename U > | |
matrix< T > & | castFrom (const genericMatrix< U > &other) |
matrix< T > & | castFrom (const genericMatrix< T > &other) |
template<typename U > | |
matrix< T > & | castFrom (const genericMatrix< U > &other, const int fromRow, const int fromCol, const int toRow=container::MaxIndex, const int toCol=container::MaxIndex) |
matrix< T > & | castFrom (const genericMatrix< T > &other, const int fromRow, const int fromCol, const int toRow=container::MaxIndex, const int toCol=container::MaxIndex) |
const std::string & | name () const |
virtual matrix< T > * | clone () const |
virtual matrix< T > * | newInstance () const |
bool | prettyCloseTo (const genericMatrix< T > &other, const T &tolerance) const |
matrix< T > & | operator= (const genericMatrix< T > &other) |
Apply Methods. | |
matrix< T > & | apply (T(*function)(T)) |
matrix< T > & | apply (const genericMatrix< T > &other, T(*function)(T)) |
matrix< T > & | apply (T(*function)(const T &)) |
matrix< T > & | apply (const genericMatrix< T > &other, T(*function)(const T &)) |
matrix< T > & | apply (const genericMatrix< T > &other, T(*function)(const T &, const T &)) |
matrix< T > & | apply (const genericMatrix< T > &other, T(*function)(T, T)) |
matrix< T > & | apply (const genericMatrix< T > &a, const genericMatrix< T > &b, T(*function)(const T &, const T &)) |
matrix< T > & | apply (const genericMatrix< T > &a, const genericMatrix< T > &b, T(*function)(T, T)) |
Arithmetical Operations | |
matrix< T > & | add (const genericMatrix< T > &other) |
matrix< T > & | add (const genericMatrix< T > &a, const genericMatrix< T > &b) |
matrix< T > & | add (const T value) |
matrix< T > & | add (const genericMatrix< T > &other, const T value) |
matrix< T > & | operator+= (const T value) |
matrix< T > & | operator+= (const genericMatrix< T > &other) |
matrix< T > | operator+ (const genericMatrix< T > &other) const |
matrix< T > | operator+ (const T value) const |
matrix< T > | operator- (const genericMatrix< T > &other) const |
matrix< T > | operator- (const T value) const |
matrix< T > & | addScaled (const T b, const genericMatrix< T > &other) |
matrix< T > & | addScaled (const genericMatrix< T > &matA, const T b, const genericMatrix< T > &matB) |
matrix< T > & | addScaled (const T a, const genericMatrix< T > &first, const T b, const genericMatrix< T > &second) |
matrix< T > & | subtract (const genericMatrix< T > &other) |
matrix< T > & | subtract (const genericMatrix< T > &a, const genericMatrix< T > &b) |
matrix< T > & | subtract (const T value) |
matrix< T > & | subtract (const genericMatrix< T > &other, const T value) |
matrix< T > & | operator-= (const T value) |
matrix< T > & | operator-= (const genericMatrix< T > &other) |
matrix< T > & | multiply (const genericMatrix< T > &other) |
matrix< T > & | multiply (const matrix< T > &first, const genericMatrix< T > &second) |
row_type & | multiply (const row_type &other, row_type &result) const |
row_type & | multiply (row_type &srcdest) const |
matrix< T > & | multiply (const T value) |
matrix< T > & | multiply (const genericMatrix< T > &other, const T value) |
matrix< T > & | operator*= (const genericMatrix< T > &other) |
matrix< T > & | operator*= (const T value) |
matrix< T > | operator* (const genericMatrix< T > &other) const |
row_type & | leftMultiply (const row_type &vct, row_type &result) const |
row_type & | leftMultiply (row_type &srcDest) const |
matrix< T > & | leftMultiply (const matrix< T > &mat) |
matrix< T > & | divide (const T value) |
matrix< T > & | divide (const genericMatrix< T > &other, const T value) |
matrix< T > & | operator/= (const T value) |
matrix< T > & | emultiply (const genericMatrix< T > &other) |
matrix< T > & | emultiply (const genericMatrix< T > &a, const genericMatrix< T > &b) |
matrix< T > & | edivide (const genericMatrix< T > &other) |
matrix< T > & | edivide (const genericMatrix< T > &a, const genericMatrix< T > &b) |
matrix< T > & | outerProduct (const row_type &a, const row_type &b) |
matrix< T > & | transpose () |
template<typename U > | |
matrix< T > & | transpose (const genericMatrix< U > &other) |
T | computeSumOfElements () const |
T | computeProductOfElements () const |
T | trace () const |
Find extreme values | |
T | findMinimum () const |
size_type | findIndexOfMinimum () const |
T | findMaximum () const |
size_type | findIndexOfMaximum () const |
void | findExtremes (T &theMinimum, T &theMaximum) const |
void | findIndexOfExtremes (size_type &theIdxMinimum, size_type &theIdxMaximum) const |
Protected Member Functions | |
Memory allocation and deallocation | |
Restrict all memory allocation and deallocation to these functions. | |
virtual row_type * | allocNewRows (const int n) |
The cvr::matrix class allows the representation of n x m matrices. The rows will be indexed between 0 and n-1, and the columns between 0 and m-1.
All types defined in cvrTypes.h use static members and can be contained by the cvr::vector and cvr::matrix classes.
The matrix class is a container class implemented as template.
If you need to create a matrix of floats with 20 rows and 15 columns, all elements initialized with an initial value of 4.27 just create it:
cvr::matrix<float> myMat(20,15,4.27f) // creates matrix with 300 elements // all initialized with 4.27f
To access the matrix elements use the access operators. There are many possibilities. With at(const int row, const int col) is possible to access an element directly. With getRow(const int row) you can get the row vector. You cannot for instance resize nor change the memory referenced in this vector (see cvr::vector::resize). For example:
float accu = 0; // initialize accumulator cvr::matrix<float> myMat(20,15,4.27f) cvr::vector<float> myVct; for (int j = 0; j < myMat.rows(); j++) { for (int i = 0; i < myMat.columns(); i++) { tmp += myMat.at(j,i); // access each element of the matrix: // j is the row and i the column } } myMat.getRowCopy(5,myVct); // copy the sixth row in myVct! myVct.resize(6); // Valid, the vector has its own memory! myMat.at(5).resize(6) // ERROR!! the vector is not resizable!
The image representation in the CVR-Lib is based on the cvr::matrix class. It is quite confusing to use first the y-coordinate and then the x-coordinate to access the image elements. To avoid confusion use the cvr::point class to access the elements of the matrix:
cvr::channel8 aChannel(20,15); // creates an 8-bit image cvr::channel8::value_type tmp; // tmp is of the element type of the // channel8! cvr::ipoint p; for (p.y = 0; p.y < aChannel.rows(); p.y++) { for (p.x = 0; p.x < aChannel.columns(); p.x++) { tmp += aChannel.at(p); // access each element of the matrix: // equivalent to: tmp += aChannel.at(p.y,p.x)! } }
The matrix has following methods:
typedef genericMatrix<T>::const_iterator cvr::matrix< T >::const_iterator |
typedef genericMatrix<T>::iterator cvr::matrix< T >::iterator |
typedef vector<T> cvr::matrix< T >::row_type |
typedef genericMatrix<T>::size_type cvr::matrix< T >::size_type |
typedef genericMatrix<T>::value_type cvr::matrix< T >::value_type |
cvr::matrix< T >::matrix | ( | ) | [explicit] |
Default constructor creates an empty matrix.
cvr::matrix< T >::matrix | ( | const int | rows, | |
const int | cols | |||
) | [explicit] |
cvr::matrix< T >::matrix | ( | const size_type & | size | ) | [explicit] |
cvr::matrix< T >::matrix | ( | const int | rows, | |
const int | cols, | |||
const T & | iniValue | |||
) | [explicit] |
cvr::matrix< T >::matrix | ( | const size_type & | size, | |
const T & | iniValue | |||
) | [explicit] |
Create a connected size.y
x size.x
matrix and initializes all elements with iniValue.
size | cvr::point with the size of the matrix (size.x is the number of columns and size.y the number of rows) | |
iniValue | all elements will be initialized with this value |
cvr::matrix< T >::matrix | ( | const int | rows, | |
const int | cols, | |||
const T | data[] | |||
) | [explicit] |
Create a connected rows
x cols
Matrix and initializes all elements with the data pointed by data.
The first cols-elements of the data will be copied on the first row, the next ones on the second row and so on.
cvr::matrix< T >::matrix | ( | const size_type & | dim, | |
const T | data[] | |||
) | [explicit] |
Create a connected dim.y
x dim.x
matrix and initializes all elements with the data pointed by data.
The first dim.x -elements of the data will be copied on the first row, the next ones on the second row and so on.
dim | matrix dimensions | |
data | pointer to the memory block with the data to be initialized with. |
cvr::matrix< T >::matrix | ( | const int | rows, | |
const int | cols, | |||
T | data[], | |||
const eConstantReference | constRef | |||
) | [explicit] |
Create a rows x cols genericMatrix and use the given data as if it was given through the useExternData().
rows | number of rows of the genericMatrix | |
cols | number of columns of the genericMatrix | |
data | pointer to the memory block with the data to be initialized with. | |
constRef | indicate if the memory block for the matrix can or cannot be modified |
cvr::matrix< T >::matrix | ( | const size_type & | theSize, | |
T | data[], | |||
const eConstantReference | constRef | |||
) | [explicit] |
Create a rows x cols genericMatrix and use the given data as if it was given through the useExternData().
theSize | number of columns and rows of the genericMatrix | |
data | pointer to the memory block with the data to be initialized with. | |
constRef | indicate if the memory block for the matrix can or cannot be modified |
cvr::matrix< T >::matrix | ( | const genericMatrix< T > & | other | ) | [explicit] |
cvr::matrix< T >::matrix | ( | const genericMatrix< T > & | other, | |
const int | fromRow, | |||
const int | fromCol, | |||
const int | toRow = container::MaxIndex , |
|||
const int | toCol = container::MaxIndex | |||
) | [explicit] |
Copy constructor.
Create this matrix as a connected copy of another matrix for this const version, the data will be always copied! It is also possible to create a copy of a submatrix of another matrix.
other | the matrix to be copied. | |
fromRow | initial row of the other matrix to be copied | |
fromCol | initial column of the other matrix to be copied | |
toRow | last row to be copied of the other matrix | |
toCol | last column to be copied of the other matrix |
cvr::matrix<int> m(4,6,0); // integer matrix with 25 elements // ... // initialize Matrix with: // 0 1 2 3 4 5 // 2 1 5 4 0 3 // 1 2 1 2 3 2 // 3 3 2 1 2 3 cvr::matrix<int> sm(m,0,2,1,3) // last line will lead to // following contents in sm: // 1 2 3 // 1 5 4 // 2 1 2
cvr::matrix< T >::matrix | ( | const genericMatrix< T > & | other, | |
const size_type & | from, | |||
const size_type & | to | |||
) | [explicit] |
Copy constructor.
Copy a submatrix of another matrix.
cvr::matrix< T >::matrix | ( | const genericMatrix< T > & | other, | |
const genericVector< int > & | rows | |||
) | [explicit] |
Copy constructor.
Create this matrix as a connected copy of another matrix taking only the rows indicated by the vector. for this const version, the data will be always copied! Multiple occurence of one row index in rows is allowed.
other | the matrix to be copied. | |
rows | inidices of the rows to be copied |
cvr::vector<int> rows(2); // initialize with // 1 3 cvr::matrix<int> m(4,6,0); // integer matrix with 25 elements // ... // initialize Matrix with: // 0 1 2 3 4 5 // 2 1 5 4 0 3 // 1 2 1 2 3 2 // 3 3 2 1 2 3 cvr::matrix<int> sm(m,rows) // last line will lead to // following contents in sm: // 2 1 5 4 0 3 // 3 3 2 1 2 3
virtual cvr::matrix< T >::~matrix | ( | ) | [virtual] |
Destructor.
matrix<T>& cvr::matrix< T >::add | ( | const genericMatrix< T > & | other, | |
const T | value | |||
) |
matrix<T>& cvr::matrix< T >::add | ( | const T | value | ) |
matrix<T>& cvr::matrix< T >::add | ( | const genericMatrix< T > & | a, | |
const genericMatrix< T > & | b | |||
) |
matrix<T>& cvr::matrix< T >::add | ( | const genericMatrix< T > & | other | ) |
matrix<T>& cvr::matrix< T >::addScaled | ( | const T | a, | |
const genericMatrix< T > & | first, | |||
const T | b, | |||
const genericMatrix< T > & | second | |||
) |
Leave the scaled sum of two matrices in this matrix.
The matrices must be of the same types and dimensions. Let be the first matrix and the second matrix with corresponding scaling factors and , further this matrix, then this method performs:
a | scaling factor for first | |
first | the first matrix to be added after scaling | |
b | scaling factor for second | |
second | the second matrix to be added after scaling |
matrix<T>& cvr::matrix< T >::addScaled | ( | const genericMatrix< T > & | matA, | |
const T | b, | |||
const genericMatrix< T > & | matB | |||
) |
matrix<T>& cvr::matrix< T >::addScaled | ( | const T | b, | |
const genericMatrix< T > & | other | |||
) |
virtual row_type* cvr::matrix< T >::allocNewRows | ( | const int | n | ) | [inline, protected, virtual] |
matrix<T>& cvr::matrix< T >::apply | ( | const genericMatrix< T > & | a, | |
const genericMatrix< T > & | b, | |||
T(*)(T, T) | function | |||
) | [inline] |
A two-parameter C-function receives the i-th elements of both given matrices and leaves the result here.
Note that both matrices must have the same size!
a | the first matrix | |
b | the second matrix | |
function | a pointer to C-function with two parameters |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::apply | ( | const genericMatrix< T > & | a, | |
const genericMatrix< T > & | b, | |||
T(*)(const T &, const T &) | function | |||
) | [inline] |
A two-parameter C-function receives the i-th elements of both given matrices and leaves the result here.
Note that both matrices must have the same size!
a | the first matrix | |
b | the second matrix | |
function | a pointer to C-function with two parameters |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::apply | ( | const genericMatrix< T > & | other, | |
T(*)(T, T) | function | |||
) | [inline] |
A two-parameter C-function receives the i-th elements of this and the given matrix and the result will be left in this matrix.
Note that both matrices must have the same size!
other | the second matrix to be considered (the first matrix will be this object!) | |
function | a pointer to C-function with two parameters |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::apply | ( | const genericMatrix< T > & | other, | |
T(*)(const T &, const T &) | function | |||
) | [inline] |
A two-parameter C-function receives the i-th elements of this and the given matrix and the result will be left in this matrix.
Note that both matrices must have the same size!
other | the second matrix to be considered (the first matrix will be this object!) | |
function | a pointer to C-function with two parameters |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::apply | ( | const genericMatrix< T > & | other, | |
T(*)(const T &) | function | |||
) | [inline] |
Applies a C-function to each element of the other matrix.
other | the matrix which elements will go through the given function. | |
function | a pointer to a C-function |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::apply | ( | T(*)(const T &) | function | ) | [inline] |
Applies a C-function to each element of the matrix.
function | a pointer to a C-function |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::apply | ( | const genericMatrix< T > & | other, | |
T(*)(T) | function | |||
) | [inline] |
Applies a C-function to each element of the other matrix.
other | the matrix which elements will go through the given function. | |
function | a pointer to a C-function |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::apply | ( | T(*)(T) | function | ) | [inline] |
Applies a C-function to each element of the matrix.
function | a pointer to a C-function |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::castFrom | ( | const genericMatrix< T > & | other, | |
const int | fromRow, | |||
const int | fromCol, | |||
const int | toRow = container::MaxIndex , |
|||
const int | toCol = container::MaxIndex | |||
) |
This is just an alias for copy(const genericMatrix<T>&, const int fromRow, const int fromCol, const int toRow, const int toCol) to facilitate generic programming.
other | The genericMatrix to be copied. | |
fromRow | initial row of the other genericMatrix to be copied | |
fromCol | initial column of the other genericMatrix to be copied | |
toRow | last row to be copied of the other genericMatrix | |
toCol | last column to be copied of the other genericMatrix |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::castFrom | ( | const genericMatrix< U > & | other, | |
const int | fromRow, | |||
const int | fromCol, | |||
const int | toRow = container::MaxIndex , |
|||
const int | toCol = container::MaxIndex | |||
) | [inline] |
Copy a submatrix of the other genericMatrix by casting each of its elements.
other | The genericMatrix to be casted | |
fromRow | initial row of the other genericMatrix to be copied | |
fromCol | initial column of the other genericMatrix to be copied | |
toRow | last row to be copied of the other genericMatrix | |
toCol | last column to be copied of the other genericMatrix |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::castFrom | ( | const genericMatrix< T > & | other | ) | [inline] |
Copy the other matrix by casting each of its elements.
This 'specialization' ensures that the copy() method is used when U==T.
other | The matrix to be casted (copied) |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::castFrom | ( | const genericMatrix< U > & | other | ) | [inline] |
Copy the other matrix by casting each of its elements Example:.
cvr::matrix<int> matA(10,10,1);// a matrix of integers cvr::matrix<double> matB; // a matrix of doubles matB.castFrom(matA); // this will copy matA in matB!!
other | The matrix to be casted |
Reimplemented from cvr::genericMatrix< T >.
virtual matrix<T>* cvr::matrix< T >::clone | ( | ) | const [virtual] |
Create a clone of this matrix.
Reimplemented from cvr::genericMatrix< T >.
Reimplemented in cvr::channel, cvr::channel32, cvr::channel8, cvr::channelC, and cvr::image.
T cvr::matrix< T >::computeProductOfElements | ( | ) | const |
Calculate the product of all elements of the vector.
This member can be used with classes which define the operator '*='
T cvr::matrix< T >::computeSumOfElements | ( | ) | const |
Calculate the sum of all elements of the matrix.
This member can be used with classes which define the operator '+='
Reimplemented in cvr::channel32, and cvr::channel8.
matrix<T>& cvr::matrix< T >::copy | ( | const genericMatrix< T > & | other, | |
const irectangle & | window | |||
) | [inline] |
Assigment operator.
Copy the contents of other in this object.
The result of the copy is always a connected matrix. I.e. you cannot copy the sub-matrix property of another matrix.
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::copy | ( | const genericMatrix< T > & | other, | |
const size_type & | from, | |||
const size_type & | to | |||
) | [inline] |
Assigment operator.
copy the contents of other in this object.
The result of the copy is always a connected matrix. I.e. you cannot copy the sub-matrix property of another matrix.
other | the other matrix to be copied | |
from | initial indices of submatrix to be copied | |
to | final indices of submatrix to be copied (included) |
matrix<T>& cvr::matrix< T >::copy | ( | const genericMatrix< T > & | other, | |
const int | fromRow, | |||
const int | fromCol, | |||
const int | toRow = container::MaxIndex , |
|||
const int | toCol = container::MaxIndex | |||
) | [inline] |
Assigment operator.
copy the contents of other in this object.
The result of the copy is always a connected matrix. I.e. you cannot copy the sub-matrix property of another matrix.
other | the other matrix to be copied | |
fromRow | initial row of the other matrix to be copied | |
fromCol | initial column of the other matrix to be copied | |
toRow | last row to be copied of the other matrix | |
toCol | last column to be copied of the other matrix |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::copy | ( | const genericMatrix< T > & | other | ) | [inline] |
Assigment operator.
Copy the contents of other in this object.
The result of the copy is always a connected matrix. I.e. you cannot copy the sub-matrix property of another matrix.
other | the other matrix to be copied |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::copyColumns | ( | const genericMatrix< T > & | other, | |
const genericVector< int > & | idx | |||
) | [inline] |
Assigment operator.
Copy the contents of the specified columns of other into this object. Multiple occurence of one column index in idx is allowed.
other | the other matrix to be copied | |
idx | indices of the rows to be copied. |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::copyRows | ( | const genericMatrix< T > & | other, | |
const genericVector< int > & | idx | |||
) | [inline] |
Assigment operator.
Copy the contents of the specified rows of other into this object. Multiple occurence of one row index in idx is allowed.
other | the other matrix to be copied | |
idx | indices of the rows to be copied. |
Reimplemented from cvr::genericMatrix< T >.
matrix<T>& cvr::matrix< T >::divide | ( | const genericMatrix< T > & | other, | |
const T | value | |||
) |
matrix<T>& cvr::matrix< T >::divide | ( | const T | value | ) |
matrix<T>& cvr::matrix< T >::edivide | ( | const genericMatrix< T > & | a, | |
const genericMatrix< T > & | b | |||
) |
matrix<T>& cvr::matrix< T >::edivide | ( | const genericMatrix< T > & | other | ) |
matrix<T>& cvr::matrix< T >::emultiply | ( | const genericMatrix< T > & | a, | |
const genericMatrix< T > & | b | |||
) |
matrix<T>& cvr::matrix< T >::emultiply | ( | const genericMatrix< T > & | other | ) |
void cvr::matrix< T >::findExtremes | ( | T & | theMinimum, | |
T & | theMaximum | |||
) | const |
Get the extremes of the matrix (smallest and biggest elements).
void cvr::matrix< T >::findIndexOfExtremes | ( | size_type & | theIdxMinimum, | |
size_type & | theIdxMaximum | |||
) | const |
Get the indices of the extremes of the matrix (smallest and biggest elements).
size_type cvr::matrix< T >::findIndexOfMaximum | ( | ) | const |
Get the index of the biggest element of the matrix.
size_type cvr::matrix< T >::findIndexOfMinimum | ( | ) | const |
Get the index of the smallest element of the matrix.
T cvr::matrix< T >::findMaximum | ( | ) | const |
Get the biggest element of the matrix.
T cvr::matrix< T >::findMinimum | ( | ) | const |
Get the smallest element of the matrix.
void cvr::matrix< T >::getColumnCopy | ( | const int | col, | |
row_type & | theCol | |||
) | const [inline] |
Return genericMatrix-column as a vector.
This method copies the data of the genericMatrix, therefore is not as fast as getRow()
col | the number of the column to be copied | |
theCol | a vector, where the column vector of the genericMatrix should be copied. |
row_type cvr::matrix< T >::getColumnCopy | ( | const int | col | ) | const [inline] |
void cvr::matrix< T >::getDiagonal | ( | row_type & | diag | ) | const [inline] |
Return the diagonal elements of the genericMatrix as vector.
This method copies the diagonal elements of the genericMatrix into the vector. If the genericMatrix is non-symmetrical, the vector will be of dimension min(rows(),columns()).
diag | a vector, where the diagonal of the genericMatrix should be copied. |
row_type cvr::matrix< T >::getDiagonal | ( | ) | const [inline] |
const row_type& cvr::matrix< T >::getRow | ( | const int | row | ) | const [inline] |
Return matrix-row as a const vector.
This method works fast, since it returns a reference to the row vector. The data will NOT be copied.
row | the row to be accessed |
Reimplemented from cvr::genericMatrix< T >.
row_type& cvr::matrix< T >::getRow | ( | const int | row | ) | [inline] |
Return matrix-row as a vector.
This method works fast, since it returns a reference to the row vector. The data will NOT be copied.
row | the row to be accessed |
Reimplemented from cvr::genericMatrix< T >.
Referenced by cvr::channelC::mapLinear(), and cvr::channel::mapLinear().
void cvr::matrix< T >::getRowCopy | ( | const int | row, | |
row_type & | theRow | |||
) | const [inline] |
Copy a row vector in the given parameter.
This method copies the data of a given row of the genericMatrix in the given vector.
row | the number of the row to be copied | |
theRow | the vector, where the data will be copied |
row_type cvr::matrix< T >::getRowCopy | ( | const int | row | ) | const [inline] |
matrix<T>& cvr::matrix< T >::leftMultiply | ( | const matrix< T > & | mat | ) |
row_type& cvr::matrix< T >::leftMultiply | ( | row_type & | srcDest | ) | const |
Multiply the given vector srcdest with this matrix, and save the result in the same vector.
The given vector will be interpreted as a row-vector (or a transposed column vector).
srcDest | the vector to be multiplied with, and where the result must be written. |
row_type& cvr::matrix< T >::leftMultiply | ( | const row_type & | vct, | |
row_type & | result | |||
) | const |
matrix<T>& cvr::matrix< T >::multiply | ( | const genericMatrix< T > & | other, | |
const T | value | |||
) |
matrix<T>& cvr::matrix< T >::multiply | ( | const T | value | ) |
row_type& cvr::matrix< T >::multiply | ( | row_type & | srcdest | ) | const |
Multiply this matrix with a vector and leave the result in same vector (In-Place Method) A reference to the vector is returned.
srcdest | the vector to be multiplied with. Its dimension must be equal to the number of columns of the matrix. The result vector will be left here too, and the resulting size will be the number of rows of the matrix. |
row_type& cvr::matrix< T >::multiply | ( | const row_type & | other, | |
row_type & | result | |||
) | const |
Multiply this matrix with a vector and leave the result in result.
A reference to result is returned.
other | the vector to be multiplied with. Its dimension must be equal to the number of columns of the matrix. | |
result | the resulting vector. It will have a number of dimensions equal to the number of rows of the matrix. |
matrix<T>& cvr::matrix< T >::multiply | ( | const matrix< T > & | first, | |
const genericMatrix< T > & | second | |||
) |
matrix<T>& cvr::matrix< T >::multiply | ( | const genericMatrix< T > & | other | ) |
const std::string& cvr::matrix< T >::name | ( | ) | const [virtual] |
Returns the name of this class.
Reimplemented from cvr::genericMatrix< T >.
Reimplemented in cvr::channel, cvr::channel32, cvr::channel8, cvr::channelC, and cvr::image.
virtual matrix<T>* cvr::matrix< T >::newInstance | ( | ) | const [virtual] |
Create a new empty matrix.
Reimplemented from cvr::genericMatrix< T >.
Reimplemented in cvr::channel, cvr::channel32, cvr::channel8, cvr::channelC, and cvr::image.
matrix<T> cvr::matrix< T >::operator* | ( | const genericMatrix< T > & | other | ) | const [inline] |
Multiplication operation.
other | the other matrix to be multiplied with. |
matrix<T>& cvr::matrix< T >::operator*= | ( | const T | value | ) | [inline] |
Alias for multiply(const T& value).
value | the constant value to be multiplied with |
matrix<T>& cvr::matrix< T >::operator*= | ( | const genericMatrix< T > & | other | ) | [inline] |
matrix<T> cvr::matrix< T >::operator+ | ( | const T | value | ) | const |
matrix<T> cvr::matrix< T >::operator+ | ( | const genericMatrix< T > & | other | ) | const |
Add other matrix to this matrix and leave the result in a new matrix.
This object is not changed.
other | the other matrix to be added with. |
matrix<T>& cvr::matrix< T >::operator+= | ( | const genericMatrix< T > & | other | ) | [inline] |
matrix<T>& cvr::matrix< T >::operator+= | ( | const T | value | ) | [inline] |
Alias for add(const T value).
value | a constant value to be added to all matrix elements |
matrix<T> cvr::matrix< T >::operator- | ( | const T | value | ) | const |
matrix<T> cvr::matrix< T >::operator- | ( | const genericMatrix< T > & | other | ) | const |
Subtract other matrix from this matrix and leave the result in a new matrix.
This object is not changed.
other | the other matrix to be added with. |
matrix<T>& cvr::matrix< T >::operator-= | ( | const genericMatrix< T > & | other | ) | [inline] |
matrix<T>& cvr::matrix< T >::operator-= | ( | const T | value | ) | [inline] |
Alias for subtract(const T value).
value | a constant value to be subtracted from all matrix elements |
matrix<T>& cvr::matrix< T >::operator/= | ( | const T | value | ) |
Alias for divide(const T& value).
value | the constant value to be divided by |
matrix<T>& cvr::matrix< T >::operator= | ( | const genericMatrix< T > & | other | ) | [inline] |
Assigment operator (alias for copy(other)).
other | the matrix to be copied |
Reimplemented from cvr::genericMatrix< T >.
const row_type& cvr::matrix< T >::operator[] | ( | const int | row | ) | const [inline] |
row_type& cvr::matrix< T >::operator[] | ( | const int | row | ) | [inline] |
matrix<T>& cvr::matrix< T >::outerProduct | ( | const row_type & | a, | |
const row_type & | b | |||
) |
Outer-product of two vectors.
The result will be left in this matrix. The dimensions of this matrix will change if needed. The outer product of two column vectors is defined as
a | first vector (will determine the number of rows) | |
b | second vector (will determine the number of columns) |
bool cvr::matrix< T >::prettyCloseTo | ( | const genericMatrix< T > & | other, | |
const T & | tolerance | |||
) | const |
Compare this matrix with other, and use the given tolerance to determine if the value of each element of the other matrix approximately equals the values of the actual matrix elements.
An element x is approximately equal to another element y with a tolerance t, if following equation holds: x-t < y < x+t
This method is mainly used for matrices containing floating point values.
other | the other matrix to be compared with | |
tolerance | the tolerance to be used |
void cvr::matrix< T >::setIdentity | ( | const T | scale = T(1) |
) |
matrix<T>& cvr::matrix< T >::subtract | ( | const genericMatrix< T > & | other, | |
const T | value | |||
) |
matrix<T>& cvr::matrix< T >::subtract | ( | const T | value | ) |
matrix<T>& cvr::matrix< T >::subtract | ( | const genericMatrix< T > & | a, | |
const genericMatrix< T > & | b | |||
) |
matrix<T>& cvr::matrix< T >::subtract | ( | const genericMatrix< T > & | other | ) |
T cvr::matrix< T >::trace | ( | ) | const |
matrix<T>& cvr::matrix< T >::transpose | ( | const genericMatrix< U > & | other | ) | [inline] |
matrix<T>& cvr::matrix< T >::transpose | ( | ) |
Transpose matrix and leave the result here.
If the matrix is square this is actually a fast on-place operation. However, if the matrix is not square a temporary matrix is created with the new dimensions. This can be less efficient than using transpose(const matrix&) directly on a temporary matrix if many matrices of the same size need to be transposed.