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