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 //
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 
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 
44 PXR_NAMESPACE_OPEN_SCOPE
45 
46 template <>
47 struct GfIsGfDualQuat<class GfDualQuatf> { static const bool value = true; };
48 
50 float GfDot(const GfDualQuatf& dq1, const GfDualQuatf& dq2);
51 
52 
66 class GfDualQuatf final
67 {
68  public:
69  typedef float ScalarType;
70 
73 
81  explicit GfDualQuatf( float realVal ) : _real( realVal ), _dual( 0 ) {}
82 
86  explicit GfDualQuatf( const GfQuatf &real )
87  : _real( real ), _dual( 0 ) {
88  }
89 
91  GfDualQuatf( const GfQuatf &real, const GfQuatf &dual )
92  : _real( real ), _dual( dual ) {
93  }
94 
96  GfDualQuatf( const GfQuatf &rotation, const GfVec3f &translation )
97  : _real( rotation ) {
98  SetTranslation( translation );
99  }
100 
102  GF_API
103  explicit GfDualQuatf(const GfDualQuatd &other);
105  GF_API
106  GfDualQuatf(const GfDualQuath &other);
107 
109  void SetReal(const GfQuatf &real) {
110  _real = real;
111  }
112 
114  void SetDual(const GfQuatf &dual) {
115  _dual = dual;
116  }
117 
119  const GfQuatf &GetReal() const {
120  return _real;
121  }
122 
124  const GfQuatf &GetDual() const {
125  return _dual;
126  }
127 
130  static GfDualQuatf GetZero() {
132  }
133 
138  }
139 
141  GF_API
142  std::pair<float, float> GetLength() const;
143 
147  GF_API
149 
154  GF_API
155  std::pair<float, float> Normalize(float eps = GF_MIN_VECTOR_LENGTH);
156 
158  GF_API
159  GfDualQuatf GetConjugate() const;
160 
162  GF_API
163  GfDualQuatf GetInverse() const;
164 
166  GF_API
167  void SetTranslation( const GfVec3f &translation );
168 
170  GF_API
171  GfVec3f GetTranslation() const;
172 
174  friend inline size_t hash_value(const GfDualQuatf &dq) {
175  return TfHash::Combine(dq.GetReal(), dq.GetDual());
176  }
177 
180  bool operator ==(const GfDualQuatf &dq) const {
181  return (GetReal() == dq.GetReal() &&
182  GetDual() == dq.GetDual());
183  }
184 
187  bool operator !=(const GfDualQuatf &dq) const {
188  return ! (*this == dq);
189  }
190 
193  _real += dq._real;
194  _dual += dq._dual;
195  return *this;
196  }
197 
200  _real -= dq._real;
201  _dual -= dq._dual;
202  return *this;
203  }
204 
206  GF_API
207  GfDualQuatf &operator *=(const GfDualQuatf &dq);
208 
211  _real *= s;
212  _dual *= s;
213  return *this;
214  }
215 
218  return (*this) *= 1.0 / s;
219  }
220 
222  friend GfDualQuatf operator +(const GfDualQuatf &dq1,
223  const GfDualQuatf &dq2) {
224  GfDualQuatf dqt = dq1;
225  return dqt += dq2;
226  }
227 
229  friend GfDualQuatf operator -(const GfDualQuatf &dq1,
230  const GfDualQuatf &dq2) {
231  GfDualQuatf dqt = dq1;
232  return dqt -= dq2;
233  }
234 
236  friend GfDualQuatf operator *(const GfDualQuatf &dq1,
237  const GfDualQuatf &dq2) {
238  GfDualQuatf dqt = dq1;
239  return dqt *= dq2;
240  }
241 
243  friend GfDualQuatf operator *(const GfDualQuatf &dq, float s) {
244  GfDualQuatf dqt = dq;
245  return dqt *= s;
246  }
247 
249  friend GfDualQuatf operator *(float s, const GfDualQuatf &dq) {
250  GfDualQuatf dqt = dq;
251  return dqt *= s;
252  }
253 
255  friend GfDualQuatf operator /(const GfDualQuatf &dq, float s) {
256  GfDualQuatf dqt = dq;
257  return dqt /= s;
258  }
259 
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 
272 GF_API std::ostream &operator<<(std::ostream &out, const GfDualQuatf &dq);
273 
274 
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 
281 PXR_NAMESPACE_CLOSE_SCOPE
282 
283 #endif // PXR_BASE_GF_DUALQUATF_H
float GfDot(const GfDualQuatf &dq1, const GfDualQuatf &dq2)
Return the dot (inner) product of two dual quaternions.
Definition: dualQuatf.h:277
void SetDual(const GfQuatf &dual)
Sets the dual part of the dual quaternion.
Definition: dualQuatf.h:114
static GfDualQuatf GetZero()
Returns the zero dual quaternion, which has a real part of (0,0,0,0) and a dual part of (0,...
Definition: dualQuatf.h:130
Basic type: a real part quaternion and a dual part quaternion.
Definition: dualQuatd.h:66
GF_API GfDualQuatf GetConjugate() const
Returns the conjugate of this dual quaternion.
GF_API std::ostream & operator<<(std::ostream &out, const GfDualQuatf &dq)
Output a GfDualQuatf using the format ((rw, rx, ry, rz), (dw, dx, dy, dz)).
friend size_t hash_value(const GfDualQuatf &dq)
Hash.
Definition: dualQuatf.h:174
friend GfDualQuatf operator -(const GfDualQuatf &dq1, const GfDualQuatf &dq2)
Component-wise binary difference operator.
Definition: dualQuatf.h:229
GfDualQuatf(const GfQuatf &rotation, const GfVec3f &translation)
This constructor initializes from a rotation and a translation components.
Definition: dualQuatf.h:96
Basic type for a vector of 3 float components.
Definition: vec3f.h:62
GF_API GfDualQuatf & operator *=(const GfDualQuatf &dq)
Post-multiplies dual quaternion dq into this dual quaternion.
GfDualQuatf & operator+=(const GfDualQuatf &dq)
Component-wise unary sum operator.
Definition: dualQuatf.h:192
A metafunction with a static const bool member 'value' that is true for GfDualQuat types and false fo...
Definition: traits.h:52
Declares Gf types.
GF_API GfDualQuatf GetInverse() const
Returns the inverse of this dual quaternion.
bool operator==(const GfDualQuatf &dq) const
Component-wise dual quaternion equality test.
Definition: dualQuatf.h:180
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:59
static GfQuatf GetIdentity()
Return the identity quaternion, with real coefficient 1 and an imaginary coefficients all zero.
Definition: quatf.h:102
void SetReal(const GfQuatf &real)
Sets the real part of the dual quaternion.
Definition: dualQuatf.h:109
GF_API std::pair< float, float > Normalize(float eps=GF_MIN_VECTOR_LENGTH)
Normalizes this dual quaternion in place.
static GfDualQuatf GetIdentity()
Returns the identity dual quaternion, which has a real part of (1,0,0,0) and a dual part of (0,...
Definition: dualQuatf.h:136
GfDualQuatf(float realVal)
Initialize the real part to realVal and the imaginary part to zero quaternion.
Definition: dualQuatf.h:81
friend GfDualQuatf operator *(const GfDualQuatf &dq1, const GfDualQuatf &dq2)
Returns the product of dual quaternions dq1 and dq2.
Definition: dualQuatf.h:236
friend GfDualQuatf operator *(float s, const GfDualQuatf &dq)
Returns the product of dual quaternion dq and scalar s.
Definition: dualQuatf.h:249
GfDualQuatf & operator/=(float s)
Scales this dual quaternion by 1 / s.
Definition: dualQuatf.h:217
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:519
GF_API GfDualQuatf GetNormalized(float eps=GF_MIN_VECTOR_LENGTH) const
Returns a normalized (unit-length) version of this dual quaternion.
Basic type: a real part quaternion and a dual part quaternion.
Definition: dualQuatf.h:66
GfDualQuatf(const GfQuatf &real, const GfQuatf &dual)
This constructor initializes the real and dual parts.
Definition: dualQuatf.h:91
const GfQuatf & GetDual() const
Returns the dual part of the dual quaternion.
Definition: dualQuatf.h:124
GfDualQuatf & operator -=(const GfDualQuatf &dq)
Component-wise unary difference operator.
Definition: dualQuatf.h:199
const GfQuatf & GetReal() const
Returns the real part of the dual quaternion.
Definition: dualQuatf.h:119
GF_API GfVec3f GetTranslation() const
Get the translation component of this dual quaternion.
GF_API std::pair< float, float > GetLength() const
Returns geometric length of this dual quaternion.
bool operator !=(const GfDualQuatf &dq) const
Component-wise dual quaternion inequality test.
Definition: dualQuatf.h:187
GF_API void SetTranslation(const GfVec3f &translation)
Set the translation component of this dual quaternion.
static GfQuatf GetZero()
Return the zero quaternion, with real coefficient 0 and an imaginary coefficients all zero.
Definition: quatf.h:98
friend GfDualQuatf operator+(const GfDualQuatf &dq1, const GfDualQuatf &dq2)
Component-wise binary sum operator.
Definition: dualQuatf.h:222
GfDualQuatf & operator *=(float s)
Scales this dual quaternion by s.
Definition: dualQuatf.h:210
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
GF_API GfVec3f Transform(const GfVec3f &vec) const
Transforms the row vector vec by the dual quaternion.
Basic type: a real part quaternion and a dual part quaternion.
Definition: dualQuath.h:67
GfDualQuatf(const GfQuatf &real)
Initialize the real part to real quaternion and the imaginary part to zero quaternion.
Definition: dualQuatf.h:86
friend GfDualQuatf operator *(const GfDualQuatf &dq, float s)
Returns the product of dual quaternion dq and scalar s.
Definition: dualQuatf.h:243
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.
Definition: limits.h:34