Main MRPT website > C++ reference
MRPT logo
List of all members | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
mrpt::math::CMatrixB Class Reference

Detailed Description

This class is a "CSerializable" wrapper for "CMatrixBool".

Note
For a complete introduction to Matrices and vectors in MRPT, see: http://www.mrpt.org/Matrices_vectors_arrays_and_Linear_Algebra_MRPT_and_Eigen_classes

Definition at line 47 of file CMatrixB.h.

#include <mrpt/math/CMatrixB.h>

Inheritance diagram for mrpt::math::CMatrixB:
Inheritance graph
[legend]

Public Types

typedef T value_type
 The type of the matrix elements. More...
 
typedef T & reference
 
typedef const T & const_reference
 
typedef std::size_t size_type
 
typedef std::ptrdiff_t difference_type
 

Public Member Functions

 CMatrixB (size_t row=1, size_t col=1)
 Constructor. More...
 
 CMatrixB (const CMatrixBool &m)
 Copy constructor. More...
 
CMatrixB & operator= (const CMatrixBool &m)
 Assignment operator for float matrixes. More...
 
mrpt::utils::CObjectPtr duplicateGetSmartPtr () const
 Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object will exist as long as any copy of this smart pointer). More...
 
CObject * clone () const
 Cloning interface for smart pointers. More...
 
template<size_t N>
void ASSERT_ENOUGHROOM (size_t r, size_t c) const
 Checks whether the rows [r-N,r+N] and the columns [c-N,c+N] are present in the matrix. More...
 
void fillAll (const T &val)
 
void swap (CMatrixTemplate< T > &o)
 Swap with another matrix very efficiently (just swaps a pointer and two integer values). More...
 
size_t getRowCount () const
 Number of rows in the matrix. More...
 
size_t getColCount () const
 Number of columns in the matrix. More...
 
CMatrixTemplateSize size () const
 Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x)) More...
 
void setSize (size_t row, size_t col, bool zeroNewElements=false)
 Changes the size of matrix, maintaining the previous contents. More...
 
void resize (const CMatrixTemplateSize &siz, bool zeroNewElements=false)
 This method just checks has no effects in this class, but raises an exception if the expected size does not match. More...
 
T & operator() (size_t row, size_t col)
 Subscript operator to get/set individual elements. More...
 
const T & operator() (size_t row, size_t col) const
 Subscript operator to get individual elements. More...
 
T & operator() (size_t ith)
 Subscript operator to get/set an individual element from a row or column matrix. More...
 
T operator() (size_t ith) const
 Subscript operator to get/set an individual element from a row or column matrix. More...
 
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. More...
 
void set_unsafe (size_t row, size_t col, const T &v)
 Fast but unsafe method to write a value in the matrix. More...
 
const T & get_unsafe (size_t row, size_t col) const
 Fast but unsafe method to read a value from the matrix. More...
 
T & get_unsafe (size_t row, size_t col)
 Fast but unsafe method to get a reference from the matrix. More...
 
T * get_unsafe_row (size_t row)
 Fast but unsafe method to obtain a pointer to a given row of the matrix (Use only in time critical applications) More...
 
const 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 critical applications) More...
 
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. More...
 
template<class Derived >
void extractSubmatrix (const size_t row1, const size_t row2, const size_t col1, const size_t col2, Eigen::MatrixBase< Derived > &out) const
 
void extractRows (size_t firstRow, size_t lastRow, CMatrixTemplate< T > &out) const
 Gets a series of contiguous rows. More...
 
void extractColumns (size_t firstCol, size_t lastCol, CMatrixTemplate< T > &out) const
 Gets a series of contiguous columns. More...
 
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::exceptionOn index out of bounds.
More...
 
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::exceptionOn index out of bounds.
More...
 
void appendRow (const std::vector< T > &in)
 Appends a new row to the MxN matrix from a 1xN vector. More...
 
void appendCol (const std::vector< T > &in)
 Appends a new column to the matrix from a vector. More...
 
void insertCol (size_t nCol, const std::vector< T > &in)
 Inserts a column from a vector, replacing the current contents of that column. More...
 
void getAsVector (std::vector< T > &out) const
 Returns a vector containing the matrix's values. More...
 

Static Public Attributes

static const
mrpt::utils::TRuntimeClassId 
classCObject
 
RTTI stuff
static const
mrpt::utils::TRuntimeClassId 
classCSerializable
 

Protected Member Functions

void realloc (size_t row, size_t col, bool newElementsToZero=false)
 Internal use only: It reallocs the memory for the 2D matrix, maintaining the previous contents if posible. More...
 
CSerializable virtual methods
void writeToStream (mrpt::utils::CStream &out, int *getVersion) const
 Introduces a pure virtual method responsible for writing to a CStream. More...
 
