LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::genericMatrix< T > Class Template Reference
[Aggregate Data Types]

GenericMatrix container class. More...

#include <ltiGenericMatrix.h>

Inheritance diagram for lti::genericMatrix< T >:
Inheritance graph
[legend]
Collaboration diagram for lti::genericMatrix< T >:
Collaboration graph
[legend]

List of all members.

Classes

class  const_iterator
 const iterator type (allows read-only operations). More...
class  iterator
 iterator type (allows read and write operations). More...

Public Types

enum  eStoreMode { Connected, Line }
typedef T value_type
typedef ipoint size_type

Public Member Functions

 genericMatrix ()
 genericMatrix (const int rows, const int cols, const T &iniValue=T())
 genericMatrix (const int rows, const int cols, const T data[])
 genericMatrix (const ipoint &size, const T &iniValue=T())
 genericMatrix (const genericMatrix< T > &other, const int fromRow=0, const int toRow=MaxInt32, const int fromCol=0, const int toCol=MaxInt32)
 genericMatrix (const bool init, const int rows, const int cols)
 genericMatrix (const bool init, const ipoint &size)
 genericMatrix (const genericMatrix< T > &other, const genericVector< int > &rows)
 genericMatrix (const bool copyData, genericMatrix< T > &other, const int fromRow=0, const int toRow=MaxInt32, const int fromCol=0, const int toCol=MaxInt32)
virtual ~genericMatrix ()
virtual const char * getTypeName () const
bool ownsData () const
void restoreOwnership ()
void useExternData (const int rows, const int cols, T *data)
void attach (const int rows, const int cols, T *data)
void detach (genericMatrix< T > &receiver)
void detach (genericVector< T > &receiver)
void exchange (genericMatrix< T > &other)
void swap (genericMatrix< T > &other)
eStoreMode getMode () const
int rows () const
int columns () const
int lastRow () const
int lastColumn () const
int metaRows () const
int metaColumns () const
const size_typesize () const
iterator begin ()
const_iterator begin () const
iterator end ()
const_iterator end () const
iterator inverseBegin ()
const_iterator inverseBegin () const
iterator inverseEnd ()
const_iterator inverseEnd () const
void resize (const int newRows, const int newCols, const T &iniValue=T(), const bool copyData=true, const bool initNew=true)
void clear ()
bool empty () const
void resize (const ipoint &newDim, const T &iniValue=T(), const bool copyData=true, const bool initNew=true)
void fill (const T &iniValue, const int fromRow=0, const int fromCol=0, const int toRow=MaxInt32, const int toCol=MaxInt32)
void fill (const T &iniValue, const ipoint &from, const ipoint &to=point(MaxInt32, MaxInt32))
void fill (const T &iniValue, const irectangle &window)
void fill (const T data[], const int fromRow=0, const int fromCol=0, const int toRow=MaxInt32, const int toCol=MaxInt32)
void fill (const T data[], const ipoint &from, const ipoint &to=point(MaxInt32, MaxInt32))
void fill (const T data[], const irectangle &window)
void fill (const genericMatrix< T > &mat, const int fromRow=0, const int fromCol=0, const int toRow=MaxInt32, const int toCol=MaxInt32, const int startAtRow=0, const int startAtCol=0)
void fill (const genericMatrix< T > &mat, const ipoint &from, const ipoint &to=point(MaxInt32, MaxInt32), const ipoint &startAt=point(0, 0))
void fill (const genericMatrix< T > &mat, const irectangle &window, const ipoint &start=point(0, 0))
T & at (const int row, const int col)
const T & at (const int row, const int col) const
T & at (const int pos)
const T & at (const int pos) const
T & at (const ipoint &p)
const T & at (const ipoint &p) const
genericVector< T > & getRow (const int row)
const genericVector< T > & getRow (const int row) const
genericVector< T > & operator[] (const int row)
const genericVector< T > & operator[] (const int row) const
void getRowCopy (const int row, genericVector< T > &theRow) const
genericVector< T > getRowCopy (const int row) const
void getColumnCopy (const int col, genericVector< T > &theCol) const
genericVector< T > getColumnCopy (const int col) const
void getDiagonal (genericVector< T > &diag) const
genericVector< T > getDiagonal () const
void setDiagonal (const genericVector< T > &diag)
void setRow (const int row, const genericVector< T > &theRow)
void setColumn (const int col, const genericVector< T > &theCol)
genericMatrix< T > & copy (const genericMatrix< T > &other)
genericMatrix< T > & copy (const genericMatrix< T > &other, const int fromRow, const int toRow=MaxInt32, const int fromCol=0, const int toCol=MaxInt32)
genericMatrix< T > & copy (const genericMatrix< T > &other, const irectangle &window)
genericMatrix< T > & copy (const genericMatrix< T > &other, const genericVector< int > &idx, bool rows=true)
template<class U >
genericMatrix< T > & castFrom (const genericMatrix< U > &other)
virtual mathObjectclone () const
bool equals (const genericMatrix< T > &other) const
bool operator== (const genericMatrix< T > &other) const
genericMatrix< T > & operator= (const genericMatrix< T > &other)
Apply Methods

Following methods are used to apply simple functions to each element of the vector.



