cisst-saw
Loading...
Searching...
No Matches
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 Author(s): Anton Deguet
6 Created on: 2005-08-19
7
8 (C) Copyright 2005-2018 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19#pragma once
20#ifndef _vctMatrixRotation3ConstBase_h
21#define _vctMatrixRotation3ConstBase_h
22
27
31
33
54template <class _containerType>
55class vctMatrixRotation3ConstBase: public _containerType
56{
57public:
58 enum {ROWS = 3, COLS = 3};
59 enum {DIMENSION = 3};
60 typedef _containerType BaseType;
61 typedef _containerType ContainerType;
63
64 /* no need to document, inherit doxygen documentation from base class */
65 VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type);
66
69
72
73
74protected:
76 inline void ThrowUnlessIsNormalized(void) const CISST_THROW(std::runtime_error) {
77 if (! IsNormalized()) {
78 cmnThrow(std::runtime_error("vctMatrixRotation3ConstBase: This rotation is not normalized"));
79 }
80 }
81
86 template <class _inputType>
87 inline void ThrowUnlessIsNormalized(const _inputType & input) const CISST_THROW(std::runtime_error) {
88 if (! input.IsNormalized()) {
89 cmnThrow(std::runtime_error("vctMatrixRotation3ConstBase: Input is not normalized"));
90 }
91 }
92
93public:
94
103
107 RotationValueType Normalized(void) const; // implemented in vctMatrixRotation3.h
108
116 inline bool IsNormalized(value_type tolerance = TypeTraits::Tolerance()) const {
117 NormType columnNorm;
118 columnNorm = this->Column(0).Norm();
119 if (vctUnaryOperations<NormType>::AbsValue::Operate(columnNorm - 1) > tolerance)
120 return false;
121 columnNorm = this->Column(1).Norm();
122 if (vctUnaryOperations<NormType>::AbsValue::Operate(columnNorm - 1) > tolerance)
123 return false;
124 columnNorm = this->Column(2).Norm();
125 if (vctUnaryOperations<NormType>::AbsValue::Operate(columnNorm - 1) > tolerance)
126 return false;
127 value_type columnDot;
128 columnDot = vctDotProduct(this->Column(0), this->Column(1));
129 if (vctUnaryOperations<value_type>::AbsValue::Operate(columnDot) > tolerance)
130 return false;
131 columnDot = vctDotProduct(this->Column(0), this->Column(2));
132 if (vctUnaryOperations<value_type>::AbsValue::Operate(columnDot) > tolerance)
133 return false;
134 columnDot = vctDotProduct(this->Column(1), this->Column(2));
135 if (vctUnaryOperations<value_type>::AbsValue::Operate(columnDot) > tolerance)
136 return false;
137 return true;
138 }
139
143 RotationValueType Inverse(void) const; // implemented in vctMatrixRotation3.h
144
145
153 template <stride_type __stride1, class __dataPtrType1,
154 stride_type __stride2, class __dataPtrType2>
155 inline void
158 CMN_ASSERT(input.Pointer() != output.Pointer());
159 // Implementation note: We think working on a local copy of the input
160 // is faster than working on the members, because of fewer indirections,
161 // especially when combined with the dot product operation.
162 const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
163 output[0] = vctDotProduct( this->Row(0), inputCopy );
164 output[1] = vctDotProduct( this->Row(1), inputCopy );
165 output[2] = vctDotProduct( this->Row(2), inputCopy );
166 }
167
168
177 template <stride_type __stride, class __dataPtrType>
181 this->ApplyTo(input, result);
182 return result;
183 }
184
185
194 inline RotationValueType
195 ApplyTo(const ThisType & input) const {
196 CMN_ASSERT(input.Pointer() != this->Pointer());
197 RotationValueType result;
198 this->ApplyTo(input, result);
199 return result;
200 }
201
202
207 template <class __vectorOwnerType1, class __vectorOwnerType2>
208 inline void
211 CISST_THROW(std::runtime_error)
212 {
213 CMN_ASSERT(input.Pointer() != output.Pointer());
214 CMN_ASSERT(input.size() == DIMENSION);
215 CMN_ASSERT(output.size() == DIMENSION);
216 // see implementation note for fixed size i/o version
217 const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
218 output[0] = vctDotProduct( this->Row(0), inputCopy );
219 output[1] = vctDotProduct( this->Row(1), inputCopy );
220 output[2] = vctDotProduct( this->Row(2), inputCopy );
221 }
222
223
224 template <class __vectorOwnerType, stride_type __stride, class __dataPtrType>
225 inline void
228 CISST_THROW(std::runtime_error)
229 {
230 CMN_ASSERT(input.Pointer() != output.Pointer());
231 CMN_ASSERT(input.size() == DIMENSION);
232 // see implementation note for fixed size i/o version
233 const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
234 output[0] = vctDotProduct( this->Row(0), inputCopy );
235 output[1] = vctDotProduct( this->Row(1), inputCopy );
236 output[2] = vctDotProduct( this->Row(2), inputCopy );
237 }
238
239
243 template <class __vectorOwnerType>
247 this->ApplyTo(input, result);
248 return result;
249 }
250
258 template <stride_type __stride1, class __dataPtrType1,
259 stride_type __stride2, class __dataPtrType2>
260 inline void
263 CMN_ASSERT(input.Pointer() != output.Pointer());
264 // see implementation note for fixed size i/o ApplyTo() version
265 const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
266 output[0] = vctDotProduct( inputCopy, this->Column(0) );
267 output[1] = vctDotProduct( inputCopy, this->Column(1) );
268 output[2] = vctDotProduct( inputCopy, this->Column(2) );
269 }
270
271
280 template <stride_type __stride, class __dataPtrType>
287
291 template <class __vectorOwnerType>
295 this->ApplyInverseTo(input, result);
296 return result;
297 }
298
299
300
308 inline void ApplyInverseTo(const ThisType & input, ThisType & output) const {
309 CMN_ASSERT(input.Pointer() != output.Pointer());
310 output.ProductOf(this->TransposeRef(), input);
311 }
312
313
322 inline RotationValueType ApplyInverseTo(const ThisType & input) const {
323 CMN_ASSERT(input.Pointer() != this->Pointer());
324 RotationValueType result;
325 this->ApplyInverseTo(input, result);
326 return result;
327 }
328
329
334 template <class __vectorOwnerType1, class __vectorOwnerType2>
335 inline void
338 {
339 CMN_ASSERT(input.Pointer() != output.Pointer());
340 CMN_ASSERT(input.size() == DIMENSION);
341 CMN_ASSERT(output.size() == DIMENSION);
342 // see implementation note for fixed size i/o ApplyTo() version
343 const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
344 output[0] = vctDotProduct( inputCopy, this->Column(0) );
345 output[1] = vctDotProduct( inputCopy, this->Column(1) );
346 output[2] = vctDotProduct( inputCopy, this->Column(2) );
347 }
348
353 template <class __vectorOwnerType, stride_type __stride, class __dataPtrType>
354 inline void
357 {
358 CMN_ASSERT(input.Pointer() != output.Pointer());
359 CMN_ASSERT(input.size() == DIMENSION);
360 // see implementation note for fixed size i/o ApplyTo() version
361 const vctFixedSizeVector<value_type, 3> inputCopy( input[0], input[1], input[2] );
362 output[0] = vctDotProduct( inputCopy, this->Column(0) );
363 output[1] = vctDotProduct( inputCopy, this->Column(1) );
364 output[2] = vctDotProduct( inputCopy, this->Column(2) );
365 }
366
369 template <size_type __cols,
370 stride_type __rowStride1, stride_type __colStride1, class __dataPtrType1,
371 stride_type __rowStride2, stride_type __colStride2, class __dataPtrType2>
378
381 template <class __matrixOwnerType1, class __matrixOwnerType2>
384 {
385 CMN_ASSERT((input.rows() == DIMENSION) && (output.rows() == DIMENSION) && (input.cols() == output.cols()));
386 CMN_ASSERT(input.Pointer() != output.Pointer());
388 output.ProductOf(myRef, input);
389 }
390
393 template <size_type __cols,
394 stride_type __rowStride1, stride_type __colStride1, class __dataPtrType1,
395 stride_type __rowStride2, stride_type __colStride2, class __dataPtrType2>
402
405 template <class __matrixOwnerType1, class __matrixOwnerType2>
408 {
409 CMN_ASSERT((input.rows() == DIMENSION) && (output.rows() == DIMENSION) && (input.cols() == output.cols()));
410 CMN_ASSERT(input.Pointer() != output.Pointer());
412 output.ProductOf(myInvRef, input);
413 }
414
422 {
423 return this->ApplyTo(input);
424 }
425
430 template <stride_type __stride, class __dataPtrType>
436
441 template <class __vectorOwnerType1>
444 {
445 return this->ApplyTo(input);
446 }
447
448
449
456 inline bool AlmostEquivalent(const ThisType & other,
457 value_type tolerance = TypeTraits::Tolerance()) const {
458 return this->AlmostEqual(other, tolerance);
459 }
460};
461
462
463#endif // _vctMatrixRotation3ConstBase_h
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:145
Dynamic matrix referencing existing memory (const).
Definition vctDynamicConstMatrixRef.h:81
Definition vctForwardDeclarations.h:119
Definition vctDynamicMatrixBase.h:43
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition vctDynamicMatrixBase.h:143
ThisType & ProductOf(const vctDynamicConstMatrixBase< __matrixOwnerType, _elementType > &matrix, const value_type scalar)
Definition vctDynamicMatrixBase.h:971
Definition vctDynamicVectorBase.h:62
pointer Pointer(index_type index=0)
Definition vctDynamicVectorBase.h:155
A template for a fixed size matrix with fixed spacing in memory.
Definition vctFixedSizeConstMatrixBase.h:104
const_pointer Pointer(size_type rowIndex, size_type colIndex) const
Definition vctFixedSizeConstMatrixBase.h:329
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeConstVectorBase.h:108
const_pointer Pointer(size_type index=0) const
Definition vctFixedSizeConstVectorBase.h:268
A template for a fixed size matrix with fixed spacings in memory.
Definition vctFixedSizeMatrixBase.h:60
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition vctFixedSizeMatrixBase.h:161
ThisType & ProductOf(const vctFixedSizeConstMatrixBase< _rows, _cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix, const value_type scalar)
Definition vctFixedSizeMatrixBase.h:909
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeVectorBase.h:77
pointer Pointer(size_type index=0)
Definition vctFixedSizeVectorBase.h:226
Implementation of a fixed-size vector using template metaprogramming.
Definition vctFixedSizeVector.h:54
Define a rotation matrix for a space of dimension 3.
Definition vctMatrixRotation3ConstBase.h:56
@ DIMENSION
Definition vctMatrixRotation3ConstBase.h:59
@ ROWS
Definition vctMatrixRotation3ConstBase.h:58
@ COLS
Definition vctMatrixRotation3ConstBase.h:58
RotationValueType operator*(const ThisType &input) const
Definition vctMatrixRotation3ConstBase.h:421
ContainerType BaseType
Definition vctMatrixRotation3ConstBase.h:60
RotationValueType ApplyTo(const ThisType &input) const
Definition vctMatrixRotation3ConstBase.h:195
RotationValueType Normalized(void) const
Definition vctMatrixRotation3.h:394
RotationValueType Inverse(void) const
Definition vctMatrixRotation3.h:403
bool IsNormalized(value_type tolerance=TypeTraits::Tolerance()) const
Definition vctMatrixRotation3ConstBase.h:116
void ApplyInverseTo(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &input, vctFixedSizeVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &output) const
Definition vctMatrixRotation3ConstBase.h:355
void ApplyInverseTo(const vctDynamicConstMatrixBase< __matrixOwnerType1, value_type > &input, vctDynamicMatrixBase< __matrixOwnerType2, value_type > &output) const
Definition vctMatrixRotation3ConstBase.h:406
static CISST_EXPORT const RotationValueType & Identity()
vctFixedSizeVector< value_type, DIMENSION > ApplyTo(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &input) const
Definition vctMatrixRotation3ConstBase.h:245
void ApplyTo(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &input, vctDynamicVectorBase< __vectorOwnerType2, value_type > &output) const CISST_THROW(std
Definition vctMatrixRotation3ConstBase.h:209
RotationValueType ApplyInverseTo(const ThisType &input) const
Definition vctMatrixRotation3ConstBase.h:322
ContainerType ContainerType
Definition vctMatrixRotation3ConstBase.h:61
vctFixedSizeVector< value_type, DIMENSION > ApplyInverseTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &input) const
Definition vctMatrixRotation3ConstBase.h:282
void ApplyInverseTo(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &input, vctDynamicVectorBase< __vectorOwnerType2, value_type > &output) const
Definition vctMatrixRotation3ConstBase.h:336
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:396
vctFixedSizeVector< value_type, DIMENSION > ApplyInverseTo(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &input) const
Definition vctMatrixRotation3ConstBase.h:293
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 vctDynamicConstVectorBase< __vectorOwnerType, value_type > &input, vctFixedSizeVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &output) const CISST_THROW(std
Definition vctMatrixRotation3ConstBase.h:226
void ThrowUnlessIsNormalized(const _inputType &input) const CISST_THROW(std
Definition vctMatrixRotation3ConstBase.h:87
VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type)
bool AlmostEquivalent(const ThisType &other, value_type tolerance=TypeTraits::Tolerance()) const
Definition vctMatrixRotation3ConstBase.h:456
vctMatrixRotation3< value_type > RotationValueType
Definition vctMatrixRotation3ConstBase.h:68
void ApplyInverseTo(const ThisType &input, ThisType &output) const
Definition vctMatrixRotation3ConstBase.h:308
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:372
vctFixedSizeVector< value_type, DIMENSION > ApplyTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride, value_type, __dataPtrType > &input) const
Definition vctMatrixRotation3ConstBase.h:179
void ThrowUnlessIsNormalized(void) const CISST_THROW(std
Definition vctMatrixRotation3ConstBase.h:76
void ApplyTo(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &input, vctFixedSizeVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &output) const
Definition vctMatrixRotation3ConstBase.h:156
vctMatrixRotation3ConstBase< ContainerType > ThisType
Definition vctMatrixRotation3ConstBase.h:62
void ApplyTo(const vctDynamicConstMatrixBase< __matrixOwnerType1, value_type > &input, vctDynamicMatrixBase< __matrixOwnerType2, value_type > &output) const
Definition vctMatrixRotation3ConstBase.h:382
cmnTypeTraits< value_type > TypeTraits
Definition vctMatrixRotation3ConstBase.h:71
Define a rotation matrix for a space of dimension 3.
Definition vctMatrixRotation3.h:51
static OutputElementType Operate(const InputElementType &input)
Definition vctUnaryOperations.h:86
#define CMN_ASSERT(expr)
Definition cmnAssert.h:97
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
ConstRowRefType Row(size_type index) const CISST_THROW(std
Definition vctDynamicConstMatrixBase.h:367
bool AlmostEqual(const vctDynamicConstMatrixBase< __matrixOwnerType, _elementType > &otherMatrix, value_type tolerance) const
Definition vctDynamicConstMatrixBase.h:721
ConstRefTransposeType TransposeRef(void) const
Definition vctDynamicConstMatrixBase.h:980
ConstColumnRefType Column(size_type index) const CISST_THROW(std
Definition vctDynamicConstMatrixBase.h:372
_elementType vctDotProduct(const vctDynamicConstVectorBase< _vector1OwnerType, _elementType > &vector1, const vctDynamicConstVectorBase< _vector2OwnerType, _elementType > &vector2)
Definition vctDynamicConstVectorBase.h:1087
Declaration of vctDynamicMatrix.
Macros to export the symbols of cisstVector (in a Dll).
Declaration of vctFixedSizeMatrix.
Forward declarations and #define for cisstVector.