void readFromStream (mrpt::utils::CStream &in, int version)
 Introduces a pure virtual method responsible for loading from a CStream This can not be used directly be users, instead use "stream >> object;" for reading it from a stream or "stream >> object_ptr;" if the class is unknown apriori. More...
 

Protected Attributes

T ** m_Val
 
size_t m_Rows
 
size_t m_Cols
 

RTTI stuff

typedef CMatrixBPtr SmartPtr
 
static mrpt::utils::CLASSINIT _init_CMatrixB
 
static mrpt::utils::TRuntimeClassId classCMatrixB
 
static const
mrpt::utils::TRuntimeClassId * 
classinfo
 
static const
mrpt::utils::TRuntimeClassId * 
_GetBaseClass ()
 
virtual const
mrpt::utils::TRuntimeClassId * 
GetRuntimeClass () const
 Returns information about the class of an object in runtime. More...
 
virtual mrpt::utils::CObject * duplicate () const
 Returns a copy of the object, indepently of its class. More...
 
static mrpt::utils::CObject * CreateObject ()
 
static CMatrixBPtr Create ()
 

Member Typedef Documentation

template<class T>
typedef const T& mrpt::math::CMatrixTemplate< T >::const_reference
inherited

Definition at line 66 of file CMatrixTemplate.h.

template<class T>
typedef std::ptrdiff_t mrpt::math::CMatrixTemplate< T >::difference_type
inherited

Definition at line 68 of file CMatrixTemplate.h.

template<class T>
typedef T& mrpt::math::CMatrixTemplate< T >::reference
inherited

Definition at line 65 of file CMatrixTemplate.h.

template<class T>
typedef std::size_t mrpt::math::CMatrixTemplate< T >::size_type
inherited

Definition at line 67 of file CMatrixTemplate.h.

A typedef for the associated smart pointer

Definition at line 50 of file CMatrixB.h.

template<class T>
typedef T mrpt::math::CMatrixTemplate< T >::value_type
inherited

The type of the matrix elements.

Definition at line 64 of file CMatrixTemplate.h.

Constructor & Destructor Documentation

mrpt::math::CMatrixB::CMatrixB ( size_t  row = 1,
size_t  col = 1 
)
inline

Constructor.

Definition at line 54 of file CMatrixB.h.

mrpt::math::CMatrixB::CMatrixB ( const CMatrixBool &  m)
inline

Copy constructor.

Definition at line 60 of file CMatrixB.h.

Member Function Documentation

static const mrpt::utils::TRuntimeClassId* mrpt::math::CMatrixB::_GetBaseClass ( )
staticprotected
template<class T>
void mrpt::math::CMatrixTemplate< T >::appendCol ( const std::vector< T > &  in)
inlineinherited

Appends a new column to the matrix from a vector.

  The length of the vector must match the number of rows of the matrix, unless it is (0,0).
  \exception std::exception On size mismatch.
See Also
extractCol
appendRow

Definition at line 538 of file CMatrixTemplate.h.

References ASSERT_, mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, and mrpt::math::CMatrixTemplate< T >::realloc().

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

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.
vector_double v(7),w(7);
// ...
M.appendRow(v);
M.appendRow(w);
Exceptions
std::exceptionOn incorrect vector length.
See Also
extractRow
appendCol

Definition at line 509 of file CMatrixTemplate.h.

References ASSERT_, mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, and mrpt::math::CMatrixTemplate< T >::realloc().

template<class T>
template<size_t N>
void mrpt::math::CMatrixTemplate< T >::ASSERT_ENOUGHROOM ( size_t  r,
size_t  c 
) const
inlineinherited

Checks whether the rows [r-N,r+N] and the columns [c-N,c+N] are present in the matrix.

Definition at line 127 of file CMatrixTemplate.h.

References ASSERT_, mrpt::math::CMatrixTemplate< T >::getColCount(), and mrpt::math::CMatrixTemplate< T >::getRowCount().

CObject* mrpt::utils::CObject::clone ( ) const
inlineinherited

Cloning interface for smart pointers.

Definition at line 154 of file CObject.h.

static CMatrixBPtr mrpt::math::CMatrixB::Create ( )
static
static mrpt::utils::CObject* mrpt::math::CMatrixB::CreateObject ( )
static
virtual mrpt::utils::CObject* mrpt::math::CMatrixB::duplicate ( ) const
virtual

Returns a copy of the object, indepently of its class.

Implements mrpt::utils::CObject.

mrpt::utils::CObjectPtr mrpt::utils::CObject::duplicateGetSmartPtr ( ) const
inlineinherited

Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object will exist as long as any copy of this smart pointer).

Definition at line 151 of file CObject.h.

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

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