genericMatrix< T > & apply (T(*function)(T))
genericMatrix< T > & apply (const genericMatrix< T > &other, T(*function)(T))
genericMatrix< T > & apply (T(*function)(const T &))
genericMatrix< T > & apply (const genericMatrix< T > &other, T(*function)(const T &))
genericMatrix< T > & apply (const genericMatrix< T > &other, T(*function)(const T &, const T &))
genericMatrix< T > & apply (const genericMatrix< T > &other, T(*function)(T, T))
genericMatrix< T > & apply (const genericMatrix< T > &a, const genericMatrix< T > &b, T(*function)(const T &, const T &))
genericMatrix< T > & apply (const genericMatrix< T > &a, const genericMatrix< T > &b, T(*function)(T, T))
Input and Output



virtual bool write (ioHandler &handler, const bool complete=true) const
virtual bool read (ioHandler &handler, const bool complete=true)

Protected Member Functions

virtual genericVector< T > * allocRows (const int n)

Protected Attributes

int & numRows
int & numColumns
ipoint theSize
int lastRowIdx
int lastColIdx
int metaNumRows
int metaNumColumns
int totalSize
bool ownData
eStoreMode mode
T * theElements
genericVector< T > * rowAddressTable

Detailed Description

template<class T>
class lti::genericMatrix< T >

GenericMatrix container class.

The lti::genericMatrix class allows the representation of n x m matrices of any type showing . The rows will be indexed between 0 and n-1, and the columns between 0 and m-1.

All types defined in ltiTypes.h use static members and can be contained by the lti::genericVector and lti::genericMatrix classes.

The genericMatrix class is a container class implemented as template.

If you need to create a genericMatrix of floats with 20 rows and 15 columns, all elements initialized with an initial value of 4.27 just create it:

 lti::genericMatrix<float> myMat(20,15,4.27f) // creates genericMatrix 
                                              // with 300 elements
                                              // all initialized with 4.27f

To access the genericMatrix 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 at(const int row) you can get the row vector. You cannot for instance resize nor change the memory referenced in this vector (see lti::genericVector::resize()). For example:

 float accu = 0; // initialize accumulator
 lti::genericMatrix<float> myMat(20,15,4.27f)
 lti::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 genericMatrix:
                         // 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 genericMatrix has following methods:


Member Typedef Documentation

template<class T>
typedef ipoint lti::genericMatrix< T >::size_type
template<class T>
typedef T lti::genericMatrix< T >::value_type

Member Enumeration Documentation

template<class T>
enum lti::genericMatrix::eStoreMode

The data can be stored sequentially in the memory or in lines.

The "Line" modus will be used when a matrix is created as a submatrix of another "Connected" matrix.

Enumerator:
Connected 

the data is stored as a single memory block

Line 

each line has its own memory block.

The iterators do not work on this mode, but you can iterate on each row


Constructor & Destructor Documentation

template<class T>
lti::genericMatrix< T >::genericMatrix (  ) 

Default constructor creates an empty genericMatrix.

template<class T>
lti::genericMatrix< T >::genericMatrix ( const int  rows,
const int  cols,
const T &  iniValue = T() 
)

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

Parameters:
rows number of rows of the genericMatrix
cols number of columns of the genericMatrix
iniValue all elements will be initialized with this value
template<class T>
lti::genericMatrix< T >::genericMatrix ( const int  rows,
const int  cols,
const T  data[] 
)

Create a rows x cols genericMatrix and initialize 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 genericMatrix
cols number of columns of the genericMatrix
data pointer to the memory block with the data to be initialized with.
template<class T>
lti::genericMatrix< T >::genericMatrix ( const ipoint size,
const T &  iniValue = T() 
)

This constructor creates a connected size.y x size.x GenericMatrix and initializes all elements with iniValue.

Parameters:
size lti::point with the size of the genericMatrix (size.x is the number of columns and size.y the number of rows)
iniValue all elements will be initialized with this value
template<class T>
lti::genericMatrix< T >::genericMatrix ( const genericMatrix< T > &  other,
const int  fromRow = 0,
const int  toRow = MaxInt32,
const int  fromCol = 0,
const int  toCol = MaxInt32 
)

Copy constructor.

create this genericMatrix as a connected copy of another genericMatrix for this const version, the data will be always copied! It is also possible to create a copy of a subgenericMatrix of another genericMatrix.

Parameters:
other the genericMatrix to be copied.
fromRow initial row of the other genericMatrix to be copied
toRow last row to be copied of the other genericMatrix
fromCol initial column of the other genericMatrix to be copied
toCol last column to be copied of the other genericMatrix

Example:

 lti::genericMatrix<int> m(4,6,0); // integer genericMatrix with 25 
                                   // elements
 // ...
 // initialize GenericMatrix 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

 lti::genericMatrix<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<class T>
lti::genericMatrix< T >::genericMatrix ( const bool  init,
const int  rows,
const int  cols 
)

If init is true this constructor is equivalent to calling genericMatrix(const int rows, const int cols), and thus initializing all elements with T().

However, in some cases the elements need not be initialized during construction, since complex initializion is required. Especially for large matrices, the unnecessary constructor initialization is very time consuming.

If init is false, memory is allocated but no initialization takes place. Thus the following is equivalent:

 genericMatrix<int> a(false,100,100);

 genericMatrix<int> a;
 a.resize(100,100,0,false,false);
Parameters:
init initialize genericMatrix or not
rows number of rows of the genericMatrix
cols number of columns of the genericMatrix
template<class T>
lti::genericMatrix< T >::genericMatrix ( const bool  init,
const ipoint size 
)

If init is true this constructor is equivalent to calling genericMatrix(const int rows, const int cols), and thus initializing all elements with T().

However, in some cases the elements need not be initialized during construction, since complex initializion is required. Especially for large matrices, the unnecessary constructor initialization is very time consuming.

