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 =========================================================================*/
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 
180 
183 
186 
188  vtkQuaternion<T> operator*(const T& scalar) const;
189 
192  void operator*=(const T& scalar) const;
193 
196 
198  vtkQuaternion<T> operator/(const T& scalar) const;
199 
201 
202  void operator/=(const T& scalar);
203 };
205 
207 
210 #define vtkQuaternionIdentity(quaternionType, type) \
211 quaternionType Identity() const \
212 { \
213  return quaternionType(vtkQuaternion<type>::Identity().GetData()); \
214 }
215 #define vtkQuaternionNormalized(quaternionType, type) \
216 quaternionType Normalized() const \
217 { \
218  return quaternionType(vtkQuaternion<type>::Normalized().GetData()); \
219 }
220 #define vtkQuaternionConjugated(quaternionType, type) \
221 quaternionType Conjugated() const \
222 { \
223  return quaternionType(vtkQuaternion<type>::Conjugated().GetData()); \
224 }
225 #define vtkQuaternionInverse(quaternionType, type) \
226 quaternionType Inverse() const \
227 { \
228  return quaternionType(vtkQuaternion<type>::Inverse().GetData()); \
229 }
230 #define vtkQuaternionUnitLog(quaternionType, type) \
231 quaternionType UnitLog() const \
232 { \
233  return quaternionType( \
234  vtkQuaternion<type>::UnitLog().GetData()); \
235 }
236 #define vtkQuaternionUnitExp(quaternionType, type) \
237 quaternionType UnitExp() const \
238 { \
239  return quaternionType( \
240  vtkQuaternion<type>::UnitExp().GetData()); \
241 }
242 #define vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
243 quaternionType NormalizedWithAngleInDegrees() const \
244 { \
245  return quaternionType( \
246  vtkQuaternion<type>::NormalizedWithAngleInDegrees().GetData()); \
247 }
248 #define vtkQuaternionSlerp(quaternionType, type) \
249 quaternionType Slerp(type t, const quaternionType& q) const \
250 { \
251  return quaternionType( \
252  vtkQuaternion<type>::Slerp(t, q).GetData()); \
253 }
254 #define vtkQuaternionInnerPoint(quaternionType, type) \
255 quaternionType InnerPoint(const quaternionType& q1, \
256  const quaternionType& q2) const \
257 { \
258  return quaternionType( \
259  vtkQuaternion<type>::InnerPoint(q1, q2).GetData()); \
260 }
261 #define vtkQuaternionOperatorPlus(quaternionType, type) \
262 inline quaternionType operator+(const quaternionType& q) const \
263 { \
264  return quaternionType( ( \
265  static_cast< vtkQuaternion<type> > (*this) + \
266  static_cast< vtkQuaternion<type> > (q)).GetData()); \
267 }
268 #define vtkQuaternionOperatorMinus(quaternionType, type) \
269 inline quaternionType operator-(const quaternionType& q) const \
270 { \
271  return quaternionType( ( \
272  static_cast< vtkQuaternion<type> > (*this) - \
273  static_cast< vtkQuaternion<type> > (q)).GetData()); \
274 }
275 #define vtkQuaternionOperatorMultiply(quaternionType, type) \
276 inline quaternionType operator*(const quaternionType& q) const \
277 { \
278  return quaternionType( ( \
279  static_cast< vtkQuaternion<type> > (*this) * \
280  static_cast< vtkQuaternion<type> > (q)).GetData()); \
281 }
282 #define vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
283 inline quaternionType operator*(const type& scalar) const \
284 { \
285  return quaternionType( ( \
286  static_cast< vtkQuaternion<type> > (*this) * \
287  scalar).GetData()); \
288 }
289 #define vtkQuaternionOperatorDivide(quaternionType, type) \
290 inline quaternionType operator/(const quaternionType& q) const \
291 { \
292  return quaternionType( ( \
293  static_cast< vtkQuaternion<type> > (*this) / \
294  static_cast< vtkQuaternion<type> > (q)).GetData()); \
295 }
296 #define vtkQuaternionOperatorDivideScalar(quaternionType, type) \
297 inline quaternionType operator/(const type& scalar) const \
298 { \
299  return quaternionType( ( \
300  static_cast< vtkQuaternion<type> > (*this) / \
301  scalar).GetData()); \
302 }
303 
304 
305 #define vtkQuaternionOperatorMacro(quaternionType, type) \
306 vtkQuaternionIdentity(quaternionType, type) \
307 vtkQuaternionNormalized(quaternionType, type) \
308 vtkQuaternionConjugated(quaternionType, type) \
309 vtkQuaternionInverse(quaternionType, type) \
310 vtkQuaternionUnitLog(quaternionType, type) \
311 vtkQuaternionUnitExp(quaternionType, type) \
312 vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
313 vtkQuaternionSlerp(quaternionType, type) \
314 vtkQuaternionInnerPoint(quaternionType, type) \
315 vtkQuaternionOperatorPlus(quaternionType, type) \
316 vtkQuaternionOperatorMinus(quaternionType, type) \
317 vtkQuaternionOperatorMultiply(quaternionType, type) \
318 vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
319 vtkQuaternionOperatorDivide(quaternionType, type) \
320 vtkQuaternionOperatorDivideScalar(quaternionType, type)
321 
322 // .NAME vtkQuaternionf - Float quaternion type.
323 //
324 // .SECTION Description
325 // This class is uses vtkQuaternion with float type data.
326 // For futher description, see the templated class vtkQuaternion.
327 // @sa vtkQuaterniond vtkQuaternion
328 class vtkQuaternionf : public vtkQuaternion<float>
329 {
330 public:
332  explicit vtkQuaternionf(float w, float x, float y, float z)
333  : vtkQuaternion<float>(w, x, y, z) {}
334  explicit vtkQuaternionf(float scalar) : vtkQuaternion<float>(scalar) {}
335  explicit vtkQuaternionf(const float *init) : vtkQuaternion<float>(init) {}
337 };
338 
339 // .NAME vtkQuaterniond - Double quaternion type.
340 //
341 // .SECTION Description
342 // This class is uses vtkQuaternion with double type data.
343 // For futher description, seethe templated class vtkQuaternion.
344 // @sa vtkQuaternionf vtkQuaternion
345 class vtkQuaterniond : public vtkQuaternion<double>
346 {
347 public:
349  explicit vtkQuaterniond(double w, double x, double y, double z)
350  : vtkQuaternion<double>(w, x, y, z) {}
351  explicit vtkQuaterniond(double scalar) : vtkQuaternion<double>(scalar) {}
352  explicit vtkQuaterniond(const double *init) : vtkQuaternion<double>(init) {}
354 };
355 
356 #include "vtkQuaternion.txx"
357 
358 #endif // vtkQuaternion_h
359 // 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
#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)
VTKWRAPPINGJAVA_EXPORT jlong q(JNIEnv *env, jobject obj)
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