cisst-saw
Loading...
Searching...
No Matches
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
14This software is provided "as is" under an open source license, with
15no warranty. The complete license can be found in license.txt and
16http://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
29
34
49template <class _containerType>
50class vctFrame4x4ConstBase: public _containerType
51{
52public:
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
64 typedef typename BaseType::RowValueType RowValueType;
65 typedef typename BaseType::ColumnValueType ColumnValueType;
66 typedef typename BaseType::RowRefType RowRefType;
67 typedef typename BaseType::ColumnRefType ColumnRefType;
68 typedef typename BaseType::ConstRowRefType ConstRowRefType;
69 typedef typename BaseType::ConstColumnRefType ConstColumnRefType;
70 typedef typename BaseType::DiagonalRefType DiagonalRefType;
71 typedef typename BaseType::ConstDiagonalRefType ConstDiagonalRefType;
72 typedef typename BaseType::RefTransposeType RefTransposeType;
73 typedef typename BaseType::ConstRefTransposeType ConstRefTransposeType;
75
77
78 /* Types to maintain internal references to subparts of the 4x4 matrix. */
85
86protected:
87 /* Internal references to rotation matrix, translation vector and
88 first 3 element of last row. */
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
106public:
107
108
111 this->UpdateReferences();
112 }
113
119
121 return this->TranslationRef;
122 }
123
124 inline ConstRotationRefType Rotation(void) const {
125 return this->RotationRef;
126 }
127
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>
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
265 ApplyTo(size_type inputSize, const vctFixedSizeVector<value_type, DIMENSION> * input,
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
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>
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>
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 }
355
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
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition cmnTypeTraits.h:155
static Type Tolerance(void)
Definition cmnTypeTraits.h:170
Definition vctForwardDeclarations.h:119
Definition vctDynamicVectorBase.h:62
A template for a fixed size matrix with fixed spacing in memory.
Definition vctFixedSizeConstMatrixBase.h:104
ConstColumnRefType Column(size_type index) const
Definition vctFixedSizeConstMatrixBase.h:406
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeConstVectorBase.h:108
Definition vctForwardDeclarations.h:86
A template for a fixed size matrix with fixed spacings in memory.
Definition vctFixedSizeMatrixBase.h:60
ColumnRefType Column(size_type index)
Definition vctFixedSizeMatrixBase.h:249
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeVectorBase.h:77
ThisType & DifferenceOf(const vctFixedSizeConstVectorBase< _size, __stride1, value_type, __dataPtrType1 > &vector1, const vctFixedSizeConstVectorBase< _size, __stride2, value_type, __dataPtrType2 > &vector2)
Definition vctFixedSizeVectorBase.h:820
value_type & Y(void)
Definition vctFixedSizeVectorBase.h:572
value_type & Z(void)
Definition vctFixedSizeVectorBase.h:585
value_type & X(void)
Definition vctFixedSizeVectorBase.h:559
Implementation of a fixed-size vector using template metaprogramming.
Definition vctFixedSizeVector.h:54
Definition vctForwardDeclarations.h:89
Template base class for a 4x4 frame.
Definition vctFrame4x4Base.h:48
ConstRotationRefType Rotation(void) const
Definition vctFrame4x4Base.h:91
ThisType & InverseOf(const vctFrame4x4ConstBase< __containerType > &otherFrame)
Definition vctFrame4x4Base.h:212
ConstTranslationRefType Translation(void) const
Definition vctFrame4x4Base.h:87
ConstTranslationRefType Translation(void) const
Definition vctFrame4x4ConstBase.h:120
vctFixedSizeVector< value_type, DIMENSION > ApplyInverseTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &input) const
Definition vctFrame4x4ConstBase.h:316
bool AlmostEqual(const ThisType &other, value_type tolerance=TypeTraits::Tolerance()) const
Definition vctFrame4x4ConstBase.h:369
bool Equal(const ThisType &other) const
Definition vctFrame4x4ConstBase.h:347
BaseType::ConstColumnRefType ConstColumnRefType
Definition vctFrame4x4ConstBase.h:69
vctFrame4x4< value_type, COLSTRIDE<=ROWSTRIDE > FrameValueType
Definition vctFrame4x4ConstBase.h:74
void ApplyTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &input, vctFixedSizeVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &output) const
Definition vctFrame4x4ConstBase.h:161
vctFixedSizeVector< value_type, DIMENSION > ApplyTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &input) const
Definition vctFrame4x4ConstBase.h:180
BaseType::RefTransposeType RefTransposeType
Definition vctFrame4x4ConstBase.h:72
vctFixedSizeConstVectorRef< value_type, DIMENSION, ROWSTRIDE > ConstTranslationRefType
Definition vctFrame4x4ConstBase.h:80
void UpdateReferences(void)
Definition vctFrame4x4ConstBase.h:97
BaseType::RowRefType RowRefType
Definition vctFrame4x4ConstBase.h:66
void ApplyInverseTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &input, vctFixedSizeVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &output) const
Definition vctFrame4x4ConstBase.h:277
cmnTypeTraits< value_type > TypeTraits
Definition vctFrame4x4ConstBase.h:76
TranslationRefType TranslationRef
Definition vctFrame4x4ConstBase.h:90
FrameValueType ApplyInverseTo(const vctFrame4x4ConstBase< __containerType > &input) const
Definition vctFrame4x4ConstBase.h:332
ContainerType BaseType
Definition vctFrame4x4ConstBase.h:55
vctFixedSizeVectorRef< value_type, DIMENSION, COLSTRIDE > PerspectiveRefType
Definition vctFrame4x4ConstBase.h:81
bool AlmostEquivalent(const ThisType &other, value_type tolerance=TypeTraits::Tolerance()) const
Definition vctFrame4x4ConstBase.h:382
BaseType::DiagonalRefType DiagonalRefType
Definition vctFrame4x4ConstBase.h:70
BaseType::ColumnValueType ColumnValueType
Definition vctFrame4x4ConstBase.h:65
vctFixedSizeConstVectorRef< value_type, DIMENSION, COLSTRIDE > ConstPerspectiveRefType
Definition vctFrame4x4ConstBase.h:82
BaseType::ConstDiagonalRefType ConstDiagonalRefType
Definition vctFrame4x4ConstBase.h:71
@ ROWS
Definition vctFrame4x4ConstBase.h:53
@ COLS
Definition vctFrame4x4ConstBase.h:53
void ApplyTo(const vctFrame4x4ConstBase< __containerType1 > &input, vctFrame4x4Base< __containerType2 > &output) const
Definition vctFrame4x4ConstBase.h:197
void ApplyTo(size_type inputSize, const vctFixedSizeVector< value_type, DIMENSION > *input, vctFixedSizeVector< value_type, DIMENSION > *output) const
Definition vctFrame4x4ConstBase.h:265
@ DIMENSION
Definition vctFrame4x4ConstBase.h:54
@ ROWSTRIDE
Definition vctFrame4x4ConstBase.h:62
@ COLSTRIDE
Definition vctFrame4x4ConstBase.h:62
PerspectiveRefType PerspectiveRef
Definition vctFrame4x4ConstBase.h:91
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
bool IsNormalized(value_type tolerance=TypeTraits::Tolerance()) const
Definition vctFrame4x4ConstBase.h:143
vctFrame4x4ConstBase(void)
Definition vctFrame4x4ConstBase.h:110
BaseType::ColumnRefType ColumnRefType
Definition vctFrame4x4ConstBase.h:67
BaseType::RowValueType RowValueType
Definition vctFrame4x4ConstBase.h:64
ConstRotationRefType Rotation(void) const
Definition vctFrame4x4ConstBase.h:124
vctFixedSizeVectorRef< value_type, DIMENSION, ROWSTRIDE > TranslationRefType
Definition vctFrame4x4ConstBase.h:79
vctMatrixRotation3Ref< value_type, ROWSTRIDE, COLSTRIDE > RotationRefType
Definition vctFrame4x4ConstBase.h:83
void ApplyInverseTo(const vctFrame4x4ConstBase< __containerType1 > &input, vctFrame4x4Base< __containerType2 > &output) const
Definition vctFrame4x4ConstBase.h:324
ContainerType ContainerType
Definition vctFrame4x4ConstBase.h:56
vctMatrixRotation3ConstRef< value_type, ROWSTRIDE, COLSTRIDE > ConstRotationRefType
Definition vctFrame4x4ConstBase.h:84
void ApplyTo(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &input, vctDynamicVectorBase< __vectorOwnerType2, value_type > &output) const
Definition vctFrame4x4ConstBase.h:228
BaseType::ConstRefTransposeType ConstRefTransposeType
Definition vctFrame4x4ConstBase.h:73
vctFrame4x4ConstBase< ContainerType > ThisType
Definition vctFrame4x4ConstBase.h:57
static CISST_EXPORT const FrameValueType & Identity(void)
void ApplyInverseTo(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &input, vctDynamicVectorBase< __vectorOwnerType2, value_type > &output) const
Definition vctFrame4x4ConstBase.h:293
ConstPerspectiveRefType Perspective(void) const
Definition vctFrame4x4ConstBase.h:128
FrameValueType ApplyTo(const vctFrame4x4ConstBase< __containerType > &input) const
Definition vctFrame4x4ConstBase.h:215
RotationRefType RotationRef
Definition vctFrame4x4ConstBase.h:89
bool operator==(const ThisType &other) const
Definition vctFrame4x4ConstBase.h:352
VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type)
BaseType::ConstRowRefType ConstRowRefType
Definition vctFrame4x4ConstBase.h:68
FrameValueType Inverse(void) const
Definition vctFrame4x4.h:171
Template base class for a 4x4 frame.
Definition vctFrame4x4.h:51
bool IsNormalized(value_type tolerance=TypeTraits::Tolerance()) const
Definition vctMatrixRotation3ConstBase.h:116
void ApplyInverseTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &input, vctFixedSizeVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &output) const
Definition vctMatrixRotation3ConstBase.h:261
void ApplyTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &input, vctFixedSizeVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &output) const
Definition vctMatrixRotation3ConstBase.h:156
Define a rotation matrix for a space of dimension 3.
Definition vctMatrixRotation3ConstRef.h:52
Define a rotation matrix for a space of dimension 3.
Definition vctMatrixRotation3Ref.h:52
#define CISST_EXPORT
Definition cmnExportMacros.h:50
ConstRowRefType Row(size_type index) const CISST_THROW(std
Definition vctDynamicConstMatrixBase.h:367
const_pointer Pointer(index_type rowIndex, index_type colIndex) const
Definition vctDynamicConstMatrixBase.h:306
Macros to export the symbols of cisstVector (in a Dll).
Declaration of vctFixedSizeVectorRef.
Declaration of vctMatrixRotation3Ref.
Declaration of vctMatrixRotation3Ref.