If init is false, memory is allocated but no initialization takes place. Thus the following is equivalent:

 genericMatrix<int> a(false,100,100);

 genericMatrix<int> a;
 a.resize(100,100,0,false,false);
Parameters:
init initialize genericMatrix or not
size desired size for the genericMatrix
template<class T>
lti::genericMatrix< T >::genericMatrix ( const genericMatrix< T > &  other,
const genericVector< int > &  rows 
)

copy constructor.

create this genericMatrix as a connected copy of another genericMatrix 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 genericMatrix to be copied.
rows inidices of the rows to be copied

Example:

 lti::vector<int> rows(2);
 // initialize with
 // 1 3
 lti::genericMatrix<int> m(4,6,0); // integer genericMatrix with 25
                                   // elements
 // ...
 // initialize GenericMatrix 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

 lti::genericMatrix<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<class T>
lti::genericMatrix< T >::genericMatrix ( const bool  copyData,
genericMatrix< T > &  other,
const int  fromRow = 0,
const int  toRow = MaxInt32,
const int  fromCol = 0,
const int  toCol = MaxInt32 
)

copy constructor (reference to a submatrix).

creates submatrix of another matrix.

if copyData == true, the new object has its own data (equivalent to previous copy constructor).

if copyData == false, the new object has references to the other matrix, which means that the data is not necessarily consecutive. (This will not be a connected but a lined matrix)

Those algorithms which use direct access to the matrix memory block should check first if the memory lies in a consecutive block! (see getMode())

Parameters:
copyData should the data of the other matrix be copied or not
other the matrix with the data to be copied or to be shared
fromRow initial row of the other matrix to be copied
toRow last row to be copied of the other matrix
fromCol initial column of the other matrix to be copied
toCol last column to be copied of the other matrix
template<class T>
virtual lti::genericMatrix< T >::~genericMatrix (  )  [virtual]

destructor


Member Function Documentation

template<class T>
virtual genericVector<T>* lti::genericMatrix< T >::allocRows ( const int  n  )  [inline, protected, virtual]
template<class T>
genericMatrix<T>& lti::genericMatrix< T >::apply ( const genericMatrix< T > &  a,
const genericMatrix< T > &  b,
T(*)(T, T)  function 
)

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 genericMatrix
b the second genericMatrix
function a pointer to C-function with two parameters
Returns:
a reference to the actual genericMatrix

Reimplemented in lti::matrix< T >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, and lti::matrix< sqrType >.

template<class T>
genericMatrix<T>& lti::genericMatrix< T >::apply ( const genericMatrix< T > &  a,
const genericMatrix< T > &  b,
T(*)(const T &, const T &)  function 
)

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 genericMatrix
b the second genericMatrix
function a pointer to C-function with two parameters
Returns:
a reference to the actual genericMatrix

Reimplemented in lti::matrix< T >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, and lti::matrix< sqrType >.

template<class T>
genericMatrix<T>& lti::genericMatrix< T >::apply ( const genericMatrix< T > &  other,
T(*)(T, T)  function 
)

a two-parameter C-function receives the i-th elements of this and the given genericMatrix and the result will be left in this genericMatrix.

Note that both matrices must have the same size!

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

Reimplemented in lti::matrix< T >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, and lti::matrix< sqrType >.

template<class T>
genericMatrix<T>& lti::genericMatrix< T >::apply ( const genericMatrix< T > &  other,
T(*)(const T &, const T &)  function 
)

a two-parameter C-function receives the i-th elements of this and the given genericMatrix and the result will be left in this genericMatrix.

Note that both matrices must have the same size!

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

Reimplemented in lti::matrix< T >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, and lti::matrix< sqrType >.

template<class T>
genericMatrix<T>& lti::genericMatrix< T >::apply ( const genericMatrix< T > &  other,
T(*)(const T &)  function 
)

applies a C-function to each element of the other genericMatrix

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

Reimplemented in lti::matrix< T >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, and lti::matrix< sqrType >.

template<class T>
genericMatrix<T>& lti::genericMatrix< T >::apply ( T(*)(const T &)  function  ) 

applies a C-function to each element of the genericMatrix.

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

Reimplemented in lti::matrix< T >, lti::matrix< int32 >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, lti::matrix< sqrType >, lti::matrix< rgbPixel >, and lti::matrix< ubyte >.

template<class T>
genericMatrix<T>& lti::genericMatrix< T >::apply ( const genericMatrix< T > &  other,
T(*)(T)  function 
)

applies a C-function to each element of the other genericMatrix

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

Reimplemented in lti::matrix< T >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, and lti::matrix< sqrType >.

template<class T>
genericMatrix<T>& lti::genericMatrix< T >::apply ( T(*)(T)  function  ) 

applies a C-function to each element of the genericMatrix.

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

Reimplemented in lti::matrix< T >, lti::matrix< int32 >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, lti::matrix< sqrType >, lti::matrix< rgbPixel >, and lti::matrix< ubyte >.

template<class T>
const T& lti::genericMatrix< T >::at ( const ipoint p  )  const [inline]

const access operator of genericMatrix element as a point in a 2D-Map

Parameters:
p position of the element (this is equivalent to at(p.y,p.x))
Returns:
a const reference to the vector element

Reimplemented in lti::kernel2D< T >, lti::kernel2D< float >, and lti::kernel2D< ubyte >.

template<class T>
T& lti::genericMatrix< T >::at ( const ipoint p  )  [inline]

access operator of genericMatrix element as a point in a 2D-Map

Parameters:
p position of the element (this is equivalent to at(p.y,p.x))
Returns:
a reference to the genericMatrix element

