Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
mrpt::math::CMatrixTemplateObjects< T > Class Template Reference

Detailed Description

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

This template class extends the class "CMatrixTemplate" for storing "objects" at each matrix entry.

This class allows a very efficient representation of sparse matrixes where each cell is an arbitrary C++ class, but its use must carefully observe the following rules:

See also
CMatrixTemplate

Definition at line 47 of file CMatrixTemplateObjects.h.

#include <mrpt/math/CMatrixTemplateObjects.h>

Inheritance diagram for mrpt::math::CMatrixTemplateObjects< T >:
Inheritance graph

Public Types

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

Public Member Functions

 CMatrixTemplateObjects (const CMatrixTemplate< T > &m)
 Copy constructor. More...
 
 CMatrixTemplateObjects (size_t row=3, size_t col=3)
 Constructor. More...
 
virtual void setSize (size_t row, size_t col)
 Changes the size of matrix. More...
 
virtual ~CMatrixTemplateObjects ()
 Destructor. More...
 
void freeAllObjects ()
 Delete all the objects in the matrix and set all entries to nullptr. More...
 
CMatrixTemplateObjectsoperator= (const CMatrixTemplateObjects &m)
 Assignment operator. More...
 
void setDestroyBehavior (bool freeObjects=true)
 Sets the behavior on matrix destroy. More...
 
void allocAllObjects ()
 Alloc memory for all the non-NULL entries in the matrix. More...
 
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 rows () const
 Number of rows in the matrix. More...
 
size_t cols () 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...
 
void extractSubmatrix (const size_t row1, const size_t row2, const size_t col1, const size_t col2, EIGEN_MATRIX &out) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
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) More...
 
void extractCol (size_t nCol, CMatrixTemplate< T * > &out, int startingRow=0) const
 Gets a given column to a vector (without modifying the matrix) 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...
 

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

Protected Attributes

T * ** m_Val
 
size_t m_Rows
 
size_t m_Cols
 

Private Attributes

bool m_freeObjects
 

Member Typedef Documentation

◆ const_reference

using mrpt::math::CMatrixTemplate< T * >::const_reference = const T * &
inherited

Definition at line 79 of file CMatrixTemplate.h.

◆ difference_type

Definition at line 81 of file CMatrixTemplate.h.

◆ reference

using mrpt::math::CMatrixTemplate< T * >::reference = T * &
inherited

Definition at line 78 of file CMatrixTemplate.h.

◆ size_type

using mrpt::math::CMatrixTemplate< T * >::size_type = std::size_t
inherited

Definition at line 80 of file CMatrixTemplate.h.

◆ value_type

using mrpt::math::CMatrixTemplate< T * >::value_type = T *
inherited

The type of the matrix elements.

Definition at line 77 of file CMatrixTemplate.h.

Constructor & Destructor Documentation

◆ CMatrixTemplateObjects() [1/2]

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

Copy constructor.

Definition at line 55 of file CMatrixTemplateObjects.h.

◆ CMatrixTemplateObjects() [2/2]

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

Constructor.

Definition at line 62 of file CMatrixTemplateObjects.h.

◆ ~CMatrixTemplateObjects()

template<class T >
virtual mrpt::math::CMatrixTemplateObjects< T >::~CMatrixTemplateObjects ( )
inlinevirtual

Member Function Documentation

◆ allocAllObjects()

template<class T >
void mrpt::math::CMatrixTemplateObjects< T >::allocAllObjects ( )
inline

Alloc memory for all the non-NULL entries in the matrix.

See the general description of the class on the top.

Definition at line 121 of file CMatrixTemplateObjects.h.

◆ appendCol()

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

Exceptions
std::exceptionOn size mismatch.
See also
extractCol
appendRow

Definition at line 649 of file CMatrixTemplate.h.

◆ appendRow()

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.

// ...
M.appendRow(v);
M.appendRow(w);
Exceptions
std::exceptionOn incorrect vector length.
See also
extractRow
appendCol

Definition at line 620 of file CMatrixTemplate.h.

◆ ASSERT_ENOUGHROOM()

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

◆ cols()

size_t mrpt::math::CMatrixTemplate< T * >::cols
inlineinherited

Number of columns in the matrix.

See also
rows(), getColCount, nr, nc

Definition at line 302 of file CMatrixTemplate.h.

◆ extractCol() [1/2]

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

◆ extractCol() [2/2]

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

◆ extractColumns()

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

Gets a series of contiguous columns.

Exceptions
std::logic_errorOn index out of bounds
See also
extractColumn
extractRows

Definition at line 564 of file CMatrixTemplate.h.

◆ extractRows()

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

Gets a series of contiguous rows.

Exceptions
std::logic_errorOn index out of bounds
See also
extractRow
extractColumns

Definition at line 552 of file CMatrixTemplate.h.

◆ extractSubmatrix() [1/2]

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

