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 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_DUALQUATD_H
29 #define PXR_BASE_GF_DUALQUATD_H
30 
31 /// \file gf/dualQuatd.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/quatd.h"
40 #include "pxr/base/tf/hash.h"
41 
42 #include <iosfwd>
43 
45 
46 template <>
47 struct GfIsGfDualQuat<class GfDualQuatd> { static const bool value = true; };
48 
49 /// Return the dot (inner) product of two dual quaternions.
50 double GfDot(const GfDualQuatd& dq1, const GfDualQuatd& dq2);
51 
52 
53 /// \class GfDualQuatd
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 GfDualQuatd final
67 {
68  public:
69  typedef double 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 GfDualQuatd( double 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 GfDualQuatd( const GfQuatd &real )
87  : _real( real ), _dual( 0 ) {
88  }
89 
90  /// This constructor initializes the real and dual parts.
91  GfDualQuatd( const GfQuatd &real, const GfQuatd &dual )
92  : _real( real ), _dual( dual ) {
93  }
94 
95  /// This constructor initializes from a rotation and a translation components.
96  GfDualQuatd( const GfQuatd &rotation, const GfVec3d &translation )
97  : _real( rotation ) {
98  SetTranslation( translation );
99  }
100 
101  /// Implicitly convert from GfDualQuatf.
102  GF_API
103  GfDualQuatd(const GfDualQuatf &other);
104  /// Implicitly convert from GfDualQuath.
105  GF_API
106  GfDualQuatd(const GfDualQuath &other);
107 
108  /// Sets the real part of the dual quaternion.
109  void SetReal(const GfQuatd &real) {
110  _real = real;
111  }
112 
113  /// Sets the dual part of the dual quaternion.
114  void SetDual(const GfQuatd &dual) {
115  _dual = dual;
116  }
117 
118  /// Returns the real part of the dual quaternion.
119  const GfQuatd &GetReal() const {
120  return _real;
121  }
122 
123  /// Returns the dual part of the dual quaternion.
124  const GfQuatd &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 GfDualQuatd 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<double, double> 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
148  GfDualQuatd GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const;
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<double, double> Normalize(double eps = GF_MIN_VECTOR_LENGTH);
156 
157  /// Returns the conjugate of this dual quaternion.
158  GF_API
159  GfDualQuatd GetConjugate() const;
160 
161  /// Returns the inverse of this dual quaternion.
162  GF_API
163  GfDualQuatd GetInverse() const;
164 
165  /// Set the translation component of this dual quaternion.
166  GF_API
167  void SetTranslation( const GfVec3d &translation );
168 
169  /// Get the translation component of this dual quaternion.
170  GF_API
171  GfVec3d GetTranslation() const;
172 
173  /// Hash.
174  friend inline size_t hash_value(const GfDualQuatd &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 GfDualQuatd &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 GfDualQuatd &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  GfDualQuatd &operator *=(const GfDualQuatd &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 GfDualQuatd operator +(const GfDualQuatd &dq1,
223  const GfDualQuatd &dq2) {
224  GfDualQuatd dqt = dq1;
225  return dqt += dq2;
226  }
227 
228  /// Component-wise binary difference operator.
229  friend GfDualQuatd operator -(const GfDualQuatd &dq1,
230  const GfDualQuatd &dq2) {
231  GfDualQuatd dqt = dq1;
232  return dqt -= dq2;
233  }
234 
235  /// Returns the product of dual quaternions \p dq1 and \p dq2.
236  friend GfDualQuatd operator *(const GfDualQuatd &dq1,
237  const GfDualQuatd &dq2) {
238  GfDualQuatd dqt = dq1;
239  return dqt *= dq2;
240  }
241 
242  /// Returns the product of dual quaternion \p dq and scalar \p s.
243  friend GfDualQuatd operator *(const GfDualQuatd &dq, double s) {
244  GfDualQuatd dqt = dq;
245  return dqt *= s;
246  }
247 
248  /// Returns the product of dual quaternion \p dq and scalar \p s.
249  friend GfDualQuatd operator *(double s, const GfDualQuatd &dq) {
250  GfDualQuatd dqt = dq;
251  return dqt *= s;
252  }
253 
254  /// Returns the product of dual quaternion \p dq and scalar 1 / \p s.
255  friend GfDualQuatd operator /(const GfDualQuatd &dq, double s) {
256  GfDualQuatd dqt = dq;
257  return dqt /= s;
258  }
259 
260  /// Transforms the row vector \e vec by the dual quaternion.
261  GF_API
262  GfVec3d Transform(const GfVec3d &vec) const;
263 
264  private:
265  GfQuatd _real; // for rotation
266  GfQuatd _dual; // for translation
267 };
268 
269 
270 /// Output a GfDualQuatd 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 GfDualQuatd &dq);
273 
274 
275 /// Returns the dot (inner) product of two dual quaternions.
276 inline double
277 GfDot(const GfDualQuatd& dq1, const GfDualQuatd& dq2) {
278  return GfDot(dq1.GetReal(), dq2.GetReal()) + GfDot(dq1.GetDual(), dq2.GetDual());
279 }
280 
282 
283 #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:174
GfDualQuatd & operator/=(double s)
Scales this dual quaternion by 1 / s.
Definition: dualQuatd.h:217
friend GfDualQuatd operator/(const GfDualQuatd &dq, double s)
Returns the product of dual quaternion dq and scalar 1 / s.
Definition: dualQuatd.h:255
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:623
GF_API GfDualQuatd GetNormalized(double eps=GF_MIN_VECTOR_LENGTH) const
GfDualQuatd(const GfQuatd &real)
Definition: dualQuatd.h:86
GfDualQuatd & operator-=(const GfDualQuatd &dq)
Component-wise unary difference operator.
Definition: dualQuatd.h:199
GfDualQuatd & operator+=(const GfDualQuatd &dq)
Component-wise unary sum operator.
Definition: dualQuatd.h:192
GfDualQuatd()
The default constructor leaves the dual quaternion undefined.
Definition: dualQuatd.h:72
GLdouble s
Definition: glad.h:3009
GfDualQuatd(double realVal)
Definition: dualQuatd.h:81
static GfDualQuatd GetIdentity()
Definition: dualQuatd.h:136
friend GfDualQuatd operator+(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Component-wise binary sum operator.
Definition: dualQuatd.h:222
static GfQuatd GetIdentity()
Definition: quatd.h:102
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:124
void SetDual(const GfQuatd &dual)
Sets the dual part of the dual quaternion.
Definition: dualQuatd.h:114
static GfDualQuatd GetZero()
Definition: dualQuatd.h:130
double ScalarType
Definition: dualQuatd.h:69
SIM_API const UT_StringHolder rotation
void SetReal(const GfQuatd &real)
Sets the real part of the dual quaternion.
Definition: dualQuatd.h:109
const GfQuatd & GetReal() const
Returns the real part of the dual quaternion.
Definition: dualQuatd.h:119
double GfDot(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Return the dot (inner) product of two dual quaternions.
Definition: dualQuatd.h:277
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:96
friend GfDualQuatd operator-(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Component-wise binary difference operator.
Definition: dualQuatd.h:229
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:492
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
bool operator!=(const GfDualQuatd &dq) const
Definition: dualQuatd.h:187
friend GfDualQuatd operator*(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Returns the product of dual quaternions dq1 and dq2.
Definition: dualQuatd.h:236
Definition: vec3d.h:62
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:91
GF_API GfVec3d GetTranslation() const
Get the translation component of this dual quaternion.
static GfQuatd GetZero()
Definition: quatd.h:98
Definition: core.h:1131
Definition: quatd.h:59
bool operator==(const GfDualQuatd &dq) const
Definition: dualQuatd.h:180
#define GF_MIN_VECTOR_LENGTH
Definition: limits.h:34
GfDualQuatd(const GfQuatd &real, const GfQuatd &dual)
This constructor initializes the real and dual parts.
Definition: dualQuatd.h:91
#define GF_API
Definition: api.h:40