CVR-Lib last update 20 Sep 2009

cvr::matrix< T > Class Template Reference
[Linear AlgebraAggregate Data Types]

Mathematical matrix container class. More...

#include <cvrMatrix.h>

Inheritance diagram for cvr::matrix< T >:

Inheritance graph
[legend]
Collaboration diagram for cvr::matrix< T >:

Collaboration graph
[legend]

List of all members.

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_typegetRow (const int row)
const row_typegetRow (const int row) const
row_typeoperator[] (const int row)
const row_typeoperator[] (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.
Following methods are used to apply simple functions to each element of the vector.

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_typemultiply (const row_type &other, row_type &result) const
row_typemultiply (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_typeleftMultiply (const row_type &vct, row_type &result) const
row_typeleftMultiply (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)
computeSumOfElements () const
computeProductOfElements () const
trace () const
Find extreme values
findMinimum () const
size_type findIndexOfMinimum () const
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_typeallocNewRows (const int n)


Detailed Description

template<typename T>
class cvr::matrix< T >

Mathematical matrix container class.

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)!
   }
 }

See also:
cvr::image, cvr::channel, cvr::channel8, cvr::dmatrix, cvr::fmatrix, cvr::imatrix
The parent class is cvr::genericMatrix and provides many memory management options.

The matrix has following methods:


Member Typedef Documentation

template<typename T>
typedef genericMatrix<T>::const_iterator cvr::matrix< T >::const_iterator

Const iterator.

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
typedef genericMatrix<T>::iterator cvr::matrix< T >::iterator

Iterator.

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
typedef vector<T> cvr::matrix< T >::row_type

The row type of a cvr::matrix is a cvr::vector.

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
typedef genericMatrix<T>::size_type cvr::matrix< T >::size_type

Return type of the size() member.

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
typedef genericMatrix<T>::value_type cvr::matrix< T >::value_type

Type of the contained data.

Reimplemented from cvr::genericMatrix< T >.


Constructor & Destructor Documentation

template<typename T>
cvr::matrix< T >::matrix (  )  [explicit]

Default constructor creates an empty matrix.

template<typename T>
cvr::matrix< T >::matrix ( const int  rows,
const int  cols 
) [explicit]

Create a connected rows x cols matrix but leave all elements uninitialized.

Parameters:
rows number of rows of the matrix
cols number of columns of the matrix

template<typename T>
cvr::matrix< T >::matrix ( const size_type size  )  [explicit]

Create a connected size.y x size.x matrix but leave all elements uninitialized.

Parameters:
size size of the matrix (size.x columns and size.y rows)

template<typename T>
cvr::matrix< T >::matrix ( const int  rows,
const int  cols,
const T &  iniValue 
) [explicit]

Create a connected rows x cols matrix and initializes all elements with iniValue.

Parameters:
rows number of rows of the matrix
cols number of columns of the matrix
iniValue all elements will be initialized with this value

template<typename T>
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.

Parameters:
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

template<typename T>
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.

Parameters:
rows number of rows of the matrix
cols number of columns of the matrix
data pointer to the memory block with the data to be initialized with.

template<typename T>
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.

Parameters:
dim matrix dimensions
data pointer to the memory block with the data to be initialized with.

template<typename T>
cvr::matrix< T >::matrix ( const int  rows,
const int  cols,
data[],
const eConstantReference  constRef 
) [explicit]

Create a rows x cols genericMatrix and use the given data as if it was given through the useExternData().

Note:
Please observe that the third argument makes a huge difference to the constructors that do not have it. Here the data is not copied, just a reference is kept. Without the third argument, the data is always copied.
See also:
useExternData()
The first cols-elements of the data will be copied on the first row, the next ones on the second row and so on.

Parameters:
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

template<typename T>
cvr::matrix< T >::matrix ( const size_type theSize,
data[],
const eConstantReference  constRef 
) [explicit]

Create a rows x cols genericMatrix and use the given data as if it was given through the useExternData().

See also:
useExternData()
The first cols-elements of the data will be copied on the first row, the next ones on the second row and so on.

Note:
Please observe that the third argument makes a huge difference to the constructors that do not have it. Here the data is not copied, just a reference is kept. Without the third argument, the data is always copied.
Parameters:
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