Exceptions
std::exceptionOn index out of bounds.

Definition at line 463 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, and THROW_EXCEPTION.

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

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

Exceptions
std::exceptionOn index out of bounds.

Definition at line 481 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, mrpt::math::CMatrixTemplate< T >::setSize(), and THROW_EXCEPTION.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractColumns ( size_t  firstCol,
size_t  lastCol,
CMatrixTemplate< T > &  out 
) const
inlineinherited

Gets a series of contiguous columns.

  \exception std::logic_error On index out of bounds
See Also
extractColumn
extractRows

Definition at line 455 of file CMatrixTemplate.h.

References mrpt::math::detail::extractMatrix(), mrpt::math::CMatrixTemplate< T >::m_Rows, and mrpt::math::CMatrixTemplate< T >::setSize().

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractRows ( size_t  firstRow,
size_t  lastRow,
CMatrixTemplate< T > &  out 
) const
inlineinherited

Gets a series of contiguous rows.

  \exception std::logic_error On index out of bounds
See Also
extractRow
extractColumns

Definition at line 445 of file CMatrixTemplate.h.

References mrpt::math::detail::extractMatrix(), mrpt::math::CMatrixTemplate< T >::m_Cols, and mrpt::math::CMatrixTemplate< T >::setSize().

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
inlineinherited
template<class T>
template<class Derived >
void mrpt::math::CMatrixTemplate< T >::extractSubmatrix ( const size_t  row1,
const size_t  row2,
const size_t  col1,
const size_t  col2,
Eigen::MatrixBase< Derived > &  out 
) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 426 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, and THROW_EXCEPTION.

template<class T>
void mrpt::math::CMatrixTemplate< T >::fillAll ( const T &  val)
inlineinherited

Fill all the elements with a given value (Note: named "fillAll" since "fill" will be used by child classes)

Definition at line 133 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, and mrpt::math::CMatrixTemplate< T >::m_Val.

template<class T>
const T& mrpt::math::CMatrixTemplate< T >::get_unsafe ( size_t  row,
size_t  col 
) const
inlineinherited

Fast but unsafe method to read a value from the matrix.

Definition at line 364 of file CMatrixTemplate.h.

References mrpt::format(), mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, and THROW_EXCEPTION.

template<class T>
T& mrpt::math::CMatrixTemplate< T >::get_unsafe ( size_t  row,
size_t  col 
)
inlineinherited

Fast but unsafe method to get a reference from the matrix.

Definition at line 375 of file CMatrixTemplate.h.

References mrpt::format(), mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, and THROW_EXCEPTION.

template<class T>
T* mrpt::math::CMatrixTemplate< T >::get_unsafe_row ( size_t  row)
inlineinherited

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

Definition at line 386 of file CMatrixTemplate.h.

References mrpt::format(), mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, PRIuPTR, and THROW_EXCEPTION.

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

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

Definition at line 397 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::m_Val.

template<class T>
void mrpt::math::CMatrixTemplate< T >::getAsVector ( std::vector< T > &  out) const
inlineinherited

Returns a vector containing the matrix's values.

Definition at line 566 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, and mrpt::math::CMatrixTemplate< T >::m_Val.

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::getColCount ( ) const
inlineinherited

Number of columns in the matrix.

See Also
getRowCount, getColCount, nr, nc

Definition at line 250 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::m_Cols.

Referenced by mrpt::math::CMatrixTemplate< T >::ASSERT_ENOUGHROOM().

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::getRowCount ( ) const
inlineinherited

Number of rows in the matrix.

See Also
getRowCount, getColCount, nr, nc

Definition at line 245 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::m_Rows.

Referenced by mrpt::math::CMatrixTemplate< T >::ASSERT_ENOUGHROOM().

virtual const mrpt::utils::TRuntimeClassId* mrpt::math::CMatrixB::GetRuntimeClass ( ) const
virtual

Returns information about the class of an object in runtime.

Reimplemented from mrpt::utils::CSerializable.

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

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

  \exception std::exception On index out of bounds
See Also
extractCol

Definition at line 553 of file CMatrixTemplate.h.

References ASSERT_, mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, and THROW_EXCEPTION.

template<class T>
T& mrpt::math::CMatrixTemplate< T >::operator() ( size_t  row,
size_t  col 
)
inlineinherited
template<class T>
const T& mrpt::math::CMatrixTemplate< T >::operator() ( size_t  row,
size_t  col 
) const
inlineinherited
template<class T>
T& mrpt::math::CMatrixTemplate< T >::operator() ( size_t  ith)
inlineinherited

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

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

Definition at line 298 of file CMatrixTemplate.h.

References ASSERT_, mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, and THROW_EXCEPTION_CUSTOM_MSG1.

