VTK
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> class vtkQuaternion : public vtkTuple<T, 4>
39{
40public:
45
49 explicit vtkQuaternion(const T& scalar) : vtkTuple<T, 4>(scalar) {}
50
56 explicit vtkQuaternion(const T* init) : vtkTuple<T, 4>(init) {}
57
61 vtkQuaternion(const T& w, const T& x, const T& y, const T& z);
62
66 T SquaredNorm() const;
67
71 T Norm() const;
72
76 void ToIdentity();
77
83
89
94
98 void Conjugate();
99
104
110 void Invert();
111
116
122 void ToUnitLog();
123
130
136 void ToUnitExp();
137
144
150
156
158
161 void Set(const T& w, const T& x, const T& y, const T& z);
162 void Set(T quat[4]);
163 void Get(T quat[4]) const;
165
167
170 void SetW(const T& w);
171 const T& GetW() const;
173
175
178 void SetX(const T& x);
179 const T& GetX() const;
181
183
186 void SetY(const T& y);
187 const T& GetY() const;
189
191
194 void SetZ(const T& z);
195 const T& GetZ() const;
197
199
203 T GetRotationAngleAndAxis(T axis[3]) const;
204 void SetRotationAngleAndAxis(T angle, T axis[3]);
206 const T& angle, const T& x, const T& y, const T& z);
208
212 template<typename CastTo> vtkQuaternion<CastTo> Cast() const;
213
219 void ToMatrix3x3(T A[3][3]) const;
220
227 void FromMatrix3x3(const T A[3][3]);
228
236
243 const vtkQuaternion<T>& q2) const;
244
249
254
259
263 vtkQuaternion<T> operator*(const T& scalar) const;
264
268 void operator*=(const T& scalar) const;
269
274
278 vtkQuaternion<T> operator/(const T& scalar) const;
279
281
284 void operator/=(const T& scalar);
285};
287
292#define vtkQuaternionIdentity(quaternionType, type) \
293quaternionType Identity() const \
294{ \
295 return quaternionType(vtkQuaternion<type>::Identity().GetData()); \
296}
297#define vtkQuaternionNormalized(quaternionType, type) \
298quaternionType Normalized() const \
299{ \
300 return quaternionType(vtkQuaternion<type>::Normalized().GetData()); \
301}
302#define vtkQuaternionConjugated(quaternionType, type) \
303quaternionType Conjugated() const \
304{ \
305 return quaternionType(vtkQuaternion<type>::Conjugated().GetData()); \
306}
307#define vtkQuaternionInverse(quaternionType, type) \
308quaternionType Inverse() const \
309{ \
310 return quaternionType(vtkQuaternion<type>::Inverse().GetData()); \
311}
312#define vtkQuaternionUnitLog(quaternionType, type) \
313quaternionType UnitLog() const \
314{ \
315 return quaternionType( \
316 vtkQuaternion<type>::UnitLog().GetData()); \
317}
318#define vtkQuaternionUnitExp(quaternionType, type) \
319quaternionType UnitExp() const \
320{ \
321 return quaternionType( \
322 vtkQuaternion<type>::UnitExp().GetData()); \
323}
324#define vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
325quaternionType NormalizedWithAngleInDegrees() const \
326{ \
327 return quaternionType( \
328 vtkQuaternion<type>::NormalizedWithAngleInDegrees().GetData()); \
329}
330#define vtkQuaternionSlerp(quaternionType, type) \
331quaternionType Slerp(type t, const quaternionType& q) const \
332{ \
333 return quaternionType( \
334 vtkQuaternion<type>::Slerp(t, q).GetData()); \
335}
336#define vtkQuaternionInnerPoint(quaternionType, type) \
337quaternionType InnerPoint(const quaternionType& q1, \
338 const quaternionType& q2) const \
339{ \
340 return quaternionType( \
341 vtkQuaternion<type>::InnerPoint(q1, q2).GetData()); \
342}
343#define vtkQuaternionOperatorPlus(quaternionType, type) \
344inline quaternionType operator+(const quaternionType& q) const \
345{ \
346 return quaternionType( ( \
347 static_cast< vtkQuaternion<type> > (*this) + \
348 static_cast< vtkQuaternion<type> > (q)).GetData()); \
349}
350#define vtkQuaternionOperatorMinus(quaternionType, type) \
351inline quaternionType operator-(const quaternionType& q) const \
352{ \
353 return quaternionType( ( \
354 static_cast< vtkQuaternion<type> > (*this) - \
355 static_cast< vtkQuaternion<type> > (q)).GetData()); \
356}
357#define vtkQuaternionOperatorMultiply(quaternionType, type) \
358inline quaternionType operator*(const quaternionType& q) const \
359{ \
360 return quaternionType( ( \
361 static_cast< vtkQuaternion<type> > (*this) * \
362 static_cast< vtkQuaternion<type> > (q)).GetData()); \
363}
364#define vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
365inline quaternionType operator*(const type& scalar) const \
366{ \
367 return quaternionType( ( \
368 static_cast< vtkQuaternion<type> > (*this) * \
369 scalar).GetData()); \
370}
371#define vtkQuaternionOperatorDivide(quaternionType, type) \
372inline quaternionType operator/(const quaternionType& q) const \
373{ \
374 return quaternionType( ( \
375 static_cast< vtkQuaternion<type> > (*this) / \
376 static_cast< vtkQuaternion<type> > (q)).GetData()); \
377}
378#define vtkQuaternionOperatorDivideScalar(quaternionType, type) \
379inline quaternionType operator/(const type& scalar) const \
380{ \
381 return quaternionType( ( \
382 static_cast< vtkQuaternion<type> > (*this) / \
383 scalar).GetData()); \
384}
385
386#define vtkQuaternionOperatorMacro(quaternionType, type) \
387vtkQuaternionIdentity(quaternionType, type) \
388vtkQuaternionNormalized(quaternionType, type) \
389vtkQuaternionConjugated(quaternionType, type) \
390vtkQuaternionInverse(quaternionType, type) \
391vtkQuaternionUnitLog(quaternionType, type) \
392vtkQuaternionUnitExp(quaternionType, type) \
393vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
394vtkQuaternionSlerp(quaternionType, type) \
395vtkQuaternionInnerPoint(quaternionType, type) \
396vtkQuaternionOperatorPlus(quaternionType, type) \
397vtkQuaternionOperatorMinus(quaternionType, type) \
398vtkQuaternionOperatorMultiply(quaternionType, type) \
399vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
400vtkQuaternionOperatorDivide(quaternionType, type) \
401vtkQuaternionOperatorDivideScalar(quaternionType, type)
402
403// .NAME vtkQuaternionf - Float quaternion type.
404//
405// .SECTION Description
406// This class is uses vtkQuaternion with float type data.
407// For futher description, see the templated class vtkQuaternion.
408// @sa vtkQuaterniond vtkQuaternion
409class vtkQuaternionf : public vtkQuaternion<float>
410{
411public:
413 explicit vtkQuaternionf(float w, float x, float y, float z)
414 : vtkQuaternion<float>(w, x, y, z) {}
415 explicit vtkQuaternionf(float scalar) : vtkQuaternion<float>(scalar) {}
416 explicit vtkQuaternionf(const float *init) : vtkQuaternion<float>(init) {}
418};
419
420// .NAME vtkQuaterniond - Double quaternion type.
421//
422// .SECTION Description
423// This class is uses vtkQuaternion with double type data.
424// For futher description, seethe templated class vtkQuaternion.
425// @sa vtkQuaternionf vtkQuaternion
426class vtkQuaterniond : public vtkQuaternion<double>
427{
428public:
430 explicit vtkQuaterniond(double w, double x, double y, double z)
431 : vtkQuaternion<double>(w, x, y, z) {}
432 explicit vtkQuaterniond(double scalar) : vtkQuaternion<double>(scalar) {}
433 explicit vtkQuaterniond(const double *init) : vtkQuaternion<double>(init) {}
435};
436
437#include "vtkQuaternion.txx"
438
439#endif // vtkQuaternion_h
440// VTK-HeaderTest-Exclude: vtkQuaternion.h
templated base type for storage of quaternions.
Definition: vtkQuaternion.h:39
static vtkQuaternion< T > Identity()
Return the identity quaternion.
void SetRotationAngleAndAxis(T angle, T axis[3])
vtkQuaternion(const T &scalar)
Initialize all of the quaternion's elements with the supplied scalar.
Definition: vtkQuaternion.h:49
void SetX(const T &x)
Set/Get the x component of the quaternion, i.e.
void Set(T quat[4])
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)
void SetW(const T &w)
Set/Get the w component of the quaternion, i.e.
const T & GetX() const
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
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)
Initalize the quaternion's elements with the elements of the supplied array.
Definition: vtkQuaternion.h:56
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
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
const T & GetW() const
vtkQuaterniond(double w, double x, double y, double z)
vtkQuaternionOperatorMacro(vtkQuaterniond, double)
vtkQuaterniond(const double *init)
vtkQuaterniond(double scalar)
vtkQuaternionf(float scalar)
vtkQuaternionf(const float *init)
vtkQuaternionf(float w, float x, float y, float z)
templated base type for containers of constant size.
Definition: vtkTuple.h:36
#define vtkQuaternionOperatorMacro(quaternionType, type)