Reimplemented in lti::kernel2D< T >, lti::kernel2D< float >, and lti::kernel2D< ubyte >.

template<class T>
const T& lti::genericMatrix< T >::at ( const int  pos  )  const [inline]

access element at the given position.

(can be used only in connected matrices. See constructors for more information on this.)

With this operator the genericMatrix can be accessed as a vector, where the rows of the genericMatrix are concatenated. The access to the genericMatrix with at(row,col) is equivalent to at(row*columns()+col).

Parameters:
pos the index of the element of the genericMatrix
Returns:
a reference to the genericMatrix element
template<class T>
T& lti::genericMatrix< T >::at ( const int  pos  )  [inline]

access element at the given position.

(can be used only in connected matrices. See constructors for more information on this.)

With this operator the genericMatrix can be accessed as a vector, where the rows of the genericMatrix are concatenated. The access to the genericMatrix with at(row,col) is equivalent to at(row*columns()+col).

Parameters:
pos the index of the element of the genericMatrix
Returns:
a reference to the genericMatrix element
template<class T>
const T& lti::genericMatrix< T >::at ( const int  row,
const int  col 
) const [inline]

read-only access at the given row and column

Parameters:
row the row of the element
col the column of the element
Returns:
a reference to the genericMatrix element
template<class T>
T& lti::genericMatrix< T >::at ( const int  row,
const int  col 
) [inline]
template<class T>
void lti::genericMatrix< T >::attach ( const int  rows,
const int  cols,
T *  data 
)

Attach extern data to the genericMatrix.

This member allows the use of this object as an access-functor for the 'data'. An access to the element at (r,c) is equivalent to data[r*columns() + c]. If rows and cols are invalid dimensions, the behaviour will be unpredictible.

The memory will be administrated by this genericMatrix object, and may be deleted if required (genericMatrix deleted or resized!). The user should not try to manipulate the memory allocation of the data after the attachment! See also useExternData().

Parameters:
rows number of rows
cols number of columns
data a pointer to the memory block to be used

Example:

 lti::genericMatrix<int> myMat;
 int block1[25];
 int* block2;
 block2 = new int[25];

 myMat.useExternData(5,5,block1); // ok
 myMat.attach(5,5,block1); // wrong!!! genericMatrix will try 
                           // to manipulate stack memory: 
                           // DO NOT DO THIS!!!!!
 myMat.attach(5,5,block2); // ok!  but do not try to delete the memory
                           //      block2!!
template<class T>
const_iterator lti::genericMatrix< T >::begin (  )  const [inline]

returns first element of the genericMatrix as a const_iterator.

Note that you can not change the values of the genericMatrix elements when you use a const_iterator. See also begin() for an example

template<class T>
iterator lti::genericMatrix< T >::begin (  )  [inline]

returns iterator to the begin of the genericMatrix The use of the interators is similar to the iterators of the Standard Template Library (STL).

If you need to iterate on all elements of the genericMatrix, you can use following code:

 int tmp,accu;                  // a temporal variable
 lti::genericMatrix<int> myMat(10,8,1); // a vector with 10 elements
 lti::genericMatrix<int>::iterator it;  // an iterator

 for (it=myMat.begin();it!=myMat.end();it++) {
   tmp = *it;                   // tmp has value of element pointed
                                // by the iterator.
   accu += tmp;
   (*it) = accu;                // change the value in the genericMatrix.
 }

Please note that if you define it as a const_iterator, you can not make something like *it=accu.

Referenced by lti::cityBlockDistance(), lti::distanceSqr(), and lti::regionGrowing::mask().

template<class T>
template<class U >
genericMatrix<T>& lti::genericMatrix< T >::castFrom ( const genericMatrix< U > &  other  )  [inline]

copy the other genericMatrix by casting each of its elements

Parameters:
other The genericMatrix to be casted

Example:

   lti::genericMatrix<int> matA(10,10,1);// a genericMatrix of integers
   lti::genericMatrix<double> matB;      // a genericMatrix of doubles

   matB.castFrom(matA);          // this will copy matA in matB!!

Reimplemented in lti::kernel2D< T >, and lti::matrix< T >.

template<class T>
void lti::genericMatrix< T >::clear (  ) 

clears the genericMatrix (at the end this will be an empty genericMatrix)

Referenced by lti::medianFilter::realMedian().

template<class T>
virtual mathObject* lti::genericMatrix< T >::clone (  )  const [virtual]
template<class T>
int lti::genericMatrix< T >::columns (  )  const [inline]
template<class T>
genericMatrix<T>& lti::genericMatrix< T >::copy ( const genericMatrix< T > &  other,
const genericVector< int > &  idx,
bool  rows = true 
)

copy the contents of the specified rows/columns of other into this object.

Multiple occurence of one row/column index in idx is allowed. If the argument rows is true, idx specifies rows, if false idx specifies columns.

The result of the copy is always a connected genericMatrix. I.e. you cannot copy the sub-genericMatrix property of another genericMatrix.

Parameters:
other the other genericMatrix to be copied
idx indices of the rows to be copied.
rows if true works on rows, else on columns
template<class T>
genericMatrix<T>& lti::genericMatrix< T >::copy ( const genericMatrix< T > &  other,
const irectangle window 
) [inline]

copy the contents in the rectangle windows of other in this object.

The result of the copy is always a connected genericMatrix. I.e. you cannot copy the sub-genericMatrix property of another genericMatrix.

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

Reimplemented in lti::matrix< T >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, and lti::matrix< sqrType >.

