MRPT logo

mrpt::math::CMatrixTemplate< T > Class Template Reference

This template class provides the basic functionality for a general 2D any-size, resizable container of numerical or non-numerical elements. More...

#include <mrpt/math/CMatrixTemplate.h>

List of all members.

Public Member Functions

void extractCol (size_t nCol, std::vector< T > &out, int startingRow=0) const
 Returns a given column to a vector (without modifying the matrix)
Exceptions:
std::exception On index out of bounds.

void extractCol (size_t nCol, CMatrixTemplate< T > &out, int startingRow=0) const
 Gets a given column to a vector (without modifying the matrix)
Exceptions:
std::exception On index out of bounds.

template<class F >
void extractRow (size_t nRow, std::vector< F > &out, size_t startingCol=0) const
 Gets a given row to a vector (without modifying the matrix)
Exceptions:
std::exception On index out of bounds.

template<class F >
void extractRow (size_t nRow, CMatrixTemplate< F > &out, size_t startingCol=0) const
 Gets a given row to a vector (without modifying the matrix)
Exceptions:
std::exception On index out of bounds.

 CMatrixTemplate (const CMatrixTemplate &m)
 Constructors.
 CMatrixTemplate (size_t row=3, size_t col=3)
template<typename V , size_t N>
 CMatrixTemplate (size_t row, size_t col, V(&theArray)[N])
 Constructor from a given size and a C array.
virtual ~CMatrixTemplate ()
 Destructor.
CMatrixTemplateoperator= (const CMatrixTemplate &m)
 Assignment operator from another matrix.
template<typename V , size_t N>
CMatrixTemplateoperator= (V(&theArray)[N])
 Assignment operator for initializing from a C array (The matrix must be set to the correct size before invoking this asignament).
size_t getRowCount () const
 Number of rows in the matrix.
size_t getColCount () const
 Number of columns in the matrix.
size_t nr () const
 Number of rows in the matrix.
size_t nc () const
 Number of columns in the matrix.
void setSize (size_t row, size_t col)
 Changes the size of matrix, maintaining the previous contents.
bool IsSquare () const
 Check for type of matrix.
T & operator() (size_t row, size_t col)
 Subscript operator to get/set individual elements.
operator() (size_t row, size_t col) const
 Subscript operator to get/set individual elements.
T & operator() (size_t ith)
 Subscript operator to get/set an individual element from a row or column matrix.
operator() (size_t ith) const
 Subscript operator to get/set an individual element from a row or column matrix.
void set_unsafe (size_t row, size_t col, const T &v)
 Fast but unsafe method to write a value in the matrix.
get_unsafe (size_t row, size_t col) const
 Fast but unsafe method to read a value from the matrix.
T * get_unsafe_row (size_t row) const
 Fast but unsafe method to obtain a pointer to a given row of the matrix (Use only in time critical applications).
void insertRow (size_t nRow, const std::vector< T > &in)
 Inserts a row from a vector, replacing the current contents of that row.
void appendRow (const std::vector< T > &in)
 Appends a new row to the MxN matrix from a 1xN vector.
void insertCol (size_t nCol, const std::vector< T > &in)
 Inserts a column from a vector, replacing the current contents of that column.
template<class R >
void insertMatrix (size_t nRow, size_t nCol, const CMatrixTemplate< R > &in)
 Inserts a matrix into this matrix Notice that the matrix must "fit" into the existing size of this matrix.
void insertMatrixTranspose (size_t nRow, size_t nCol, const CMatrixTemplate< T > &in)
 Inserts the transpose of a given matrix into this matrix Notice that the matrix must "fit" into the existing size of this matrix.
void insertMatrix (size_t nRow, size_t nCol, const std::vector< T > &in)
 Inserts a matrix line (vector) into this matrix Notice that the matrix must "fit" into the existing size of this matrix.
void joinMatrix (const CMatrixTemplate< T > &left_up, const CMatrixTemplate< T > &right_up, const CMatrixTemplate< T > &left_down, const CMatrixTemplate< T > &right_down)
 Inserts 4 matrixes corresponding to the "four corners" into this matrix.
void fill (const T &val)
 Fill the matrix with a given value:.
void extractSubmatrix (const size_t row1, const size_t row2, const size_t col1, const size_t col2, CMatrixTemplate< T > &out) const
 Get a submatrix, given its bounds.
CMatrixTemplate< T > operator() (const size_t row1, const size_t row2, const size_t col1, const size_t col2) const
 Subscript operator to get a submatrix.
void exchangeColumns (size_t col1, size_t col2)
 Interchanges two columns of the matrix.
void exchangeRows (size_t row1, size_t row2)
 Interchanges two rows of the matrix.
void deleteRow (size_t row)
 Deletes a row of the matrix.
