HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dualQuatd.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 ////////////////////////////////////////////////////////////////////////
8 // This file is generated by a script. Do not edit directly. Edit the
9 // dualQuat.template.h file to make changes.
10 
11 #ifndef PXR_BASE_GF_DUALQUATD_H
12 #define PXR_BASE_GF_DUALQUATD_H
13 
14 /// \file gf/dualQuatd.h
15 /// \ingroup group_gf_LinearAlgebra
16 
17 #include "pxr/pxr.h"
18 #include "pxr/base/gf/api.h"
19 #include "pxr/base/gf/declare.h"
20 #include "pxr/base/gf/traits.h"
21 
22 #include "pxr/base/gf/quatd.h"
23 #include "pxr/base/tf/hash.h"
24 
25 #include <iosfwd>
26 
28 
29 template <>
30 struct GfIsGfDualQuat<class GfDualQuatd> { static const bool value = true; };
31 
32 /// Return the dot (inner) product of two dual quaternions.
33 double GfDot(const GfDualQuatd& dq1, const GfDualQuatd& dq2);
34 
35 
36 /// \class GfDualQuatd
37 /// \ingroup group_gf_LinearAlgebra
38 ///
39 /// Basic type: a real part quaternion and a dual part quaternion.
40 ///
41 /// This class represents a generalized dual quaternion that has a real part
42 /// and a dual part quaternions. Dual quaternions are used to represent a
43 /// combination of rotation and translation.
44 ///
45 /// References:
46 /// https://www.cs.utah.edu/~ladislav/kavan06dual/kavan06dual.pdf
47 /// https://faculty.sites.iastate.edu/jia/files/inline-files/dual-quaternion.pdf
48 ///
49 class GfDualQuatd final
50 {
51  public:
52  typedef double ScalarType;
53 
54  /// The default constructor leaves the dual quaternion undefined.
56 
57  /// Initialize the real part to \p realVal and the imaginary part
58  /// to zero quaternion.
59  ///
60  /// Since quaternions typically must be normalized, reasonable values for
61  /// \p realVal are -1, 0, or 1. Other values are legal but are likely to
62  /// be meaningless.
63  ///
64  explicit GfDualQuatd( double realVal ) : _real( realVal ), _dual( 0 ) {}
65 
66  /// Initialize the real part to \p real quaternion and the imaginary part
67  /// to zero quaternion.
68  ///
69  explicit GfDualQuatd( const GfQuatd &real )
70  : _real( real ), _dual( 0 ) {
71  }
72 
73  /// This constructor initializes the real and dual parts.
74  GfDualQuatd( const GfQuatd &real, const GfQuatd &dual )
75  : _real( real ), _dual( dual ) {
76  }
77 
78  /// This constructor initializes from a rotation and a translation components.
79  GfDualQuatd( const GfQuatd &rotation, const GfVec3d &translation )
80  : _real( rotation ) {
81  SetTranslation( translation );
82  }
83 
84  /// Implicitly convert from GfDualQuatf.
85  GF_API
86  GfDualQuatd(const GfDualQuatf &other);
87  /// Implicitly convert from GfDualQuath.
88  GF_API
89  GfDualQuatd(const GfDualQuath &other);
90 
91  /// Sets the real part of the dual quaternion.
92  void SetReal(const GfQuatd &real) {
93  _real = real;
94  }
95 
96  /// Sets the dual part of the dual quaternion.
97  void SetDual(const GfQuatd &dual) {
98  _dual = dual;
99  }
100 
101  /// Returns the real part of the dual quaternion.
102  const GfQuatd &GetReal() const {
103  return _real;
104  }
105 
106  /// Returns the dual part of the dual quaternion.
107  const GfQuatd &GetDual() const {
108  return _dual;
109  }
110 
111  /// Returns the zero dual quaternion, which has a real part of (0,0,0,0) and
112  /// a dual part of (0,0,0,0).
113  static GfDualQuatd GetZero() {
115  }
116 
117  /// Returns the identity dual quaternion, which has a real part of (1,0,0,0) and
118  /// a dual part of (0,0,0,0).
121  }
122 
123  /// Returns geometric length of this dual quaternion.
124  GF_API
125  std::pair<double, double> GetLength() const;
126 
127  /// Returns a normalized (unit-length) version of this dual quaternion.
128  /// If the length of this dual quaternion is smaller than \p
129  /// eps, this returns the identity dual quaternion.
130  GF_API
131  GfDualQuatd GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const;
132 
133  /// Normalizes this dual quaternion in place.
134  /// Normalizes this dual quaternion in place to unit length, returning the
135  /// length before normalization. If the length of this dual quaternion is
136  /// smaller than \p eps, this sets the dual quaternion to identity.
137  GF_API
138  std::pair<double, double> Normalize(double eps = GF_MIN_VECTOR_LENGTH);
139 
140  /// Returns the conjugate of this dual quaternion.
141  GF_API
142  GfDualQuatd GetConjugate() const;
143 
144  /// Returns the inverse of this dual quaternion.
145  GF_API
146  GfDualQuatd GetInverse() const;
147 
148  /// Set the translation component of this dual quaternion.
149  GF_API
150  void SetTranslation( const GfVec3d &translation );
151 
152  /// Get the translation component of this dual quaternion.
153  GF_API
154  GfVec3d GetTranslation() const;
155 
156  /// Hash.
157  friend inline size_t hash_value(const GfDualQuatd &dq) {
158  return TfHash::Combine(dq.GetReal(), dq.GetDual());
159  }
160 
161  /// Component-wise dual quaternion equality test. The real and dual parts
162  /// must match exactly for dual quaternions to be considered equal.
163  bool operator ==(const GfDualQuatd &dq) const {
164  return (GetReal() == dq.GetReal() &&
165  GetDual() == dq.GetDual());
166  }
167 
168  /// Component-wise dual quaternion inequality test. The real and dual
169  /// parts must match exactly for dual quaternions to be considered equal.
170  bool operator !=(const GfDualQuatd &dq) const {
171  return ! (*this == dq);
172  }
173 
174  /// Component-wise unary sum operator.
176  _real += dq._real;
177  _dual += dq._dual;
178  return *this;
179  }
180 
181  /// Component-wise unary difference operator.
183  _real -= dq._real;
184  _dual -= dq._dual;
185  return *this;
186  }
187 
188  /// Post-multiplies dual quaternion \p dq into this dual quaternion.
189  GF_API
190  GfDualQuatd &operator *=(const GfDualQuatd &dq);
191 
192  /// Scales this dual quaternion by \p s.
194  _real *= s;
195  _dual *= s;
196  return *this;
197  }
198 
199  /// Scales this dual quaternion by 1 / \p s.
201  return (*this) *= 1.0 / s;
202  }
203 
204  /// Component-wise binary sum operator.
205  friend GfDualQuatd operator +(const GfDualQuatd &dq1,
206  const GfDualQuatd &dq2) {
207  GfDualQuatd dqt = dq1;
208  return dqt += dq2;
209  }
210 
211  /// Component-wise binary difference operator.
212  friend GfDualQuatd operator -(const GfDualQuatd &dq1,
213  const GfDualQuatd &dq2) {
214  GfDualQuatd dqt = dq1;
215  return dqt -= dq2;
216  }
217 
218  /// Returns the product of dual quaternions \p dq1 and \p dq2.
219  friend GfDualQuatd operator *(const GfDualQuatd &dq1,
220  const GfDualQuatd &dq2) {
221  GfDualQuatd dqt = dq1;
222  return dqt *= dq2;
223  }
224 
225  /// Returns the product of dual quaternion \p dq and scalar \p s.
226  friend GfDualQuatd operator *(const GfDualQuatd &dq, double s) {
227  GfDualQuatd dqt = dq;
228  return dqt *= s;
229  }
230 
231  /// Returns the product of dual quaternion \p dq and scalar \p s.
232  friend GfDualQuatd operator *(double s, const GfDualQuatd &dq) {
233  GfDualQuatd dqt = dq;
234  return dqt *= s;
235  }
236 
237  /// Returns the product of dual quaternion \p dq and scalar 1 / \p s.
238  friend GfDualQuatd operator /(const GfDualQuatd &dq, double s) {
239  GfDualQuatd dqt = dq;
240  return dqt /= s;
241  }
242 
243  /// Transforms the row vector \e vec by the dual quaternion.
244  GF_API
245  GfVec3d Transform(const GfVec3d &vec) const;
246 
247  private:
248  GfQuatd _real; // for rotation
249  GfQuatd _dual; // for translation
250 };
251 
252 
253 /// Output a GfDualQuatd using the format ((rw, rx, ry, rz), (dw, dx, dy, dz)).
254 /// \ingroup group_gf_DebuggingOutput
255 GF_API std::ostream &operator<<(std::ostream &out, const GfDualQuatd &dq);
256 
257 
258 /// Returns the dot (inner) product of two dual quaternions.
259 inline double
260 GfDot(const GfDualQuatd& dq1, const GfDualQuatd& dq2) {
261  return GfDot(dq1.GetReal(), dq2.GetReal()) + GfDot(dq1.GetDual(), dq2.GetDual());
262 }
263 
265 
266 #endif // PXR_BASE_GF_DUALQUATD_H
GF_API std::pair< double, double > Normalize(double eps=GF_MIN_VECTOR_LENGTH)
friend size_t hash_value(const GfDualQuatd &dq)
Hash.
Definition: dualQuatd.h:157
GfDualQuatd & operator/=(double s)
Scales this dual quaternion by 1 / s.
Definition: dualQuatd.h:200
friend GfDualQuatd operator/(const GfDualQuatd &dq, double s)
Returns the product of dual quaternion dq and scalar 1 / s.
Definition: dualQuatd.h:238
GF_API GfDualQuatd & operator*=(const GfDualQuatd &dq)
Post-multiplies dual quaternion dq into this dual quaternion.
GF_API void SetTranslation(const GfVec3d &translation)
Set the translation component of this dual quaternion.
GF_API GfDualQuatd GetInverse() const
Returns the inverse of this dual quaternion.
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:632
GF_API GfDualQuatd GetNormalized(double eps=GF_MIN_VECTOR_LENGTH) const
GfDualQuatd(const GfQuatd &real)
Definition: dualQuatd.h:69
GfDualQuatd & operator-=(const GfDualQuatd &dq)
Component-wise unary difference operator.
Definition: dualQuatd.h:182
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GfDualQuatd & operator+=(const GfDualQuatd &dq)
Component-wise unary sum operator.
Definition: dualQuatd.h:175
GfDualQuatd()
The default constructor leaves the dual quaternion undefined.
Definition: dualQuatd.h:55
GLdouble s
Definition: glad.h:3009
GfDualQuatd(double realVal)
Definition: dualQuatd.h:64
static GfDualQuatd GetIdentity()
Definition: dualQuatd.h:119
friend GfDualQuatd operator+(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Component-wise binary sum operator.
Definition: dualQuatd.h:205
static GfQuatd GetIdentity()
Definition: quatd.h:85
GF_API GfDualQuatd GetConjugate() const
Returns the conjugate of this dual quaternion.
const GfQuatd & GetDual() const
Returns the dual part of the dual quaternion.
Definition: dualQuatd.h:107
void SetDual(const GfQuatd &dual)
Sets the dual part of the dual quaternion.
Definition: dualQuatd.h:97
static GfDualQuatd GetZero()
Definition: dualQuatd.h:113
double ScalarType
Definition: dualQuatd.h:52
SIM_API const UT_StringHolder rotation
void SetReal(const GfQuatd &real)
Sets the real part of the dual quaternion.
Definition: dualQuatd.h:92
const GfQuatd & GetReal() const
Returns the real part of the dual quaternion.
Definition: dualQuatd.h:102
double GfDot(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Return the dot (inner) product of two dual quaternions.
Definition: dualQuatd.h:260
GF_API std::pair< double, double > GetLength() const
Returns geometric length of this dual quaternion.
GfDualQuatd(const GfQuatd &rotation, const GfVec3d &translation)
This constructor initializes from a rotation and a translation components.
Definition: dualQuatd.h:79
friend GfDualQuatd operator-(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Component-wise binary difference operator.
Definition: dualQuatd.h:212
GF_API std::ostream & operator<<(std::ostream &out, const GfDualQuatd &dq)
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
bool operator!=(const GfDualQuatd &dq) const
Definition: dualQuatd.h:170
friend GfDualQuatd operator*(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Returns the product of dual quaternions dq1 and dq2.
Definition: dualQuatd.h:219
Definition: vec3d.h:45
GF_API GfVec3d Transform(const GfVec3d &vec) const
Transforms the row vector vec by the dual quaternion.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GF_API GfVec3d GetTranslation() const
Get the translation component of this dual quaternion.
static GfQuatd GetZero()
Definition: quatd.h:81
Definition: quatd.h:42
bool operator==(const GfDualQuatd &dq) const
Definition: dualQuatd.h:163
#define GF_MIN_VECTOR_LENGTH
Definition: limits.h:17
GfDualQuatd(const GfQuatd &real, const GfQuatd &dual)
This constructor initializes the real and dual parts.
Definition: dualQuatd.h:74
#define GF_API
Definition: api.h:23