cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctFrame4x4ConstBase.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: 2007-09-13
8 
9  (C) Copyright 2007-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 _vctFrame4x4ConstBase_h
23 #define _vctFrame4x4ConstBase_h
24 
33 #include <cisstVector/vctExport.h>
34 
49 template <class _containerType>
50 class vctFrame4x4ConstBase: public _containerType
51 {
52 public:
53  enum {ROWS = 4, COLS = 4};
54  enum {DIMENSION = 3};
55  typedef _containerType BaseType;
56  typedef _containerType ContainerType;
58 
59  /* no need to document, inherit doxygen documentation from base class */
60  VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type);
61 
62  enum {ROWSTRIDE = ContainerType::ROWSTRIDE, COLSTRIDE = ContainerType::COLSTRIDE};
63 
66  typedef typename BaseType::RowRefType RowRefType;
75 
77 
78  /* Types to maintain internal references to subparts of the 4x4 matrix. */
85 
86 protected:
87  /* Internal references to rotation matrix, translation vector and
88  first 3 element of last row. */
89  RotationRefType RotationRef;
90  TranslationRefType TranslationRef;
91  PerspectiveRefType PerspectiveRef;
92 
97  inline void UpdateReferences(void) {
98  // Rotation matrix is 3 by 3 starting at 0, 0
99  RotationRef.SetRef(this->Pointer(0, 0));
100  // Translation is a vector 3, column starting at 0, 3
101  TranslationRef.SetRef(this->Pointer(0, DIMENSION));
102  // Perspective is a vector 3, row starting a 3, 0
103  PerspectiveRef.SetRef(this->Pointer(DIMENSION, 0));
104  }
105 
106 public:
107 
108 
110  vctFrame4x4ConstBase(void) {
112  }
113 
118  static CISST_EXPORT const FrameValueType & Identity(void);
119 
120  inline ConstTranslationRefType Translation(void) const {
121  return this->TranslationRef;
122  }
123 
124  inline ConstRotationRefType Rotation(void) const {
125  return this->RotationRef;
126  }
127 
128  inline ConstPerspectiveRefType Perspective(void) const {
129  return this->PerspectiveRef;
130  }
131 
132 
133  FrameValueType Inverse(void) const; // implemented in vctFrame4x4.h
134 
135 
143  inline bool IsNormalized(value_type tolerance = TypeTraits::Tolerance()) const {
144  return (this->Row(DIMENSION).AlmostEqual(RowValueType(static_cast<value_type>(0.0),
145  static_cast<value_type>(0.0),
146  static_cast<value_type>(0.0),
147  static_cast<value_type>(1.0)),
148  tolerance)
149  && this->RotationRef.IsNormalized(tolerance));
150  }
151 
159  template <stride_type __stride1, class __dataPtrType1, stride_type __stride2, class __dataPtrType2>
160  inline void
163  this->RotationRef.ApplyTo(input, output);
164  output.X() += this->TranslationRef.X();
165  output.Y() += this->TranslationRef.Y();
166  output.Z() += this->TranslationRef.Z();
167  }
168 
169 
178  template <stride_type __stride, class __dataPtrType>
182  this->ApplyTo(input, result);
183  return result;
184  }
185 
186 
196  template <class __containerType1, class __containerType2>
198  vctFrame4x4Base<__containerType2> & output) const {
199  typename TranslationRefType::CopyType temp;
200  RotationRef.ApplyTo(input.Translation(), temp);
201  (output.Rotation()).ProductOf(RotationRef, input.Rotation());
202  (output.Translation()).SumOf(temp, TranslationRef);
203  }
204 
205 
214  template <class __containerType>
215  inline FrameValueType ApplyTo(const vctFrame4x4ConstBase<__containerType> & input) const {
216  FrameValueType result;
217  this->ApplyTo(input, result);
218  return result;
219  }
220 
221 
226  template <class __vectorOwnerType1, class __vectorOwnerType2>
227  inline void
230  {
231  this->RotationRef.ApplyTo(input, output);
232  output[0] += this->TranslationRef[0];
233  output[1] += this->TranslationRef[1];
234  output[2] += this->TranslationRef[2];
235  }
236 
237 
239  template <size_type __cols, stride_type __rowStride1, stride_type __colStride1, class __dataPtrType1,
240  stride_type __rowStride2, stride_type __colStride2, class __dataPtrType2>
241  inline void
244  {
246  typedef typename inputType::ConstColumnRefType inputColumnType;
248  typedef typename outputType::ColumnRefType outputColumnType;
249  index_type columnIndex;
250  for (columnIndex = 0; columnIndex < __cols; ++columnIndex) {
251  const inputColumnType inputColumn(input.Column(columnIndex));
252  outputColumnType outputColumn(output.Column(columnIndex));
253  this->ApplyTo(inputColumn, outputColumn);
254  }
255  }
256 
257 
264  inline void
267  {
268  index_type index;
269  for (index = 0; index < inputSize; ++index) {
270  this->ApplyTo(input[index], output[index]);
271  }
272  }
273 
274 
275  template <stride_type __stride1, class __dataPtrType1, stride_type __stride2, class __dataPtrType2>
276  inline void
280  temp.DifferenceOf(input, this->TranslationRef);
281  this->RotationRef.ApplyInverseTo(temp, output);
282  }
283 
291  template <class __vectorOwnerType1, class __vectorOwnerType2>
292  inline void
295  const vctFixedSizeVector<value_type, DIMENSION> temp(input[0] - this->TranslationRef[0],
296  input[1] - this->TranslationRef[1],
297  input[2] - this->TranslationRef[2]);
298  typename TranslationRefType::CopyType result;
299  this->RotationRef.ApplyInverseTo(temp, result);
300  output[0] = result[0];
301  output[1] = result[1];
302  output[2] = result[2];
303  }
304 
305 
314  template <stride_type __stride, class __dataPtrType>
318  this->ApplyInverseTo(input, result);
319  return result;
320  }
321 
322 
323  template <class __containerType1, class __containerType2>
325  vctFrame4x4Base<__containerType2> & output) const {
326  FrameValueType inverse;
327  inverse.InverseOf(*this);
328  inverse.ApplyTo(input, output);
329  }
330 
331  template <class __containerType>
332  inline FrameValueType ApplyInverseTo(const vctFrame4x4ConstBase<__containerType> & input) const {
333  FrameValueType result;
334  this->ApplyInverseTo(input, result);
335  return result;
336  }
337 
347  inline bool Equal(const ThisType & other) const {
348  return (this->RotationRef.Equal(other.Rotation())
349  && this->TranslationRef.Equal(other.Translation()));
350  }
351 
352  inline bool operator == (const ThisType & other) const {
353  return this->Equal(other);
354  }
356 
357 
369  inline bool AlmostEqual(const ThisType & other,
370  value_type tolerance = TypeTraits::Tolerance()) const {
371  return (this->RotationRef.AlmostEqual(other.Rotation(), tolerance)
372  && this->TranslationRef.AlmostEqual(other.Translation(), tolerance));
373  }
374 
375 
382  inline bool AlmostEquivalent(const ThisType & other,
383  value_type tolerance = TypeTraits::Tolerance()) const {
384  return this->AlmostEqual(other, tolerance);
385  }
386 
387 };
388 
389 
390 #endif // _vctFrame4x4Base_h
391 
size_t index_type
Definition: vctContainerTraits.h:36
Template base class for a 4x4 frame.
Definition: vctForwardDeclarations.h:234
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
value_type & Y(void)
Definition: vctFixedSizeVectorBase.h:572
A template for a fixed size matrix with fixed spacing in memory.
Definition: vctFixedSizeConstMatrixBase.h:103
void ApplyInverseTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &input, vctFixedSizeVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &output) const
Definition: vctFrame4x4ConstBase.h:277
bool AlmostEquivalent(const ThisType &other, value_type tolerance=TypeTraits::Tolerance()) const
Definition: vctFrame4x4ConstBase.h:382
BaseType::ConstRowRefType ConstRowRefType
Definition: vctFrame4x4ConstBase.h:68
vctFixedSizeVector< value_type, DIMENSION > ApplyTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &input) const
Definition: vctFrame4x4ConstBase.h:180
An implementation of the ``abstract'' vctFixedSizeVectorBase.
Definition: vctFixedSizeVectorRef.h:46
Declaration of vctMatrixRotation3Ref.
Definition: vctFrame4x4ConstBase.h:53
BaseType::ConstRefTransposeType ConstRefTransposeType
Definition: vctFrame4x4ConstBase.h:73
Define a rotation matrix for a space of dimension 3.
Definition: vctForwardDeclarations.h:202
BaseType::RowRefType RowRefType
Definition: vctFrame4x4ConstBase.h:66
An implementation of the ``abstract'' vctFixedSizeConstVectorBase.
Definition: vctFixedSizeConstVectorRef.h:50
size_t size_type
Definition: vctContainerTraits.h:35
bool operator==(const ThisType &other) const
Definition: vctFrame4x4ConstBase.h:352
_containerType BaseType
Definition: vctFrame4x4ConstBase.h:55
_containerType ContainerType
Definition: vctFrame4x4ConstBase.h:56
FrameValueType ApplyInverseTo(const vctFrame4x4ConstBase< __containerType > &input) const
Definition: vctFrame4x4ConstBase.h:332
Template base class for a 4x4 frame.
Definition: vctForwardDeclarations.h:236
Template base class for a 4x4 frame.
Definition: vctForwardDeclarations.h:235
void ApplyTo(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &input, vctDynamicVectorBase< __vectorOwnerType2, value_type > &output) const
Definition: vctFrame4x4ConstBase.h:228
BaseType::ConstDiagonalRefType ConstDiagonalRefType
Definition: vctFrame4x4ConstBase.h:71
Implementation of a fixed-size vector using template metaprogramming.
Definition: vctFixedSizeVector.h:52
bool AlmostEqual(const ThisType &other, value_type tolerance=TypeTraits::Tolerance()) const
Definition: vctFrame4x4ConstBase.h:369
VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type)
BaseType::RefTransposeType RefTransposeType
Definition: vctFrame4x4ConstBase.h:72
vctFrame4x4ConstBase< ContainerType > ThisType
Definition: vctFrame4x4ConstBase.h:57
void ApplyTo(const vctFixedSizeConstMatrixBase< DIMENSION, __cols, __rowStride1, __colStride1, value_type, __dataPtrType1 > &input, vctFixedSizeMatrixBase< DIMENSION, __cols, __rowStride2, __colStride2, value_type, __dataPtrType2 > &output) const
Definition: vctFrame4x4ConstBase.h:242
Definition: vctFrame4x4ConstBase.h:54
value_type & X(void)
Definition: vctFixedSizeVectorBase.h:559
A template for a fixed size matrix with fixed spacings in memory.
Definition: vctFixedSizeMatrixBase.h:58
BaseType::RowValueType RowValueType
Definition: vctFrame4x4ConstBase.h:64
class cmnTypeTraits< value_type > TypeTraits
Definition: vctFixedSizeMatrix.h:75
BaseType::DiagonalRefType DiagonalRefType
Definition: vctFrame4x4ConstBase.h:70
ConstPerspectiveRefType Perspective(void) const
Definition: vctFrame4x4ConstBase.h:128
BaseType::ColumnRefType ColumnRefType
Definition: vctFrame4x4ConstBase.h:67
Define a rotation matrix for a space of dimension 3.
Definition: vctForwardDeclarations.h:201
Definition: vctFrame4x4ConstBase.h:53
void ApplyTo(size_type inputSize, const vctFixedSizeVector< value_type, DIMENSION > *input, vctFixedSizeVector< value_type, DIMENSION > *output) const
Definition: vctFrame4x4ConstBase.h:265
An implementation of the ``abstract'' vctFixedSizeMatrixBase.
Definition: vctFixedSizeMatrixRef.h:46
ConstTranslationRefType Translation(void) const
Definition: vctFrame4x4Base.h:89
void ApplyInverseTo(const vctFrame4x4ConstBase< __containerType1 > &input, vctFrame4x4Base< __containerType2 > &output) const
Definition: vctFrame4x4ConstBase.h:324
ConstRotationRefType Rotation(void) const
Definition: vctFrame4x4Base.h:93
void ApplyTo(const vctFrame4x4ConstBase< __containerType1 > &input, vctFrame4x4Base< __containerType2 > &output) const
Definition: vctFrame4x4ConstBase.h:197
ConstRotationRefType Rotation(void) const
Definition: vctFrame4x4ConstBase.h:124
Declaration of vctFixedSizeVectorRef.
FrameValueType ApplyTo(const vctFrame4x4ConstBase< __containerType > &input) const
Definition: vctFrame4x4ConstBase.h:215
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeVectorBase.h:76
vctFixedSizeVector< value_type, DIMENSION > ApplyInverseTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &input) const
Definition: vctFrame4x4ConstBase.h:316
ptrdiff_t stride_type
Definition: vctContainerTraits.h:37
void ApplyTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &input, vctFixedSizeVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &output) const
Definition: vctFrame4x4ConstBase.h:161
BaseType::ColumnValueType ColumnValueType
Definition: vctFrame4x4ConstBase.h:65
BaseType::ConstColumnRefType ConstColumnRefType
Definition: vctFrame4x4ConstBase.h:69
Definition: vctDynamicConstVectorBase.h:77
vctFrame4x4< value_type, COLSTRIDE<=ROWSTRIDE > FrameValueType;typedef cmnTypeTraits< value_type > TypeTraits;typedef vctFixedSizeVectorRef< value_type, DIMENSION, ROWSTRIDE > TranslationRefType;typedef vctFixedSizeConstVectorRef< value_type, DIMENSION, ROWSTRIDE > ConstTranslationRefType;typedef vctFixedSizeVectorRef< value_type, DIMENSION, COLSTRIDE > PerspectiveRefType;typedef vctFixedSizeConstVectorRef< value_type, DIMENSION, COLSTRIDE > ConstPerspectiveRefType;typedef vctMatrixRotation3Ref< value_type, ROWSTRIDE, COLSTRIDE > RotationRefType;typedef vctMatrixRotation3ConstRef< value_type, ROWSTRIDE, COLSTRIDE > ConstRotationRefType;protected:RotationRefType RotationRef;TranslationRefType TranslationRef;PerspectiveRefType PerspectiveRef;inline void UpdateReferences(void){RotationRef.SetRef(this->Pointer(0, 0));TranslationRef.SetRef(this->Pointer(0, DIMENSION));PerspectiveRef.SetRef(this->Pointer(DIMENSION, 0));}public:vctFrame4x4ConstBase(void){this-> UpdateReferences()
Definition: vctFrame4x4ConstBase.h:111
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
void SumOf(const PlainObjectBase< OtherDerived1 > &other1, const PlainObjectBase< OtherDerived2 > &other2)
Definition: cisstVectorEigenAddons.h:24
ConstTranslationRefType Translation(void) const
Definition: vctFrame4x4ConstBase.h:120
value_type & Z(void)
Definition: vctFixedSizeVectorBase.h:585
void ApplyInverseTo(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &input, vctDynamicVectorBase< __vectorOwnerType2, value_type > &output) const
Definition: vctFrame4x4ConstBase.h:293
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
ColumnRefType Column(size_type index)
Definition: vctFixedSizeMatrixBase.h:249
ThisType & DifferenceOf(const vctFixedSizeConstVectorBase< _size, __stride1, value_type, __dataPtrType1 > &vector1, const vctFixedSizeConstVectorBase< _size, __stride2, value_type, __dataPtrType2 > &vector2)
Definition: vctFixedSizeVectorBase.h:820
FrameValueType Inverse(void) const
Definition: vctFrame4x4.h:171
Definition: vctFrame4x4ConstBase.h:62
static CISST_EXPORT const FrameValueType & Identity(void)
Declaration of vctMatrixRotation3Ref.
bool IsNormalized(value_type tolerance=TypeTraits::Tolerance()) const
Definition: vctFrame4x4ConstBase.h:143
Definition: vctDynamicVectorBase.h:61
Definition: vctFrame4x4ConstBase.h:62
bool Equal(const ThisType &other) const
Definition: vctFrame4x4ConstBase.h:347