HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_DualQuaternion.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_DualQuaternion library (C++)
7  *
8  * COMMENTS: This class implements dual quaternions.
9  *
10  *
11  */
12 
13 
14 #ifndef __UT_DualQuaternion_h__
15 #define __UT_DualQuaternion_h__
16 
17 #include "UT_Quaternion.h"
18 #include "UT_API.h"
19 #include <stdio.h>
20 
21 ///
22 /// Dual quaternion class
23 ///
24 template <typename T>
26 {
27 public:
29  /// Constructs from real and dual part
30  UT_DualQuaternionT(const UT_QuaternionT<T> &real, const UT_QuaternionT<T> &dual);
31 
32  /// Constructs from components in real and dual part
33  UT_DualQuaternionT(T real_qx, T real_qy, T real_qz, T real_qw,
34  T dual_qx, T dual_qy, T dual_qz, T dual_qw);
35 
36  /// Constructs from rotation quaternion and translation vector
38 
39  /// Constructs from a transform matrix
40  UT_DualQuaternionT(const UT_Matrix4 &xform);
41 
42  /// Copy constructor
44 
45  void updateFromXform(const UT_Matrix4T<T> &xform);
46  void updateFromXform(const UT_Matrix3T<T> &xform);
47 
48  void updateFromRotTransPair(const UT_QuaternionT<T> &r,
49  const UT_Vector3T<T> &t);
50  void updateFromRotTransPair(const UT_QuaternionT<T> &r,
51  T tx,
52  T ty,
53  T tz);
54 
55  /////////////////////////////////
56  /// Methods
57  /////////////////////////////////
58 
59  // Normalizes the dual quaternion to have length of 1
60  void normalize();
61 
62  // Changes quaternion into its conjugate
63  void conjugate();
64 
65  // Change quaternion into an 0 rotation and 0 translation components
66  void identity();
67 
68  // Returns a vector that is transformed by the dual quaternion
69  // Requires this is normalized
70  void transform(const UT_Vector3T<T> &vec, UT_Vector3T<T> &dst) const;
71 
72  // Returns a vector that has only the rotation component applied
73  // Requires this is normalized
74  void rotate(const UT_Vector3T<T> &vec, UT_Vector3T<T> &dst) const;
75 
76  // Returns a xform that is represented by the dual quaternion
77  // Requires this is normalized
78  UT_Matrix4 convertToXform() const;
79 
80 
81  //////////////////////////////////////
82  /// Operators
83  //////////////////////////////////////
84 
85  inline UT_DualQuaternionT &operator+=(const UT_DualQuaternionT &dq);
86  inline UT_DualQuaternionT &operator*=(T scalar);
88  inline UT_DualQuaternionT &operator-=(const UT_DualQuaternionT &dq);
89  inline bool operator==(const UT_DualQuaternionT &dq) const;
90  inline bool operator!=(const UT_DualQuaternionT &dq) const;
91  // todo: hash
92 
93  friend std::ostream &operator<<(std::ostream &os, const UT_DualQuaternionT<T> &dq)
94  {
95  dq.outTo(os);
96  return os;
97  }
98 
99  //////////////////////////////////
100  /// Getters
101  //////////////////////////////////
102 
103  const T *realData() const;
104  const T *dualData() const;
105  const UT_QuaternionT<T> &getReal() const;
106  const UT_QuaternionT<T> &getDual() const;
107  const UT_QuaternionT<T> &getTranslation() const;
108  const UT_QuaternionT<T> &getRotation() const;
109 
110 protected:
111  void outTo(std::ostream &os) const;
112 
113 private:
114 
115  /// Real or non-dual part of the dual quaternion.
116  /// It represents the rotation component of an xform
117  UT_QuaternionT<T> myReal;
118 
119  /// Dual part of the dual quaternion.
120  /// It represents the translation components
121  UT_QuaternionT<T> myDual;
122 
123 };
124 
125 
126 ///////////////////////////////////////
127 /// Operator implementations
128 ///////////////////////////////////////
129 
130 template <typename T>
131 inline UT_DualQuaternionT<T> &
133 {
134  myDual += dq.getDual();
135  myReal += dq.getReal();
136  return (*this);
137 }
138 
139 template <typename T>
140 inline UT_DualQuaternionT<T> &
142 {
143  myDual *= scalar;
144  myReal *= scalar;
145  return (*this);
146 }
147 
148 template <typename T>
149 inline UT_DualQuaternionT<T> &
151 {
152  myDual = myReal * dq.getDual() + myDual * dq.getReal();
153  myReal *= dq.getReal();
154  return (*this);
155 }
156 
157 template <typename T>
158 inline UT_DualQuaternionT<T> &
160 {
161  myDual = myDual - dq.getDual();
162  myReal = myReal - dq.getReal();
163  return (*this);
164 }
165 
166 template <typename T>
167 inline bool
169 {
170  return ( myDual == dq.getDual() ) &&
171  ( myReal == dq.getReal() );
172 }
173 
174 template <typename T>
175 inline bool
177 {
178  return ( myDual != dq.getDual() ) ||
179  ( myReal != dq.getReal() );
180 }
181 
182 
183 
184 //////////////////////////////////
185 /// typedefs
186 //////////////////////////////////
187 
192 
193 
194 #endif
UT_DualQuaternionT< fpreal32 > UT_DualQuaternion
typedefs
const UT_QuaternionT< T > & getDual() const
#define UT_API
Definition: UT_API.h:12
3D Vector class.
UT_DualQuaternionT & operator*=(T scalar)
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
UT_DualQuaternionT< fpreal64 > UT_DualQuaternionD
UT_DualQuaternionT< fpreal > UT_DualQuaternionR
UT_DualQuaternionT & operator-=(const UT_DualQuaternionT &dq)
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
const Vec2< S > & operator*=(Vec2< S > &v, const Matrix33< T > &m)
Definition: ImathMatrix.h:3330
GA_API const UT_StringHolder transform
bool operator!=(const UT_DualQuaternionT &dq) const
UT_DualQuaternionT< fpreal32 > UT_DualQuaternionF
bool operator==(const UT_DualQuaternionT &dq) const
GLenum GLenum dst
Definition: glcorearb.h:1792
Quaternion class.
Definition: UT_Quaternion.h:44
const UT_QuaternionT< T > & getReal() const
GLboolean r
Definition: glcorearb.h:1221
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
UT_DualQuaternionT & operator+=(const UT_DualQuaternionT &dq)
Operators.
void outTo(std::ostream &os) const