cisst-saw
Loading...
Searching...
No Matches
vctFixedSizeMatrixRef.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
6 Created on: 2003-11-04
7
8 (C) Copyright 2003-2015 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 _vctFixedSizeMatrixRef_h
21#define _vctFixedSizeMatrixRef_h
22
27
29
44template <class _elementType, vct::size_type _rows, vct::size_type _cols,
45 vct::stride_type _rowStride, vct::stride_type _colStride>
47 <_rows, _cols,_rowStride, _colStride, _elementType,
48 typename vctFixedSizeMatrixTraits<_elementType, _rows, _cols, _rowStride, _colStride>::pointer>
49{
50 public:
51 /* define most types from vctContainerTraits */
53
54 typedef vctFixedSizeMatrixTraits<_elementType, _rows, _cols,
55 _rowStride, _colStride> MatrixTraits;
56
57 typedef typename MatrixTraits::iterator iterator;
61
62 typedef vctFixedSizeMatrixRef<value_type, _rows, _cols,
63 _rowStride, _colStride> ThisType;
64 typedef vctFixedSizeMatrixBase<_rows, _cols, _rowStride, _colStride, value_type,
65 typename MatrixTraits::pointer> BaseType;
66
70
73 SetRef(p);
74 }
75
80 template <size_type __rows, size_type __cols, class __dataPtrType>
85
86
89 template <size_type __rows, size_type __cols, class __dataPtrType>
92 & matrix, index_type startRow, index_type startCol )
93 {
94 SetRef(matrix, startRow, startCol);
95 }
96
100 template <class __matrixOwnerType>
102 index_type startRow, index_type startCol)
103 {
104 SetRef(matrix, startRow, startCol);
105 }
106
108 void SetRef(pointer p) {
109 this->Data = p;
110 }
111
112 void SetRef(const ThisType & other) {
113 this->SetRef(other.Data);
114 }
115
125 template <size_type __rows, size_type __cols, class __dataPtrType>
127 index_type startRow, index_type startCol)
128 {
129 if ((startRow + this->rows() > matrix.rows()) || (startCol + this->cols() > matrix.cols())) {
130 cmnThrow(std::out_of_range("vctFixedSizeMatrixRef SetRef out of range"));
131 }
132 SetRef(matrix.Pointer(startRow, startCol));
133 }
134
135 template <class __dataPtrType>
140
150 template <class __matrixOwnerType>
152 index_type startRow, index_type startCol)
153 {
154 if ((this->row_stride() != matrix.row_stride()) || (this->col_stride() == matrix.col_stride())) {
155 cmnThrow(std::runtime_error("vctFixedSizeMatrixRef SetRef with incompatible stride(s)"));
156 }
157 if ((startRow + this->rows() > matrix.rows()) || (startCol + this->cols() > matrix.cols())) {
158 cmnThrow(std::out_of_range("vctFixedSizeMatrixRef SetRef out of range"));
159 }
160 SetRef(matrix.Pointer(startRow, startCol));
161 }
162
169 inline ThisType & operator = (const ThisType & other) {
170 return reinterpret_cast<ThisType &>(this->Assign(other));
171 }
172
173 template <stride_type __rowStride, stride_type __colStride>
175 return reinterpret_cast<ThisType &>(this->Assign(other));
176 }
177
178 template <stride_type __rowStride, stride_type __colStride, class __elementType, class __dataPtrType>
180 return reinterpret_cast<ThisType &>(this->Assign(other));
181 }
182
183 template <class __matrixOwnerType>
185 return reinterpret_cast<ThisType &>(this->Assign(other));
186 }
187
188
190 inline ThisType & operator = (const value_type & value) {
191 this->SetAll(value);
192 return *this;
193 }
194
195};
196
197
198#ifndef DOXYGEN
199
200/* MultiplyMatrixVector function declaration is in
201 vctFixedSizeVectorBase. This is an auxiliary function which
202 multiplies matrix*vector and stored the result directly into a
203 matrix */
204template <vct::size_type _resultSize, vct::stride_type _resultStride, class _resultElementType, class _resultDataPtrType,
205 vct::size_type _matrixCols, vct::stride_type _matrixRowStride, vct::stride_type _matrixColStride, class _matrixDataPtrType,
206 vct::stride_type _vectorStride, class _vectorDataPtrType>
208 // create matrix references to both vectors and use the matrix product
210 const vctFixedSizeConstMatrixBase<_resultSize, _matrixCols, _matrixRowStride, _matrixColStride,
211 _resultElementType, _matrixDataPtrType> & matrix,
213{
215 inputVectorRef(vector.Pointer());
217 resultRef.ProductOf(matrix, inputVectorRef);
218}
219
220/* MultiplyVectorMatrix function declaration is in
221 vctFixedSizeVectorBase. This is an auxiliary function which
222 multiplies vector*matrix and stored the result directly into a
223 vector */
224template <vct::size_type _resultSize, vct::stride_type _resultStride, class _resultElementType, class _resultDataPtrType,
225 vct::size_type _vectorSize, vct::stride_type _vectorStride, class _vectorDataPtrType,
226 vct::stride_type _matrixRowStride, vct::stride_type _matrixColStride, class _matrixDataPtrType >
230 const vctFixedSizeConstMatrixBase<_vectorSize, _resultSize, _matrixRowStride, _matrixColStride,
231 _resultElementType, _matrixDataPtrType> & matrix
232 )
233{
234 // create matrix references to both vectors and use the matrix product
235 const vctFixedSizeConstMatrixRef<_resultElementType, 1, _vectorSize, (_vectorStride*_vectorSize), _vectorStride>
236 inputVectorRef(vector.Pointer());
237 vctFixedSizeMatrixRef<_resultElementType, 1, _resultSize, (_resultStride*_resultSize), _resultStride>
238 resultRef(result.Pointer());
239 resultRef.ProductOf(inputVectorRef, matrix);
240}
241
242#endif // DOXYGEN
243
244
245#endif // _vctFixedSizeMatrixRef_h
Definition vctForwardDeclarations.h:145
Definition vctDynamicMatrixBase.h:43
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition vctDynamicMatrixBase.h:143
A template for a fixed size matrix with fixed spacing in memory.
Definition vctFixedSizeConstMatrixBase.h:104
size_type cols() const
Definition vctFixedSizeConstMatrixBase.h:282
size_type rows() const
Definition vctFixedSizeConstMatrixBase.h:277
Definition vctForwardDeclarations.h:106
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeConstVectorBase.h:108
const_pointer Pointer(size_type index=0) const
Definition vctFixedSizeConstVectorBase.h:268
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
Definition vctForwardDeclarations.h:110
Define common container related types based on the properties of a fixed size container.
Definition vctFixedSizeMatrixTraits.h:47
vctFixedStrideMatrixConstIterator< _elementType, -_colStride, _cols, -_rowStride > const_reverse_iterator
Definition vctFixedSizeMatrixTraits.h:62
vctFixedStrideMatrixIterator< _elementType, _colStride, _cols, _rowStride > iterator
Definition vctFixedSizeMatrixTraits.h:53
vctFixedStrideMatrixConstIterator< _elementType, _colStride, _cols, _rowStride > const_iterator
Definition vctFixedSizeMatrixTraits.h:56
vctFixedStrideMatrixIterator< _elementType, -_colStride, _cols, -_rowStride > reverse_iterator
Definition vctFixedSizeMatrixTraits.h:59
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeVectorBase.h:77
pointer Pointer(size_type index=0)
Definition vctFixedSizeVectorBase.h:226
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
size_t size_type
Definition vctContainerTraits.h:35
ptrdiff_t stride_type
Definition vctContainerTraits.h:37
#define VCT_CONTAINER_TRAITS_TYPEDEFS(type)
Definition vctContainerTraits.h:50
OwnerType::const_iterator const_iterator
Definition vctDynamicConstMatrixBase.h:95
difference_type row_stride() const
Definition vctDynamicConstMatrixBase.h:263
OwnerType::iterator iterator
Definition vctDynamicConstMatrixBase.h:92
size_type rows() const
Definition vctDynamicConstMatrixBase.h:238
OwnerType::const_reverse_iterator const_reverse_iterator
Definition vctDynamicConstMatrixBase.h:101
vctDynamicConstMatrixBase< _matrixOwnerType, _elementType > ThisType
Definition vctDynamicConstMatrixBase.h:86
OwnerType::reverse_iterator reverse_iterator
Definition vctDynamicConstMatrixBase.h:98
ThisType & operator=(const vctDynamicConstMatrixBase< __matrixOwnerType, __elementType > &otherMatrix)
Definition vctDynamicMatrix.h:255
vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension > BaseType
Definition vctDynamicNArray.h:133
void SetRef(pointer p)
Definition vctFixedSizeConstMatrixRef.h:114
vctFixedSizeMatrixTraits< _elementType, _rows, _cols, _rowStride, _colStride > MatrixTraits
Definition vctFixedSizeConstMatrixRef.h:59
Declaration of vctFixedSizeMatrixBase.
void MultiplyVectorMatrix(vctFixedSizeVectorBase< _resultSize, _resultStride, _resultElementType, _resultDataPtrType > &result, const vctFixedSizeConstVectorBase< _vectorSize, _vectorStride, _resultElementType, _vectorDataPtrType > &vector, const vctFixedSizeConstMatrixBase< _vectorSize, _resultSize, _matrixRowStride, _matrixColStride, _resultElementType, _matrixDataPtrType > &matrix)
Definition vctFixedSizeMatrixRef.h:227
void MultiplyMatrixVector(vctFixedSizeVectorBase< _resultSize, _resultStride, _resultElementType, _resultDataPtrType > &result, const vctFixedSizeConstMatrixBase< _resultSize, _matrixCols, _matrixRowStride, _matrixColStride, _resultElementType, _matrixDataPtrType > &matrix, const vctFixedSizeConstVectorBase< _matrixCols, _vectorStride, _resultElementType, _vectorDataPtrType > &vector)
Definition vctFixedSizeMatrixRef.h:207