template<class T>
genericMatrix<T>& lti::genericMatrix< T >::copy ( const genericMatrix< T > &  other,
const int  fromRow,
const int  toRow = MaxInt32,
const int  fromCol = 0,
const int  toCol = MaxInt32 
)

copy the contents of the rectangle described by the indices of other into this object.

The result of the copy is always a connected genericMatrix. I.e. you cannot copy the sub-genericMatrix property of another genericMatrix.

Parameters:
other the other genericMatrix to be copied
fromRow initial row of the other genericMatrix to be copied
toRow last row to be copied of the other genericMatrix
fromCol initial column of the other genericMatrix to be copied
toCol last column to be copied of the other genericMatrix

Reimplemented in lti::matrix< T >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, and lti::matrix< sqrType >.

template<class T>
genericMatrix<T>& lti::genericMatrix< T >::copy ( const genericMatrix< T > &  other  ) 

copy the contents of other in this object.

The result of the copy is always a connected genericMatrix. I.e. you cannot copy the sub-genericMatrix property of another genericMatrix.

Parameters:
other the other genericMatrix to be copied

Reimplemented from lti::ioObject.

Reimplemented in lti::kernel2D< T >, lti::matrix< T >, lti::kernel2D< float >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, and lti::matrix< sqrType >.

template<class T>
void lti::genericMatrix< T >::detach ( genericVector< T > &  receiver  ) 

Free the data of this object and hand it over to the "receiver".

The value of ownsData is also transfered to the receiver. (see Note).

This function makes a "memory block transfusion" to a vector by concatenating the rows of the genericMatrix. It is a very efficient way to move the data of this genericMatrix into a vector, if you don't need the source data anymore!

Note: This method will fail if this genericMatrix is not connected. Also take care that if the attach() or useExternData() methods of this genericMatrix have been called before detachment, the same rules for memory management apply now for the receiver.

At the end of the detachment, this genericMatrix will be empty.

Parameters:
receiver the genericMatrix which will receive the memory block. All data of that genericMatrix will be first deleted!
template<class T>
void lti::genericMatrix< T >::detach ( genericMatrix< T > &  receiver  ) 

Free the data of this object and hand it over to the "receiver".

The value of ownsData is also transfered to the receiver. (see Note).

This function makes a "memory block transfusion" to another genericMatrix. It is a very efficient way to make a copy of this genericMatrix, if you don't need the source data anymore!

Note: This method will fail if this genericMatrix is not connected. Also take care that if the attach() or useExternData() methods of this genericMatrix have been called before detachment, the same rules for memory management apply now for the receiver.

At the end of the detachment, this genericMatrix will be empty.

Parameters:
receiver the genericMatrix which will receive the memory block. All data of that genericMatrix will be first deleted!

Referenced by lti::geometricTransform::apply(), lti::decimation::apply(), lti::geometricTransform::rotate(), and lti::geometricTransform::scale().

template<class T>
bool lti::genericMatrix< T >::empty (  )  const

returns true if the genericMatrix is empty

Referenced by lti::medianFilter::realMedian().

template<class T>
const_iterator lti::genericMatrix< T >::end (  )  const [inline]

returns iterator to the end of the genericMatrix

template<class T>
iterator lti::genericMatrix< T >::end (  )  [inline]
template<class T>
bool lti::genericMatrix< T >::equals ( const genericMatrix< T > &  other  )  const

Compare this genericMatrix with other.

Parameters:
other the other genericMatrix to be compared with
Returns:
true if both matrices have the same elements and same size
template<class T>
void lti::genericMatrix< T >::exchange ( genericMatrix< T > &  other  ) 
Deprecated:
Please use swap instead
template<class T>
void lti::genericMatrix< T >::fill ( const genericMatrix< T > &  mat,
const irectangle window,
const ipoint start = point(0, 0) 
) [inline]

fills the region of this genericMatrix specified by window with the contents of the genericMatrix mat starting at start.

If these values are out of bounds, they will be (internally) adjusted to correct values.

Parameters:
mat pointer to the data to be copied
window the window to be filled
start the start position of the region to be copied of the genericMatrix mat
template<class T>
void lti::genericMatrix< T >::fill ( const genericMatrix< T > &  mat,
const ipoint from,
const ipoint to = point(MaxInt32, MaxInt32),
const ipoint startAt = point(0, 0) 
) [inline]

fills this genericMatrix between the "from's" and "to's" with the contents of the genericMatrix mat starting at startAtRow and startAtCol

Parameters:
mat the genericMatrix with the data to be copied
from first position of the subgenericMatrix to be filled
to last position of the subgenericMatrix to be filled
startAt starting position of mat where the data is located.
template<class T>
void lti::genericMatrix< T >::fill ( const genericMatrix< T > &  mat,
const int  fromRow = 0,
const int  fromCol = 0,
const int  toRow = MaxInt32,
const int  toCol = MaxInt32,
const int  startAtRow = 0,
const int  startAtCol = 0 
)

fills this genericMatrix between the "from's" and "to's" with the contents of the genericMatrix mat starting at startAtRow and startAtCol

WARNING: Syntax changed for the parameters: the old version was fromRow,toRow, fromCol,toCol. Now the order is: fromRow,FROMCOL,TOROW,toCol. This allow to give the from coordinates only!

Parameters:
mat the genericMatrix with the data to be copied
fromRow first row of the subgenericMatrix to be filled
fromCol first column of the subgenericMatrix to be filled
toRow last row of the subgenericMatrix to be filled
toCol last column of the subgenericMatrix to be filled
startAtRow starting row of mat where the data is located.
startAtCol starting column of mat where the data is located.
template<class T>
void lti::genericMatrix< T >::fill ( const T  data[],
const irectangle window 
) [inline]

