Go to the documentation of this file.
26 using Base = std::array<size_t, 2>;
46 inline operator size_t(
void)
const {
return 2; }
90 void realloc(
size_t row,
size_t col,
bool newElementsToZero =
false)
95 bool doZeroColumns = newElementsToZero && (col >
m_Cols);
96 size_t sizeZeroColumns =
sizeof(T) * (col -
m_Cols);
108 m_Val =
static_cast<T**
>(
112 size_t row_size = col *
sizeof(T);
121 m_Val[
r] =
static_cast<T*
>(
135 ::memset(
m_Val[
r], 0, row_size);
152 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
190 const size_t cropColCount)
195 realloc(cropRowCount, cropColCount);
196 for (
size_t i = 0; i <
m_Rows; i++)
209 template <
typename V,
size_t N>
218 "Mismatch between matrix size %lu x %lu and array of "
220 static_cast<long unsigned>(
m_Rows),
221 static_cast<long unsigned>(
m_Cols),
222 static_cast<long unsigned>(N)))
224 for (
size_t i = 0; i <
m_Rows; i++)
225 for (
size_t j = 0; j <
m_Cols; j++)
226 m_Val[i][j] =
static_cast<T
>(theArray[idx++]);
233 template <
typename V>
237 const size_t N = theVector.size();
242 "Mismatch between matrix size %lu x %lu and array of "
244 static_cast<long unsigned>(
m_Rows),
245 static_cast<long unsigned>(
m_Cols),
246 static_cast<long unsigned>(N)))
248 for (
size_t i = 0; i <
m_Rows; i++)
249 for (
size_t j = 0; j <
m_Cols; j++)
250 m_Val[i][j] =
static_cast<T
>(*(it++));
259 for (
size_t i = 0; i <
m_Rows; i++)
276 template <
typename V,
size_t N>
284 "Mismatch between matrix size %lu x %lu and array of "
289 for (
size_t i = 0; i <
m_Rows; i++)
290 for (
size_t j = 0; j <
m_Cols; j++)
291 m_Val[i][j] =
static_cast<T
>(theArray[idx++]);
313 void setSize(
size_t row,
size_t col,
bool zeroNewElements =
false)
323 setSize(siz[0], siz[1], zeroNewElements);
330 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
334 "Indexes (%lu,%lu) out of range. Matrix is %lux%lu",
335 static_cast<unsigned long>(
row),
336 static_cast<unsigned long>(col),
337 static_cast<unsigned long>(
m_Rows),
338 static_cast<unsigned long>(
m_Cols)));
347 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
351 "Indexes (%lu,%lu) out of range. Matrix is %lux%lu",
352 static_cast<unsigned long>(
row),
353 static_cast<unsigned long>(col),
354 static_cast<unsigned long>(
m_Rows),
355 static_cast<unsigned long>(
m_Cols)));
366 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
372 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
375 "Index %u out of range!",
static_cast<unsigned>(ith));
377 return m_Val[0][ith];
382 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
385 "Index %u out of range!",
static_cast<unsigned>(ith));
387 return m_Val[ith][0];
397 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
403 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
406 "Index %u out of range!",
static_cast<unsigned>(ith));
408 return m_Val[0][ith];
413 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
416 "Index %u out of range!",
static_cast<unsigned>(ith));
418 return m_Val[ith][0];
430 "Indexes (%lu,%lu) out of range. Matrix is %lux%lu",
431 static_cast<unsigned long>(
row),
432 static_cast<unsigned long>(col),
433 static_cast<unsigned long>(
m_Rows),
434 static_cast<unsigned long>(
m_Cols)));
447 "Indexes (%lu,%lu) out of range. Matrix is %lux%lu",
448 static_cast<unsigned long>(
row),
449 static_cast<unsigned long>(col),
450 static_cast<unsigned long>(
m_Rows),
451 static_cast<unsigned long>(
m_Cols)));
464 "Indexes (%lu,%lu) out of range. Matrix is %lux%lu",
465 static_cast<unsigned long>(
row),
466 static_cast<unsigned long>(col),
467 static_cast<unsigned long>(
m_Rows),
468 static_cast<unsigned long>(
m_Cols)));
482 "Row index %lu out of range. Matrix is %lux%lu",
483 static_cast<unsigned long>(
row),
484 static_cast<unsigned long>(
m_Rows),
485 static_cast<unsigned long>(
m_Cols)));
497 const size_t row1,
const size_t row2,
const size_t col1,
498 const size_t col2)
const
509 const size_t row1,
const size_t row2,
const size_t col1,
512 int nrows = int(row2) - int(row1) + 1;
513 int ncols = int(col2) - int(col1) + 1;
514 if (nrows <= 0 || ncols <= 0)
522 for (
int i = 0; i < nrows; i++)
523 for (
int j = 0; j < ncols; j++)
527 template <
class EIGEN_MATRIX>
529 const size_t row1,
const size_t row2,
const size_t col1,
530 const size_t col2, EIGEN_MATRIX& out)
const
532 int nrows = int(row2) - int(row1) + 1;
533 int ncols = int(col2) - int(col1) + 1;
534 if (nrows <= 0 || ncols <= 0)
536 out =
typename EIGEN_MATRIX::PlainObject();
541 out.resize(nrows, ncols);
542 for (
int i = 0; i < nrows; i++)
543 for (
int j = 0; j < ncols; j++)
544 out.coeffRef(i, j) =
m_Val[i + row1][j + col1];
574 void extractCol(
size_t nCol, std::vector<T>& out,
int startingRow = 0)
const
577 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
585 for (i = 0; i <
n; i++) out[i] =
m_Val[i + startingRow][nCol];
595 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
603 for (i = 0; i <
n; i++) out(i, 0) =
m_Val[i + startingRow][nCol];
674 size_t n =
in.size();
677 for (
size_t i = 0; i <
n; i++)
m_Val[i][nCol] =
in[i];
686 for (
size_t i = 0; i <
m_Rows; i++)
void fillAll(const T &val)
CMatrixTemplate(size_t row, size_t col, V(&theArray)[N])
Constructor from a given size and a C array.
CMatrixTemplate & operator=(const CMatrixTemplate &m)
Assignment operator from another matrix.
void aligned_free(void *ptr)
CMatrixTemplate(size_t row, size_t col, const V &theVector)
Constructor from a given size and a STL container (std::vector, std::list,...) with the initial value...
const Scalar * const_iterator
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
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 o...
CMatrixBool & operator=(const CMatrixTemplate< bool > &m)
Assignment operator for float matrixes.
std::array< size_t, 2 > Base
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn't exist already.
Declares a matrix of booleans (non serializable).
CMatrixBool(size_t row=1, size_t col=1)
Constructor.
const T & get_unsafe(size_t row, size_t col) const
Fast but unsafe method to read a value from the matrix.
Auxiliary class used in CMatrixTemplate:size(), CMatrixTemplate::resize(), CMatrixFixedNumeric::size(...
void insertCol(size_t nCol, const std::vector< T > &in)
Inserts a column from a vector, replacing the current contents of that column.
This template class provides the basic functionality for a general 2D any-size, resizable container o...
CMatrixTemplate(const CMatrixTemplate &m)
Constructors.
CMatrixTemplate(size_t row=1, size_t col=1)
T & operator()(size_t ith)
Subscript operator to get/set an individual element from a row or column matrix.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void * aligned_malloc(size_t size, size_t alignment)
void extractCol(size_t nCol, std::vector< T > &out, int startingRow=0) const
Returns a given column to a vector (without modifying the matrix)
#define THROW_EXCEPTION(msg)
#define ASSERT_(f)
Defines an assertion mechanism.
bool operator!=(const CMatrixTemplateSize &o) const
void getAsVector(std::vector< T > &out) const
Returns a vector containing the matrix's values.
CMatrixTemplate & operator=(V(&theArray)[N])
Assignment operator for initializing from a C array (The matrix must be set to the correct size befor...
size_t rows() const
Number of rows in the matrix.
void * aligned_realloc(void *ptr, size_t size, size_t alignment)
#define MRPT_COMPILE_TIME_ASSERT(expression)
T & get_unsafe(size_t row, size_t col)
Fast but unsafe method to get a reference from the matrix.
void set_unsafe(size_t row, size_t col, const T &v)
Fast but unsafe method to write a value in the matrix.
void extractMatrix(const MATORG &M, const size_t first_row, const size_t first_col, MATDEST &outMat)
Extract a submatrix - The output matrix must be set to the required size before call.
T & operator()(size_t row, size_t col)
Subscript operator to get/set individual elements.
GLdouble GLdouble GLdouble r
T operator()(size_t ith) const
Subscript operator to get/set an individual element from a row or column matrix.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
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 extractColumns(size_t firstCol, size_t lastCol, CMatrixTemplate< T > &out) const
Gets a series of contiguous columns.
void appendRow(const std::vector< T > &in)
Appends a new row to the MxN matrix from a 1xN vector.
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 ap...
std::ptrdiff_t difference_type
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 pos...
void appendCol(const std::vector< T > &in)
Appends a new column to the matrix from a vector.
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 do...
CMatrixTemplate(const CMatrixTemplate &m, const size_t cropRowCount, const size_t cropColCount)
Copy constructor & crop from another matrix.
void extractRows(size_t firstRow, size_t lastRow, CMatrixTemplate< T > &out) const
Gets a series of contiguous rows.
bool operator==(const CMatrixTemplateSize &o) const
GLenum GLenum GLvoid * row
CMatrixTemplateSize(const size_t *d)
void extractCol(size_t nCol, CMatrixTemplate< T > &out, int startingRow=0) const
Gets a given column to a vector (without modifying the matrix)
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.
size_t cols() const
Number of columns in the matrix.
virtual ~CMatrixTemplate()
Destructor.
const T & operator()(size_t row, size_t col) const
Subscript operator to get individual elements.
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.
CMatrixTemplateSize size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
void swap(CMatrixTemplate< T > &o)
Swap with another matrix very efficiently (just swaps a pointer and two integer values).
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 applica...
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 | |