VTK  9.2.6
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=========================================================================*/
36#ifndef vtkQuaternion_h
37#define vtkQuaternion_h
38
39#include "vtkTuple.h"
40
41template <typename T>
42class vtkQuaternion : public vtkTuple<T, 4>
43{
44public:
49
53 explicit vtkQuaternion(const T& scalar)
54 : vtkTuple<T, 4>(scalar)
55 {
56 }
57
63 explicit vtkQuaternion(const T* init)
64 : vtkTuple<T, 4>(init)
65 {
66 }
67
71 vtkQuaternion(const T& w, const T& x, const T& y, const T& z);
72
76 T SquaredNorm() const;
77
81 T Norm() const;
82
86 void ToIdentity();
87
93
99
104
108 void Conjugate();
109
114
120 void Invert();
121
126
132 void ToUnitLog();
133
140
146 void ToUnitExp();
147
154
160
166
168
171 void Set(const T& w, const T& x, const T& y, const T& z);
172 void Set(T quat[4]);
173 void Get(T quat[4]) const;
175
177
180 void SetW(const T& w);
181 const T& GetW() const;
183
185
188 void SetX(const T& x);
189 const T& GetX() const;
191
193
196 void SetY(const T& y);
197 const T& GetY() const;
199
201
204 void SetZ(const T& z);
205 const T& GetZ() const;
207
209
213 T GetRotationAngleAndAxis(T axis[3]) const;
214 void SetRotationAngleAndAxis(T angle, T axis[3]);
215 void SetRotationAngleAndAxis(const T& angle, const T& x, const T& y, const T& z);
217
221 template <typename CastTo>
223
229 void ToMatrix3x3(T A[3][3]) const;
230
237 void FromMatrix3x3(const T A[3][3]);
238
246
253
258
263
268
272 vtkQuaternion<T> operator*(const T& scalar) const;
273
277 void operator*=(const T& scalar) const;
278
283
287 vtkQuaternion<T> operator/(const T& scalar) const;
288
290
293 void operator/=(const T& scalar);
295};
296
301#define vtkQuaternionIdentity(quaternionType, type) \
302 quaternionType Identity() const \
303 { \
304 return quaternionType(vtkQuaternion<type>::Identity().GetData()); \
305 }
306#define vtkQuaternionNormalized(quaternionType, type) \
307 quaternionType Normalized() const \
308 { \
309 return quaternionType(vtkQuaternion<type>::Normalized().GetData()); \
310 }
311#define vtkQuaternionConjugated(quaternionType, type) \
312 quaternionType Conjugated() const \
313 { \
314 return quaternionType(vtkQuaternion<type>::Conjugated().GetData()); \
315 }
316#define vtkQuaternionInverse(quaternionType, type) \
317 quaternionType Inverse() const \
318 { \
319 return quaternionType(vtkQuaternion<type>::Inverse().GetData()); \
320 }
321#define vtkQuaternionUnitLog(quaternionType, type) \
322 quaternionType UnitLog() const \
323 { \
324 return quaternionType(vtkQuaternion<type>::UnitLog().GetData()); \
325 }
326#define vtkQuaternionUnitExp(quaternionType, type) \
327 quaternionType UnitExp() const \
328 { \
329 return quaternionType(vtkQuaternion<type>::UnitExp().GetData()); \
330 }
331#define vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
332 quaternionType NormalizedWithAngleInDegrees() const \
333 { \
334 return quaternionType(vtkQuaternion<type>::NormalizedWithAngleInDegrees().GetData()); \
335 }
336#define vtkQuaternionSlerp(quaternionType, type) \
337 quaternionType Slerp(type t, const quaternionType& q) const \
338 { \
339 return quaternionType(vtkQuaternion<type>::Slerp(t, q).GetData()); \
340 }
341#define vtkQuaternionInnerPoint(quaternionType, type) \
342 quaternionType InnerPoint(const quaternionType& q1, const quaternionType& q2) const \
343 { \
344 return quaternionType(vtkQuaternion<type>::InnerPoint(q1, q2).GetData()); \
345 }
346#define vtkQuaternionOperatorPlus(quaternionType, type) \
347 inline quaternionType operator+(const quaternionType& q) const \
348 { \
349 return quaternionType( \
350 (static_cast<vtkQuaternion<type>>(*this) + static_cast<vtkQuaternion<type>>(q)).GetData()); \
351 }
352#define vtkQuaternionOperatorMinus(quaternionType, type) \
353 inline quaternionType operator-(const quaternionType& q) const \
354 { \
355 return quaternionType( \
356 (static_cast<vtkQuaternion<type>>(*this) - static_cast<vtkQuaternion<type>>(q)).GetData()); \
357 }
358#define vtkQuaternionOperatorMultiply(quaternionType, type) \
359 inline quaternionType operator*(const quaternionType& q) const \
360 { \
361 return quaternionType( \
362 (static_cast<vtkQuaternion<type>>(*this) * static_cast<vtkQuaternion<type>>(q)).GetData()); \
363 }
364#define vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
365 inline quaternionType operator*(const type& scalar) const \
366 { \
367 return quaternionType((static_cast<vtkQuaternion<type>>(*this) * scalar).GetData()); \
368 }
369#define vtkQuaternionOperatorDivide(quaternionType, type) \
370 inline quaternionType operator/(const quaternionType& q) const \
371 { \
372 return quaternionType( \
373 (static_cast<vtkQuaternion<type>>(*this) / static_cast<vtkQuaternion<type>>(q)).GetData()); \
374 }
375#define vtkQuaternionOperatorDivideScalar(quaternionType, type) \
376 inline quaternionType operator/(const type& scalar) const \
377 { \
378 return quaternionType((static_cast<vtkQuaternion<type>>(*this) / scalar).GetData()); \
379 }
380
381#define vtkQuaternionOperatorMacro(quaternionType, type) \
382 vtkQuaternionIdentity(quaternionType, type); \
383 vtkQuaternionNormalized(quaternionType, type); \
384 vtkQuaternionConjugated(quaternionType, type); \
385 vtkQuaternionInverse(quaternionType, type); \
386 vtkQuaternionUnitLog(quaternionType, type); \
387 vtkQuaternionUnitExp(quaternionType, type); \
388 vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type); \
389 vtkQuaternionSlerp(quaternionType, type); \
390 vtkQuaternionInnerPoint(quaternionType, type); \
391 vtkQuaternionOperatorPlus(quaternionType, type); \
392 vtkQuaternionOperatorMinus(quaternionType, type); \
393 vtkQuaternionOperatorMultiply(quaternionType, type); \
394 vtkQuaternionOperatorMultiplyScalar(quaternionType, type); \
395 vtkQuaternionOperatorDivide(quaternionType, type); \
396 vtkQuaternionOperatorDivideScalar(quaternionType, type)
397
398// .NAME vtkQuaternionf - Float quaternion type.
399//
400// .SECTION Description
401// This class is uses vtkQuaternion with float type data.
402// For further description, see the templated class vtkQuaternion.
403// @sa vtkQuaterniond vtkQuaternion
404class vtkQuaternionf : public vtkQuaternion<float>
405{
406public:
407 vtkQuaternionf() = default;
408 explicit vtkQuaternionf(float w, float x, float y, float z)
409 : vtkQuaternion<float>(w, x, y, z)
410 {
411 }
412 explicit vtkQuaternionf(float scalar)
413 : vtkQuaternion<float>(scalar)
414 {
415 }
416 explicit vtkQuaternionf(const float* init)
417 : vtkQuaternion<float>(init)
418 {
419 }
421};
422
423// .NAME vtkQuaterniond - Double quaternion type.
424//
425// .SECTION Description
426// This class is uses vtkQuaternion with double type data.
427// For further description, seethe templated class vtkQuaternion.
428// @sa vtkQuaternionf vtkQuaternion
429class vtkQuaterniond : public vtkQuaternion<double>
430{
431public:
432 vtkQuaterniond() = default;
433 explicit vtkQuaterniond(double w, double x, double y, double z)
434 : vtkQuaternion<double>(w, x, y, z)
435 {
436 }
437 explicit vtkQuaterniond(double scalar)
438 : vtkQuaternion<double>(scalar)
439 {
440 }
441 explicit vtkQuaterniond(const double* init)
442 : vtkQuaternion<double>(init)
443 {
444 }
446};
447
448#include "vtkQuaternion.txx"
449
450#endif // vtkQuaternion_h
451// VTK-HeaderTest-Exclude: vtkQuaternion.h
templated base type for storage of quaternions.
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.
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.
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