fills genericMatrix elements with iniValue.

The fill "area" is limited by window. If these values are out of bounds, they will be (internally) adjusted to correct values.

Parameters:
data pointer to the data to be copied
window the window to be filled
template<class T>
void lti::genericMatrix< T >::fill ( const T  data[],
const ipoint from,
const ipoint to = point(MaxInt32, MaxInt32) 
) [inline]

fills genericMatrix elements with the data pointed by data.

The fill "area" is limited by fromCol,toCol, fromRow and toRow. If these values are out of bounds, they will be (internally) adjusted to correct values.

Parameters:
data pointer to the data to be copied.
from first position of the subgenericMatrix to be filled
to last position of the subgenericMatrix to be filled
template<class T>
void lti::genericMatrix< T >::fill ( const T  data[],
const int  fromRow = 0,
const int  fromCol = 0,
const int  toRow = MaxInt32,
const int  toCol = MaxInt32 
)

fills genericMatrix elements with the data pointed by data.

The fill "area" is limited by fromCol,toCol, fromRow and toRow. If these values are out of bounds, they will be (internally) adjusted to correct values.

WARNING: Syntax changed for the parameters: the old version was fromRow,toRow, fromCol,toCol. Now the order is: fromRow,FROMCOL,TOROW,toCol. This allow to give the first coordinates only!

Parameters:
data pointer to the data to be copied.
fromRow first row of the subgenericMatrix to be filled
fromCol first column of the subgenericMatrix to be filled
toRow last row of the subgenericMatrix to be filled
toCol last column of the subgenericMatrix to be filled
template<class T>
void lti::genericMatrix< T >::fill ( const T &  iniValue,
const irectangle window 
) [inline]

fills genericMatrix elements with iniValue.

The fill "area" is limited by window. If these values are out of bounds, they will be (internally) adjusted to correct values.

Parameters:
iniValue the elements will be initialized with this value
window the window to be filled
template<class T>
void lti::genericMatrix< T >::fill ( const T &  iniValue,
const ipoint from,
const ipoint to = point(MaxInt32, MaxInt32) 
) [inline]

fills genericMatrix elements with iniValue.

The fill "area" is limited by from and to points If these values are out of bounds, they will be (internally) adjusted to correct values.

Parameters:
iniValue the elements will be initialized with this value
from first position of the subgenericMatrix to be filled
to last row of the subgenericMatrix to be filled
template<class T>
void lti::genericMatrix< T >::fill ( const T &  iniValue,
const int  fromRow = 0,
const int  fromCol = 0,
const int  toRow = MaxInt32,
const int  toCol = MaxInt32 
)

fills genericMatrix elements with iniValue.

The fill "area" is limited by fromCol,toCol, fromRow and toRow. If these values are out of bounds, they will be (internally) adjusted to correct values.

WARNING: Syntax changed for the parameters: the old version was fromRow,toRow, fromCol,toCol. Now the order is: fromRow,FROMCOL,TOROW,toCol. This allow to give the first coordinates only!

Parameters:
iniValue the elements will be initialized with this value
fromRow first row of the subgenericMatrix to be filled
fromCol first column of the subgenericMatrix to be filled
toRow last row of the subgenericMatrix to be filled
toCol last column of the subgenericMatrix to be filled
template<class T>
genericVector<T> lti::genericMatrix< T >::getColumnCopy ( const int  col  )  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
Returns:
a vector with the contents of the column of the genericMatrix

Reimplemented in lti::matrix< T >, lti::matrix< int32 >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, lti::matrix< sqrType >, lti::matrix< rgbPixel >, and lti::matrix< ubyte >.

template<class T>
void lti::genericMatrix< T >::getColumnCopy ( const int  col,
genericVector< T > &  theCol 
) const

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<class T>
genericVector<T> lti::genericMatrix< T >::getDiagonal (  )  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()).

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

Reimplemented in lti::matrix< T >, lti::matrix< int32 >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, lti::matrix< sqrType >, lti::matrix< rgbPixel >, and lti::matrix< ubyte >.

template<class T>
void lti::genericMatrix< T >::getDiagonal ( genericVector< T > &  diag  )  const

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<class T>
eStoreMode lti::genericMatrix< T >::getMode (  )  const [inline]

Data storage mode.

Returns the data storage mode, which can be:

  • Connected if the memory is a single block, or
  • Line if the memory of each line is allocated in different places.

For the lined-matrices the interators will not work. You can however iterate on each individual row, which are always connected.

The only possible way to get a lined-matrix is as a submatrix of another one, using the appropriate constructor: genericMatrix(const bool, genericMatrix<T>&,const int,const int, const int,const int)

template<class T>
const genericVector<T>& lti::genericMatrix< T >::getRow ( const int  row  )  const [inline]

return genericMatrix-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 in lti::matrix< T >, lti::matrix< int32 >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, lti::matrix< sqrType >, lti::matrix< rgbPixel >, and lti::matrix< ubyte >.

template<class T>
genericVector<T>& lti::genericMatrix< T >::getRow ( const int  row  )  [inline]

return genericMatrix-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 in lti::matrix< T >, lti::matrix< int32 >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, lti::matrix< sqrType >, lti::matrix< rgbPixel >, and lti::matrix< ubyte >.

Referenced by lti::genericMatrix< bool >::castFrom().

template<class T>
genericVector<T> lti::genericMatrix< T >::getRowCopy ( const int  row  )  const [inline]

