VTK
dox/Common/Math/vtkQuaternion.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkQuaternion.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00032 #ifndef __vtkQuaternion_h
00033 #define __vtkQuaternion_h
00034 
00035 #include "vtkTuple.h"
00036 
00037 template<typename T> class vtkQuaternion : public vtkTuple<T, 4>
00038 {
00039 public:
00041   vtkQuaternion();
00042 
00044   explicit vtkQuaternion(const T& scalar) : vtkTuple<T, 4>(scalar) {}
00045 
00050   explicit vtkQuaternion(const T* init) : vtkTuple<T, 4>(init) {}
00051 
00053   vtkQuaternion(const T& w, const T& x, const T& y, const T& z);
00054 
00056   T SquaredNorm() const;
00057 
00059   T Norm() const;
00060 
00062   void ToIdentity();
00063 
00066   static vtkQuaternion<T> Identity();
00067 
00069   T Normalize();
00070 
00072   vtkQuaternion<T> Normalized() const;
00073 
00075   void Conjugate();
00076 
00078   vtkQuaternion<T> Conjugated() const;
00079 
00082   void Invert();
00083 
00085   vtkQuaternion<T> Inverse() const;
00086 
00089   void ToUnitLog();
00090 
00093   vtkQuaternion<T> UnitLog() const;
00094 
00098   void ToUnitExp();
00099 
00103   vtkQuaternion<T> UnitExp() const;
00104 
00107   void NormalizeWithAngleInDegrees();
00108 
00111   vtkQuaternion<T> NormalizedWithAngleInDegrees() const;
00112 
00114 
00115   void Set(const T& w, const T& x, const T& y, const T& z);
00116   void Set(T quat[4]);
00117   void Get(T quat[4]) const;
00119 
00121 
00122   void SetW(const T& w);
00123   const T& GetW() const;
00125 
00127 
00128   void SetX(const T& x);
00129   const T& GetX() const;
00131 
00133 
00134   void SetY(const T& y);
00135   const T& GetY() const;
00137 
00139 
00140   void SetZ(const T& z);
00141   const T& GetZ() const;
00143 
00145 
00147   T GetRotationAngleAndAxis(T axis[3]) const;
00148   void SetRotationAngleAndAxis(T angle, T axis[3]);
00149   void SetRotationAngleAndAxis(
00150     const T& angle, const T& x, const T& y, const T& z);
00152 
00154   template<typename CastTo> vtkQuaternion<CastTo> Cast() const;
00155 
00158   void ToMatrix3x3(T A[3][3]) const;
00159 
00163   void FromMatrix3x3(const T A[3][3]);
00164 
00169   vtkQuaternion<T> Slerp(T t, const vtkQuaternion<T>& q) const;
00170 
00172 
00174   vtkQuaternion<T> InnerPoint(const vtkQuaternion<T>& q1,
00175     const vtkQuaternion<T>& q2) const;
00177 
00179   vtkQuaternion<T> operator+(const vtkQuaternion<T>& q) const;
00180 
00182   vtkQuaternion<T> operator-(const vtkQuaternion<T>& q) const;
00183 
00185   vtkQuaternion<T> operator*(const vtkQuaternion<T>& q) const;
00186 
00188   vtkQuaternion<T> operator*(const T& scalar) const;
00189 
00192   void operator*=(const T& scalar) const;
00193 
00195   vtkQuaternion<T> operator/(const vtkQuaternion<T>& q) const;
00196 
00198   vtkQuaternion<T> operator/(const T& scalar) const;
00199 
00201 
00202   void operator/=(const T& scalar);
00203 };
00205 
00207 
00210 #define vtkQuaternionIdentity(quaternionType, type) \
00211 quaternionType Identity() const \
00212 { \
00213   return quaternionType(vtkQuaternion<type>::Identity().GetData()); \
00214 }
00215 #define vtkQuaternionNormalized(quaternionType, type) \
00216 quaternionType Normalized() const \
00217 { \
00218   return quaternionType(vtkQuaternion<type>::Normalized().GetData()); \
00219 }
00220 #define vtkQuaternionConjugated(quaternionType, type) \
00221 quaternionType Conjugated() const \
00222 { \
00223   return quaternionType(vtkQuaternion<type>::Conjugated().GetData()); \
00224 }
00225 #define vtkQuaternionInverse(quaternionType, type) \
00226 quaternionType Inverse() const \
00227 { \
00228   return quaternionType(vtkQuaternion<type>::Inverse().GetData()); \
00229 }
00230 #define vtkQuaternionUnitLog(quaternionType, type) \
00231 quaternionType UnitLog() const \
00232 { \
00233   return quaternionType( \
00234     vtkQuaternion<type>::UnitLog().GetData()); \
00235 }
00236 #define vtkQuaternionUnitExp(quaternionType, type) \
00237 quaternionType UnitExp() const \
00238 { \
00239   return quaternionType( \
00240     vtkQuaternion<type>::UnitExp().GetData()); \
00241 }
00242 #define vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
00243 quaternionType NormalizedWithAngleInDegrees() const \
00244 { \
00245   return quaternionType( \
00246     vtkQuaternion<type>::NormalizedWithAngleInDegrees().GetData()); \
00247 }
00248 #define vtkQuaternionSlerp(quaternionType, type) \
00249 quaternionType Slerp(type t, const quaternionType& q) const \
00250 { \
00251   return quaternionType( \
00252     vtkQuaternion<type>::Slerp(t, q).GetData()); \
00253 }
00254 #define vtkQuaternionInnerPoint(quaternionType, type) \
00255 quaternionType InnerPoint(const quaternionType& q1, \
00256                           const quaternionType& q2) const \
00257 { \
00258   return quaternionType( \
00259     vtkQuaternion<type>::InnerPoint(q1, q2).GetData()); \
00260 }
00261 #define vtkQuaternionOperatorPlus(quaternionType, type) \
00262 inline quaternionType operator+(const quaternionType& q) const \
00263 { \
00264   return quaternionType( ( \
00265     static_cast< vtkQuaternion<type> > (*this) + \
00266     static_cast< vtkQuaternion<type> > (q)).GetData()); \
00267 }
00268 #define vtkQuaternionOperatorMinus(quaternionType, type) \
00269 inline quaternionType operator-(const quaternionType& q) const \
00270 { \
00271   return quaternionType( ( \
00272     static_cast< vtkQuaternion<type> > (*this) - \
00273     static_cast< vtkQuaternion<type> > (q)).GetData()); \
00274 }
00275 #define vtkQuaternionOperatorMultiply(quaternionType, type) \
00276 inline quaternionType operator*(const quaternionType& q) const \
00277 { \
00278   return quaternionType( ( \
00279     static_cast< vtkQuaternion<type> > (*this) * \
00280     static_cast< vtkQuaternion<type> > (q)).GetData()); \
00281 }
00282 #define vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
00283 inline quaternionType operator*(const type& scalar) const \
00284 { \
00285   return quaternionType( ( \
00286     static_cast< vtkQuaternion<type> > (*this) * \
00287     scalar).GetData()); \
00288 }
00289 #define vtkQuaternionOperatorDivide(quaternionType, type) \
00290 inline quaternionType operator/(const quaternionType& q) const \
00291 { \
00292   return quaternionType( ( \
00293     static_cast< vtkQuaternion<type> > (*this) / \
00294     static_cast< vtkQuaternion<type> > (q)).GetData()); \
00295 }
00296 #define vtkQuaternionOperatorDivideScalar(quaternionType, type) \
00297 inline quaternionType operator/(const type& scalar) const \
00298 { \
00299   return quaternionType( ( \
00300     static_cast< vtkQuaternion<type> > (*this) / \
00301     scalar).GetData()); \
00302 }
00303 
00304 
00305 #define vtkQuaternionOperatorMacro(quaternionType, type) \
00306 vtkQuaternionIdentity(quaternionType, type) \
00307 vtkQuaternionNormalized(quaternionType, type) \
00308 vtkQuaternionConjugated(quaternionType, type) \
00309 vtkQuaternionInverse(quaternionType, type) \
00310 vtkQuaternionUnitLog(quaternionType, type) \
00311 vtkQuaternionUnitExp(quaternionType, type) \
00312 vtkQuaternionNormalizedWithAngleInDegrees(quaternionType, type) \
00313 vtkQuaternionSlerp(quaternionType, type) \
00314 vtkQuaternionInnerPoint(quaternionType, type) \
00315 vtkQuaternionOperatorPlus(quaternionType, type) \
00316 vtkQuaternionOperatorMinus(quaternionType, type) \
00317 vtkQuaternionOperatorMultiply(quaternionType, type) \
00318 vtkQuaternionOperatorMultiplyScalar(quaternionType, type) \
00319 vtkQuaternionOperatorDivide(quaternionType, type) \
00320 vtkQuaternionOperatorDivideScalar(quaternionType, type)
00321 
00322 // .NAME vtkQuaternionf - Float quaternion type.
00323 //
00324 // .SECTION Description
00325 // This class is uses vtkQuaternion with float type data.
00326 // For futher description, see the templated class vtkQuaternion.
00327 // @sa vtkQuaterniond vtkQuaternion
00328 class vtkQuaternionf : public vtkQuaternion<float>
00329 {
00330 public:
00331   vtkQuaternionf() {}
00332   explicit vtkQuaternionf(float w, float x, float y, float z)
00333     : vtkQuaternion<float>(w, x, y, z) {}
00334   explicit vtkQuaternionf(float scalar) : vtkQuaternion<float>(scalar) {}
00335   explicit vtkQuaternionf(const float *init) : vtkQuaternion<float>(init) {}
00336   vtkQuaternionOperatorMacro(vtkQuaternionf, float)
00337 };
00338 
00339 // .NAME vtkQuaterniond - Double quaternion type.
00340 //
00341 // .SECTION Description
00342 // This class is uses vtkQuaternion with double type data.
00343 // For futher description, seethe templated class vtkQuaternion.
00344 // @sa vtkQuaternionf vtkQuaternion
00345 class vtkQuaterniond : public vtkQuaternion<double>
00346 {
00347 public:
00348   vtkQuaterniond() {}
00349   explicit vtkQuaterniond(double w, double x, double y, double z)
00350     : vtkQuaternion<double>(w, x, y, z) {}
00351   explicit vtkQuaterniond(double scalar) : vtkQuaternion<double>(scalar) {}
00352   explicit vtkQuaterniond(const double *init) : vtkQuaternion<double>(init) {}
00353   vtkQuaternionOperatorMacro(vtkQuaterniond, double);
00354 };
00355 
00356 #include "vtkQuaternion.txx"
00357 
00358 #endif // __vtkQuaternion_h
00359 // VTK-HeaderTest-Exclude: vtkQuaternion.h