template<typename T>
cvr::matrix< T >::matrix ( const genericMatrix< T > &  other  )  [explicit]

Copy constructor.

Create this matrix as a connected copy of another matrix.

template<typename T>
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.

Parameters:
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
Example:
 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

template<typename T>
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.

template<typename T>
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.

Parameters:
other the matrix to be copied.
rows inidices of the rows to be copied
Example:
 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

template<typename T>
virtual cvr::matrix< T >::~matrix (  )  [virtual]

Destructor.


Member Function Documentation

template<typename T>
matrix<T>& cvr::matrix< T >::add ( const genericMatrix< T > &  other,
const T  value 
)

Add constant value to the other matrix and leave result here.

Parameters:
other the other matrix
value a constant value to be added to all matrix elements
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::add ( const T  value  ) 

Add constant value to this matrix, and leave result here.

Parameters:
value a constant value to be added to all matrix elements
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::add ( const genericMatrix< T > &  a,
const genericMatrix< T > &  b 
)

Add matrices a and b and write the result in this matrix.

Parameters:
a the first matrix
b the second matrix
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::add ( const genericMatrix< T > &  other  ) 

Add other matrix to this matrix, and leave result here.

Parameters:
other the matrix to be added with
Returns:
a reference to the actual matrix

template<typename T>
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 $A$ be the first matrix and $B$ the second matrix with corresponding scaling factors $a$ and $b$, further $C$ this matrix, then this method performs:

$C=a\cdot A+b\cdot B$

Parameters:
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
Returns:
a reference to this matrix

template<typename T>
matrix<T>& cvr::matrix< T >::addScaled ( const genericMatrix< T > &  matA,
const T  b,
const genericMatrix< T > &  matB 
)

Add a matrix A with a matrix B scaled by $b$, and leave the result in this matrix.

The matrices must be of the same types and dimensions. This method performs:

$A+b\cdot B$

Parameters:
matA the first matrix
b scaling factor for matB
matB the matrix to be added after scaling
Returns:
a reference to this matrix

template<typename T>
matrix<T>& cvr::matrix< T >::addScaled ( const T  b,
const genericMatrix< T > &  other 
)

Add another matrix scaled by $b$ to this matrix.

The matrices must be of the same types and dimensions. Let $A$ be this matrix and $B$ the other matrix, then this method performs:

$A=A+b\cdot B$

Parameters:
b scaling factor for other
other the matrix to be added after scaling
Returns:
a reference to this matrix

template<typename T>
virtual row_type* cvr::matrix< T >::allocNewRows ( const int  n  )  [inline, protected, virtual]

Allocate n number of rows or the appropriate type.

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
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!

Parameters:
a the first matrix
b the second matrix
function a pointer to C-function with two parameters
Returns:
a reference to the actual matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename 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!

Parameters:
a the first matrix
b the second matrix
function a pointer to C-function with two parameters
Returns:
a reference to the actual matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename 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!

Parameters:
other the second matrix to be considered (the first matrix will be this object!)
function a pointer to C-function with two parameters
Returns:
a reference to the actual matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename 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!

Parameters:
other the second matrix to be considered (the first matrix will be this object!)
function a pointer to C-function with two parameters
Returns:
a reference to the actual matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename 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.

Parameters:
other the matrix which elements will go through the given function.
function a pointer to a C-function
Returns:
a reference to the actual matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
matrix<T>& cvr::matrix< T >::apply ( T(*)(const T &)  function  )  [inline]

Applies a C-function to each element of the matrix.

Parameters:
function a pointer to a C-function
Returns:
a reference to the actual matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename 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.

Parameters:
other the matrix which elements will go through the given function.
function a pointer to a C-function
Returns:
a reference to the actual matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
matrix<T>& cvr::matrix< T >::apply ( T(*)(T)  function  )  [inline]

Applies a C-function to each element of the matrix.

Parameters:
function a pointer to a C-function
Returns:
a reference to the actual matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename 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.

Parameters:
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
Returns:
a reference to the current casted matrix.

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
template<typename U >
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.

Parameters:
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
Returns:
a reference to the current casted matrix.

Reimplemented from cvr::genericMatrix< T >.

template<typename 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.

Parameters:
other The matrix to be casted (copied)

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
template<typename U >
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!!

