cisst-saw
Loading...
Searching...
No Matches
vctDynamicMatrixRef.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5 Author(s): Ofri Sadowsky, Anton Deguet
6 Created on: 2004-07-01
7
8 (C) Copyright 2004-2018 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19#pragma once
20#ifndef _vctDynamicMatrixRef_h
21#define _vctDynamicMatrixRef_h
22
27
30
73template <class _elementType>
74class vctDynamicMatrixRef: public vctDynamicMatrixBase<vctDynamicMatrixRefOwner<_elementType>, _elementType>
75{
76public:
77 /* documented in base class */
79 enum {DIMENSION = 2};
81
89
91 SetRef(0, 0, 1, 1, 0);
92 }
93
101 BaseType()
102 {
103 SetRef(other.sizes(), other.strides(), const_cast<pointer>(other.Pointer()));
104 }
105
111 vctDynamicMatrixRef(size_type rows, size_type cols, stride_type rowStride, stride_type colStride,
112 pointer dataPointer)
113 {
114 SetRef(rows, cols, rowStride, colStride, dataPointer);
115 }
116
117 vctDynamicMatrixRef(const nsize_type & matrixSize, stride_type rowStride, stride_type colStride,
118 pointer dataPointer)
119 {
120 SetRef(matrixSize, rowStride, colStride, dataPointer);
121 }
122
123 vctDynamicMatrixRef(const nsize_type & matrixSize, const nstride_type & matrixStride,
124 pointer dataPointer)
125 {
126 SetRef(matrixSize, matrixStride, dataPointer);
127 }
128
129
130
136 vctDynamicMatrixRef(size_type rows, size_type cols, pointer dataPointer, bool storageOrder = VCT_DEFAULT_STORAGE)
137 {
138 SetRef(rows, cols, dataPointer, storageOrder);
139 }
140
141 vctDynamicMatrixRef(const nsize_type & matrixSize, pointer dataPointer, bool storageOrder = VCT_DEFAULT_STORAGE)
142 {
143 SetRef(matrixSize, dataPointer, storageOrder);
144 }
145
146
147
153 template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
158
169 template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
171 size_type startRow, size_type startCol, size_type rows, size_type cols)
172 {
173 SetRef(otherMatrix, startRow, startCol, rows, cols);
174 }
175
181 template <class __ownerType>
183 {
184 SetRef(otherMatrix);
185 }
186
197 //@
198 template <class __ownerType>
200 size_type startRow, size_type startCol, size_type rows, size_type cols)
201 {
202 SetRef(otherMatrix, startRow, startCol, rows, cols);
203 }
204
205 template <class __ownerType>
207 const nsize_type & start, const nsize_type & matrixSize)
208 {
209 SetRef(otherMatrix, start, matrixSize);
210 }
211
212
217 void SetRef(size_type rows, size_type cols,
218 stride_type rowStride, stride_type colStride,
219 pointer dataPointer) {
220 this->Matrix.SetRef(rows, cols, rowStride, colStride, dataPointer);
221 }
222
223 void SetRef(const nsize_type & matrixSize,
224 stride_type rowStride, stride_type colStride,
225 pointer dataPointer) {
226 this->Matrix.SetRef(matrixSize, rowStride, colStride, dataPointer);
227 }
228
229 void SetRef(const nsize_type & matrixSize,
230 const nstride_type & matrixStride,
231 pointer dataPointer) {
232 this->Matrix.SetRef(matrixSize, matrixStride, dataPointer);
233 }
234
235
236
242 void SetRef(size_type rows, size_type cols, pointer dataPointer, bool storageOrder = VCT_DEFAULT_STORAGE)
243 {
244 this->Matrix.SetRef(rows, cols, dataPointer, storageOrder);
245 }
246
247 void SetRef(const nsize_type & sizes, pointer dataPointer, bool storageOrder = VCT_DEFAULT_STORAGE)
248 {
249 this->Matrix.SetRef(sizes, dataPointer, storageOrder);
250 }
251
252
253
257 template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
259 {
260 SetRef(otherMatrix.rows(), otherMatrix.cols(), otherMatrix.row_stride(), otherMatrix.col_stride(),
261 otherMatrix.Pointer());
262 }
263
276 template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
278 size_type startRow, size_type startCol, size_type rows, size_type cols)
279 {
280 if ( (startRow + rows > otherMatrix.rows()) || (startCol + cols > otherMatrix.cols()) ) {
281 cmnThrow(std::out_of_range("vctDynamicMatrixRef SetRef out of range"));
282 }
283 SetRef(rows, cols, otherMatrix.row_stride(), otherMatrix.col_stride(), otherMatrix.Pointer(startRow, startCol));
284 }
285
289 template <class __ownerType>
291 {
292 SetRef(otherMatrix.rows(), otherMatrix.cols(), otherMatrix.row_stride(), otherMatrix.col_stride(),
293 otherMatrix.Pointer());
294 }
295
309 template <class __ownerType>
311 size_type startRow, size_type startCol, size_type rows, size_type cols)
312 {
313 if ( (startRow + rows > otherMatrix.rows()) || (startCol + cols > otherMatrix.cols()) ) {
314 cmnThrow(std::out_of_range("vctDynamicMatrixRef SetRef out of range"));
315 }
316 SetRef(rows, cols, otherMatrix.row_stride(), otherMatrix.col_stride(),
317 otherMatrix.Pointer(startRow, startCol));
318 }
319
320 template <class __ownerType>
322 const nsize_type & start, const nsize_type & matrixSize)
323 {
324 SetRef(otherMatrix,
325 start.Element(0), start.Element(1), matrixSize.Element(0), matrixSize.Element(1));
326 }
327
328
335 inline ThisType & operator = (const ThisType & other) {
336 return reinterpret_cast<ThisType &>(this->Assign(other));
337 }
338
340 return reinterpret_cast<ThisType &>(this->Assign(other));
341 }
342
343 template <class __matrixOwnerType, typename __elementType>
345 return reinterpret_cast<ThisType &>(this->Assign(other));
346 }
347
348 template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
352
353
355 inline ThisType & operator = (const value_type & value) {
356 this->SetAll(value);
357 return *this;
358 }
359
363 void DeSerializeRaw(std::istream & inputStream) CISST_THROW(std::runtime_error)
364 {
365 // get and set size
366 size_type myRows;
367 size_type myCols;
368 cmnDeSerializeRaw(inputStream, myRows);
369 cmnDeSerializeRaw(inputStream, myCols);
370
371 if ((myRows != this->rows()) || (myCols != this->cols())) {
372 cmnThrow(std::runtime_error("vctDynamicMatrixRef::DeSerializeRaw: Sizes of matrices don't match"));
373 }
374
375 // get data
376 size_type indexRow, indexCol;
377 for (indexRow = 0; indexRow < myRows; ++indexRow) {
378 for (indexCol = 0; indexCol < myCols; ++indexCol) {
379 cmnDeSerializeRaw(inputStream, this->Element(indexRow, indexCol));
380 }
381 }
382 }
383
384};
385
386
387/*
388 Methods declared and use for vctDynamicVectorBase. Implemented here
389 since these need the const-matrix base.
390*/
391#ifndef DOXYGEN
392template <class _resultVectorOwnerType, class _matrixOwnerType, class _vectorOwnerType, class _elementType>
393inline
397 const vctDynamicConstMatrixRef<_elementType> inputVectorRef(vector.size(), 1,
398 vector.stride(), 1,
399 vector.Pointer());
400 vctDynamicMatrixRef<_elementType> resultRef(result.size(), 1,
401 result.stride(), 1,
402 result.Pointer());
403 resultRef.ProductOf(matrix, inputVectorRef);
404}
405
406
407template <class _resultVectorOwnerType, class _vectorOwnerType, class _matrixOwnerType, class _elementType>
408inline
412 const vctDynamicConstMatrixRef<_elementType> inputVectorRef(1, vector.size() * vector.stride(),
413 1, vector.stride(),
414 vector.Pointer());
415 vctDynamicMatrixRef<_elementType> resultRef(1, result.size() * result.stride(),
416 1, result.stride(),
417 result.Pointer());
418 resultRef.ProductOf(inputVectorRef, matrix);
419}
420#endif // DOXYGEN
421
422#endif // _vctDynamicMatrixRef_h
Definition vctForwardDeclarations.h:145
Dynamic matrix referencing existing memory (const).
Definition vctDynamicConstMatrixRef.h:81
Definition vctForwardDeclarations.h:119
Definition vctDynamicMatrixBase.h:43
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition vctDynamicMatrixBase.h:143
ThisType & Assign(const vctDynamicConstMatrixBase< __matrixOwnerType, value_type > &other)
Definition vctDynamicMatrixBase.h:509
reference Element(size_type rowIndex, size_type colIndex)
Definition vctDynamicMatrixBase.h:214
value_type SetAll(const value_type value)
Definition vctDynamicMatrixBase.h:452
ThisType & ProductOf(const vctDynamicConstMatrixBase< __matrixOwnerType, _elementType > &matrix, const value_type scalar)
Definition vctDynamicMatrixBase.h:971
Dynamic matrix referencing existing memory.
Definition vctDynamicMatrixRef.h:75
vctDynamicMatrixRef(const ThisType &other)
Definition vctDynamicMatrixRef.h:100
vctDynamicMatrixBase< vctDynamicMatrixRefOwner< value_type >, value_type > BaseType
Definition vctDynamicMatrixRef.h:84
vctDynamicMatrixRef(size_type rows, size_type cols, pointer dataPointer, bool storageOrder=VCT_DEFAULT_STORAGE)
Definition vctDynamicMatrixRef.h:136
void DeSerializeRaw(std::istream &inputStream) CISST_THROW(std
Definition vctDynamicMatrixRef.h:363
void SetRef(vctDynamicMatrixBase< __ownerType, _elementType > &otherMatrix, size_type startRow, size_type startCol, size_type rows, size_type cols)
Definition vctDynamicMatrixRef.h:310
vctDynamicMatrixRefOwner< value_type > MatrixOwnerType
Definition vctDynamicMatrixRef.h:83
void SetRef(const nsize_type &matrixSize, stride_type rowStride, stride_type colStride, pointer dataPointer)
Definition vctDynamicMatrixRef.h:223
VCT_NARRAY_TRAITS_TYPEDEFS(DIMENSION)
void SetRef(vctDynamicMatrixBase< __ownerType, _elementType > &otherMatrix, const nsize_type &start, const nsize_type &matrixSize)
Definition vctDynamicMatrixRef.h:321
vctDynamicMatrixRef(size_type rows, size_type cols, stride_type rowStride, stride_type colStride, pointer dataPointer)
Definition vctDynamicMatrixRef.h:111
@ DIMENSION
Definition vctDynamicMatrixRef.h:79
MatrixOwnerType::const_iterator const_iterator
Definition vctDynamicMatrixRef.h:86
MatrixOwnerType::const_reverse_iterator const_reverse_iterator
Definition vctDynamicMatrixRef.h:88
vctDynamicMatrixRef(vctFixedSizeMatrixBase< __rows, __cols, __rowStride, __colStride, _elementType, __dataPtrType > &otherMatrix, size_type startRow, size_type startCol, size_type rows, size_type cols)
Definition vctDynamicMatrixRef.h:170
vctDynamicMatrixRef(vctDynamicMatrixBase< __ownerType, _elementType > &otherMatrix)
Definition vctDynamicMatrixRef.h:182
vctDynamicMatrixRef(const nsize_type &matrixSize, stride_type rowStride, stride_type colStride, pointer dataPointer)
Definition vctDynamicMatrixRef.h:117
MatrixOwnerType::iterator iterator
Definition vctDynamicMatrixRef.h:85
void SetRef(size_type rows, size_type cols, stride_type rowStride, stride_type colStride, pointer dataPointer)
Definition vctDynamicMatrixRef.h:217
vctDynamicMatrixRef(vctDynamicMatrixBase< __ownerType, _elementType > &otherMatrix, size_type startRow, size_type startCol, size_type rows, size_type cols)
Definition vctDynamicMatrixRef.h:199
void SetRef(const nsize_type &sizes, pointer dataPointer, bool storageOrder=VCT_DEFAULT_STORAGE)
Definition vctDynamicMatrixRef.h:247
void SetRef(vctDynamicMatrixBase< __ownerType, _elementType > &otherMatrix)
Definition vctDynamicMatrixRef.h:290
vctDynamicMatrixRef()
Definition vctDynamicMatrixRef.h:90
ThisType & operator=(const ThisType &other)
Definition vctDynamicMatrixRef.h:335
void SetRef(vctFixedSizeMatrixBase< __rows, __cols, __rowStride, __colStride, _elementType, __dataPtrType > &otherMatrix)
Definition vctDynamicMatrixRef.h:258
vctDynamicMatrixRef< value_type > ThisType
Definition vctDynamicMatrixRef.h:82
vctDynamicMatrixRef(vctFixedSizeMatrixBase< __rows, __cols, __rowStride, __colStride, _elementType, __dataPtrType > &otherMatrix)
Definition vctDynamicMatrixRef.h:154
void SetRef(size_type rows, size_type cols, pointer dataPointer, bool storageOrder=VCT_DEFAULT_STORAGE)
Definition vctDynamicMatrixRef.h:242
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
void SetRef(vctFixedSizeMatrixBase< __rows, __cols, __rowStride, __colStride, _elementType, __dataPtrType > &otherMatrix, size_type startRow, size_type startCol, size_type rows, size_type cols)
Definition vctDynamicMatrixRef.h:277
MatrixOwnerType::reverse_iterator reverse_iterator
Definition vctDynamicMatrixRef.h:87
vctDynamicMatrixRef(const nsize_type &matrixSize, pointer dataPointer, bool storageOrder=VCT_DEFAULT_STORAGE)
Definition vctDynamicMatrixRef.h:141
vctDynamicMatrixRef(const nsize_type &matrixSize, const nstride_type &matrixStride, pointer dataPointer)
Definition vctDynamicMatrixRef.h:123
void SetRef(const nsize_type &matrixSize, const nstride_type &matrixStride, pointer dataPointer)
Definition vctDynamicMatrixRef.h:229
vctDynamicMatrixRef(vctDynamicMatrixBase< __ownerType, _elementType > &otherMatrix, const nsize_type &start, const nsize_type &matrixSize)
Definition vctDynamicMatrixRef.h:206
Definition vctDynamicMatrixRefOwner.h:40
vctVarStrideMatrixIterator< value_type > reverse_iterator
Definition vctDynamicMatrixRefOwner.h:53
vctVarStrideMatrixConstIterator< value_type > const_reverse_iterator
Definition vctDynamicMatrixRefOwner.h:51
vctVarStrideMatrixConstIterator< value_type > const_iterator
Definition vctDynamicMatrixRefOwner.h:50
vctVarStrideMatrixIterator< value_type > iterator
Definition vctDynamicMatrixRefOwner.h:52
void SetRef(size_type rows, size_type cols, pointer dataPointer, bool storageOrder)
Definition vctDynamicMatrixRefOwner.h:74
Definition vctDynamicVectorBase.h:62
pointer Pointer(index_type index=0)
Definition vctDynamicVectorBase.h:155
A template for a fixed size matrix with fixed spacing in memory.
Definition vctFixedSizeConstMatrixBase.h:104
size_type cols() const
Definition vctFixedSizeConstMatrixBase.h:282
difference_type row_stride() const
Definition vctFixedSizeConstMatrixBase.h:303
size_type rows() const
Definition vctFixedSizeConstMatrixBase.h:277
difference_type col_stride() const
Definition vctFixedSizeConstMatrixBase.h:309
A template for a fixed size matrix with fixed spacings in memory.
Definition vctFixedSizeMatrixBase.h:60
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition vctFixedSizeMatrixBase.h:161
void cmnDeSerializeRaw(std::istream &inputStream, _elementType &data) CISST_THROW(std
Definition cmnDeSerializer.h:82
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
size_type cols() const
Definition vctDynamicConstMatrixBase.h:243
OwnerType Matrix
Definition vctDynamicConstMatrixBase.h:167
const nsize_type & sizes(void) const
Definition vctDynamicConstMatrixBase.h:233
size_type rows() const
Definition vctDynamicConstMatrixBase.h:238
Declaration of vctDynamicConstMatrixRef.
Declaration of vctDynamicMatrixBase.
void vctMultiplyMatrixVector(vctDynamicVectorBase< _resultVectorOwnerType, _elementType > &result, const vctDynamicConstMatrixBase< _matrixOwnerType, _elementType > &matrix, const vctDynamicConstVectorBase< _vectorOwnerType, _elementType > &vector)
Definition vctDynamicMatrixRef.h:394
void vctMultiplyVectorMatrix(vctDynamicVectorBase< _resultVectorOwnerType, _elementType > &result, const vctDynamicConstVectorBase< _vectorOwnerType, _elementType > &vector, const vctDynamicConstMatrixBase< _matrixOwnerType, _elementType > &matrix)
Definition vctDynamicMatrixRef.h:409
const bool VCT_DEFAULT_STORAGE
Definition vctForwardDeclarations.h:47