cisst-saw
Loading...
Searching...
No Matches
vctMatrixRotation3Base.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 _vctMatrixRotation3Base_h
21#define _vctMatrixRotation3Base_h
22
27
34
35
36#ifndef DOXYGEN
37#ifndef SWIG
38
39// helper functions for subtemplated methods of a templated class
40template <class _matrixType, class _quaternionType>
41void
43 const vctQuaternionRotation3Base<_quaternionType> & quaternionRotation);
44
45#endif // SWIG
46#endif // DOXYGEN
47
48
69template <class _containerType>
71{
72public:
73 enum {ROWS = 3, COLS = 3};
74 enum {DIMENSION = 3};
75 typedef _containerType ContainerType;
79
80 /* no need to document, inherit doxygen documentation from base class */
81 VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type);
82
85
86 // MJ: support for gcc 4.6 compilation (not to have -fpermissive)
88
102
104 template <class __containerType>
105 inline ThisType &
107 CISST_THROW(std::runtime_error)
108 {
109 this->FromRaw(other);
111 return *this;
112 }
113
114
116 inline ThisType &
117 From(const value_type & element00, const value_type & element01, const value_type & element02,
118 const value_type & element10, const value_type & element11, const value_type & element12,
119 const value_type & element20, const value_type & element21, const value_type & element22)
120 CISST_THROW(std::runtime_error)
121 {
122 this->FromRaw(element00, element01, element02,
123 element10, element11, element12,
124 element20, element21, element22);
126 return *this;
127 }
128
135 template <stride_type __stride1, class __dataPtrType1,
136 stride_type __stride2, class __dataPtrType2,
137 stride_type __stride3, class __dataPtrType3>
138 inline ThisType &
142 bool vectorsAreColumns = true)
143 CISST_THROW(std::runtime_error)
144 {
145 this->FromRaw(v1, v2, v3, vectorsAreColumns);
147 return *this;
148 }
149
150
157 template <class __vectorOwnerType1,
158 class __vectorOwnerType2,
159 class __vectorOwnerType3>
160 inline ThisType &
164 bool vectorsAreColumns = true)
165 CISST_THROW(std::runtime_error)
166 {
167 this->FromRaw(v1, v2, v3, vectorsAreColumns);
169 return *this;
170 }
171
173 inline ThisType &
174 From(const vctAxisAngleRotation3<value_type> & axisAngleRotation)
175 CISST_THROW(std::runtime_error)
176 {
177 this->ThrowUnlessIsNormalized(axisAngleRotation);
178 return this->FromRaw(axisAngleRotation);
179 }
180
182 template <class __containerType>
183 inline ThisType &
185 CISST_THROW(std::runtime_error)
186 {
187 this->ThrowUnlessIsNormalized(quaternionRotation);
188 return this->FromRaw(quaternionRotation);
189 }
190
191
193 template <class __containerType>
194 inline ThisType &
196 CISST_THROW(std::runtime_error)
197 {
198 this->ThrowUnlessIsNormalized(rodriguezRotation);
199 return this->FromRaw(rodriguezRotation);
200 }
201
203 template <vctEulerRotation3Order::OrderType __order>
204 inline ThisType &
205 From(const vctEulerRotation3<__order> & eulerRotation)
206 CISST_THROW(std::runtime_error)
207 {
208 this->ThrowUnlessIsNormalized(eulerRotation);
209 return this->FromRaw(eulerRotation);
210 }
211
213
214
215
216
217
218
228
230 template <class __containerType>
231 inline ThisType &
233 CISST_THROW(std::runtime_error)
234 {
235 this->FromRaw(other);
236 this->NormalizedSelf();
237 return *this;
238 }
239
240
242 inline ThisType &
243 FromNormalized(const value_type & element00, const value_type & element01, const value_type & element02,
244 const value_type & element10, const value_type & element11, const value_type & element12,
245 const value_type & element20, const value_type & element21, const value_type & element22)
246 {
247 this->FromRaw(element00, element01, element02,
248 element10, element11, element12,
249 element20, element21, element22);
250 this->NormalizedSelf();
251 return *this;
252 }
253
260 template <stride_type __stride1, class __dataPtrType1,
261 stride_type __stride2, class __dataPtrType2,
262 stride_type __stride3, class __dataPtrType3>
263 inline ThisType &
267 bool vectorsAreColumns = true)
268 CISST_THROW(std::runtime_error)
269 {
270 this->FromRaw(v1, v2, v3, vectorsAreColumns);
271 this->NormalizedSelf();
272 return *this;
273 }
274
275
282 template <class __vectorOwnerType1,
283 class __vectorOwnerType2,
284 class __vectorOwnerType3>
285 inline ThisType &
289 bool vectorsAreColumns = true)
290 {
291 this->FromRaw(v1, v2, v3, vectorsAreColumns);
292 this->NormalizedSelf();
293 return *this;
294 }
295
297 inline ThisType &
299 {
300 return this->FromRaw(axisAngleRotation.Normalized());
301 }
302
308 template <class __containerType>
309 inline ThisType &
311 {
312 return this->FromRaw(quaternionRotation.Normalized());
313 }
314
315
317 template <class __containerType>
318 inline ThisType &
320 {
321 return this->FromRaw(rodriguezRotation.Normalized());
322 }
323
324
326 template <vctEulerRotation3Order::OrderType __order>
327 inline ThisType &
329 {
330 return this->FromRaw(eulerRotation.Normalized());
331 }
332
333
334
335
336
337
338
348
350 template <class __containerType>
351 inline ThisType &
353 CISST_THROW(std::runtime_error)
354 {
355 this->Assign(other);
356 return *this;
357 }
358
359
361 inline ThisType &
362 FromRaw(const value_type & element00, const value_type & element01, const value_type & element02,
363 const value_type & element10, const value_type & element11, const value_type & element12,
364 const value_type & element20, const value_type & element21, const value_type & element22)
365 {
366 this->Assign(element00, element01, element02,
367 element10, element11, element12,
368 element20, element21, element22);
369 return *this;
370 }
371
372
379 template <stride_type __stride1, class __dataPtrType1,
380 stride_type __stride2, class __dataPtrType2,
381 stride_type __stride3, class __dataPtrType3>
382 inline ThisType &
386 bool vectorsAreColumns = true)
387 {
388 if (vectorsAreColumns) {
389 this->Column(0).Assign(v1);
390 this->Column(1).Assign(v2);
391 this->Column(2).Assign(v3);
392 } else {
393 this->Row(0).Assign(v1);
394 this->Row(1).Assign(v2);
395 this->Row(2).Assign(v3);
396 }
397 return *this;
398 }
399
400
407 template <class __vectorOwnerType1,
408 class __vectorOwnerType2,
409 class __vectorOwnerType3>
410 inline ThisType &
414 bool vectorsAreColumns = true)
415 CISST_THROW(std::runtime_error)
416 {
417 CMN_ASSERT(v1.size() == DIMENSION);
418 CMN_ASSERT(v2.size() == DIMENSION);
419 CMN_ASSERT(v3.size() == DIMENSION);
420 if (vectorsAreColumns) {
421 this->Column(0).Assign(v1);
422 this->Column(1).Assign(v2);
423 this->Column(2).Assign(v3);
424 } else {
425 this->Row(0).Assign(v1);
426 this->Row(1).Assign(v2);
427 this->Row(2).Assign(v3);
428 }
429 return *this;
430 }
431
432
434 ThisType &
435 FromRaw(const vctAxisAngleRotation3<value_type> & axisAngleRotation);
436
437
439 template <class __containerType>
440 inline ThisType &
442 vctMatrixRotation3BaseFromRaw(*this, quaternionRotation);
443 return *this;
444 }
445
446
448 template <class __containerType>
449 inline ThisType &
451 return this->FromRaw(vctAxisAngleRotation3<value_type>(rodriguezRotation, VCT_DO_NOT_NORMALIZE));
452 }
453
455 template <vctEulerRotation3Order::OrderType __order>
456 inline ThisType &
457 FromRaw(const vctEulerRotation3<__order> & eulerRotation) {
458 vctEulerToMatrixRotation3(eulerRotation, *this);
459 return *this;
460 }
461
465 inline ThisType &
466 FromRaw(const ThisType & otherRotation) {
467 return reinterpret_cast<ThisType &>(this->Assign(otherRotation));
468 }
469
470
480 template <stride_type __rowStride, stride_type __colStride, class __dataPtrType>
481 inline ThisType &
483 this->Assign(matrix);
484 return *this;
485 }
486
487
488
493 quaternion.FromRaw(*this);
494 quaternion.NormalizedSelf();
495 this->From(quaternion);
496 return *this;
497 }
498
499
502 inline ThisType & NormalizedOf(ThisType & otherMatrix) {
503 CMN_ASSERT(otherMatrix.Pointer() != this->Pointer());
504 *this = otherMatrix;
505 this->NormalizedSelf();
506 return *this;
507 }
508
509
512 inline ThisType &
514 // could use the transpose operator but this seems more efficient
515 value_type tmp;
516 tmp = this->Element(0, 1); this->Element(0, 1) = this->Element(1, 0); this->Element(1, 0) = tmp;
517 tmp = this->Element(0, 2); this->Element(0, 2) = this->Element(2, 0); this->Element(2, 0) = tmp;
518 tmp = this->Element(1, 2); this->Element(1, 2) = this->Element(2, 1); this->Element(2, 1) = tmp;
519 return *this;
520 }
521
522
525 inline ThisType &
526 InverseOf(const ThisType & otherRotation) {
527 CMN_ASSERT(otherRotation.Pointer() != this->Pointer());
528 this->TransposeOf(otherRotation);
529 return *this;
530 }
531};
532
533
534
535template <class _containerType>
538
539 typedef vctAxisAngleRotation3<value_type> AxisAngleType;
540
541 const typename AxisAngleType::AngleType angle = axisAngleRotation.Angle();
542 const typename AxisAngleType::AxisType axis = axisAngleRotation.Axis();
543
544 const AngleType sinAngle = AngleType(sin(angle));
545 const AngleType cosAngle = AngleType(cos(angle));
546 const AngleType CompCosAngle = 1 - cosAngle;
547
548 // first column
549 this->Element(0, 0) = value_type(axis[0] * axis[0] * CompCosAngle + cosAngle);
550 this->Element(1, 0) = value_type(axis[0] * axis[1] * CompCosAngle + axis[2] * sinAngle);
551 this->Element(2, 0) = value_type(axis[0] * axis[2] * CompCosAngle - axis[1] * sinAngle);
552
553 // second column
554 this->Element(0, 1) = value_type(axis[1] * axis[0] * CompCosAngle - axis[2] * sinAngle);
555 this->Element(1, 1) = value_type(axis[1] * axis[1] * CompCosAngle + cosAngle);
556 this->Element(2, 1) = value_type(axis[1] * axis[2] * CompCosAngle + axis[0] * sinAngle);
557
558 // third column
559 this->Element(0, 2) = value_type(axis[2] * axis[0] * CompCosAngle + axis[1] * sinAngle);
560 this->Element(1, 2) = value_type(axis[2] * axis[1] * CompCosAngle - axis[0] * sinAngle);
561 this->Element(2, 2) = value_type(axis[2] * axis[2] * CompCosAngle + cosAngle);
562
563 return *this;
564}
565
566
567template <class _matrixType, class _quaternionType>
568void
570 const vctQuaternionRotation3Base<_quaternionType> & quaternionRotation) {
571
572 typedef typename _matrixType::value_type value_type;
573
574 value_type xx = quaternionRotation.X() * quaternionRotation.X();
575 value_type xy = quaternionRotation.X() * quaternionRotation.Y();
576 value_type xz = quaternionRotation.X() * quaternionRotation.Z();
577 value_type xr = quaternionRotation.X() * quaternionRotation.R();
578 value_type yy = quaternionRotation.Y() * quaternionRotation.Y();
579 value_type yz = quaternionRotation.Y() * quaternionRotation.Z();
580 value_type yr = quaternionRotation.Y() * quaternionRotation.R();
581 value_type zz = quaternionRotation.Z() * quaternionRotation.Z();
582 value_type zr = quaternionRotation.Z() * quaternionRotation.R();
583 matrixRotation.Assign(1 - 2 * (yy + zz), 2 * (xy - zr), 2 * (xz + yr),
584 2 * (xy + zr), 1 - 2 * (xx + zz), 2 * (yz - xr),
585 2 * (xz - yr), 2 * (yz + xr), 1 - 2 * (xx + yy));
586}
587
588#endif // _vctMatrixRotation3Base_h
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition cmnTypeTraits.h:155
_elementType value_type
Definition mtsGenericObjectProxy.h:329
Define a rotation based on an axis and an angle for a space of dimension 3.
Definition vctAxisAngleRotation3.h:93
const AxisType & Axis(void) const
Definition vctAxisAngleRotation3.h:312
ThisType Normalized(void) const
Definition vctAxisAngleRotation3.h:540
const AngleType & Angle(void) const
Definition vctAxisAngleRotation3.h:322
Definition vctForwardDeclarations.h:119
Definition vctEulerRotation3.h:154
ThisType Normalized(void) const
Definition vctEulerRotation3.h:248
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeConstVectorBase.h:108
A template for a fixed size matrix with fixed spacings in memory.
Definition vctFixedSizeMatrixBase.h:60
Define a rotation matrix for a space of dimension 3.
Definition vctMatrixRotation3Base.h:71
vctMatrixRotation3Base< ContainerType > ThisType
Definition vctMatrixRotation3Base.h:77
ThisType & FromRaw(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &v1, const vctFixedSizeConstVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &v2, const vctFixedSizeConstVectorBase< DIMENSION, __stride3, value_type, __dataPtrType3 > &v3, bool vectorsAreColumns=true)
Definition vctMatrixRotation3Base.h:383
ThisType & FromNormalized(const vctEulerRotation3< __order > &eulerRotation)
Definition vctMatrixRotation3Base.h:328
ThisType & FromRaw(const value_type &element00, const value_type &element01, const value_type &element02, const value_type &element10, const value_type &element11, const value_type &element12, const value_type &element20, const value_type &element21, const value_type &element22)
Definition vctMatrixRotation3Base.h:362
@ ROWS
Definition vctMatrixRotation3Base.h:73
@ COLS
Definition vctMatrixRotation3Base.h:73
ThisType & FromRaw(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &v1, const vctDynamicConstVectorBase< __vectorOwnerType2, value_type > &v2, const vctDynamicConstVectorBase< __vectorOwnerType3, value_type > &v3, bool vectorsAreColumns=true) CISST_THROW(std
Definition vctMatrixRotation3Base.h:411
vctMatrixRotation3Base()
Definition vctMatrixRotation3Base.h:87
ThisType & From(const value_type &element00, const value_type &element01, const value_type &element02, const value_type &element10, const value_type &element11, const value_type &element12, const value_type &element20, const value_type &element21, const value_type &element22) CISST_THROW(std
Definition vctMatrixRotation3Base.h:117
ThisType & FromNormalized(const vctRodriguezRotation3Base< __containerType > &rodriguezRotation)
Definition vctMatrixRotation3Base.h:319
ThisType & From(const vctQuaternionRotation3Base< __containerType > &quaternionRotation) CISST_THROW(std
Definition vctMatrixRotation3Base.h:184
ThisType & FromNormalized(const vctMatrixRotation3Base< __containerType > &other) CISST_THROW(std
Definition vctMatrixRotation3Base.h:232
ThisType & From(const vctMatrixRotation3Base< __containerType > &other) CISST_THROW(std
Definition vctMatrixRotation3Base.h:106
ThisType & FromRaw(const vctAxisAngleRotation3< value_type > &axisAngleRotation)
@ DIMENSION
Definition vctMatrixRotation3Base.h:74
ThisType & From(const vctRodriguezRotation3Base< __containerType > &rodriguezRotation) CISST_THROW(std
Definition vctMatrixRotation3Base.h:195
vctMatrixRotation3ConstBase< ContainerType > BaseType
Definition vctMatrixRotation3Base.h:76
VCT_CONTAINER_TRAITS_TYPEDEFS(typename ContainerType::value_type)
ThisType & FromNormalized(const vctQuaternionRotation3Base< __containerType > &quaternionRotation)
Definition vctMatrixRotation3Base.h:310
ThisType & InverseOf(const ThisType &otherRotation)
Definition vctMatrixRotation3Base.h:526
ThisType & FromRaw(const vctRodriguezRotation3Base< __containerType > &rodriguezRotation)
Definition vctMatrixRotation3Base.h:450
ThisType & From(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &v1, const vctDynamicConstVectorBase< __vectorOwnerType2, value_type > &v2, const vctDynamicConstVectorBase< __vectorOwnerType3, value_type > &v3, bool vectorsAreColumns=true) CISST_THROW(std
Definition vctMatrixRotation3Base.h:161
ThisType & NormalizedOf(ThisType &otherMatrix)
Definition vctMatrixRotation3Base.h:502
vctMatrixRotation3Base< typename ContainerType::MatrixValueType > RotationValueType
Definition vctMatrixRotation3Base.h:78
ThisType & From(const vctAxisAngleRotation3< value_type > &axisAngleRotation) CISST_THROW(std
Definition vctMatrixRotation3Base.h:174
cmnTypeTraits< value_type > TypeTraits
Definition vctMatrixRotation3Base.h:84
ThisType & FromRaw(const vctMatrixRotation3Base< __containerType > &other) CISST_THROW(std
Definition vctMatrixRotation3Base.h:352
ThisType & FromRaw(const ThisType &otherRotation)
Definition vctMatrixRotation3Base.h:466
ThisType & FromRaw(const vctQuaternionRotation3Base< __containerType > &quaternionRotation)
Definition vctMatrixRotation3Base.h:441
ContainerType ContainerType
Definition vctMatrixRotation3Base.h:75
ThisType & FromNormalized(const vctDynamicConstVectorBase< __vectorOwnerType1, value_type > &v1, const vctDynamicConstVectorBase< __vectorOwnerType2, value_type > &v2, const vctDynamicConstVectorBase< __vectorOwnerType3, value_type > &v3, bool vectorsAreColumns=true)
Definition vctMatrixRotation3Base.h:286
ThisType & FromRaw(const vctFixedSizeMatrixBase< ROWS, COLS, __rowStride, __colStride, value_type, __dataPtrType > &matrix)
Definition vctMatrixRotation3Base.h:482
ThisType & From(const vctEulerRotation3< __order > &eulerRotation) CISST_THROW(std
Definition vctMatrixRotation3Base.h:205
ThisType & From(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &v1, const vctFixedSizeConstVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &v2, const vctFixedSizeConstVectorBase< DIMENSION, __stride3, value_type, __dataPtrType3 > &v3, bool vectorsAreColumns=true) CISST_THROW(std
Definition vctMatrixRotation3Base.h:139
ThisType & NormalizedSelf(void)
Definition vctMatrixRotation3Base.h:491
ThisType & InverseSelf(void)
Definition vctMatrixRotation3Base.h:513
ThisType & FromNormalized(const vctAxisAngleRotation3< value_type > &axisAngleRotation)
Definition vctMatrixRotation3Base.h:298
ThisType & FromNormalized(const value_type &element00, const value_type &element01, const value_type &element02, const value_type &element10, const value_type &element11, const value_type &element12, const value_type &element20, const value_type &element21, const value_type &element22)
Definition vctMatrixRotation3Base.h:243
ThisType & FromRaw(const vctEulerRotation3< __order > &eulerRotation)
Definition vctMatrixRotation3Base.h:457
ThisType & FromNormalized(const vctFixedSizeConstVectorBase< DIMENSION, __stride1, value_type, __dataPtrType1 > &v1, const vctFixedSizeConstVectorBase< DIMENSION, __stride2, value_type, __dataPtrType2 > &v2, const vctFixedSizeConstVectorBase< DIMENSION, __stride3, value_type, __dataPtrType3 > &v3, bool vectorsAreColumns=true) CISST_THROW(std
Definition vctMatrixRotation3Base.h:264
Define a rotation matrix for a space of dimension 3.
Definition vctMatrixRotation3ConstBase.h:56
void ThrowUnlessIsNormalized(void) const CISST_THROW(std
Definition vctMatrixRotation3ConstBase.h:76
const_reference R(void) const
Definition vctQuaternionBase.h:101
Define a rotation quaternion for a space of dimension 3.
Definition vctQuaternionRotation3Base.h:64
ThisType & NormalizedSelf(void)
Definition vctQuaternionRotation3Base.h:522
ThisType & FromRaw(const vctQuaternionRotation3Base< __containerType > &other)
Definition vctQuaternionRotation3Base.h:450
ThisType Normalized(void) const
Definition vctQuaternionRotation3Base.h:532
Define a rotation based on the rodriguez representation for a space of dimension 3.
Definition vctRodriguezRotation3Base.h:68
ThisType Normalized(void) const
Definition vctRodriguezRotation3Base.h:302
#define CMN_ASSERT(expr)
Definition cmnAssert.h:97
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
STL namespace.
Declaration of vctAxisAngleRotation3.
ConstRowRefType Row(size_type index) const CISST_THROW(std
Definition vctDynamicConstMatrixBase.h:367
const_reference Element(size_type rowIndex, size_type colIndex) const
Definition vctDynamicConstMatrixBase.h:362
ConstColumnRefType Column(size_type index) const CISST_THROW(std
Definition vctDynamicConstMatrixBase.h:372
vctDynamicConstMatrixBase< _matrixOwnerType, _elementType > ThisType
Definition vctDynamicConstMatrixBase.h:86
Declaration of vctEulerRotation3.
Macros to export the symbols of cisstVector (in a Dll).
const bool VCT_DO_NOT_NORMALIZE
Definition vctForwardDeclarations.h:67
void vctMatrixRotation3BaseFromRaw(vctMatrixRotation3Base< _matrixType > &matrixRotation, const vctQuaternionRotation3Base< _quaternionType > &quaternionRotation)
Definition vctMatrixRotation3Base.h:569
Declaration of vctMatrixRotation3ConstBase.
Declaration of vctQuaternionRotation3Base.
Declaration of vctRodriguezRotation3Base.