VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 =========================================================================*/
32 #ifndef __vtkQuaternion_h
33 #define __vtkQuaternion_h
34 
35 #include "vtkTuple.h"
36 
37 template<typename T> class vtkQuaternion : public vtkTuple<T, 4>
38 {
39 public:
41  vtkQuaternion();
42 
44  explicit vtkQuaternion(const T& scalar) : vtkTuple<T, 4>(scalar) {}
45 
50  explicit vtkQuaternion(const T* init) : vtkTuple<T, 4>(init) {}
51 
53  vtkQuaternion(const T& w, const T& x, const T& y, const T& z);
54 
56  T SquaredNorm() const;
57 
59  T Norm() const;
60 
62  void ToIdentity();
63 
66  static vtkQuaternion<T> Identity();
67 
69  T Normalize();
70 
73 
75  void Conjugate();
76 
79 
82  void Invert();
83 
85  vtkQuaternion<T> Inverse() const;
86 
89  void ToUnitLog();
90 
93  vtkQuaternion<T> UnitLog() const;
94 
98  void ToUnitExp();
99 
103  vtkQuaternion<T> UnitExp() const;
104 
108 
112 
114 
115  void Set(const T& w, const T& x, const T& y, const T& z);
116  void Set(T quat[4]);
117  void Get(T quat[4]) const;
119 
121 
122  void SetW(const T& w);
123  const T& GetW() const;
125 
127 
128  void SetX(const T& x);
129  const T& GetX() const;
131 
133 
134  void SetY(const T& y);
135  const T& GetY() const;
137 
139 
140  void SetZ(const T& z);
141  const T& GetZ() const;
143 
145 
147  T GetRotationAngleAndAxis(T axis[3]) const;
148  void SetRotationAngleAndAxis(T angle, T axis[3]);
150  const T& angle, const T& x, const T& y, const T& z);
152 
154  template<typename CastTo> vtkQuaternion<CastTo> Cast() const;
155 
158  void ToMatrix3x3(T A[3][3]) const;
159 
163  void FromMatrix3x3(const T A[3][3]);
164 
169  vtkQuaternion<T> Slerp(T t, const vtkQuaternion<T>& q) const;
170 
172 
175  const vtkQuaternion<T>& q2) const;
177 
179  void operator=(const vtkQuaternion<T>& q);
180 
183 
186 
189 
191  vtkQuaternion<T> operator*(const T& scalar) const;
192 
195  void operator*=(const T& scalar) const;
196 
199 
201  vtkQuaternion<T> operator/(const T& scalar) const;
202 
204 
205  void operator/=(const T& scalar);
206 };
208 
210 
213 #define vtkQuaternionIdentity(quaternionType, type) \
214 quaternionType Identity() const \
215 { \
216  return quaternionType(vtkQuaternion<type>::Identity().GetData()); \
217 }
218 #define vtkQuaternionNormalized(quaternionType, type) \
219 quaternionType Normalized() const \
220 { \
221  return quaternionType(vtkQuaternion<type>::Normalized().GetData()); \
222 }
223 #define vtkQuaternionConjugated(quaternionType, type) \
224 quaternionType Conjugated() const \
225 { \
226  return quaternionType(vtkQuaternion<type>::Conjugated().GetData()); \
227 }
228 #define vtkQuaternionInverse(quaternionType, type) \
229 quaternionType Inverse() const \
230 { \
231  return quaternionType(vtkQuaternion<type>::Inverse().GetData()); \
232 }
233 #define vtkQuaternionUnitLog(quaternionType, type) \
234 quaternionType UnitLog() const \
235 { \
236  return quaternionType( \
237  vtkQuaternion<type>::UnitLog().GetData()); \
238 }
239 #define vtkQuaternionUnitExp(quaternionType, type) \
240 quaternionType UnitExp() const \
241 { \
242  return quaternionType( \
243  vtkQuaternion<type>::UnitExp().GetData()); \
244 }
245 #define vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
246 quaternionType NormalizedWithAngleInDegrees() const \
247 { \
248  return quaternionType( \
249  vtkQuaternion<type>::NormalizedWithAngleInDegrees().GetData()); \
250 }
251 #define vtkQuaternionSlerp(quaternionType, type) \
252 quaternionType Slerp(type t, const quaternionType& q) const \
253 { \
254  return quaternionType( \
255  vtkQuaternion<type>::Slerp(t, q).GetData()); \
256 }
257 #define vtkQuaternionInnerPoint(quaternionType, type) \
258 quaternionType InnerPoint(const quaternionType& q1, \
259  const quaternionType& q2) const \
260 { \
261  return quaternionType( \
262  vtkQuaternion<type>::InnerPoint(q1, q2).GetData()); \
263 }
264 #define vtkQuaternionOperatorPlus(quaternionType, type) \
265 inline quaternionType operator+(const quaternionType& q) const \
266 { \
267  return quaternionType( ( \
268  static_cast< vtkQuaternion<type> > (*this) + \
269  static_cast< vtkQuaternion<type> > (q)).GetData()); \
270 }
271 #define vtkQuaternionOperatorMinus(quaternionType, type) \
272 inline quaternionType operator-(const quaternionType& q) const \
273 { \
274  return quaternionType( ( \
275  static_cast< vtkQuaternion<type> > (*this) - \
276  static_cast< vtkQuaternion<type> > (q)).GetData()); \
277 }
278 #define vtkQuaternionOperatorMultiply(quaternionType, type) \
279 inline quaternionType operator*(const quaternionType& q) const \
280 { \
281  return quaternionType( ( \
282  static_cast< vtkQuaternion<type> > (*this) * \
283  static_cast< vtkQuaternion<type> > (q)).GetData()); \
284 }
285 #define vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
286 inline quaternionType operator*(const type& scalar) const \
287 { \
288  return quaternionType( ( \
289  static_cast< vtkQuaternion<type> > (*this) * \
290  scalar).GetData()); \
291 }
292 #define vtkQuaternionOperatorDivide(quaternionType, type) \
293 inline quaternionType operator/(const quaternionType& q) const \
294 { \
295  return quaternionType( ( \
296  static_cast< vtkQuaternion<type> > (*this) / \
297  static_cast< vtkQuaternion<type> > (q)).GetData()); \
298 }
299 #define vtkQuaternionOperatorDivideScalar(quaternionType, type) \
300 inline quaternionType operator/(const type& scalar) const \
301 { \
302  return quaternionType( ( \
303  static_cast< vtkQuaternion<type> > (*this) / \
304  scalar).GetData()); \
305 }
306 
307 
308 #define vtkQuaternionOperatorMacro(quaternionType, type) \
309 vtkQuaternionIdentity(quaternionType, type) \
310 vtkQuaternionNormalized(quaternionType, type) \
311 vtkQuaternionConjugated(quaternionType, type) \
312 vtkQuaternionInverse(quaternionType, type) \
313 vtkQuaternionUnitLog(quaternionType, type) \
314 vtkQuaternionUnitExp(quaternionType, type) \
315 vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
316 vtkQuaternionSlerp(quaternionType, type) \
317 vtkQuaternionInnerPoint(quaternionType, type) \
318 vtkQuaternionOperatorPlus(quaternionType, type) \
319 vtkQuaternionOperatorMinus(quaternionType, type) \
320 vtkQuaternionOperatorMultiply(quaternionType, type) \
321 vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
322 vtkQuaternionOperatorDivide(quaternionType, type) \
323 vtkQuaternionOperatorDivideScalar(quaternionType, type)
324 
325 // .NAME vtkQuaternionf - Float quaternion type.
326 //
327 // .SECTION Description
328 // This class is uses vtkQuaternion with float type data.
329 // For futher description, see the templated class vtkQuaternion.
330 // @sa vtkQuaterniond vtkQuaternion
331 class vtkQuaternionf : public vtkQuaternion<float>
332 {
333 public:
335  explicit vtkQuaternionf(float w, float x, float y, float z)
336  : vtkQuaternion<float>(w, x, y, z) {}
337  explicit vtkQuaternionf(float scalar) : vtkQuaternion<float>(scalar) {}
338  explicit vtkQuaternionf(const float *init) : vtkQuaternion<float>(init) {}
340 };
341 
342 // .NAME vtkQuaterniond - Double quaternion type.
343 //
344 // .SECTION Description
345 // This class is uses vtkQuaternion with double type data.
346 // For futher description, seethe templated class vtkQuaternion.
347 // @sa vtkQuaternionf vtkQuaternion
348 class vtkQuaterniond : public vtkQuaternion<double>
349 {
350 public:
352  explicit vtkQuaterniond(double w, double x, double y, double z)
353  : vtkQuaternion<double>(w, x, y, z) {}
354  explicit vtkQuaterniond(double scalar) : vtkQuaternion<double>(scalar) {}
355  explicit vtkQuaterniond(const double *init) : vtkQuaternion<double>(init) {}
357 };
358 
359 #include "vtkQuaternion.txx"
360 
361 #endif // __vtkQuaternion_h
362 // VTK-HeaderTest-Exclude: vtkQuaternion.h
vtkQuaternion< T > UnitLog() const
vtkQuaternionf(float scalar)
void SetZ(const T &z)
void ToMatrix3x3(T A[3][3]) const
vtkQuaternion< T > operator/(const vtkQuaternion< T > &q) const
const T & GetZ() const
vtkQuaterniond(double w, double x, double y, double z)
T SquaredNorm() const
void NormalizeWithAngleInDegrees()
void operator/=(const T &scalar)
vtkQuaternion< T > operator-(const vtkQuaternion< T > &q) const
vtkQuaternion< T > Normalized() const
vtkQuaternion< T > NormalizedWithAngleInDegrees() const
templated base type for storage of quaternions.
Definition: vtkQuaternion.h:37
vtkQuaternion< T > UnitExp() const
void SetRotationAngleAndAxis(T angle, T axis[3])
T GetRotationAngleAndAxis(T axis[3]) const
vtkQuaterniond(double scalar)
void Get(T quat[4]) const
vtkQuaternionOperatorMacro(vtkQuaterniond, double)
const T & GetY() const
void SetY(const T &y)
vtkQuaternion< T > Slerp(T t, const vtkQuaternion< T > &q) const
void Conjugate()
vtkQuaternion(const T *init)
Definition: vtkQuaternion.h:50
vtkQuaternionf(const float *init)
templated base type for containers of constant size.
Definition: vtkTuple.h:34
void FromMatrix3x3(const T A[3][3])
vtkQuaternion< CastTo > Cast() const
const T & GetW() const
const T & GetX() const
vtkQuaternion< T > InnerPoint(const vtkQuaternion< T > &q1, const vtkQuaternion< T > &q2) const
vtkQuaternionf(float w, float x, float y, float z)
void ToUnitExp()
void SetW(const T &w)
vtkQuaternion< T > operator+(const vtkQuaternion< T > &q) const
vtkQuaternion< T > Inverse() const
void operator=(const vtkQuaternion< T > &q)
#define vtkQuaternionOperatorMacro(quaternionType, type)
vtkQuaterniond(const double *init)
vtkQuaternion(const T &scalar)
Definition: vtkQuaternion.h:44
void ToIdentity()
void Set(const T &w, const T &x, const T &y, const T &z)
void ToUnitLog()
T Norm() const
void operator*=(const T &scalar) const
void SetX(const T &x)
vtkQuaternion< T > operator*(const vtkQuaternion< T > &q) const
static vtkQuaternion< T > Identity()
vtkQuaternion< T > Conjugated() const