template<class T>
T mrpt::math::CMatrixTemplate< T >::operator() ( size_t  ith) const
inlineinherited

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

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

Definition at line 326 of file CMatrixTemplate.h.

References ASSERT_, mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, mrpt::math::CMatrixTemplate< T >::m_Val, and THROW_EXCEPTION_CUSTOM_MSG1.

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
inlineinherited

Subscript operator to get a submatrix.

Definition at line 403 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::extractSubmatrix().

CMatrixB& mrpt::math::CMatrixB::operator= ( const CMatrixBool &  m)
inline

Assignment operator for float matrixes.

Definition at line 66 of file CMatrixB.h.

References mrpt::math::CMatrixTemplate< T >::operator=().

void mrpt::math::CMatrixB::readFromStream ( mrpt::utils::CStream &  in,
int  version 
)
protectedvirtual

Introduces a pure virtual method responsible for loading from a CStream This can not be used directly be users, instead use "stream >> object;" for reading it from a stream or "stream >> object_ptr;" if the class is unknown apriori.

Parameters
inThe input binary stream where the object data must read from.
versionThe version of the object stored in the stream: use this version number in your code to know how to read the incoming data.
Exceptions
std::exceptionOn any error, see CStream::ReadBuffer
See Also
CStream

Implements mrpt::utils::CSerializable.

template<class T>
void mrpt::math::CMatrixTemplate< T >::realloc ( size_t  row,
size_t  col,
bool  newElementsToZero = false 
)
inlineprotectedinherited
template<class T>
void mrpt::math::CMatrixTemplate< T >::resize ( const CMatrixTemplateSize &  siz,
bool  zeroNewElements = false 
)
inlineinherited

This method just checks has no effects in this class, but raises an exception if the expected size does not match.

Definition at line 268 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::setSize().

template<class T>
void mrpt::math::CMatrixTemplate< T >::set_unsafe ( size_t  row,
size_t  col,
const T &  v 
)
inlineinherited
template<class T>
void mrpt::math::CMatrixTemplate< T >::setSize ( size_t  row,
size_t  col,
bool  zeroNewElements = false 
)
inlineinherited
template<class T>
CMatrixTemplateSize mrpt::math::CMatrixTemplate< T >::size ( ) const
inlineinherited

Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))

Definition at line 253 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::m_Cols, and mrpt::math::CMatrixTemplate< T >::m_Rows.

template<class T>
void mrpt::math::CMatrixTemplate< T >::swap ( CMatrixTemplate< T > &  o)
inlineinherited

Swap with another matrix very efficiently (just swaps a pointer and two integer values).

Definition at line 140 of file CMatrixTemplate.h.

References mrpt::math::CMatrixTemplate< T >::m_Cols, mrpt::math::CMatrixTemplate< T >::m_Rows, and mrpt::math::CMatrixTemplate< T >::m_Val.

void mrpt::math::CMatrixB::writeToStream ( mrpt::utils::CStream &  out,
int *  getVersion 
) const
protectedvirtual

Introduces a pure virtual method responsible for writing to a CStream.

This can not be used directly be users, instead use "stream << object;" for writing it to a stream.

Parameters
outThe output binary stream where object must be dumped.
getVersionIf NULL, the object must be dumped. If not, only the version of the object dump must be returned in this pointer. This enables the versioning of objects dumping and backward compatibility with previously stored data.
Exceptions
std::exceptionOn any error, see CStream::WriteBuffer
See Also
CStream

Implements mrpt::utils::CSerializable.

Member Data Documentation

mrpt::utils::CLASSINIT mrpt::math::CMatrixB::_init_CMatrixB
staticprotected

Definition at line 50 of file CMatrixB.h.

mrpt::utils::TRuntimeClassId mrpt::math::CMatrixB::classCMatrixB
static

Definition at line 50 of file CMatrixB.h.

const mrpt::utils::TRuntimeClassId mrpt::utils::CObject::classCObject
staticinherited

Definition at line 139 of file CObject.h.

const mrpt::utils::TRuntimeClassId mrpt::utils::CSerializable::classCSerializable
staticinherited

Definition at line 56 of file CSerializable.h.

const mrpt::utils::TRuntimeClassId* mrpt::math::CMatrixB::classinfo
static

Definition at line 50 of file CMatrixB.h.

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::m_Cols
protectedinherited
template<class T>
size_t mrpt::math::CMatrixTemplate< T >::m_Rows
protectedinherited
template<class T>
T** mrpt::math::CMatrixTemplate< T >::m_Val
protectedinherited



Page generated by Doxygen 1.8.3.1 for MRPT 0.9.6 SVN: at Mon May 27 08:59:54 UTC 2013