void deleteColumn (size_t col)
 Deletes a column of the matrix.
template<class R >
void extractMatrix (size_t nRow, size_t nCol, CMatrixTemplate< R > &in) const
 Extract a sub matrix from a matrix:
Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

void extractMatrix (size_t nRow, size_t nCol, size_t nrows, size_t ncols, CMatrixTemplate< T > &outMat) const
 Extract a sub matrix from a matrix:
Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

void extractMatrix (size_t nRow, size_t nCol, std::vector< T > &in) const
 Extract a sub matrix (vector) from a matrix:
Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

std::vector< T > extractMatrix (size_t nRow, size_t nCol, size_t ncols) const
 Extract a sub matrix (vector) from a matrix:
Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

std::string inMatlabFormat () const
 Dump matrix in matlab format.
bool fromMatlabStringFormat (const std::string &s)
 Read a matrix from a string in Matlab-like format, for example "[1 0 2; 0 4 -1]" The string must start with '[' and end with ']'.

Protected Member Functions

void realloc (size_t row, size_t col, bool newElementsToZero=false)
 Internal use only: It realloc the memory for the 2D matrix, maintaining the previous contents if posible.

Protected Attributes

T ** m_Val
size_t m_Rows
size_t m_Cols


Detailed Description

template<class T>
class mrpt::math::CMatrixTemplate< T >

This template class provides the basic functionality for a general 2D any-size, resizable container of numerical or non-numerical elements.

NOTES:

See also:
CMatrixTemplateNumeric

Definition at line 51 of file CMatrixTemplate.h.


Constructor & Destructor Documentation

template<class T>
mrpt::math::CMatrixTemplate< T >::CMatrixTemplate ( const CMatrixTemplate< T > &  m  )  [inline]

Constructors.

Definition at line 183 of file CMatrixTemplate.h.

template<class T>
mrpt::math::CMatrixTemplate< T >::CMatrixTemplate ( size_t  row = 3,
size_t  col = 3 
) [inline]

Definition at line 188 of file CMatrixTemplate.h.

template<class T>
template<typename V , size_t N>
mrpt::math::CMatrixTemplate< T >::CMatrixTemplate ( size_t  row,
size_t  col,
V(&)  theArray[N] 
) [inline]

Constructor from a given size and a C array.

The array length must match cols x row.

  const double numbers[] = {
    1,2,3,
    4,5,6 };
         CMatrixDouble   M(3,2, numbers);

Definition at line 202 of file CMatrixTemplate.h.

template<class T>
virtual mrpt::math::CMatrixTemplate< T >::~CMatrixTemplate (  )  [inline, virtual]

Destructor.

Definition at line 220 of file CMatrixTemplate.h.


Member Function Documentation

template<class T>
void mrpt::math::CMatrixTemplate< T >::appendRow ( const std::vector< T > &  in  )  [inline]

Appends a new row to the MxN matrix from a 1xN vector.

The lenght of the vector must match the width of the matrix, unless it's empty: in that case the matrix is resized to 1xN.

    CMatrixDouble  M(0,0);
    vector_double  v(7),w(7);
    // ...
    M.appendRow(v);
    M.appendRow(w);
Exceptions:
std::exception On incorrect vector length.
See also:
extractRow

Definition at line 439 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::deleteColumn ( size_t  col  )  [inline]

Deletes a column of the matrix.

Definition at line 631 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::deleteRow ( size_t  row  )  [inline]

Deletes a row of the matrix.

Definition at line 621 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::exchangeColumns ( size_t  col1,
size_t  col2 
) [inline]

Interchanges two columns of the matrix.

Definition at line 593 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::exchangeRows ( size_t  row1,
size_t  row2 
) [inline]

Interchanges two rows of the matrix.

Definition at line 607 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractCol ( size_t  nCol,
CMatrixTemplate< T > &  out,
int  startingRow = 0 
) const [inline]

Gets a given column to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

Definition at line 130 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractCol ( size_t  nCol,
std::vector< T > &  out,
int  startingRow = 0 
) const [inline]

Returns a given column to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

Definition at line 112 of file CMatrixTemplate.h.

template<class T>
std::vector<T> mrpt::math::CMatrixTemplate< T >::extractMatrix ( size_t  nRow,
size_t  nCol,
size_t  ncols 
) const [inline]

Extract a sub matrix (vector) from a matrix:

Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

(by AJOGD @ JAN-2007)

Definition at line 700 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractMatrix ( size_t  nRow,
size_t  nCol,
std::vector< T > &  in 
) const [inline]

Extract a sub matrix (vector) from a matrix:

Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

(by AJOGD @ JAN-2007)

Definition at line 682 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractMatrix ( size_t  nRow,
size_t  nCol,
size_t  nrows,
size_t  ncols,
CMatrixTemplate< T > &  outMat 
) const [inline]

