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