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 
41 #include <boost/functional/hash.hpp>
42 
43 #include <iosfwd>
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
47 template <>
48 struct GfIsGfDualQuat<class GfDualQuatf> { static const bool value = true; };
49 
51 float GfDot(const GfDualQuatf& dq1, const GfDualQuatf& dq2);
52 
53 
67 class GfDualQuatf final
68 {
69  public:
70  typedef float ScalarType;
71 
74 
82  explicit GfDualQuatf( float realVal ) : _real( realVal ), _dual( 0 ) {}
83 
87  explicit GfDualQuatf( const GfQuatf &real )
88  : _real( real ), _dual( 0 ) {
89  }
90 
92  GfDualQuatf( const GfQuatf &real, const GfQuatf &dual )
93  : _real( real ), _dual( dual ) {
94  }
95 
97  GfDualQuatf( const GfQuatf &rotation, const GfVec3f &translation )
98  : _real( rotation ) {
99  SetTranslation( translation );
100  }
101 
103  GF_API
104  explicit GfDualQuatf(const GfDualQuatd &other);
106  GF_API
107  GfDualQuatf(const GfDualQuath &other);
108 
110  void SetReal(const GfQuatf &real) {
111  _real = real;
112  }
113 
115  void SetDual(const GfQuatf &dual) {
116  _dual = dual;
117  }
118 
120  const GfQuatf &GetReal() const {
121  return _real;
122  }
123 
125  const GfQuatf &GetDual() const {
126  return _dual;
127  }
128 
131  static GfDualQuatf GetZero() {
133  }
134 
139  }
140 
142  GF_API
143  std::pair<float, float> GetLength() const;
144 
148  GF_API
150 
155  GF_API
156  std::pair<float, float> Normalize(float eps = GF_MIN_VECTOR_LENGTH);
157 
159  GF_API
160  GfDualQuatf GetConjugate() const;
161 
163  GF_API
164  GfDualQuatf GetInverse() const;
165 
167  GF_API
168  void SetTranslation( const GfVec3f &translation );
169 
171  GF_API
172  GfVec3f GetTranslation() const;
173 
175  friend inline size_t hash_value(const GfDualQuatf &dq) {
176  size_t h = 0;
177  boost::hash_combine(h, dq.GetReal());
178  boost::hash_combine(h, dq.GetDual());
179  return h;
180  }
181 
184  bool operator ==(const GfDualQuatf &dq) const {
185  return (GetReal() == dq.GetReal() &&
186  GetDual() == dq.GetDual());
187  }
188 
191  bool operator !=(const GfDualQuatf &dq) const {
192  return ! (*this == dq);
193  }
194 
197  _real += dq._real;
198  _dual += dq._dual;
199  return *this;
200  }
201 
204  _real -= dq._real;
205  _dual -= dq._dual;
206  return *this;
207  }
208 
210  GF_API
211  GfDualQuatf &operator *=(const GfDualQuatf &dq);
212 
215  _real *= s;
216  _dual *= s;
217  return *this;
218  }
219 
222  return (*this) *= 1.0 / s;
223  }
224 
226  friend GfDualQuatf operator +(const GfDualQuatf &dq1,
227  const GfDualQuatf &dq2) {
228  GfDualQuatf dqt = dq1;
229  return dqt += dq2;
230  }
231 
233  friend GfDualQuatf operator -(const GfDualQuatf &dq1,
234  const GfDualQuatf &dq2) {
235  GfDualQuatf dqt = dq1;
236  return dqt -= dq2;
237  }
238 
240  friend GfDualQuatf operator *(const GfDualQuatf &dq1,
241  const GfDualQuatf &dq2) {
242  GfDualQuatf dqt = dq1;
243  return dqt *= dq2;
244  }
245 
247  friend GfDualQuatf operator *(const GfDualQuatf &dq, float s) {
248  GfDualQuatf dqt = dq;
249  return dqt *= s;
250  }
251 
253  friend GfDualQuatf operator *(float s, const GfDualQuatf &dq) {
254  GfDualQuatf dqt = dq;
255  return dqt *= s;
256  }
257 
259  friend GfDualQuatf operator /(const GfDualQuatf &dq, float s) {
260  GfDualQuatf dqt = dq;
261  return dqt /= s;
262  }
263 
265  GF_API
266  GfVec3f Transform(const GfVec3f &vec) const;
267 
268  private:
269  GfQuatf _real; // for rotation
270  GfQuatf _dual; // for translation
271 };
272 
273 
276 GF_API std::ostream &operator<<(std::ostream &out, const GfDualQuatf &dq);
277 
278 
280 inline float
281 GfDot(const GfDualQuatf& dq1, const GfDualQuatf& dq2) {
282  return GfDot(dq1.GetReal(), dq2.GetReal()) + GfDot(dq1.GetDual(), dq2.GetDual());
283 }
284 
285 PXR_NAMESPACE_CLOSE_SCOPE
286 
287 #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:281
void SetDual(const GfQuatf &dual)
Sets the dual part of the dual quaternion.
Definition: dualQuatf.h:115
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:131
Basic type: a real part quaternion and a dual part quaternion.
Definition: dualQuatd.h:67
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:175
friend GfDualQuatf operator -(const GfDualQuatf &dq1, const GfDualQuatf &dq2)
Component-wise binary difference operator.
Definition: dualQuatf.h:233
GfDualQuatf(const GfQuatf &rotation, const GfVec3f &translation)
This constructor initializes from a rotation and a translation components.
Definition: dualQuatf.h:97
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
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:196
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:184
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:60
static GfQuatf GetIdentity()
Return the identity quaternion, with real coefficient 1 and an imaginary coefficients all zero.
Definition: quatf.h:103
void SetReal(const GfQuatf &real)
Sets the real part of the dual quaternion.
Definition: dualQuatf.h:110
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:137
GfDualQuatf(float realVal)
Initialize the real part to realVal and the imaginary part to zero quaternion.
Definition: dualQuatf.h:82
friend GfDualQuatf operator *(const GfDualQuatf &dq1, const GfDualQuatf &dq2)
Returns the product of dual quaternions dq1 and dq2.
Definition: dualQuatf.h:240
friend GfDualQuatf operator *(float s, const GfDualQuatf &dq)
Returns the product of dual quaternion dq and scalar s.
Definition: dualQuatf.h:253
GfDualQuatf & operator/=(float s)
Scales this dual quaternion by 1 / s.
Definition: dualQuatf.h:221
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:67
GfDualQuatf(const GfQuatf &real, const GfQuatf &dual)
This constructor initializes the real and dual parts.
Definition: dualQuatf.h:92
const GfQuatf & GetDual() const
Returns the dual part of the dual quaternion.
Definition: dualQuatf.h:125
GfDualQuatf & operator -=(const GfDualQuatf &dq)
Component-wise unary difference operator.
Definition: dualQuatf.h:203
const GfQuatf & GetReal() const
Returns the real part of the dual quaternion.
Definition: dualQuatf.h:120
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:191
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:99
friend GfDualQuatf operator+(const GfDualQuatf &dq1, const GfDualQuatf &dq2)
Component-wise binary sum operator.
Definition: dualQuatf.h:226
GfDualQuatf & operator *=(float s)
Scales this dual quaternion by s.
Definition: dualQuatf.h:214
friend GfDualQuatf operator/(const GfDualQuatf &dq, float s)
Returns the product of dual quaternion dq and scalar 1 / s.
Definition: dualQuatf.h:259
GfDualQuatf()
The default constructor leaves the dual quaternion undefined.
Definition: dualQuatf.h:73
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:68
GfDualQuatf(const GfQuatf &real)
Initialize the real part to real quaternion and the imaginary part to zero quaternion.
Definition: dualQuatf.h:87
friend GfDualQuatf operator *(const GfDualQuatf &dq, float s)
Returns the product of dual quaternion dq and scalar s.
Definition: dualQuatf.h:247
#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