Parameters:
other The matrix to be casted
Returns:
reference to this matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
virtual matrix<T>* cvr::matrix< T >::clone (  )  const [virtual]

Create a clone of this matrix.

Returns:
a pointer to a copy of this matrix

Reimplemented from cvr::genericMatrix< T >.

Reimplemented in cvr::channel, cvr::channel32, cvr::channel8, cvr::channelC, and cvr::image.

template<typename T>
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 '*='

template<typename T>
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.

template<typename T>
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.

Parameters:
other the other matrix to be copied
window rectangle define the copy area

Reimplemented from cvr::genericMatrix< T >.

template<typename 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.

Parameters:
other the other matrix to be copied
from initial indices of submatrix to be copied
to final indices of submatrix to be copied (included)

template<typename T>
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.

Parameters:
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 >.

template<typename 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.

Parameters:
other the other matrix to be copied

Reimplemented from cvr::genericMatrix< T >.

template<typename 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.

Parameters:
other the other matrix to be copied
idx indices of the rows to be copied.

Reimplemented from cvr::genericMatrix< T >.

template<typename 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.

Parameters:
other the other matrix to be copied
idx indices of the rows to be copied.

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
matrix<T>& cvr::matrix< T >::divide ( const genericMatrix< T > &  other,
const T  value 
)

Divide the elements of the other matrix by a constant value and leave the result here.

Parameters:
other the other matrix
value the constant value (divisor)
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::divide ( const T  value  ) 

Divide the elements of the matrix by a constant value, and leave the result here.

Parameters:
value the constant value (divisor)
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::edivide ( const genericMatrix< T > &  a,
const genericMatrix< T > &  b 
)

Element-wise division of a and b.

Parameters:
a the first matrix
b the second matrix (with same dimensions of a)
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::edivide ( const genericMatrix< T > &  other  ) 

Element-wise division with other matrix.

Parameters:
other the other matrix. It should have the same dimensions of this matrix.
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::emultiply ( const genericMatrix< T > &  a,
const genericMatrix< T > &  b 
)

Element-wise multiplication of a and b.

Parameters:
a the first matrix
b the second matrix (with same dimensions of a)
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::emultiply ( const genericMatrix< T > &  other  ) 

Element-wise multiplication with other matrix.

Parameters:
other the other matrix. It should have the same dimensions of this matrix.
Returns:
a reference to the actual matrix

template<typename T>
void cvr::matrix< T >::findExtremes ( T &  theMinimum,
T &  theMaximum 
) const

Get the extremes of the matrix (smallest and biggest elements).

template<typename T>
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).

template<typename T>
size_type cvr::matrix< T >::findIndexOfMaximum (  )  const

Get the index of the biggest element of the matrix.

template<typename T>
size_type cvr::matrix< T >::findIndexOfMinimum (  )  const

Get the index of the smallest element of the matrix.

template<typename T>
T cvr::matrix< T >::findMaximum (  )  const

Get the biggest element of the matrix.

template<typename T>
T cvr::matrix< T >::findMinimum (  )  const

Get the smallest element of the matrix.

template<typename T>
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()

Parameters:
col the number of the column to be copied
theCol a vector, where the column vector of the genericMatrix should be copied.

template<typename T>
row_type cvr::matrix< T >::getColumnCopy ( const int  col  )  const [inline]

Return matrix-column as a vector.

This method copies the data of the matrix, therefore is not as fast as getRow()

Parameters:
col the number of the column to be copied
Returns:
a vector with the contents of the column of the matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
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()).

Parameters:
diag a vector, where the diagonal of the genericMatrix should be copied.

template<typename T>
row_type cvr::matrix< T >::getDiagonal (  )  const [inline]

Return the diagonal elements of the matrix as vector.

This method copies the diagonal elements of the matrix into the vector. If the matrix is non-symmetrical, the vector will be of dimension min(rows(),columns()).

Returns:
a vector with the diagonal elements of the matrix.

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
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.

Parameters:
row the row to be accessed
Returns:
a const reference to the vector row

Reimplemented from cvr::genericMatrix< T >.

template<typename 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.

Parameters:
row the row to be accessed
Returns:
a reference to the vector row

Reimplemented from cvr::genericMatrix< T >.

Referenced by cvr::channelC::mapLinear(), and cvr::channel::mapLinear().

template<typename T>
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.

