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  /// GfDualQuatd value-initializes to zero and performs no default
55  /// initialization, like float or double.
56  GfDualQuatd() = default;
57 
58  /// Initialize the real part to \p realVal and the imaginary part
59  /// to zero quaternion.
60  ///
61  /// Since quaternions typically must be normalized, reasonable values for
62  /// \p realVal are -1, 0, or 1. Other values are legal but are likely to
63  /// be meaningless.
64  ///
65  explicit GfDualQuatd( double realVal ) : _real( realVal ), _dual( 0 ) {}
66 
67  /// Initialize the real part to \p real quaternion and the imaginary part
68  /// to zero quaternion.
69  ///
70  explicit GfDualQuatd( const GfQuatd &real )
71  : _real( real ), _dual( 0 ) {
72  }
73 
74  /// This constructor initializes the real and dual parts.
75  GfDualQuatd( const GfQuatd &real, const GfQuatd &dual )
76  : _real( real ), _dual( dual ) {
77  }
78 
79  /// This constructor initializes from a rotation and a translation components.
80  GfDualQuatd( const GfQuatd &rotation, const GfVec3d &translation )
81  : _real( rotation ) {
82  SetTranslation( translation );
83  }
84 
85  /// Implicitly convert from GfDualQuatf.
86  GF_API
87  GfDualQuatd(const GfDualQuatf &other);
88  /// Implicitly convert from GfDualQuath.
89  GF_API
90  GfDualQuatd(const GfDualQuath &other);
91 
92  /// Sets the real part of the dual quaternion.
93  void SetReal(const GfQuatd &real) {
94  _real = real;
95  }
96 
97  /// Sets the dual part of the dual quaternion.
98  void SetDual(const GfQuatd &dual) {
99  _dual = dual;
100  }
101 
102  /// Returns the real part of the dual quaternion.
103  const GfQuatd &GetReal() const {
104  return _real;
105  }
106 
107  /// Returns the dual part of the dual quaternion.
108  const GfQuatd &GetDual() const {
109  return _dual;
110  }
111 
112  /// Returns the zero dual quaternion, which has a real part of (0,0,0,0) and
113  /// a dual part of (0,0,0,0).
114  static GfDualQuatd GetZero() {
116  }
117 
118  /// Returns the identity dual quaternion, which has a real part of (1,0,0,0) and
119  /// a dual part of (0,0,0,0).
122  }
123 
124  /// Returns geometric length of this dual quaternion.
125  GF_API
126  std::pair<double, double> GetLength() const;
127 
128  /// Returns a normalized (unit-length) version of this dual quaternion.
129  /// If the length of this dual quaternion is smaller than \p
130  /// eps, this returns the identity dual quaternion.
131  GF_API
132  GfDualQuatd GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const;
133 
134  /// Normalizes this dual quaternion in place.
135  /// Normalizes this dual quaternion in place to unit length, returning the
136  /// length before normalization. If the length of this dual quaternion is
137  /// smaller than \p eps, this sets the dual quaternion to identity.
138  GF_API
139  std::pair<double, double> Normalize(double eps = GF_MIN_VECTOR_LENGTH);
140 
141  /// Returns the conjugate of this dual quaternion.
142  GF_API
143  GfDualQuatd GetConjugate() const;
144 
145  /// Returns the inverse of this dual quaternion.
146  GF_API
147  GfDualQuatd GetInverse() const;
148 
149  /// Set the translation component of this dual quaternion.
150  GF_API
151  void SetTranslation( const GfVec3d &translation );
152 
153  /// Get the translation component of this dual quaternion.
154  GF_API
155  GfVec3d GetTranslation() const;
156 
157  /// Hash.
158  friend inline size_t hash_value(const GfDualQuatd &dq) {
159  return TfHash::Combine(dq.GetReal(), dq.GetDual());
160  }
161 
162  /// Component-wise dual quaternion equality test. The real and dual parts
163  /// must match exactly for dual quaternions to be considered equal.
164  bool operator ==(const GfDualQuatd &dq) const {
165  return (GetReal() == dq.GetReal() &&
166  GetDual() == dq.GetDual());
167  }
168 
169  /// Component-wise dual quaternion inequality test. The real and dual
170  /// parts must match exactly for dual quaternions to be considered equal.
171  bool operator !=(const GfDualQuatd &dq) const {
172  return ! (*this == dq);
173  }
174 
175  /// Component-wise unary sum operator.
177  _real += dq._real;
178  _dual += dq._dual;
179  return *this;
180  }
181 
182  /// Component-wise unary difference operator.
184  _real -= dq._real;
185  _dual -= dq._dual;
186  return *this;
187  }
188 
189  /// Post-multiplies dual quaternion \p dq into this dual quaternion.
190  GF_API
191  GfDualQuatd &operator *=(const GfDualQuatd &dq);
192 
193  /// Scales this dual quaternion by \p s.
195  _real *= s;
196  _dual *= s;
197  return *this;
198  }
199 
200  /// Scales this dual quaternion by 1 / \p s.
202  return (*this) *= 1.0 / s;
203  }
204 
205  /// Component-wise binary sum operator.
206  friend GfDualQuatd operator +(const GfDualQuatd &dq1,
207  const GfDualQuatd &dq2) {
208  GfDualQuatd dqt = dq1;
209  return dqt += dq2;
210  }
211 
212  /// Component-wise binary difference operator.
213  friend GfDualQuatd operator -(const GfDualQuatd &dq1,
214  const GfDualQuatd &dq2) {
215  GfDualQuatd dqt = dq1;
216  return dqt -= dq2;
217  }
218 
219  /// Returns the product of dual quaternions \p dq1 and \p dq2.
220  friend GfDualQuatd operator *(const GfDualQuatd &dq1,
221  const GfDualQuatd &dq2) {
222  GfDualQuatd dqt = dq1;
223  return dqt *= dq2;
224  }
225 
226  /// Returns the product of dual quaternion \p dq and scalar \p s.
227  friend GfDualQuatd operator *(const GfDualQuatd &dq, double s) {
228  GfDualQuatd dqt = dq;
229  return dqt *= s;
230  }
231 
232  /// Returns the product of dual quaternion \p dq and scalar \p s.
233  friend GfDualQuatd operator *(double s, const GfDualQuatd &dq) {
234  GfDualQuatd dqt = dq;
235  return dqt *= s;
236  }
237 
238  /// Returns the product of dual quaternion \p dq and scalar 1 / \p s.
239  friend GfDualQuatd operator /(const GfDualQuatd &dq, double s) {
240  GfDualQuatd dqt = dq;
241  return dqt /= s;
242  }
243 
244  /// Transforms the row vector \e vec by the dual quaternion.
245  GF_API
246  GfVec3d Transform(const GfVec3d &vec) const;
247 
248  private:
249  GfQuatd _real; // for rotation
250  GfQuatd _dual; // for translation
251 };
252 
253 
254 /// Output a GfDualQuatd using the format ((rw, rx, ry, rz), (dw, dx, dy, dz)).
255 /// \ingroup group_gf_DebuggingOutput
256 GF_API std::ostream &operator<<(std::ostream &out, const GfDualQuatd &dq);
257 
258 
259 /// Returns the dot (inner) product of two dual quaternions.
260 inline double
261 GfDot(const GfDualQuatd& dq1, const GfDualQuatd& dq2) {
262  return GfDot(dq1.GetReal(), dq2.GetReal()) + GfDot(dq1.GetDual(), dq2.GetDual());
263 }
264 
266 
267 #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:158
GfDualQuatd & operator/=(double s)
Scales this dual quaternion by 1 / s.
Definition: dualQuatd.h:201
friend GfDualQuatd operator/(const GfDualQuatd &dq, double s)
Returns the product of dual quaternion dq and scalar 1 / s.
Definition: dualQuatd.h:239
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:70
GfDualQuatd & operator-=(const GfDualQuatd &dq)
Component-wise unary difference operator.
Definition: dualQuatd.h:183
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GfDualQuatd & operator+=(const GfDualQuatd &dq)
Component-wise unary sum operator.
Definition: dualQuatd.h:176
GLdouble s
Definition: glad.h:3009
GfDualQuatd(double realVal)
Definition: dualQuatd.h:65
static GfDualQuatd GetIdentity()
Definition: dualQuatd.h:120
friend GfDualQuatd operator+(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Component-wise binary sum operator.
Definition: dualQuatd.h:206
static GfQuatd GetIdentity()
Definition: quatd.h:86
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:108
void SetDual(const GfQuatd &dual)
Sets the dual part of the dual quaternion.
Definition: dualQuatd.h:98
static GfDualQuatd GetZero()
Definition: dualQuatd.h:114
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:93
const GfQuatd & GetReal() const
Returns the real part of the dual quaternion.
Definition: dualQuatd.h:103
GfDualQuatd()=default
double GfDot(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Return the dot (inner) product of two dual quaternions.
Definition: dualQuatd.h:261
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:80
friend GfDualQuatd operator-(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Component-wise binary difference operator.
Definition: dualQuatd.h:213
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
bool operator!=(const GfDualQuatd &dq) const
Definition: dualQuatd.h:171
friend GfDualQuatd operator*(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Returns the product of dual quaternions dq1 and dq2.
Definition: dualQuatd.h:220
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:82
Definition: quatd.h:42
bool operator==(const GfDualQuatd &dq) const
Definition: dualQuatd.h:164
#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:75
#define GF_API
Definition: api.h:23