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

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 53 of file CMatrixTemplate.h.


Constructor & Destructor Documentation

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

Constructors.

Definition at line 185 of file CMatrixTemplate.h.

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

Definition at line 190 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 204 of file CMatrixTemplate.h.

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

Destructor.

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

Exceptions:
std::exception On incorrect vector length.
See also:
extractRow

Definition at line 433 of file CMatrixTemplate.h.

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

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

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

Definition at line 132 of file CMatrixTemplate.h.

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

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

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

Definition at line 114 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 
) [inline]

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

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

Definition at line 169 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 
) [inline]

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

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

Definition at line 151 of file CMatrixTemplate.h.

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

Fill the matrix with a given value:.

Definition at line 545 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 409 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>
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 451 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 514 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 471 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< bool >::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 493 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 418 of file CMatrixTemplate.h.

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

Check for type of matrix.

Definition at line 310 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 530 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 295 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 287 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 368 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 340 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 328 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 317 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< double >, mrpt::math::CMatrixTemplateNumeric< float >, and mrpt::math::CMatrixTemplateNumeric< KFTYPE >.

Definition at line 251 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 229 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]

Fast but unsafe method to write a value in the matrix.

Definition at line 395 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< bool >::insertMatrix(), and mrpt::math::CMatrixTemplate< bool >::insertMatrixTranspose().

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.8 for MRPT 0.6.5 SVN:exported at Mon Jan 12 13:00:16 UTC 2009