Parameters:
row the number of the row to be copied
theRow the vector, where the data will be copied
See also:
getRow()

template<typename T>
row_type cvr::matrix< T >::getRowCopy ( const int  row  )  const [inline]

Return matrix-row as a vector.

This method copies the data of the matrix, therefore is not as fast as getRow()

Parameters:
row the number of tthe row to be copied
Returns:
a vector with the contents of the row of the matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
matrix<T>& cvr::matrix< T >::leftMultiply ( const matrix< T > &  mat  ) 

Multiply the matrix mat with this matrix, and leave the result in this matrix.

Parameters:
mat the matrix to be multiplied with.
Returns:
a reference to this matrix

template<typename T>
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).

Parameters:
srcDest the vector to be multiplied with, and where the result must be written.
Returns:
a reference to the result vector

template<typename T>
row_type& cvr::matrix< T >::leftMultiply ( const row_type vct,
row_type result 
) const

Multiply the vector vct with this matrix, and save the result in the vector result.

The given vector will be interpreted as a row-vector (or a transposed column vector).

Parameters:
vct the vector to be multiplied with.
result the resulting vector.
Returns:
a reference to the result vector

template<typename T>
matrix<T>& cvr::matrix< T >::multiply ( const genericMatrix< T > &  other,
const T  value 
)

Multiply constant value with the other matrix and leave result here.

Parameters:
other the other matrix
value the constant value to be multiplied with
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::multiply ( const T  value  ) 

Multiply constant value with this matrix, and leave result here.

Parameters:
value the constant value to be multiplied with
Returns:
a reference to the actual matrix

template<typename T>
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.

Parameters:
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.
Returns:
a reference to the result

template<typename T>
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.

Parameters:
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.
Returns:
a reference to the result

template<typename T>
matrix<T>& cvr::matrix< T >::multiply ( const matrix< T > &  first,
const genericMatrix< T > &  second 
)

Multiply first with second and leave the result in this object.

Parameters:
first the first matrix
second this second matrix will be multiplied with the first one.
Returns:
a reference to this matrix, which has now the multiplication result.

template<typename T>
matrix<T>& cvr::matrix< T >::multiply ( const genericMatrix< T > &  other  ) 

Multiply this matrix with other matrix, and leave result here.

The dimensions of this matrix will change if needed!

Parameters:
other the other matrix to be multiplied with.
Returns:
a reference to this matrix.

template<typename T>
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.

template<typename T>
virtual matrix<T>* cvr::matrix< T >::newInstance (  )  const [virtual]

Create a new empty matrix.

Returns:
a pointer to a copy of this matrix

Reimplemented from cvr::genericMatrix< T >.

Reimplemented in cvr::channel, cvr::channel32, cvr::channel8, cvr::channelC, and cvr::image.

template<typename T>
matrix<T> cvr::matrix< T >::operator* ( const genericMatrix< T > &  other  )  const [inline]

Multiplication operation.

Warning:
This overload is intended to be used sparselly, as the creation of a new matrix has its cost (memory allocation, specially). Usually, you should prefer to work with the multiply() methods and work on an already created instance.
This method creates a new matrix that contains the result of multiplying this matrix with the other one.

Parameters:
other the other matrix to be multiplied with.
Returns:
a new matrix containing the product.

template<typename T>
matrix<T>& cvr::matrix< T >::operator*= ( const T  value  )  [inline]

Alias for multiply(const T& value).

Parameters:
value the constant value to be multiplied with
Returns:
a reference to this matrix.

template<typename T>
matrix<T>& cvr::matrix< T >::operator*= ( const genericMatrix< T > &  other  )  [inline]

Alias for multiply(const matrix).

Parameters:
other the other matrix to be multiplied with.
Returns:
a reference to this matrix.

template<typename T>
matrix<T> cvr::matrix< T >::operator+ ( const T  value  )  const

Add constant value to this matrix, and leave result in a new matrix.

This object is not changed.

Parameters:
value a constant value to be added to all matrix elements
Returns:
a new matrix with the result

template<typename T>
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.

Parameters:
other the other matrix to be added with.
Returns:
a matrix with the sum of this matrix and other
Warning:
Note that the use of this operator is not as efficient as the use of the add() methods, in which the programmer can decide when to use temporal and when not...

