cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
12 This software is provided "as is" under an open source license, with
13 no warranty. The complete license can be found in license.txt and
14 http://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 
29 
44 template <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 */
52  VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType);
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 
69  {}
70 
72  vctFixedSizeMatrixRef(pointer p) {
73  SetRef(p);
74  }
75 
80  template <size_type __rows, size_type __cols, class __dataPtrType>
82  {
83  SetRef(matrix, 0, 0);
84  }
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>
137  {
138  SetRef(matrix.Pointer());
139  }
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  }
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 */
204 template <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 */
224 template <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
236  inputVectorRef(vector.Pointer());
238  resultRef(result.Pointer());
239  resultRef.ProductOf(inputVectorRef, matrix);
240 }
241 
242 #endif // DOXYGEN
243 
244 
245 #endif // _vctFixedSizeMatrixRef_h
size_t index_type
Definition: vctContainerTraits.h:36
A template for a fixed size matrix with fixed spacing in memory.
Definition: vctFixedSizeConstMatrixBase.h:103
void SetRef(pointer p)
Definition: vctFixedSizeMatrixRef.h:108
vctFixedSizeMatrixRef()
Definition: vctFixedSizeMatrixRef.h:68
vctFixedSizeMatrixRef(vctFixedSizeMatrixBase< __rows, __cols, _rowStride, _colStride, _elementType, __dataPtrType > &matrix, index_type startRow, index_type startCol)
Definition: vctFixedSizeMatrixRef.h:90
Definition: vctDynamicMatrixBase.h:42
vctFixedSizeMatrixRef(pointer p)
Definition: vctFixedSizeMatrixRef.h:72
void SetRef(const ThisType &other)
Definition: vctFixedSizeMatrixRef.h:112
ThisType & operator=(const ThisType &other)
Definition: vctFixedSizeMatrixRef.h:169
Declaration of vctFixedSizeMatrixBase.
ThisType & Assign(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, __elementType, __dataPtrType > &other)
Definition: vctFixedSizeMatrixBase.h:475
void SetRef(vctDynamicMatrixBase< __matrixOwnerType, _elementType > &matrix, index_type startRow, index_type startCol)
Definition: vctFixedSizeMatrixRef.h:151
ThisType & ProductOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix, const value_type scalar)
Definition: vctFixedSizeMatrixBase.h:909
MatrixTraits::const_reverse_iterator const_reverse_iterator
Definition: vctFixedSizeMatrixRef.h:60
size_t size_type
Definition: vctContainerTraits.h:35
Definition: vctFixedStrideMatrixIterator.h:361
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
vctFixedSizeMatrixRef< value_type, _rows, _cols, _rowStride, _colStride > ThisType
Definition: vctFixedSizeMatrixRef.h:63
Matrix iterator.
Definition: vctFixedStrideMatrixIterator.h:90
Definition: vctDynamicConstMatrixBase.h:77
vctFixedSizeMatrixBase< _rows, _cols, _rowStride, _colStride, value_type, typename MatrixTraits::pointer > BaseType
Definition: vctFixedSizeMatrixRef.h:65
vctFixedSizeMatrixTraits< _elementType, _rows, _cols, _rowStride, _colStride > MatrixTraits
Definition: vctFixedSizeMatrixRef.h:55
void SetRef(vctFixedSizeMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, __dataPtrType > &matrix)
Definition: vctFixedSizeMatrixRef.h:136
A template for a fixed size matrix with fixed spacings in memory.
Definition: vctFixedSizeMatrixBase.h:58
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition: vctDynamicMatrixBase.h:143
size_type rows() const
Definition: vctDynamicConstMatrixBase.h:238
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
An implementation of the ``abstract'' vctFixedSizeMatrixBase.
Definition: vctFixedSizeMatrixRef.h:46
size_type cols() const
Definition: vctDynamicConstMatrixBase.h:243
const_pointer Pointer(size_type index=0) const
Definition: vctFixedSizeConstVectorBase.h:268
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
vctFixedSizeMatrixRef(vctDynamicMatrixBase< __matrixOwnerType, _elementType > &matrix, index_type startRow, index_type startCol)
Definition: vctFixedSizeMatrixRef.h:101
#define cmnThrow(a)
Definition: MinimalCmn.h:4
void SetRef(vctFixedSizeMatrixBase< __rows, __cols, _rowStride, _colStride, _elementType, __dataPtrType > &matrix, index_type startRow, index_type startCol)
Definition: vctFixedSizeMatrixRef.h:126
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeVectorBase.h:76
ptrdiff_t stride_type
Definition: vctContainerTraits.h:37
MatrixTraits::iterator iterator
Definition: vctFixedSizeMatrixRef.h:57
MatrixTraits::reverse_iterator reverse_iterator
Definition: vctFixedSizeMatrixRef.h:59
difference_type row_stride() const
Definition: vctDynamicConstMatrixBase.h:263
An implementation of the ``abstract'' vctFixedSizeConstMatrixBase.
Definition: vctFixedSizeConstMatrixRef.h:50
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeConstVectorBase.h:107
difference_type col_stride() const
Definition: vctDynamicConstMatrixBase.h:268
pointer Pointer(size_type index=0)
Definition: vctFixedSizeVectorBase.h:226
Define common container related types based on the properties of a fixed size container.
Definition: vctFixedSizeMatrixTraits.h:46
MatrixTraits::const_iterator const_iterator
Definition: vctFixedSizeMatrixRef.h:58
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition: vctFixedSizeMatrixBase.h:161
vctFixedSizeMatrixRef(vctFixedSizeMatrixBase< __rows, __cols, _rowStride, _colStride, _elementType, __dataPtrType > &matrix)
Definition: vctFixedSizeMatrixRef.h:81