VTK  9.1.0
vtkQuaternion.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkQuaternion.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
33#ifndef vtkQuaternion_h
34#define vtkQuaternion_h
35
36#include "vtkTuple.h"
37
38template <typename T>
39class vtkQuaternion : public vtkTuple<T, 4>
40{
41public:
46
50 explicit vtkQuaternion(const T& scalar)
51 : vtkTuple<T, 4>(scalar)
52 {
53 }
54
60 explicit vtkQuaternion(const T* init)
61 : vtkTuple<T, 4>(init)
62 {
63 }
64
68 vtkQuaternion(const T& w, const T& x, const T& y, const T& z);
69
73 T SquaredNorm() const;
74
78 T Norm() const;
79
83 void ToIdentity();
84
90
96
101
105 void Conjugate();
106
111
117 void Invert();
118
123
129 void ToUnitLog();
130
137
143 void ToUnitExp();
144
151
157
163
165
168 void Set(const T& w, const T& x, const T& y, const T& z);
169 void Set(T quat[4]);
170 void Get(T quat[4]) const;
172
174
177 void SetW(const T& w);
178 const T& GetW() const;
180
182
185 void SetX(const T& x);
186 const T& GetX() const;
188
190
193 void SetY(const T& y);
194 const T& GetY() const;
196
198
201 void SetZ(const T& z);
202 const T& GetZ() const;
204
206
210 T GetRotationAngleAndAxis(T axis[3]) const;
211 void SetRotationAngleAndAxis(T angle, T axis[3]);
212 void SetRotationAngleAndAxis(const T& angle, const T& x, const T& y, const T& z);
214
218 template <typename CastTo>
220
226 void ToMatrix3x3(T A[3][3]) const;
227
234 void FromMatrix3x3(const T A[3][3]);
235
243
250
255
260
265
269 vtkQuaternion<T> operator*(const T& scalar) const;
270
274 void operator*=(const T& scalar) const;
275
280
284 vtkQuaternion<T> operator/(const T& scalar) const;
285
287
290 void operator/=(const T& scalar);
292};
293
298#define vtkQuaternionIdentity(quaternionType, type) \
299 quaternionType Identity() const \
300 { \
301 return quaternionType(vtkQuaternion<type>::Identity().GetData()); \
302 }
303#define vtkQuaternionNormalized(quaternionType, type) \
304 quaternionType Normalized() const \
305 { \
306 return quaternionType(vtkQuaternion<type>::Normalized().GetData()); \
307 }
308#define vtkQuaternionConjugated(quaternionType, type) \
309 quaternionType Conjugated() const \
310 { \
311 return quaternionType(vtkQuaternion<type>::Conjugated().GetData()); \
312 }
313#define vtkQuaternionInverse(quaternionType, type) \
314 quaternionType Inverse() const \
315 { \
316 return quaternionType(vtkQuaternion<type>::Inverse().GetData()); \
317 }
318#define vtkQuaternionUnitLog(quaternionType, type) \
319 quaternionType UnitLog() const \
320 { \
321 return quaternionType(vtkQuaternion<type>::UnitLog().GetData()); \
322 }
323#define vtkQuaternionUnitExp(quaternionType, type) \
324 quaternionType UnitExp() const \
325 { \
326 return quaternionType(vtkQuaternion<type>::UnitExp().GetData()); \
327 }
328#define vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
329 quaternionType NormalizedWithAngleInDegrees() const \
330 { \
331 return quaternionType(vtkQuaternion<type>::NormalizedWithAngleInDegrees().GetData()); \
332 }
333#define vtkQuaternionSlerp(quaternionType, type) \
334 quaternionType Slerp(type t, const quaternionType& q) const \
335 { \
336 return quaternionType(vtkQuaternion<type>::Slerp(t, q).GetData()); \
337 }
338#define vtkQuaternionInnerPoint(quaternionType, type) \
339 quaternionType InnerPoint(const quaternionType& q1, const quaternionType& q2) const \
340 { \
341 return quaternionType(vtkQuaternion<type>::InnerPoint(q1, q2).GetData()); \
342 }
343#define vtkQuaternionOperatorPlus(quaternionType, type) \
344 inline quaternionType operator+(const quaternionType& q) const \
345 { \
346 return quaternionType( \
347 (static_cast<vtkQuaternion<type>>(*this) + static_cast<vtkQuaternion<type>>(q)).GetData()); \
348 }
349#define vtkQuaternionOperatorMinus(quaternionType, type) \
350 inline quaternionType operator-(const quaternionType& q) const \
351 { \
352 return quaternionType( \
353 (static_cast<vtkQuaternion<type>>(*this) - static_cast<vtkQuaternion<type>>(q)).GetData()); \
354 }
355#define vtkQuaternionOperatorMultiply(quaternionType, type) \
356 inline quaternionType operator*(const quaternionType& q) const \
357 { \
358 return quaternionType( \
359 (static_cast<vtkQuaternion<type>>(*this) * static_cast<vtkQuaternion<type>>(q)).GetData()); \
360 }
361#define vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
362 inline quaternionType operator*(const type& scalar) const \
363 { \
364 return quaternionType((static_cast<vtkQuaternion<type>>(*this) * scalar).GetData()); \
365 }
366#define vtkQuaternionOperatorDivide(quaternionType, type) \
367 inline quaternionType operator/(const quaternionType& q) const \
368 { \
369 return quaternionType( \
370 (static_cast<vtkQuaternion<type>>(*this) / static_cast<vtkQuaternion<type>>(q)).GetData()); \
371 }
372#define vtkQuaternionOperatorDivideScalar(quaternionType, type) \
373 inline quaternionType operator/(const type& scalar) const \
374 { \
375 return quaternionType((static_cast<vtkQuaternion<type>>(*this) / scalar).GetData()); \
376 }
377
378#define vtkQuaternionOperatorMacro(quaternionType, type) \
379 vtkQuaternionIdentity(quaternionType, type); \
380 vtkQuaternionNormalized(quaternionType, type); \
381 vtkQuaternionConjugated(quaternionType, type); \
382 vtkQuaternionInverse(quaternionType, type); \
383 vtkQuaternionUnitLog(quaternionType, type); \
384 vtkQuaternionUnitExp(quaternionType, type); \
385 vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type); \
386 vtkQuaternionSlerp(quaternionType, type); \
387 vtkQuaternionInnerPoint(quaternionType, type); \
388 vtkQuaternionOperatorPlus(quaternionType, type); \
389 vtkQuaternionOperatorMinus(quaternionType, type); \
390 vtkQuaternionOperatorMultiply(quaternionType, type); \
391 vtkQuaternionOperatorMultiplyScalar(quaternionType, type); \
392 vtkQuaternionOperatorDivide(quaternionType, type); \
393 vtkQuaternionOperatorDivideScalar(quaternionType, type)
394
395// .NAME vtkQuaternionf - Float quaternion type.
396//
397// .SECTION Description
398// This class is uses vtkQuaternion with float type data.
399// For further description, see the templated class vtkQuaternion.
400// @sa vtkQuaterniond vtkQuaternion
401class vtkQuaternionf : public vtkQuaternion<float>
402{
403public:
404 vtkQuaternionf() = default;
405 explicit vtkQuaternionf(float w, float x, float y, float z)
406 : vtkQuaternion<float>(w, x, y, z)
407 {
408 }
409 explicit vtkQuaternionf(float scalar)
410 : vtkQuaternion<float>(scalar)
411 {
412 }
413 explicit vtkQuaternionf(const float* init)
414 : vtkQuaternion<float>(init)
415 {
416 }
418};
419
420// .NAME vtkQuaterniond - Double quaternion type.
421//
422// .SECTION Description
423// This class is uses vtkQuaternion with double type data.
424// For further description, seethe templated class vtkQuaternion.
425// @sa vtkQuaternionf vtkQuaternion
426class vtkQuaterniond : public vtkQuaternion<double>
427{
428public:
429 vtkQuaterniond() = default;
430 explicit vtkQuaterniond(double w, double x, double y, double z)
431 : vtkQuaternion<double>(w, x, y, z)
432 {
433 }
434 explicit vtkQuaterniond(double scalar)
435 : vtkQuaternion<double>(scalar)
436 {
437 }
438 explicit vtkQuaterniond(const double* init)
439 : vtkQuaternion<double>(init)
440 {
441 }
443};
444
445#include "vtkQuaternion.txx"
446
447#endif // vtkQuaternion_h
448// VTK-HeaderTest-Exclude: vtkQuaternion.h
templated base type for storage of quaternions.
Definition: vtkQuaternion.h:40
static vtkQuaternion< T > Identity()
Return the identity quaternion.
void SetRotationAngleAndAxis(T angle, T axis[3])
Set/Get the angle (in radians) and the axis corresponding to the axis-angle rotation of this quaterni...
vtkQuaternion(const T &scalar)
Initialize all of the quaternion's elements with the supplied scalar.
Definition: vtkQuaternion.h:50
void SetX(const T &x)
Set/Get the x component of the quaternion, i.e.
void Set(T quat[4])
Set/Get the w, x, y and z components of the quaternion.
void SetZ(const T &z)
Set/Get the y component of the quaternion, i.e.
vtkQuaternion< T > operator+(const vtkQuaternion< T > &q) const
Performs addition of quaternion of the same basic type.
vtkQuaternion< T > Conjugated() const
Return the conjugate form of this quaternion.
void ToUnitExp()
Convert this quaternion to a unit exponential quaternion.
void SetRotationAngleAndAxis(const T &angle, const T &x, const T &y, const T &z)
Set/Get the angle (in radians) and the axis corresponding to the axis-angle rotation of this quaterni...
void SetW(const T &w)
Set/Get the w component of the quaternion, i.e.
const T & GetX() const
Set/Get the x component of the quaternion, i.e.
T Norm() const
Get the norm of the quaternion, i.e.
vtkQuaternion< T > UnitLog() const
Return the unit log version of this quaternion.
void SetY(const T &y)
Set/Get the y component of the quaternion, i.e.
const T & GetZ() const
Set/Get the y component of the quaternion, i.e.
void operator/=(const T &scalar)
Performs in place division of the quaternions by a scalar value.
void ToMatrix3x3(T A[3][3]) const
Convert a quaternion to a 3x3 rotation matrix.
vtkQuaternion(const T *init)
Initialize the quaternion's elements with the elements of the supplied array.
Definition: vtkQuaternion.h:60
vtkQuaternion< T > Slerp(T t, const vtkQuaternion< T > &q) const
Interpolate quaternions using spherical linear interpolation between this quaternion and q1 to produc...
vtkQuaternion< CastTo > Cast() const
Cast the quaternion to the specified type and return the result.
void Invert()
Invert the quaternion in place.
void Get(T quat[4]) const
Set/Get the w, x, y and z components of the quaternion.
vtkQuaternion< T > operator/(const T &scalar) const
Performs division of the quaternions by a scalar value.
void Set(const T &w, const T &x, const T &y, const T &z)
Set/Get the w, x, y and z components of the quaternion.
void operator*=(const T &scalar) const
Performs in place multiplication of the quaternions by a scalar value.
vtkQuaternion(const T &w, const T &x, const T &y, const T &z)
Initialize the quaternion element explicitly.
vtkQuaternion< T > operator-(const vtkQuaternion< T > &q) const
Performs subtraction of quaternions of the same basic type.
T SquaredNorm() const
Get the squared norm of the quaternion.
T Normalize()
Normalize the quaternion in place.
vtkQuaternion< T > operator/(const vtkQuaternion< T > &q) const
Performs division of quaternions of the same type.
vtkQuaternion< T > UnitExp() const
Return the unit exponential version of this quaternion.
T GetRotationAngleAndAxis(T axis[3]) const
Set/Get the angle (in radians) and the axis corresponding to the axis-angle rotation of this quaterni...
void ToUnitLog()
Convert this quaternion to a unit log quaternion.
void FromMatrix3x3(const T A[3][3])
Convert a 3x3 matrix into a quaternion.
vtkQuaternion< T > operator*(const T &scalar) const
Performs multiplication of the quaternions by a scalar value.
void Conjugate()
Conjugate the quaternion in place.
vtkQuaternion< T > InnerPoint(const vtkQuaternion< T > &q1, const vtkQuaternion< T > &q2) const
Interpolates between quaternions, using spherical quadrangle interpolation.
vtkQuaternion< T > operator*(const vtkQuaternion< T > &q) const
Performs multiplication of quaternion of the same basic type.
void ToIdentity()
Set the quaternion to identity in place.
vtkQuaternion< T > Inverse() const
Return the inverted form of this quaternion.
void NormalizeWithAngleInDegrees()
Normalize a quaternion in place and transform it to so its angle is in degrees and its axis normalize...
vtkQuaternion()
Default constructor.
vtkQuaternion< T > Normalized() const
Return the normalized form of this quaternion.
vtkQuaternion< T > NormalizedWithAngleInDegrees() const
Returns a quaternion normalized and transformed so its angle is in degrees and its axis normalized.
const T & GetY() const
Set/Get the y component of the quaternion, i.e.
const T & GetW() const
Set/Get the w component of the quaternion, i.e.
vtkQuaterniond(double w, double x, double y, double z)
vtkQuaternionOperatorMacro(vtkQuaterniond, double)
vtkQuaterniond(const double *init)
vtkQuaterniond()=default
vtkQuaterniond(double scalar)
vtkQuaternionf(float scalar)
vtkQuaternionf(const float *init)
vtkQuaternionOperatorMacro(vtkQuaternionf, float)
vtkQuaternionf()=default
vtkQuaternionf(float w, float x, float y, float z)
templated base type for containers of constant size.
Definition: vtkTuple.h:38