Extract a sub matrix from a matrix:

Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

(by AJOGD @ JAN-2007)

Definition at line 664 of file CMatrixTemplate.h.

template<class T>
template<class R >
void mrpt::math::CMatrixTemplate< T >::extractMatrix ( size_t  nRow,
size_t  nCol,
CMatrixTemplate< R > &  in 
) const [inline]

Extract a sub matrix from a matrix:

Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

(by AJOGD @ JAN-2007)

Definition at line 645 of file CMatrixTemplate.h.

template<class T>
template<class F >
void mrpt::math::CMatrixTemplate< T >::extractRow ( size_t  nRow,
CMatrixTemplate< F > &  out,
size_t  startingCol = 0 
) const [inline]

Gets a given row to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

Definition at line 167 of file CMatrixTemplate.h.

template<class T>
template<class F >
void mrpt::math::CMatrixTemplate< T >::extractRow ( size_t  nRow,
std::vector< F > &  out,
size_t  startingCol = 0 
) const [inline]

Gets a given row to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

Definition at line 149 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractSubmatrix ( const size_t  row1,
const size_t  row2,
const size_t  col1,
const size_t  col2,
CMatrixTemplate< T > &  out 
) const [inline]

Get a submatrix, given its bounds.

Definition at line 569 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< CPoint3D >::operator()().

template<class T>
void mrpt::math::CMatrixTemplate< T >::fill ( const T &  val  )  [inline]

Fill the matrix with a given value:.

Definition at line 560 of file CMatrixTemplate.h.

template<class T>
bool mrpt::math::CMatrixTemplate< T >::fromMatlabStringFormat ( const std::string &  s  )  [inline]

Read a matrix from a string in Matlab-like format, for example "[1 0 2; 0 4 -1]" The string must start with '[' and end with ']'.

Rows are separated by semicolons ';' and columns in each row by one or more whitespaces ' ' or tabs.

This format is also used for CConfigFile::read_matrix.

This template method can be instantiated for matrices of the types: int, long, unsinged int, unsigned long, float, double, long double

Returns:
true on success. false if the string is malformed, and then the matrix will be resized to 0x0.
See also:
inMatlabFormat, CConfigFile::read_matrix

Definition at line 749 of file CMatrixTemplate.h.

template<class T>
T mrpt::math::CMatrixTemplate< T >::get_unsafe ( size_t  row,
size_t  col 
) const [inline]

template<class T>
T* mrpt::math::CMatrixTemplate< T >::get_unsafe_row ( size_t  row  )  const [inline]

Fast but unsafe method to obtain a pointer to a given row of the matrix (Use only in time critical applications).

Definition at line 407 of file CMatrixTemplate.h.

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::getColCount (  )  const [inline]

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::getRowCount (  )  const [inline]

template<class T>
std::string mrpt::math::CMatrixTemplate< T >::inMatlabFormat (  )  const [inline]

Dump matrix in matlab format.

This template method can be instantiated for matrices of the types: int, long, unsinged int, unsigned long, float, double, long double

See also:
fromMatlabStringFormat

Definition at line 719 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::insertCol ( size_t  nCol,
const std::vector< T > &  in 
) [inline]

Inserts a column from a vector, replacing the current contents of that column.

Exceptions:
std::exception On index out of bounds
See also:
extractCol

Definition at line 466 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::insertMatrix ( size_t  nRow,
size_t  nCol,
const std::vector< T > &  in 
) [inline]

Inserts a matrix line (vector) into this matrix Notice that the matrix must "fit" into the existing size of this matrix.

Exceptions:
std::exception On index out of bounds
See also:
extractCol By AJOGD @ MAR-2007

Definition at line 529 of file CMatrixTemplate.h.

template<class T>
template<class R >
void mrpt::math::CMatrixTemplate< T >::insertMatrix ( size_t  nRow,
size_t  nCol,
const CMatrixTemplate< R > &  in 
) [inline]

Inserts a matrix into this matrix Notice that the matrix must "fit" into the existing size of this matrix.

Parameters:
in The submatrix to insert into 'this' matrix.
nRow The row in 'this' matrix where the submatrix will be inserted (0:first).
nCol The column in 'this' matrix where the submatrix will be inserted (0:first).
Exceptions:
std::exception On index out of bounds
See also:
extractCol

Definition at line 486 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< CPoint3D >::joinMatrix().

template<class T>
void mrpt::math::CMatrixTemplate< T >::insertMatrixTranspose ( size_t  nRow,
size_t  nCol,
const CMatrixTemplate< T > &  in 
) [inline]

Inserts the transpose of a given matrix into this matrix Notice that the matrix must "fit" into the existing size of this matrix.