return genericMatrix-row as a vector.

This method copies the data of the genericMatrix, 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 genericMatrix

Reimplemented in lti::matrix< T >, lti::matrix< int32 >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, lti::matrix< sqrType >, lti::matrix< rgbPixel >, and lti::matrix< ubyte >.

template<class T>
void lti::genericMatrix< T >::getRowCopy ( const int  row,
genericVector< T > &  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<class T>
virtual const char* lti::genericMatrix< T >::getTypeName (  )  const [virtual]
template<class T>
const_iterator lti::genericMatrix< T >::inverseBegin (  )  const [inline]

This method returns an iterator that points to the last valid element of the genericMatrix.

See inverseBegin() for more details.

template<class T>
iterator lti::genericMatrix< T >::inverseBegin (  )  [inline]

This method returns an iterator that points to the last valid element of the genericMatrix.

It is used for inverse order iteration through the genericMatrix using normal iterators (as opposed to reverse iterators). This has the advantage that iterators going from front to end and in the inverse direction are the same and can thus be compared, copied etc. Further the implementation of reverse_iterators is not as fast as that of iterators and thus not desired in the LTI-Lib.

See lti::genericVector<T>::inverseBegin() for an example.

template<class T>
const_iterator lti::genericMatrix< T >::inverseEnd (  )  const [inline]

This method returns an iterator that points to the element before the first valid element of the genericMatrix.

template<class T>
iterator lti::genericMatrix< T >::inverseEnd (  )  [inline]

This method returns an iterator that points to the element before the first valid element of the genericMatrix.

It is used to mark the end for inverse order iteration through the genericMatrix using normal iterators (as opposed to reverse iterators). This has the advantage that iterators going from front to end and in the inverse direction are the same and can thus be compared, copied etc.

template<class T>
int lti::genericMatrix< T >::lastColumn (  )  const [inline]
template<class T>
int lti::genericMatrix< T >::lastRow (  )  const [inline]
template<class T>
int lti::genericMatrix< T >::metaColumns (  )  const [inline]

Number of "physical" columns of the matrix.

Returns:
If this is a Connected Matrix, (see getMode()), this member returns the same value as columns().

If this is a Line Matrix, this value is bigger or equal than columns(). If this was created with the copy constructor for a submatrix with "no copy data", this value will return the number of columns of the original matrix.

template<class T>
int lti::genericMatrix< T >::metaRows (  )  const [inline]

Number of "physical" rows of the matrix.

Returns:
If this is a Connected Matrix, (see getMode()), this member returns the same value as rows().

If this is a Line Matrix, this value is bigger or equal than rows(). If this was created with the copy constructor for a submatrix with "no copy data", this value will return the size of the original matrix.

template<class T>
genericMatrix<T>& lti::genericMatrix< T >::operator= ( const genericMatrix< T > &  other  )  [inline]

Assigment operator (alias for copy(other)).

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

Reimplemented from lti::ioObject.

Reimplemented in lti::matrix< T >, lti::matrix< value_type >, lti::matrix< double >, lti::matrix< float >, lti::matrix< int >, lti::matrix< W >, and lti::matrix< sqrType >.

template<class T>
bool lti::genericMatrix< T >::operator== ( const genericMatrix< T > &  other  )  const [inline]

Compare the contents of each element of this genericMatrix with the other one.

It assumes the type T can be compared using the operator==.

Parameters:
other the other genericMatrix to be compared with
Returns:
true if both matrices have the same elements and same size
template<class T>
const genericVector<T>& lti::genericMatrix< T >::operator[] ( const int  row  )  const [inline]
template<class T>
genericVector<T>& lti::genericMatrix< T >::operator[] ( const int  row  )  [inline]
template<class T>
bool lti::genericMatrix< T >::ownsData (  )  const [inline]

owns this object the data? returns false if this genericMatrix contains a reference to extern data.

template<class T>
virtual bool lti::genericMatrix< T >::read ( ioHandler handler,
const bool  complete = true 
) [virtual]

read the object from the given ioHandler

Reimplemented from lti::mathObject.

Reimplemented in lti::kernel2D< T >, lti::kernel2D< float >, and lti::kernel2D< ubyte >.

template<class T>
void lti::genericMatrix< T >::resize ( const ipoint newDim,
const T &  iniValue = T(),
const bool  copyData = true,
const bool  initNew = true 
) [inline]

change the dimensions of the genericMatrix.

Parameters:
newDim new dimensions of the genericMatrix
iniValue the initialization value.
copyData if this parameter is true, the old data of the genericMatrix will be copied. If it is false, the old data will be lost.
initNew if this parameter is true, then all new elements (if they exist) will be initialized with iniValue. if initNew is false, then the new elements are left uninitialized.

If the resize is possible (see useExternData()), this object will always owns the data afterwards!

This is equivalent to call resize(newDim.y,newDim.x,iniValue,copyData,initNew)

template<class T>
void lti::genericMatrix< T >::resize ( const int  newRows,
const int  newCols,
const T &  iniValue = T(),
const bool  copyData = true,
const bool  initNew = true 
)

change the dimensions of the genericMatrix.

Parameters:
newRows new number of rows
newCols new number of columns
iniValue the initialization value.
copyData if this parameter is true, the old data of the genericMatrix will be copied. If it is false, the old data will be lost.
initNew if this parameter is true, then all new elements (if they exist) will be initialized with iniValue. if initNew is false, then the new elements are left uninitialized.

For example:

   lti::genericMatrix<int> myMat;  // creates empty genericMatrix
   myMat.resize(5,5,0);     // genericMatrix with 5x5 elements 
                            // initialized with 0
   myMat.resize(10,7,2);    // genericMatrix has now 10x7 elements: the
                            // subgenericMatrix 5x5 at (0,0) has still 0s
                            // and the rest have a 2
   myMat.resize(20,10,0,false,false); // now the genericMatrix has 20
                                      // elements but their values
                                      // are unknown.
   myMat.resize(5,5,1,false,true); // the genericMatrix has now 5x5
                                   // elements all initialized with 1

   // note that the last line could also be written:

   myMat.resize(5,5,1,false);

If the new size is not equal to the old size, the genericMatrix always owns the data afterwards (i.e. new memory is allocated) even if it didn't own the data before. Otherwise the ownership remains unchanged. You can use restoreOwnership() if you just want to own the data.

Referenced by lti::decimation::apply(), lti::matrix< ubyte >::castFrom(), lti::genericMatrix< bool >::castFrom(), and lti::medianFilter::realMedian().

template<class T>
void lti::genericMatrix< T >::restoreOwnership (  ) 

If this object does not own its data, this member will create a new memory buffer with the same data and will make this genericMatrix as its owner.

You can also be sure, that the new memory block will be connected (see also getMode() ). If this genericMatrix already owns its data nothing happens.

template<class T>
int lti::genericMatrix< T >::rows (  )  const [inline]
template<class T>
void lti::genericMatrix< T >::setColumn ( const int  col,
const genericVector< T > &  theCol 
)

copy the data of a vector in a given column

Parameters:
col the column that receives the data.
theCol the vector with the data to be copied
template<class T>
void lti::genericMatrix< T >::setDiagonal ( const genericVector< T > &  diag  ) 

Sets the diagonal of the genericMatrix to the values given in the genericVector diag.

Let r be the number of rows and c be the number of columns of the matrix. Then minRC is min(r,c). Also let d be the size of diag. Only min(minRC,d) values are copied from diag. If d is smaller than minRC the remaining values on the diagonal are left untouched. The copying always starts at (0,0) of the matrix.

Parameters:
diag values to be copied into the diagonal of the matrix
template<class T>
void lti::genericMatrix< T >::setRow ( const int  row,
const genericVector< T > &  theRow 
) [inline]

copy the data of a vector in a given row

Parameters:
row the row that receives the data.
theRow the vector with the data to be copied
template<class T>
const size_type& lti::genericMatrix< T >::size (  )  const [inline]

returns the size of the genericMatrix in a lti::point structure.

Returns:
lti::point with the number of columns in its x coordinate and the number of rows in its y coordinate.

Referenced by lti::genericMatrix< bool >::castFrom(), lti::cityBlockDistance(), lti::distanceSqr(), and lti::fillPattern::setMask().

template<class T>
void lti::genericMatrix< T >::swap ( genericMatrix< T > &  other  ) 

Exchange (in a fast way) the data between this and the other genericMatrix.

Similar to detach(), this method will exchange the complete memory blocks, avoiding an element-wise copy.

Parameters:
other the genericMatrix with which the data will be exchanged.
template<class T>
void lti::genericMatrix< T >::useExternData ( const int  rows,
const int  cols,
T *  data 
)

Reference to extern data.

This member allows the use of this object as an access-functor for the 'data'. An access to the element at (r,c) is equivalent to data[r*columns() + c]. The user must take care for memory allocation and deallocation: this object will never delete the data!. If rows and cols are invalid dimensions, the behaviour will be unpredictible.

Parameters:
rows number of rows
cols number of columns
data a pointer to the memory block to be used

For an example see attach()

template<class T>
virtual bool lti::genericMatrix< T >::write ( ioHandler handler,
const bool  complete = true 
) const [virtual]

write the object in the given ioHandler

Reimplemented from lti::mathObject.

Reimplemented in lti::kernel2D< T >, lti::kernel2D< float >, and lti::kernel2D< ubyte >.


Member Data Documentation

template<class T>
int lti::genericMatrix< T >::lastColIdx [protected]

index of the last column

template<class T>
int lti::genericMatrix< T >::lastRowIdx [protected]

index of the last row

template<class T>
int lti::genericMatrix< T >::metaNumColumns [protected]

number of columns of the "physical" matrix (always bigger than the dimensions of the "active" matrix).

template<class T>
int lti::genericMatrix< T >::metaNumRows [protected]

number of rows the "physical" matrix (always bigger than the dimensions of the "active" matrix).

template<class T>
eStoreMode lti::genericMatrix< T >::mode [protected]

indicate if theElements points to consecutive memory or to "sparse" memory

template<class T>
int& lti::genericMatrix< T >::numColumns [protected]

number of columns of the genericMatrix

template<class T>
int& lti::genericMatrix< T >::numRows [protected]

number of rows of the genericMatrix

template<class T>
bool lti::genericMatrix< T >::ownData [protected]

indicates if theElements points to own data or to external data.

template<class T>
genericVector<T>* lti::genericMatrix< T >::rowAddressTable [protected]

table of pointers to the rows

template<class T>
T* lti::genericMatrix< T >::theElements [protected]

pointer to the elements of the genericMatrix

template<class T>
ipoint lti::genericMatrix< T >::theSize [protected]

theSize.x is equal numColumns and theSize.y is equal numRows

template<class T>
int lti::genericMatrix< T >::totalSize [protected]

size of theElements


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

Generated on Sat Apr 10 15:28:22 2010 for LTI-Lib by Doxygen 1.6.1