Get a submatrix, given its bounds.

See also
extractSubmatrixSymmetricalBlocks

Definition at line 508 of file CMatrixTemplate.h.

◆ extractSubmatrix() [2/2]

void mrpt::math::CMatrixTemplate< T * >::extractSubmatrix ( const size_t  row1,
const size_t  row2,
const size_t  col1,
const size_t  col2,
EIGEN_MATRIX &  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 528 of file CMatrixTemplate.h.

◆ fillAll()

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

◆ freeAllObjects()

template<class T >
void mrpt::math::CMatrixTemplateObjects< T >::freeAllObjects ( )
inline

Delete all the objects in the matrix and set all entries to nullptr.

Definition at line 87 of file CMatrixTemplateObjects.h.

Referenced by mrpt::math::CMatrixTemplateObjects< T >::~CMatrixTemplateObjects().

◆ get_unsafe() [1/2]

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

◆ get_unsafe() [2/2]

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

◆ get_unsafe_row() [1/2]

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

◆ get_unsafe_row() [2/2]

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

◆ getAsVector()

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

Returns a vector containing the matrix's values.

Definition at line 682 of file CMatrixTemplate.h.

◆ insertCol()

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.

Exceptions
std::exceptionOn index out of bounds
See also
extractCol

Definition at line 669 of file CMatrixTemplate.h.

◆ operator()() [1/5]

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

◆ operator()() [2/5]

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

◆ operator()() [3/5]

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

◆ operator()() [4/5]

T * & mrpt::math::CMatrixTemplate< T * >::operator() ( size_t  row,
size_t  col 
)
inlineinherited

Subscript operator to get/set individual elements.

Definition at line 328 of file CMatrixTemplate.h.

◆ operator()() [5/5]

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

Subscript operator to get individual elements.

Definition at line 345 of file CMatrixTemplate.h.

◆ operator=()

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

◆ realloc()

void mrpt::math::CMatrixTemplate< T * >::realloc ( size_t  row,
size_t  col,
bool  newElementsToZero = false 
)
inlineprotectedinherited

Internal use only: It reallocs the memory for the 2D matrix, maintaining the previous contents if posible.

Definition at line 90 of file CMatrixTemplate.h.

◆ resize()

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

◆ rows()

size_t mrpt::math::CMatrixTemplate< T * >::rows
inlineinherited

Number of rows in the matrix.

See also
rows(), getColCount, nr, nc

Definition at line 298 of file CMatrixTemplate.h.

◆ set_unsafe()

void mrpt::math::CMatrixTemplate< T * >::set_unsafe ( size_t  row,
size_t  col,
const T * &  v 
)
inlineinherited

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

Definition at line 424 of file CMatrixTemplate.h.

◆ setDestroyBehavior()

template<class T >
void mrpt::math::CMatrixTemplateObjects< T >::setDestroyBehavior ( bool  freeObjects = true)
inline

Sets the behavior on matrix destroy.

See the general description of the class on the top.

Definition at line 113 of file CMatrixTemplateObjects.h.

References mrpt::math::CMatrixTemplateObjects< T >::m_freeObjects.

◆ setSize() [1/2]

template<class T >
virtual void mrpt::math::CMatrixTemplateObjects< T >::setSize ( size_t  row,
size_t  col 
)
inlinevirtual

Changes the size of matrix.

Definition at line 72 of file CMatrixTemplateObjects.h.

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

◆ setSize() [2/2]

void mrpt::math::CMatrixTemplate< T * >::setSize ( size_t  row,
size_t  col,
bool  zeroNewElements = false 
)
inlineinherited

Changes the size of matrix, maintaining the previous contents.

Definition at line 313 of file CMatrixTemplate.h.

◆ size()

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

Definition at line 304 of file CMatrixTemplate.h.

◆ swap()

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

Member Data Documentation

◆ m_Cols

size_t mrpt::math::CMatrixTemplate< T * >::m_Cols
protectedinherited

Definition at line 85 of file CMatrixTemplate.h.

◆ m_freeObjects

template<class T >
bool mrpt::math::CMatrixTemplateObjects< T >::m_freeObjects
private

◆ m_Rows

size_t mrpt::math::CMatrixTemplate< T * >::m_Rows
protectedinherited

Definition at line 85 of file CMatrixTemplate.h.

◆ m_Val

T * ** mrpt::math::CMatrixTemplate< T * >::m_Val
protectedinherited

Definition at line 84 of file CMatrixTemplate.h.

mrpt::math::CMatrixDouble
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
Definition: CMatrixTemplateNumeric.h:144
w
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
mrpt::math::CVectorDouble
dynamic_vector< double > CVectorDouble
Column vector, like Eigen::MatrixXd, but automatically initialized to zeros since construction.
Definition: eigen_frwds.h:46
v
const GLdouble * v
Definition: glext.h:3678



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST