cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctMatrixRotation3ConstBase.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): Anton Deguet
7  Created on: 2005-08-19
8 
9  (C) Copyright 2005-2012 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 _vctMatrixRotation3ConstBase_h
23 #define _vctMatrixRotation3ConstBase_h
24 
33 
34 #include <cisstVector/vctExport.h>
35 
56 template <class _containerType>
57 class vctMatrixRotation3ConstBase: public _containerType
58 {
59 public:
60  enum {ROWS = 3, COLS = 3};
61  enum {DIMENSION = 3};
62  typedef _containerType BaseType;
63  typedef _containerType ContainerType;
65 
66  /* no need to document, inherit doxygen documentation from base class */
67  VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type);
68 
71 
74 
75 
76 protected:
78  inline void ThrowUnlessIsNormalized(void) const throw(std::runtime_error) {
79  if (! IsNormalized()) {
80  cmnThrow(std::runtime_error("vctMatrixRotation3ConstBase: This rotation is not normalized"));
81  }
82  }
83 
88  template <class _inputType>
89  inline void ThrowUnlessIsNormalized(const _inputType & input) const throw(std::runtime_error) {
90  if (! input.IsNormalized()) {
91  cmnThrow(std::runtime_error("vctMatrixRotation3ConstBase: Input is not normalized"));
92  }
93  }
94 
95 public:
96 
104  static CISST_EXPORT const RotationValueType & Identity();
105 
109  RotationValueType Normalized(void) const; // implemented in vctMatrixRotation3.h
110 
118  inline bool IsNormalized(value_type tolerance = TypeTraits::Tolerance()) const {
119  NormType columnNorm;
120  columnNorm = this->Column(0).Norm();
121  if (vctUnaryOperations<NormType>::AbsValue::Operate(columnNorm - 1) > tolerance)
122  return false;
123  columnNorm = this->Column(1).Norm();
124  if (vctUnaryOperations<NormType>::AbsValue::Operate(columnNorm - 1) > tolerance)
125  return false;
126  columnNorm = this->Column(2).Norm();
127  if (vctUnaryOperations<NormType>::AbsValue::Operate(columnNorm - 1) > tolerance)
128  return false;
129  value_type columnDot;
130  columnDot = vctDotProduct(this->Column(0), this->Column(1));
131  if (vctUnaryOperations<value_type>::AbsValue::Operate(columnDot) > tolerance)
132  return false;
133  columnDot = vctDotProduct(this->Column(0), this->Column(2));
134  if (vctUnaryOperations<value_type>::AbsValue::Operate(columnDot) > tolerance)
135  return false;
136  columnDot = vctDotProduct(this->Column(1), this->Column(2));
137  if (vctUnaryOperations<value_type>::AbsValue::Operate(columnDot) > tolerance)
138  return false;
139  return true;
140  }
141 
145  RotationValueType Inverse(void) const; // implemented in vctMatrixRotation3.h
146 
147 
155  template <stride_type __stride1, class __dataPtrType1,
156  stride_type __stride2, class __dataPtrType2>
157  inline void
160  CMN_ASSERT(input.Pointer() != output.Pointer());
161  // Implementation note: We think working on a local copy of the input
162  // is faster than working on the members, because of fewer indirections,
163  // especially when combined with the dot product operation.
164  const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
165  output[0] = vctDotProduct( this->Row(0), inputCopy );
166  output[1] = vctDotProduct( this->Row(1), inputCopy );
167  output[2] = vctDotProduct( this->Row(2), inputCopy );
168  }
169 
170 
179  template <stride_type __stride, class __dataPtrType>
183  this->ApplyTo(input, result);
184  return result;
185  }
186 
187 
196  inline ThisType
197  ApplyTo(const ThisType & input) const {
198  CMN_ASSERT(input.Pointer() != this->Pointer());
199  ThisType result;
200  this->ApplyTo(input, result);
201  return result;
202  }
203 
204 
209  template <class __vectorOwnerType1, class __vectorOwnerType2>
210  inline void
213  throw(std::runtime_error)
214  {
215  CMN_ASSERT(input.Pointer() != output.Pointer());
216  CMN_ASSERT(input.size() == DIMENSION);
217  CMN_ASSERT(output.size() == DIMENSION);
218  // see implementation note for fixed size i/o version
219  const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
220  output[0] = vctDotProduct( this->Row(0), inputCopy );
221  output[1] = vctDotProduct( this->Row(1), inputCopy );
222  output[2] = vctDotProduct( this->Row(2), inputCopy );
223  }
224 
225 
226  template <class __vectorOwnerType, stride_type __stride, class __dataPtrType>
227  inline void
230  throw(std::runtime_error)
231  {
232  CMN_ASSERT(input.Pointer() != output.Pointer());
233  CMN_ASSERT(input.size() == DIMENSION);
234  // see implementation note for fixed size i/o version
235  const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
236  output[0] = vctDotProduct( this->Row(0), inputCopy );
237  output[1] = vctDotProduct( this->Row(1), inputCopy );
238  output[2] = vctDotProduct( this->Row(2), inputCopy );
239  }
240 
241 
245  template <class __vectorOwnerType>
249  this->ApplyTo(input, result);
250  return result;
251  }
252 
260  template <stride_type __stride1, class __dataPtrType1,
261  stride_type __stride2, class __dataPtrType2>
262  inline void
265  CMN_ASSERT(input.Pointer() != output.Pointer());
266  // see implementation note for fixed size i/o ApplyTo() version
267  const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
268  output[0] = vctDotProduct( inputCopy, this->Column(0) );
269  output[1] = vctDotProduct( inputCopy, this->Column(1) );
270  output[2] = vctDotProduct( inputCopy, this->Column(2) );
271  }
272 
273 
282  template <stride_type __stride, class __dataPtrType>
286  this->ApplyInverseTo(input, result);
287  return result;
288  }
289 
293  template <class __vectorOwnerType>
297  this->ApplyInverseTo(input, result);
298  return result;
299  }
300 
301 
302 
310  inline void ApplyInverseTo(const ThisType & input, ThisType & output) const {
311  CMN_ASSERT(input.Pointer() != output.Pointer());
312  output.ProductOf(this->TransposeRef(), input);
313  }
314 
315 
324  inline ThisType ApplyInverseTo(const ThisType & input) const {
325  CMN_ASSERT(input.Pointer() != this->Pointer());
326  ThisType result;
327  this->ApplyInverseTo(input, result);
328  return result;
329  }
330 
331 
336  template <class __vectorOwnerType1, class __vectorOwnerType2>
337  inline void
340  {
341  CMN_ASSERT(input.Pointer() != output.Pointer());
342  CMN_ASSERT(input.size() == DIMENSION);
343  CMN_ASSERT(output.size() == DIMENSION);
344  // see implementation note for fixed size i/o ApplyTo() version
345  const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
346  output[0] = vctDotProduct( inputCopy, this->Column(0) );
347  output[1] = vctDotProduct( inputCopy, this->Column(1) );
348  output[2] = vctDotProduct( inputCopy, this->Column(2) );
349  }
350 
355  template <class __vectorOwnerType, stride_type __stride, class __dataPtrType>
356  inline void
359  {
360  CMN_ASSERT(input.Pointer() != output.Pointer());
361  CMN_ASSERT(input.size() == DIMENSION);
362  // see implementation note for fixed size i/o ApplyTo() version
363  const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
364  output[0] = vctDotProduct( inputCopy, this->Column(0) );
365  output[1] = vctDotProduct( inputCopy, this->Column(1) );
366  output[2] = vctDotProduct( inputCopy, this->Column(2) );
367  }
368 
371  template <size_type __cols,
372  stride_type __rowStride1, stride_type __colStride1, class __dataPtrType1,
373  stride_type __rowStride2, stride_type __colStride2, class __dataPtrType2>
376  {
377  CMN_ASSERT(input.Pointer() != output.Pointer());
378  output.ProductOf(*this, input);
379  }
380 
383  template <class __matrixOwnerType1, class __matrixOwnerType2>
386  {
387  CMN_ASSERT((input.rows() == DIMENSION) && (output.rows() == DIMENSION) && (input.cols() == output.cols()));
388  CMN_ASSERT(input.Pointer() != output.Pointer());
390  output.ProductOf(myRef, input);
391  }
392 
395  template <size_type __cols,
396  stride_type __rowStride1, stride_type __colStride1, class __dataPtrType1,
397  stride_type __rowStride2, stride_type __colStride2, class __dataPtrType2>
400  {
401  CMN_ASSERT(input.Pointer() != output.Pointer());
402  output.ProductOf(this->TransposeRef(), input);
403  }
404 
407  template <class __matrixOwnerType1, class __matrixOwnerType2>
410  {
411  CMN_ASSERT((input.rows() == DIMENSION) && (output.rows() == DIMENSION) && (input.cols() == output.cols()));
412  CMN_ASSERT(input.Pointer() != output.Pointer());
413  vctDynamicConstMatrixRef<value_type> myInvRef(this->TransposeRef());
414  output.ProductOf(myInvRef, input);
415  }
416 
423  ThisType operator * (const ThisType & input) const
424  {
425  return this->ApplyTo(input);
426  }
427 
432  template <stride_type __stride, class __dataPtrType>
435  {
436  return this->ApplyTo(input);
437  }
438 
443  template <class __vectorOwnerType1>
446  {
447  return this->ApplyTo(input);
448  }
449 
450 
451 
458  inline bool AlmostEquivalent(const ThisType & other,
459  value_type tolerance = TypeTraits::Tolerance()) const {
460  return this->AlmostEqual(other, tolerance);
461  }
462 };
463 
464 
465 #endif // _vctMatrixRotation3ConstBase_h
466 
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
A template for a fixed size matrix with fixed spacing in memory.
Definition: vctFixedSizeConstMatrixBase.h:103
void ApplyTo(const vctFixedSizeConstMatrixBase< DIMENSION, __cols, __rowStride1, __colStride1, value_type, __dataPtrType1 > &input, vctFixedSizeMatrixBase< DIMENSION, __cols, __rowStride2, __colStride2, value_type, __dataPtrType2 > &output) const
Definition: vctMatrixRotation3ConstBase.h:374
Declaration of vctDynamicMatrix.
ThisType ApplyInverseTo(const ThisType &input) const
Definition: vctMatrixRotation3ConstBase.h:324
vctFixedSizeVector< value_type, DIMENSION > ApplyInverseTo(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &input) const
Definition: vctMatrixRotation3ConstBase.h:295
#define CMN_ASSERT(expr)
Definition: cmnAssert.h:90
void ApplyTo(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &input, vctFixedSizeVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &output) const
Definition: vctMatrixRotation3ConstBase.h:228
void ApplyTo(const vctDynamicConstMatrixBase< __matrixOwnerType1, value_type > &input, vctDynamicMatrixBase< __matrixOwnerType2, value_type > &output) const
Definition: vctMatrixRotation3ConstBase.h:384
Definition: vctDynamicMatrixBase.h:42
RotationValueType Normalized(void) const
Definition: vctMatrixRotation3.h:389
void ApplyInverseTo(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &input, vctFixedSizeVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &output) const
Definition: vctMatrixRotation3ConstBase.h:357
Definition: vctMatrixRotation3ConstBase.h:61
void ApplyInverseTo(const ThisType &input, ThisType &output) const
Definition: vctMatrixRotation3ConstBase.h:310
_containerType ContainerType
Definition: vctMatrixRotation3ConstBase.h:63
static Type Tolerance(void)
Definition: cmnTypeTraits.h:170
Declaration of vctFixedSizeMatrix.
Forward declarations and #define for cisstVector.
ThisType & ProductOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix, const value_type scalar)
Definition: vctFixedSizeMatrixBase.h:909
cmnTypeTraits< value_type > TypeTraits
Definition: vctMatrixRotation3ConstBase.h:73
size_t size_type
Definition: vctContainerTraits.h:35
void ApplyInverseTo(const vctDynamicConstMatrixBase< __matrixOwnerType1, value_type > &input, vctDynamicMatrixBase< __matrixOwnerType2, value_type > &output) const
Definition: vctMatrixRotation3ConstBase.h:408
void ThrowUnlessIsNormalized(void) const
Definition: vctMatrixRotation3ConstBase.h:78
vctMatrixRotation3< value_type > RotationValueType
Definition: vctMatrixRotation3ConstBase.h:70
vctFixedSizeVector< value_type, DIMENSION > ApplyInverseTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &input) const
Definition: vctMatrixRotation3ConstBase.h:284
_containerType BaseType
Definition: vctMatrixRotation3ConstBase.h:62
ThisType & ProductOf(const vctDynamicConstMatrixBase< __matrixOwnerType, _elementType > &matrix, const value_type scalar)
Definition: vctDynamicMatrixBase.h:971
Definition: vctDynamicConstMatrixBase.h:77
Implementation of a fixed-size vector using template metaprogramming.
Definition: vctFixedSizeVector.h:52
void ApplyTo(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &input, vctDynamicVectorBase< __vectorOwnerType2, value_type > &output) const
Definition: vctMatrixRotation3ConstBase.h:211
Define unary operations on an object as classes.
Definition: vctUnaryOperations.h:55
ThisType operator*(const ThisType &input) const
Definition: vctMatrixRotation3ConstBase.h:423
size_type size(void) const
Definition: vctDynamicConstVectorBase.h:164
ThisType ApplyTo(const ThisType &input) const
Definition: vctMatrixRotation3ConstBase.h:197
A template for a fixed size matrix with fixed spacings in memory.
Definition: vctFixedSizeMatrixBase.h:58
RotationValueType Inverse(void) const
Definition: vctMatrixRotation3.h:398
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition: vctDynamicMatrixBase.h:143
Definition: vctMatrixRotation3ConstBase.h:60
Dynamic matrix referencing existing memory (const)
Definition: vctDynamicConstMatrixRef.h:79
vctFixedSizeVector< value_type, DIMENSION > ApplyTo(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &input) const
Definition: vctMatrixRotation3ConstBase.h:247
size_type rows() const
Definition: vctDynamicConstMatrixBase.h:238
size_type cols() const
Definition: vctDynamicConstMatrixBase.h:243
Definition: vctMatrixRotation3ConstBase.h:60
_elementType vctDotProduct(const vctDynamicConstVectorBase< _vector1OwnerType, _elementType > &vector1, const vctDynamicConstVectorBase< _vector2OwnerType, _elementType > &vector2)
Definition: vctDynamicConstVectorBase.h:1067
Define a rotation matrix for a space of dimension 3.
Definition: vctForwardDeclarations.h:198
const_pointer Pointer(size_type index=0) const
Definition: vctFixedSizeConstVectorBase.h:268
const_pointer Pointer(index_type rowIndex, index_type colIndex) const
Definition: vctDynamicConstMatrixBase.h:306
void ApplyInverseTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &input, vctFixedSizeVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &output) const
Definition: vctMatrixRotation3ConstBase.h:263
bool AlmostEquivalent(const ThisType &other, value_type tolerance=TypeTraits::Tolerance()) const
Definition: vctMatrixRotation3ConstBase.h:458
#define cmnThrow(a)
Definition: MinimalCmn.h:4
VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type)
static CISST_EXPORT const RotationValueType & Identity()
const_pointer Pointer(index_type index=0) const
Definition: vctDynamicConstVectorBase.h:221
pointer Pointer(index_type index=0)
Definition: vctDynamicVectorBase.h:155
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeVectorBase.h:76
ptrdiff_t stride_type
Definition: vctContainerTraits.h:37
Definition: vctDynamicConstVectorBase.h:77
void ApplyInverseTo(const vctFixedSizeConstMatrixBase< DIMENSION, __cols, __rowStride1, __colStride1, value_type, __dataPtrType1 > &input, vctFixedSizeMatrixBase< DIMENSION, __cols, __rowStride2, __colStride2, value_type, __dataPtrType2 > &output) const
Definition: vctMatrixRotation3ConstBase.h:398
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeConstVectorBase.h:107
pointer Pointer(size_type index=0)
Definition: vctFixedSizeVectorBase.h:226
void ApplyTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &input, vctFixedSizeVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &output) const
Definition: vctMatrixRotation3ConstBase.h:158
Macros to export the symbols of cisstVector (in a Dll).
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition: cmnTypeTraits.h:155
vctMatrixRotation3ConstBase< ContainerType > ThisType
Definition: vctMatrixRotation3ConstBase.h:64
void ApplyInverseTo(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &input, vctDynamicVectorBase< __vectorOwnerType2, value_type > &output) const
Definition: vctMatrixRotation3ConstBase.h:338
void ThrowUnlessIsNormalized(const _inputType &input) const
Definition: vctMatrixRotation3ConstBase.h:89
vctFixedSizeVector< value_type, DIMENSION > ApplyTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &input) const
Definition: vctMatrixRotation3ConstBase.h:181
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition: vctFixedSizeMatrixBase.h:161
bool IsNormalized(value_type tolerance=TypeTraits::Tolerance()) const
Definition: vctMatrixRotation3ConstBase.h:118
Definition: vctDynamicVectorBase.h:61
Define a rotation matrix for a space of dimension 3.
Definition: vctForwardDeclarations.h:200