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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 // This file is generated by a script. Do not edit directly. Edit the
26 // dualQuat.template.h file to make changes.
27 
28 #ifndef PXR_BASE_GF_DUALQUATH_H
29 #define PXR_BASE_GF_DUALQUATH_H
30 
31 /// \file gf/dualQuath.h
32 /// \ingroup group_gf_LinearAlgebra
33 
34 #include "pxr/pxr.h"
35 #include "pxr/base/gf/api.h"
36 #include "pxr/base/gf/declare.h"
37 #include "pxr/base/gf/traits.h"
38 #include "pxr/base/gf/half.h"
39 
40 #include "pxr/base/gf/quath.h"
41 #include "pxr/base/tf/hash.h"
42 
43 #include <iosfwd>
44 
46 
47 template <>
48 struct GfIsGfDualQuat<class GfDualQuath> { static const bool value = true; };
49 
50 /// Return the dot (inner) product of two dual quaternions.
51 GfHalf GfDot(const GfDualQuath& dq1, const GfDualQuath& dq2);
52 
53 
54 /// \class GfDualQuath
55 /// \ingroup group_gf_LinearAlgebra
56 ///
57 /// Basic type: a real part quaternion and a dual part quaternion.
58 ///
59 /// This class represents a generalized dual quaternion that has a real part
60 /// and a dual part quaternions. Dual quaternions are used to represent a
61 /// combination of rotation and translation.
62 ///
63 /// References:
64 /// https://www.cs.utah.edu/~ladislav/kavan06dual/kavan06dual.pdf
65 /// http://web.cs.iastate.edu/~cs577/handouts/dual-quaternion.pdf
66 ///
67 class GfDualQuath final
68 {
69  public:
70  typedef GfHalf ScalarType;
71 
72  /// The default constructor leaves the dual quaternion undefined.
74 
75  /// Initialize the real part to \p realVal and the imaginary part
76  /// to zero quaternion.
77  ///
78  /// Since quaternions typically must be normalized, reasonable values for
79  /// \p realVal are -1, 0, or 1. Other values are legal but are likely to
80  /// be meaningless.
81  ///
82  explicit GfDualQuath( GfHalf realVal ) : _real( realVal ), _dual( 0 ) {}
83 
84  /// Initialize the real part to \p real quaternion and the imaginary part
85  /// to zero quaternion.
86  ///
87  explicit GfDualQuath( const GfQuath &real )
88  : _real( real ), _dual( 0 ) {
89  }
90 
91  /// This constructor initializes the real and dual parts.
92  GfDualQuath( const GfQuath &real, const GfQuath &dual )
93  : _real( real ), _dual( dual ) {
94  }
95 
96  /// This constructor initializes from a rotation and a translation components.
97  GfDualQuath( const GfQuath &rotation, const GfVec3h &translation )
98  : _real( rotation ) {
99  SetTranslation( translation );
100  }
101 
102  /// Construct from GfDualQuatd.
103  GF_API
104  explicit GfDualQuath(const GfDualQuatd &other);
105  /// Construct from GfDualQuatf.
106  GF_API
107  explicit GfDualQuath(const GfDualQuatf &other);
108 
109  /// Sets the real part of the dual quaternion.
110  void SetReal(const GfQuath &real) {
111  _real = real;
112  }
113 
114  /// Sets the dual part of the dual quaternion.
115  void SetDual(const GfQuath &dual) {
116  _dual = dual;
117  }
118 
119  /// Returns the real part of the dual quaternion.
120  const GfQuath &GetReal() const {
121  return _real;
122  }
123 
124  /// Returns the dual part of the dual quaternion.
125  const GfQuath &GetDual() const {
126  return _dual;
127  }
128 
129  /// Returns the zero dual quaternion, which has a real part of (0,0,0,0) and
130  /// a dual part of (0,0,0,0).
131  static GfDualQuath GetZero() {
133  }
134 
135  /// Returns the identity dual quaternion, which has a real part of (1,0,0,0) and
136  /// a dual part of (0,0,0,0).
139  }
140 
141  /// Returns geometric length of this dual quaternion.
142  GF_API
143  std::pair<GfHalf, GfHalf> GetLength() const;
144 
145  /// Returns a normalized (unit-length) version of this dual quaternion.
146  /// If the length of this dual quaternion is smaller than \p
147  /// eps, this returns the identity dual quaternion.
148  GF_API
150 
151  /// Normalizes this dual quaternion in place.
152  /// Normalizes this dual quaternion in place to unit length, returning the
153  /// length before normalization. If the length of this dual quaternion is
154  /// smaller than \p eps, this sets the dual quaternion to identity.
155  GF_API
156  std::pair<GfHalf, GfHalf> Normalize(GfHalf eps = GF_MIN_VECTOR_LENGTH);
157 
158  /// Returns the conjugate of this dual quaternion.
159  GF_API
160  GfDualQuath GetConjugate() const;
161 
162  /// Returns the inverse of this dual quaternion.
163  GF_API
164  GfDualQuath GetInverse() const;
165 
166  /// Set the translation component of this dual quaternion.
167  GF_API
168  void SetTranslation( const GfVec3h &translation );
169 
170  /// Get the translation component of this dual quaternion.
171  GF_API
172  GfVec3h GetTranslation() const;
173 
174  /// Hash.
175  friend inline size_t hash_value(const GfDualQuath &dq) {
176  return TfHash::Combine(dq.GetReal(), dq.GetDual());
177  }
178 
179  /// Component-wise dual quaternion equality test. The real and dual parts
180  /// must match exactly for dual quaternions to be considered equal.
181  bool operator ==(const GfDualQuath &dq) const {
182  return (GetReal() == dq.GetReal() &&
183  GetDual() == dq.GetDual());
184  }
185 
186  /// Component-wise dual quaternion inequality test. The real and dual
187  /// parts must match exactly for dual quaternions to be considered equal.
188  bool operator !=(const GfDualQuath &dq) const {
189  return ! (*this == dq);
190  }
191 
192  /// Component-wise unary sum operator.
194  _real += dq._real;
195  _dual += dq._dual;
196  return *this;
197  }
198 
199  /// Component-wise unary difference operator.
201  _real -= dq._real;
202  _dual -= dq._dual;
203  return *this;
204  }
205 
206  /// Post-multiplies dual quaternion \p dq into this dual quaternion.
207  GF_API
208  GfDualQuath &operator *=(const GfDualQuath &dq);
209 
210  /// Scales this dual quaternion by \p s.
212  _real *= s;
213  _dual *= s;
214  return *this;
215  }
216 
217  /// Scales this dual quaternion by 1 / \p s.
219  return (*this) *= 1.0 / s;
220  }
221 
222  /// Component-wise binary sum operator.
223  friend GfDualQuath operator +(const GfDualQuath &dq1,
224  const GfDualQuath &dq2) {
225  GfDualQuath dqt = dq1;
226  return dqt += dq2;
227  }
228 
229  /// Component-wise binary difference operator.
230  friend GfDualQuath operator -(const GfDualQuath &dq1,
231  const GfDualQuath &dq2) {
232  GfDualQuath dqt = dq1;
233  return dqt -= dq2;
234  }
235 
236  /// Returns the product of dual quaternions \p dq1 and \p dq2.
237  friend GfDualQuath operator *(const GfDualQuath &dq1,
238  const GfDualQuath &dq2) {
239  GfDualQuath dqt = dq1;
240  return dqt *= dq2;
241  }
242 
243  /// Returns the product of dual quaternion \p dq and scalar \p s.
245  GfDualQuath dqt = dq;
246  return dqt *= s;
247  }
248 
249  /// Returns the product of dual quaternion \p dq and scalar \p s.
251  GfDualQuath dqt = dq;
252  return dqt *= s;
253  }
254 
255  /// Returns the product of dual quaternion \p dq and scalar 1 / \p s.
257  GfDualQuath dqt = dq;
258  return dqt /= s;
259  }
260 
261  /// Transforms the row vector \e vec by the dual quaternion.
262  GF_API
263  GfVec3h Transform(const GfVec3h &vec) const;
264 
265  private:
266  GfQuath _real; // for rotation
267  GfQuath _dual; // for translation
268 };
269 
270 
271 /// Output a GfDualQuath using the format ((rw, rx, ry, rz), (dw, dx, dy, dz)).
272 /// \ingroup group_gf_DebuggingOutput
273 GF_API std::ostream &operator<<(std::ostream &out, const GfDualQuath &dq);
274 
275 
276 /// Returns the dot (inner) product of two dual quaternions.
277 inline GfHalf
278 GfDot(const GfDualQuath& dq1, const GfDualQuath& dq2) {
279  return GfDot(dq1.GetReal(), dq2.GetReal()) + GfDot(dq1.GetDual(), dq2.GetDual());
280 }
281 
283 
284 #endif // PXR_BASE_GF_DUALQUATH_H
Definition: quath.h:60
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:120
friend size_t hash_value(const GfDualQuath &dq)
Hash.
Definition: dualQuath.h:175
GF_API std::pair< GfHalf, GfHalf > Normalize(GfHalf eps=GF_MIN_VECTOR_LENGTH)
GfDualQuath(const GfQuath &real)
Definition: dualQuath.h:87
friend GfDualQuath operator+(const GfDualQuath &dq1, const GfDualQuath &dq2)
Component-wise binary sum operator.
Definition: dualQuath.h:223
*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:623
void SetDual(const GfQuath &dual)
Sets the dual part of the dual quaternion.
Definition: dualQuath.h:115
GfDualQuath(const GfQuath &real, const GfQuath &dual)
This constructor initializes the real and dual parts.
Definition: dualQuath.h:92
bool operator==(const GfDualQuath &dq) const
Definition: dualQuath.h:181
GF_API GfVec3h Transform(const GfVec3h &vec) const
Transforms the row vector vec by the dual quaternion.
static GfQuath GetZero()
Definition: quath.h:99
GfHalf GfDot(const GfDualQuath &dq1, const GfDualQuath &dq2)
Return the dot (inner) product of two dual quaternions.
Definition: dualQuath.h:278
GfHalf ScalarType
Definition: dualQuath.h:70
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:103
GfDualQuath(const GfQuath &rotation, const GfVec3h &translation)
This constructor initializes from a rotation and a translation components.
Definition: dualQuath.h:97
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:125
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:256
SIM_API const UT_StringHolder rotation
friend GfDualQuath operator-(const GfDualQuath &dq1, const GfDualQuath &dq2)
Component-wise binary difference operator.
Definition: dualQuath.h:230
void SetReal(const GfQuath &real)
Sets the real part of the dual quaternion.
Definition: dualQuath.h:110
GF_API GfDualQuath GetInverse() const
Returns the inverse of this dual quaternion.
GfDualQuath()
The default constructor leaves the dual quaternion undefined.
Definition: dualQuath.h:73
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:519
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
GfDualQuath & operator+=(const GfDualQuath &dq)
Component-wise unary sum operator.
Definition: dualQuath.h:193
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:237
GF_API std::ostream & operator<<(std::ostream &out, const GfDualQuath &dq)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
static GfDualQuath GetZero()
Definition: dualQuath.h:131
bool operator!=(const GfDualQuath &dq) const
Definition: dualQuath.h:188
Definition: core.h:1131
GfDualQuath & operator/=(GfHalf s)
Scales this dual quaternion by 1 / s.
Definition: dualQuath.h:218
GfDualQuath(GfHalf realVal)
Definition: dualQuath.h:82
Definition: vec3h.h:63
GfDualQuath & operator-=(const GfDualQuath &dq)
Component-wise unary difference operator.
Definition: dualQuath.h:200
#define GF_MIN_VECTOR_LENGTH
Definition: limits.h:34
#define GF_API
Definition: api.h:40
static GfDualQuath GetIdentity()
Definition: dualQuath.h:137