cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctFixedSizeMatrix.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 
6  Author(s): Ofri Sadowsky
7  Created on: 2003-11-04
8 
9  (C) Copyright 2003-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 #pragma once
22 #ifndef _vctFixedSizeMatrix_h
23 #define _vctFixedSizeMatrix_h
24 
32 
33 
51 template<class _elementType, vct::size_type _rows, vct::size_type _cols, bool _rowMajor>
53 <_rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows, _elementType,
54  typename vctFixedSizeMatrixTraits<_elementType, _rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows>::array >
55 {
56  public:
57  /* define most types from vctContainerTraits */
58  VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType);
59 
60  /* no need to document, inherit doxygen documentation from vctFixedSizeVectorBase */
62 
64  typedef vctFixedSizeMatrixBase<_rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows, _elementType,
65  typename vctFixedSizeMatrixTraits<_elementType, _rows, _cols,
66  _rowMajor?_cols:1, _rowMajor?1:_rows>::array >
69 
70  typedef typename MatrixTraits::iterator iterator;
74 
75  typedef class cmnTypeTraits<value_type> TypeTraits;
76  typedef typename TypeTraits::VaArgPromotion ElementVaArgPromotion;
77 
80  {}
81 
85  explicit inline vctFixedSizeMatrix(const value_type & value) {
86  this->SetAll(value);
87  }
88 
102  inline vctFixedSizeMatrix(const value_type element0, const value_type element1, ...)
103  {
104  CMN_ASSERT( this->size() > 1 );
105  (*this).at(0) = element0;
106  (*this).at(1) = element1;
107  index_type elementIndex = 2;
108  const size_type numElements = this->size();
109  va_list nextArg;
110  va_start(nextArg, element1);
111  for (; elementIndex < numElements; ++elementIndex) {
112  (*this).at(elementIndex) = value_type( va_arg(nextArg, ElementVaArgPromotion) );
113  }
114  va_end(nextArg);
115  }
116 
122  template <class __elementType, stride_type __rowStride, stride_type __colStride, class __dataPtrType>
123  explicit inline
125  this->Assign(matrix);
126  }
127 
137  template <class __matrixOwnerType>
139  {
140  this->Assign(matrix);
141  }
142 
143  template <stride_type __rowStride, stride_type __colStride, class __elementType, class __dataPtrType>
145  // Experimental static_cast replacing reinterpret_cast. Return the reinterpret_cast if you encounter
146  // compilation errors.
147  return static_cast<ThisType &>(this->Assign(other));
148  }
149 
150  inline ThisType & operator = (const ThisType & other) {
151  return static_cast<ThisType &>(this->Assign(other));
152  }
153 
154  template <stride_type __rowStride, stride_type __colStride>
156  {
157  return static_cast<ThisType &>(this->Assign(other));
158  }
159 
160  template <stride_type __rowStride, stride_type __colStride, class __elementType>
162  {
163  this->Assign(other);
164  return *this;
165  }
166 
168  inline ThisType & operator = (const value_type & value) {
169  this->SetAll(value);
170  return *this;
171  }
172 
173 };
174 
175 
176 
177 
184 template <vct::size_type _rows, vct::size_type _cols,
185  vct::stride_type _input1RowStride, vct::stride_type _input1ColStride, class _input1Data,
186  vct::stride_type _input2RowStride, vct::stride_type _input2ColStride, class _input2Data, class _elementType>
191  result.SumOf(matrix1, matrix2);
192  return result;
193 }
194 
195 /* documented above */
196 template <vct::size_type _rows, vct::size_type _cols,
197  vct::stride_type _input1RowStride, vct::stride_type _input1ColStride, class _input1Data,
198  vct::stride_type _input2RowStride, vct::stride_type _input2ColStride, class _input2Data, class _elementType>
203  result.DifferenceOf(matrix1, matrix2);
204  return result;
205 }
207 
208 
215 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
218  const _elementType & scalar)
219 {
221  result.SumOf(matrix, scalar);
222  return result;
223 }
224 
225 /* documented above */
226 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
229  const _elementType & scalar)
230 {
232  result.DifferenceOf(matrix, scalar);
233  return result;
234 }
235 
236 /* documented above */
237 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
240  const _elementType & scalar)
241 {
243  result.ProductOf(matrix, scalar);
244  return result;
245 }
246 
247 /* documented above */
248 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
251  const _elementType & scalar)
252 {
254  result.RatioOf(matrix, scalar);
255  return result;
256 }
258 
259 
266 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
268 operator + (const _elementType & scalar,
270 {
272  result.SumOf(scalar, matrix);
273  return result;
274 }
275 
276 /* documented above */
277 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
279 operator - (const _elementType & scalar,
281 {
283  result.DifferenceOf(scalar, matrix);
284  return result;
285 }
286 
287 /* documented above */
288 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
290 operator * (const _elementType & scalar,
292 {
294  result.ProductOf(scalar, matrix);
295  return result;
296 }
297 
298 /* documented above */
299 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
301 operator / (const _elementType & scalar,
303 {
305  result.RatioOf(scalar, matrix);
306  return result;
307 }
309 
310 
311 
318 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
321 {
323  result.NegationOf(matrix);
324  return result;
325 }
327 
328 
329 template <vct::size_type _rows, vct::size_type _cols, vct::size_type _input1Cols,
330  vct::stride_type _input1RowStride, vct::stride_type _input1ColStride, class _input1DataPtrType,
331  vct::stride_type _input2RowStride, vct::stride_type _input2ColStride, class _input2DataPtrType,
332  class _elementType>
337  result.ProductOf(input1Matrix, input2Matrix);
338  return result;
339 }
340 
341 
342 template <vct::size_type _rows, vct::size_type _cols,
343  vct::stride_type _inputMatrixRowStride, vct::stride_type _inputMatrixColStride, class _inputMAtrixDataPtrType,
344  vct::stride_type _inputVectorStride, class _inputVectorDataPtrType,
345  class _elementType>
349 {
351  result.ProductOf(inputMatrix, inputVector);
352  return result;
353 }
354 
355 
356 template <vct::size_type _rows, vct::size_type _cols,
357  vct::stride_type _inputVectorStride, class _inputVectorDataPtrType,
358  vct::stride_type _inputMatrixRowStride, vct::stride_type _inputMatrixColStride, class _inputMatrixDataPtrType,
359  class _elementType>
363 {
365  result.ProductOf(inputVector, inputMatrix);
366  return result;
367 }
368 
369 
370 /*
371  Methods declared previously and implemented here because they require vctFixedSizeVector
372 */
373 #ifndef DOXYGEN
374 
375 /* documented in class vctFixedSizeConstMatrixBase */
376 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
379  MatrixValueType result;
382  Run(result, *this);
383  return result;
384 }
385 
386 /* documented in class vctFixedSizeConstMatrixBase */
387 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
390  MatrixValueType result;
393  Run(result, *this);
394  return result;
395 }
396 
397 /* documented in class vctFixedSizeConstMatrixBase */
398 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
401  MatrixValueType result;
404  Run(result, *this);
405  return result;
406 }
407 
408 /* documented in class vctFixedSizeConstMatrixBase */
409 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
412  MatrixValueType result;
415  Run(result, *this);
416  return result;
417 }
418 
419 /* documented in class vctFixedSizeConstMatrixBase */
420 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride, class _elementType, class _dataPtrType>
423  static MatrixValueType result(_elementType(0));
424 #if (CISST_COMPILER == CISST_GCC) || (CISST_COMPILER == CISST_CLANG)
425  result.Diagonal().SetAll(_elementType(1));
426 #else
427  static _elementType value(result.Diagonal().SetAll(_elementType(1)));
428 #endif
429  return result;
430 }
431 
432 /* documented in class vctFixedSizeConstMatrixBase */
433 template <vct::size_type _rows, vct::size_type _cols,
434  vct::stride_type _rowStride, vct::stride_type _colStride, class _dataPtrType,
435  vct::stride_type __rowStride, vct::stride_type __colStride, class __dataPtrType,
436  class _elementType,
437  class _elementOperationType>
440  _elementType, _dataPtrType> & matrix1,
441  const vctFixedSizeConstMatrixBase<_rows, _cols, __rowStride, __colStride,
442  _elementType, __dataPtrType> & matrix2) {
445  MoMiMi<_elementOperationType>::Run(result, matrix1, matrix2);
446  return result;
447 }
448 
449 /* documented in class vctFixedSizeConstMatrixBase */
450 template <vct::size_type _rows, vct::size_type _cols,
451  vct::stride_type _rowStride, vct::stride_type _colStride, class _dataPtrType,
452  class _elementType,
453  class _elementOperationType>
456  _elementType, _dataPtrType> & matrix,
457  const _elementType & scalar) {
460  MoMiSi<_elementOperationType>::Run(result, matrix, scalar);
461  return result;
462 }
463 #endif // DOXYGEN
464 
465 
466 #endif // _vctFixedSizeMatrix_h
467 
size_t index_type
Definition: vctContainerTraits.h:36
A template for a fixed size matrix with fixed spacing in memory.
Definition: vctFixedSizeConstMatrixBase.h:103
vctFixedSizeMatrix()
Definition: vctFixedSizeMatrix.h:79
Declaration of vctFixedSizeConstMatrixRef.
vctFixedSizeMatrix< bool, _rows, _cols > vctFixedSizeMatrixElementwiseCompareMatrix(const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &matrix1, const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, _elementType, __dataPtrType > &matrix2)
Definition: vctFixedSizeMatrix.h:439
#define CMN_ASSERT(expr)
Definition: cmnAssert.h:90
static const MatrixValueType & Eye(void)
Definition: vctFixedSizeMatrix.h:422
vctFixedSizeMatrix< _elementType, _rows, _cols > operator*(const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &matrix, const _elementType &scalar)
Definition: vctFixedSizeMatrix.h:239
vctFixedSizeMatrix< _elementType, _rows, _cols, _rowMajor > ThisType
Definition: vctFixedSizeMatrix.h:68
ThisType & Assign(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, __elementType, __dataPtrType > &other)
Definition: vctFixedSizeMatrixBase.h:475
static void Run(_outputMatrixType &outputMatrix, const _input1MatrixType &input1Matrix, const _input2MatrixType &input2Matrix)
Definition: vctFixedSizeMatrixLoopEngines.h:81
ThisType & ProductOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix, const value_type scalar)
Definition: vctFixedSizeMatrixBase.h:909
Definition: vctFixedSizeMatrixLoopEngines.h:137
size_t size_type
Definition: vctContainerTraits.h:35
Declaration of vctFixedSizeMatrixRef.
Definition: vctFixedStrideMatrixIterator.h:361
ThisType & NegationOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &otherMatrix)
Definition: vctFixedSizeMatrixBase.h:1159
Matrix iterator.
Definition: vctFixedStrideMatrixIterator.h:90
Definition: vctDynamicConstMatrixBase.h:77
Implementation of a fixed-size vector using template metaprogramming.
Definition: vctFixedSizeVector.h:52
vctFixedSizeMatrixBase< _rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows, _elementType, typename vctFixedSizeMatrixTraits< _elementType, _rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows >::array > BaseType
Definition: vctFixedSizeMatrix.h:67
vctFixedSizeMatrix(const vctDynamicConstMatrixBase< __matrixOwnerType, value_type > &matrix)
Definition: vctFixedSizeMatrix.h:138
vctFixedSizeMatrix(const value_type element0, const value_type element1,...)
Definition: vctFixedSizeMatrix.h:102
MatrixValueType Negation(void) const
Definition: vctFixedSizeMatrix.h:389
TypeTraits::VaArgPromotion ElementVaArgPromotion
Definition: vctFixedSizeMatrix.h:76
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
vctFixedSizeMatrixTraits< _elementType, _rows, _cols, _rowMajor?_cols:1, _rowMajor?1:_rows > MatrixTraits
Definition: vctFixedSizeMatrix.h:61
MatrixValueType Floor(void) const
Definition: vctFixedSizeMatrix.h:400
A template for a fixed size matrix with fixed spacings in memory.
Definition: vctFixedSizeMatrixBase.h:58
class cmnTypeTraits< value_type > TypeTraits
Definition: vctFixedSizeMatrix.h:75
MatrixValueType Abs(void) const
Definition: vctFixedSizeMatrix.h:378
vctFixedSizeMatrix< _elementType, _rows, _cols > operator-(const vctFixedSizeConstMatrixBase< _rows, _cols, _input1RowStride, _input1ColStride, _elementType, _input1Data > &matrix1, const vctFixedSizeConstMatrixBase< _rows, _cols, _input2RowStride, _input2ColStride, _elementType, _input2Data > &matrix2)
Definition: vctFixedSizeMatrix.h:200
vctFixedSizeMatrix< _elementType, _rows, _cols > operator/(const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &matrix, const _elementType &scalar)
Definition: vctFixedSizeMatrix.h:250
MatrixTraits::iterator iterator
Definition: vctFixedSizeMatrix.h:70
MatrixValueType Ceil(void) const
Definition: vctFixedSizeMatrix.h:411
vctFixedSizeMatrix< _elementType, _rows, _cols > operator+(const vctFixedSizeConstMatrixBase< _rows, _cols, _input1RowStride, _input1ColStride, _elementType, _input1Data > &matrix1, const vctFixedSizeConstMatrixBase< _rows, _cols, _input2RowStride, _input2ColStride, _elementType, _input2Data > &matrix2)
Definition: vctFixedSizeMatrix.h:188
MatrixTraits::reverse_iterator reverse_iterator
Definition: vctFixedSizeMatrix.h:72
Implementation of a fixed-size matrix using template metaprogramming.
Definition: vctFixedSizeMatrix.h:52
MatrixTraits::const_reverse_iterator const_reverse_iterator
Definition: vctFixedSizeMatrix.h:73
ThisType & operator=(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, __elementType, __dataPtrType > &other)
Definition: vctFixedSizeMatrix.h:144
vctFixedSizeMatrix< bool, _rows, _cols > vctFixedSizeMatrixElementwiseCompareScalar(const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &matrix, const _elementType &scalar)
Definition: vctFixedSizeMatrix.h:455
ptrdiff_t stride_type
Definition: vctContainerTraits.h:37
ThisType & DifferenceOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __input1RowStride, __input1ColStride, value_type, __input1DataPtrType > &input1Matrix, const vctFixedSizeConstMatrixBase< _rows, _cols, __input2RowStride, __input2ColStride, value_type, __input2DataPtrType > &input2Matrix)
Definition: vctFixedSizeMatrixBase.h:729
MatrixTraits::const_iterator const_iterator
Definition: vctFixedSizeMatrix.h:71
ThisType & RatioOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix, const value_type scalar)
Definition: vctFixedSizeMatrixBase.h:919
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
vctFixedSizeMatrix(const value_type &value)
Definition: vctFixedSizeMatrix.h:85
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition: cmnTypeTraits.h:155
vctFixedSizeMatrix(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, __elementType, __dataPtrType > &matrix)
Definition: vctFixedSizeMatrix.h:124
ThisType & SumOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __input1RowStride, __input1ColStride, value_type, __input1DataPtrType > &input1Matrix, const vctFixedSizeConstMatrixBase< _rows, _cols, __input2RowStride, __input2ColStride, value_type, __input2DataPtrType > &input2Matrix)
Definition: vctFixedSizeMatrixBase.h:717
Define common container related types based on the properties of a fixed size container.
Definition: vctFixedSizeMatrixTraits.h:46
static void Run(_outputMatrixType &outputMatrix, const _inputMatrixType &inputMatrix, const _inputScalarType inputScalar)
Definition: vctFixedSizeMatrixLoopEngines.h:270
ThisType & ProductOf(const vctFixedSizeConstVectorBase< _size, __stride, value_type, __dataPtrType > &vector, const value_type scalar)
Definition: vctFixedSizeVectorBase.h:1003