58 typename SparseMatrixMap::const_reverse_iterator;
95 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 96 if (
r >=
mRows ||
c >=
mColumns)
throw std::logic_error(
"Out of range");
106 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 107 if (
r >=
mRows ||
c >=
mColumns)
throw std::logic_error(
"Out of range");
126 template <
typename VECTOR>
127 void getRow(
size_t nRow, VECTOR& vec)
const 129 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 130 if (nRow >=
mRows)
throw std::logic_error(
"Out of range");
133 size_t nextIndex = 0;
137 const std::pair<size_t, size_t>&
index = it->first;
138 if (
index.first < nRow)
140 else if (
index.first == nRow)
142 for (
size_t i = nextIndex; i <
index.second; i++) vec[i] = T();
143 vec[
index.second] = it->second;
144 nextIndex =
index.second + 1;
148 for (
size_t i = nextIndex; i <
mColumns; i++) vec[i] = T();
158 template <
typename VECTOR>
161 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 162 if (nCol >=
mColumns)
throw std::logic_error(
"Out of range");
165 size_t nextIndex = 0;
169 const std::pair<size_t, size_t>&
index = it->first;
170 if (
index.second == nCol)
172 for (
size_t i = nextIndex; i <
index.first; i++) vec[i] = T();
173 vec[
index.first] = it->second;
174 nextIndex =
index.first + 1;
177 for (
size_t i = nextIndex; i <
mRows; i++) vec[i] = T();
189 template <
class MATRIX_LIKE>
192 for (
size_t nr = 0; nr < mat.rows(); nr++)
193 for (
size_t nc = 0; nc < mat.cols(); nc++)
194 operator()(
row + nr,
column + nc) = mat(nr, nc);
235 template <
typename VECTOR>
236 void setRow(
size_t nRow,
const VECTOR& vec,
const T& nullObject = T())
238 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 239 if (nRow >=
mRows)
throw std::logic_error(
"Out of range");
241 size_t N = vec.size();
242 if (N !=
mColumns)
throw std::logic_error(
"Wrong-sized vector");
243 for (
size_t i = 0; i < N; i++)
245 const T&
obj = vec[i];
246 std::pair<size_t, size_t>
index = std::make_pair(nRow, i);
247 if (
obj == nullObject)
260 template <
typename VECTOR>
261 void setColumn(
size_t nCol,
const VECTOR& vec,
const T& nullObject = T())
263 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 264 if (nCol >=
mColumns)
throw std::logic_error(
"Out of range");
266 size_t N = vec.size();
267 if (N !=
mRows)
throw std::logic_error(
"Wrong-sized vector");
268 for (
size_t i = 0; i < N; i++)
270 const T&
obj = vec[i];
271 std::pair<size_t, size_t>
index = std::make_pair(i, nCol);
272 if (
obj == nullObject)
288 std::vector<std::pair<size_t, size_t>> toErase;
292 const std::pair<size_t, size_t>& i = it->first;
293 if (i.first >= nRows || i.second >= nCols)
294 toErase.push_back(it->first);
298 it != toErase.end(); ++it)
307 size_t firstRow,
size_t lastRow,
size_t firstColumn,
308 size_t lastColumn)
const 310 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 312 throw std::logic_error(
"Out of range");
313 if (firstRow > lastRow || firstColumn > lastColumn)
314 throw std::logic_error(
"Invalid size");
317 lastRow + 1 - firstRow, lastColumn + 1 - firstColumn);
321 const std::pair<size_t, size_t>& i = it->first;
322 if (i.first >= firstRow && i.first <= lastRow &&
323 i.second >= firstColumn && i.second <= lastColumn)
324 res(i.first - firstRow, i.second - firstColumn) = it->second;
332 template <
typename VECTOR>
340 vec.push_back(it->second);
364 inline bool isNull(
size_t nRow,
size_t nCol)
const 367 throw std::logic_error(
"Out of range");
368 return objectList.count(std::make_pair(nRow, nCol)) == 0;
377 throw std::logic_error(
"Out of range");
378 return objectList.count(std::make_pair(nRow, nCol)) > 0;
390 std::vector<std::pair<size_t, size_t>> nulls;
392 if (it->second == nullObject) nulls.push_back(it->first);
395 it != nulls.end(); ++it)
429 if (
c <
r) std::swap(
r,
c);
439 if (
c <
r) std::swap(
r,
c);
442 throw std::logic_error(
"Out of range");
void insertMatrix(size_t row, size_t column, const MATRIX_LIKE &mat)
Inserts submatrix at a given location.
const_iterator begin() const
Returns an iterator which points to the starting point of the matrix.
bool isNotNull(size_t nRow, size_t nCol) const
Checks whether an element of the matrix is not the default object.
void getAsVector(VECTOR &vec) const
Gets a vector containing all the elements of the matrix, ignoring their position. ...
size_t getNullElements() const
Gets the amount of null elements inside the matrix.
size_t getNonNullElements() const
Gets the amount of non-null elements inside the matrix.
typename SparseMatrixMap::const_reverse_iterator const_reverse_iterator
Const reverse iterator to move through the matrix.
void getRow(size_t nRow, VECTOR &vec) const
Extracts a full row from the matrix.
void insert(size_t row, size_t column, const T &obj)
Inserts an element into the matrix.
T & operator()(size_t r, size_t c)
Reference access operator.
GLsizei GLsizei GLuint * obj
CSparseSymmetricalMatrix(const CSparseSymmetricalMatrix &o)
A sparse matrix container (with cells of any type), with iterators.
bool empty() const
Are there no elements set to !=0 ?
void purge(T nullObject=T())
Checks each non-null elements against the basic objects, erasing unnecesary references to it...
CSparseMatrixTemplate(size_t nR, size_t nC)
Constructor with default size.
This base provides a set of functions for maths stuff.
T operator()(size_t r, size_t c) const
Element access operator.
size_t cols() const
Returns the amount of columns in this matrix.
virtual ~CSparseSymmetricalMatrix()
typename std::map< std::pair< size_t, size_t >, T > SparseMatrixMap
Internal map type, used to store the actual matrix.
size_t rows() const
Returns the amount of rows in this matrix.
CSparseMatrixTemplate()
Basic constructor with no data.
size_t mRows
Size of the matrix.
const_reverse_iterator rend() const
Returns an iterator which points to the starting point of the matrix, although it's the upper limit o...
void clear()
Completely removes all elements, although maintaining the matrix's size.
CSparseSymmetricalMatrix(const CSparseMatrixTemplate< T > &o)
const_iterator end() const
Returns an iterator which points to the end of the matrix.
bool isNull(size_t nRow, size_t nCol) const
Checks whether an element of the matrix is the default object.
CSparseSymmetricalMatrix()
GLdouble GLdouble GLdouble r
T operator()(size_t r, size_t c) const
CSparseMatrixTemplate< T > operator()(size_t firstRow, size_t lastRow, size_t firstColumn, size_t lastColumn) const
Extracts a submatrix form the matrix.
void setRow(size_t nRow, const VECTOR &vec, const T &nullObject=T())
Inserts a full row into the matrix.
SparseMatrixMap objectList
Actual matrix.
GLenum GLenum GLvoid * row
void resize(size_t nRows, size_t nCols)
Changes the size of the matrix.
void getColumn(size_t nCol, VECTOR &vec) const
Extracts a full column from the matrix.
bool exists(size_t r, size_t c) const
Element access operator.
void setColumn(size_t nCol, const VECTOR &vec, const T &nullObject=T())
Inserts a full column into the matrix.
void resize(size_t matrixSize)
const_reverse_iterator rbegin() const
Returns an iterator which points to the end of the matrix, and can be used to move backwards...
GLenum GLenum GLvoid GLvoid * column
const Scalar * const_iterator
typename SparseMatrixMap::const_iterator const_iterator
Const iterator to move through the matrix.
T & operator()(size_t r, size_t c)
A sparse matrix container for square symmetrical content around the main diagonal.