template<typename T>
matrix<T>& cvr::matrix< T >::operator+= ( const genericMatrix< T > &  other  )  [inline]

Alias for add(const matrix).

Parameters:
other the matrix to be added with
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::operator+= ( const T  value  )  [inline]

Alias for add(const T value).

Parameters:
value a constant value to be added to all matrix elements
Returns:
a reference to the actual matrix

template<typename T>
matrix<T> cvr::matrix< T >::operator- ( const T  value  )  const

Subtract constant value from this matrix, and leave result in a new matrix.

This object is not changed.

Parameters:
value a constant value to be added to all matrix elements
Returns:
a new matrix with the result

template<typename T>
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.

Parameters:
other the other matrix to be added with.
Returns:
a matrix with the sum of this matrix and other
Warning:
Note that the use of this operator is not as efficient as the use of the add() methods, in which the programmer can decide when to use temporal and when not...

template<typename T>
matrix<T>& cvr::matrix< T >::operator-= ( const genericMatrix< T > &  other  )  [inline]

Alias for subtract(const matrix).

Parameters:
other the matrix to be subtracted
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::operator-= ( const T  value  )  [inline]

Alias for subtract(const T value).

Parameters:
value a constant value to be subtracted from all matrix elements
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::operator/= ( const T  value  ) 

Alias for divide(const T& value).

Parameters:
value the constant value to be divided by
Returns:
a reference to this matrix.

template<typename T>
matrix<T>& cvr::matrix< T >::operator= ( const genericMatrix< T > &  other  )  [inline]

Assigment operator (alias for copy(other)).

Parameters:
other the matrix to be copied
Returns:
a reference to the actual matrix

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
const row_type& cvr::matrix< T >::operator[] ( const int  row  )  const [inline]

Alias for getRow().

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
row_type& cvr::matrix< T >::operator[] ( const int  row  )  [inline]

Alias for getRow().

Reimplemented from cvr::genericMatrix< T >.

template<typename T>
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 \cdot b^T$

Parameters:
a first vector (will determine the number of rows)
b second vector (will determine the number of columns)
Returns:
a reference to the actual matrix

template<typename T>
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.

Parameters:
other the other matrix to be compared with
tolerance the tolerance to be used
Returns:
true if both matrices are approximatly equal

template<typename T>
void cvr::matrix< T >::setIdentity ( const T  scale = T(1)  ) 

Set the diagonal of this matrix to scale (default: 1), and all other elements to 0.

If the matrix is square (which it need not be), this results in a scaled identity matrix.

template<typename T>
matrix<T>& cvr::matrix< T >::subtract ( const genericMatrix< T > &  other,
const T  value 
)

Subtract constant value from the other matrix and leave result here.

Parameters:
other the other matrix
value a constant value to be subtracted from all matrix elements
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::subtract ( const T  value  ) 

Subtract constant value from this matrix, and leave result here.

Parameters:
value a constant value to be subtracted from all matrix elements
Returns:
a reference to the actual matrix

template<typename T>
matrix<T>& cvr::matrix< T >::subtract ( const genericMatrix< T > &  a,
const genericMatrix< T > &  b 
)

Subtract matrices b from a and write result in this matrix.

Parameters:
a the first matrix
b the second matrix
Returns:
a reference to this matrix, which is now a-b.

template<typename T>
matrix<T>& cvr::matrix< T >::subtract ( const genericMatrix< T > &  other  ) 

Subtract other matrix from this matrix, and leave result here.

Parameters:
other the matrix to be subtracted
Returns:
a reference to this matrix.

template<typename T>
T cvr::matrix< T >::trace (  )  const

Returns the trace (i.e.

the sum of the diagonal elements) of this matrix. If the matrix is not symmetrical, it will return the sum of all elements (i,i) with i from 0 to n-1; n being min(rows(),columns())

template<typename T>
template<typename U >
matrix<T>& cvr::matrix< T >::transpose ( const genericMatrix< U > &  other  )  [inline]

Transpose the other matrix and leave the result here.

If U!=T each element of other is static_cast<T> in the process.

Returns:
a reference to the actual (now transposed) matrix

template<typename T>
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.

Returns:
a reference to the actual (now transposed) matrix


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

Generated on Sun Sep 20 22:09:00 2009 for CVR-Lib by Doxygen 1.5.8