Parameters:
in The submatrix to insert into 'this' matrix.
nRow The row in 'this' matrix where the submatrix will be inserted (0:first).
nCol The column in 'this' matrix where the submatrix will be inserted (0:first).
Exceptions:
std::exception On index out of bounds
See also:
extractCol

Definition at line 508 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::insertRow ( size_t  nRow,
const std::vector< T > &  in 
) [inline]

Inserts a row from a vector, replacing the current contents of that row.

Exceptions:
std::exception On index out of bounds
See also:
extractRow

Definition at line 416 of file CMatrixTemplate.h.

template<class T>
bool mrpt::math::CMatrixTemplate< T >::IsSquare (  )  const [inline]

Check for type of matrix.

Definition at line 308 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::joinMatrix ( const CMatrixTemplate< T > &  left_up,
const CMatrixTemplate< T > &  right_up,
const CMatrixTemplate< T > &  left_down,
const CMatrixTemplate< T > &  right_down 
) [inline]

Inserts 4 matrixes corresponding to the "four corners" into this matrix.

Exceptions:
std::exception On index out of bounds
See also:
insertMatrix

Definition at line 545 of file CMatrixTemplate.h.

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::nc (  )  const [inline]

Number of columns in the matrix.

See also:
getRowCount, getColCount, nr, nc

Definition at line 293 of file CMatrixTemplate.h.

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::nr (  )  const [inline]

Number of rows in the matrix.

See also:
getRowCount, getColCount, nr, nc

Definition at line 285 of file CMatrixTemplate.h.

template<class T>
CMatrixTemplate<T> mrpt::math::CMatrixTemplate< T >::operator() ( const size_t  row1,
const size_t  row2,
const size_t  col1,
const size_t  col2 
) const [inline]

Subscript operator to get a submatrix.

Definition at line 585 of file CMatrixTemplate.h.

template<class T>
T mrpt::math::CMatrixTemplate< T >::operator() ( size_t  ith  )  const [inline]

Subscript operator to get/set an individual element from a row or column matrix.

Exceptions:
std::exception If the object is not a column or row matrix.

Definition at line 366 of file CMatrixTemplate.h.

template<class T>
T& mrpt::math::CMatrixTemplate< T >::operator() ( size_t  ith  )  [inline]

Subscript operator to get/set an individual element from a row or column matrix.

Exceptions:
std::exception If the object is not a column or row matrix.

Definition at line 338 of file CMatrixTemplate.h.

template<class T>
T mrpt::math::CMatrixTemplate< T >::operator() ( size_t  row,
size_t  col 
) const [inline]

Subscript operator to get/set individual elements.

Definition at line 326 of file CMatrixTemplate.h.

template<class T>
T& mrpt::math::CMatrixTemplate< T >::operator() ( size_t  row,
size_t  col 
) [inline]

Subscript operator to get/set individual elements.

Definition at line 315 of file CMatrixTemplate.h.

template<class T>
template<typename V , size_t N>
CMatrixTemplate& mrpt::math::CMatrixTemplate< T >::operator= ( V(&)  theArray[N]  )  [inline]

Assignment operator for initializing from a C array (The matrix must be set to the correct size before invoking this asignament).

         CMatrixDouble   M(3,2);
  const double numbers[] = {
    1,2,3,
    4,5,6 };
  M = numbers;
Refer also to the constructor with initialization data CMatrixTemplate::CMatrixTemplate

Reimplemented in mrpt::math::CMatrixTemplateNumeric< T >, mrpt::math::CMatrixTemplateNumeric< NUMTYPE >, mrpt::math::CMatrixTemplateNumeric< double >, mrpt::math::CMatrixTemplateNumeric< float >, and mrpt::math::CMatrixTemplateNumeric< KFTYPE >.

Definition at line 249 of file CMatrixTemplate.h.

template<class T>
CMatrixTemplate& mrpt::math::CMatrixTemplate< T >::operator= ( const CMatrixTemplate< T > &  m  )  [inline]

Assignment operator from another matrix.

Definition at line 227 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::realloc ( size_t  row,
size_t  col,
bool  newElementsToZero = false 
) [inline, protected]

template<class T>
void mrpt::math::CMatrixTemplate< T >::set_unsafe ( size_t  row,
size_t  col,
const T &  v 
) [inline]

template<class T>
void mrpt::math::CMatrixTemplate< T >::setSize ( size_t  row,
size_t  col 
) [inline]


Member Data Documentation

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::m_Cols [protected]

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::m_Rows [protected]

template<class T>
T** mrpt::math::CMatrixTemplate< T >::m_Val [protected]




Page generated by Doxygen 1.5.9 for MRPT 0.6.5 SVN: at Sun Aug 2 11:39:56 CDT 2009