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 //
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 
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 
42 #include <boost/functional/hash.hpp>
43 
44 #include <iosfwd>
45 
46 PXR_NAMESPACE_OPEN_SCOPE
47 
48 template <>
49 struct GfIsGfDualQuat<class GfDualQuath> { static const bool value = true; };
50 
52 GfHalf GfDot(const GfDualQuath& dq1, const GfDualQuath& dq2);
53 
54 
68 class GfDualQuath final
69 {
70  public:
71  typedef GfHalf ScalarType;
72 
75 
83  explicit GfDualQuath( GfHalf realVal ) : _real( realVal ), _dual( 0 ) {}
84 
88  explicit GfDualQuath( const GfQuath &real )
89  : _real( real ), _dual( 0 ) {
90  }
91 
93  GfDualQuath( const GfQuath &real, const GfQuath &dual )
94  : _real( real ), _dual( dual ) {
95  }
96 
98  GfDualQuath( const GfQuath &rotation, const GfVec3h &translation )
99  : _real( rotation ) {
100  SetTranslation( translation );
101  }
102 
104  GF_API
105  explicit GfDualQuath(const GfDualQuatd &other);
107  GF_API
108  explicit GfDualQuath(const GfDualQuatf &other);
109 
111  void SetReal(const GfQuath &real) {
112  _real = real;
113  }
114 
116  void SetDual(const GfQuath &dual) {
117  _dual = dual;
118  }
119 
121  const GfQuath &GetReal() const {
122  return _real;
123  }
124 
126  const GfQuath &GetDual() const {
127  return _dual;
128  }
129 
132  static GfDualQuath GetZero() {
134  }
135 
140  }
141 
143  GF_API
144  std::pair<GfHalf, GfHalf> GetLength() const;
145 
149  GF_API
151 
156  GF_API
157  std::pair<GfHalf, GfHalf> Normalize(GfHalf eps = GF_MIN_VECTOR_LENGTH);
158 
160  GF_API
161  GfDualQuath GetConjugate() const;
162 
164  GF_API
165  GfDualQuath GetInverse() const;
166 
168  GF_API
169  void SetTranslation( const GfVec3h &translation );
170 
172  GF_API
173  GfVec3h GetTranslation() const;
174 
176  friend inline size_t hash_value(const GfDualQuath &dq) {
177  size_t h = 0;
178  boost::hash_combine(h, dq.GetReal());
179  boost::hash_combine(h, dq.GetDual());
180  return h;
181  }
182 
185  bool operator ==(const GfDualQuath &dq) const {
186  return (GetReal() == dq.GetReal() &&
187  GetDual() == dq.GetDual());
188  }
189 
192  bool operator !=(const GfDualQuath &dq) const {
193  return ! (*this == dq);
194  }
195 
198  _real += dq._real;
199  _dual += dq._dual;
200  return *this;
201  }
202 
205  _real -= dq._real;
206  _dual -= dq._dual;
207  return *this;
208  }
209 
211  GF_API
212  GfDualQuath &operator *=(const GfDualQuath &dq);
213 
216  _real *= s;
217  _dual *= s;
218  return *this;
219  }
220 
223  return (*this) *= 1.0 / s;
224  }
225 
227  friend GfDualQuath operator +(const GfDualQuath &dq1,
228  const GfDualQuath &dq2) {
229  GfDualQuath dqt = dq1;
230  return dqt += dq2;
231  }
232 
234  friend GfDualQuath operator -(const GfDualQuath &dq1,
235  const GfDualQuath &dq2) {
236  GfDualQuath dqt = dq1;
237  return dqt -= dq2;
238  }
239 
241  friend GfDualQuath operator *(const GfDualQuath &dq1,
242  const GfDualQuath &dq2) {
243  GfDualQuath dqt = dq1;
244  return dqt *= dq2;
245  }
246 
248  friend GfDualQuath operator *(const GfDualQuath &dq, GfHalf s) {
249  GfDualQuath dqt = dq;
250  return dqt *= s;
251  }
252 
254  friend GfDualQuath operator *(GfHalf s, const GfDualQuath &dq) {
255  GfDualQuath dqt = dq;
256  return dqt *= s;
257  }
258 
260  friend GfDualQuath operator /(const GfDualQuath &dq, GfHalf s) {
261  GfDualQuath dqt = dq;
262  return dqt /= s;
263  }
264 
266  GF_API
267  GfVec3h Transform(const GfVec3h &vec) const;
268 
269  private:
270  GfQuath _real; // for rotation
271  GfQuath _dual; // for translation
272 };
273 
274 
277 GF_API std::ostream &operator<<(std::ostream &out, const GfDualQuath &dq);
278 
279 
281 inline GfHalf
282 GfDot(const GfDualQuath& dq1, const GfDualQuath& dq2) {
283  return GfDot(dq1.GetReal(), dq2.GetReal()) + GfDot(dq1.GetDual(), dq2.GetDual());
284 }
285 
286 PXR_NAMESPACE_CLOSE_SCOPE
287 
288 #endif // PXR_BASE_GF_DUALQUATH_H
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quath.h:61
friend size_t hash_value(const GfDualQuath &dq)
Hash.
Definition: dualQuath.h:176
friend GfDualQuath operator+(const GfDualQuath &dq1, const GfDualQuath &dq2)
Component-wise binary sum operator.
Definition: dualQuath.h:227
bool operator !=(const GfDualQuath &dq) const
Component-wise dual quaternion inequality test.
Definition: dualQuath.h:192
Basic type: a real part quaternion and a dual part quaternion.
Definition: dualQuatd.h:67
GfDualQuath & operator+=(const GfDualQuath &dq)
Component-wise unary sum operator.
Definition: dualQuath.h:197
pxr_half::half GfHalf
A 16-bit floating point data type.
Definition: half.h:43
friend GfDualQuath operator *(const GfDualQuath &dq, GfHalf s)
Returns the product of dual quaternion dq and scalar s.
Definition: dualQuath.h:248
This header serves to simply bring in the half float datatype and provide a hash_value function.
GfHalf GfDot(const GfDualQuath &dq1, const GfDualQuath &dq2)
Return the dot (inner) product of two dual quaternions.
Definition: dualQuath.h:282
GF_API GfDualQuath GetConjugate() const
Returns the conjugate of this dual quaternion.
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 void SetTranslation(const GfVec3h &translation)
Set the translation component of this dual quaternion.
const GfQuath & GetReal() const
Returns the real part of the dual quaternion.
Definition: dualQuath.h:121
GF_API std::pair< GfHalf, GfHalf > GetLength() const
Returns geometric length of this dual quaternion.
GfDualQuath(const GfQuath &real)
Initialize the real part to real quaternion and the imaginary part to zero quaternion.
Definition: dualQuath.h:88
static GfQuath GetIdentity()
Return the identity quaternion, with real coefficient 1 and an imaginary coefficients all zero.
Definition: quath.h:104
const GfQuath & GetDual() const
Returns the dual part of the dual quaternion.
Definition: dualQuath.h:126
GfDualQuath & operator -=(const GfDualQuath &dq)
Component-wise unary difference operator.
Definition: dualQuath.h:204
void SetReal(const GfQuath &real)
Sets the real part of the dual quaternion.
Definition: dualQuath.h:111
GfDualQuath & operator/=(GfHalf s)
Scales this dual quaternion by 1 / s.
Definition: dualQuath.h:222
GF_API GfVec3h Transform(const GfVec3h &vec) const
Transforms the row vector vec by the dual quaternion.
GfDualQuath(GfHalf realVal)
Initialize the real part to realVal and the imaginary part to zero quaternion.
Definition: dualQuath.h:83
GfDualQuath(const GfQuath &real, const GfQuath &dual)
This constructor initializes the real and dual parts.
Definition: dualQuath.h:93
Basic type: a real part quaternion and a dual part quaternion.
Definition: dualQuatf.h:67
GfDualQuath()
The default constructor leaves the dual quaternion undefined.
Definition: dualQuath.h:74
static GfQuath GetZero()
Return the zero quaternion, with real coefficient 0 and an imaginary coefficients all zero.
Definition: quath.h:100
static GfDualQuath GetZero()
Returns the zero dual quaternion, which has a real part of (0,0,0,0) and a dual part of (0,...
Definition: dualQuath.h:132
friend GfDualQuath operator/(const GfDualQuath &dq, GfHalf s)
Returns the product of dual quaternion dq and scalar 1 / s.
Definition: dualQuath.h:260
void SetDual(const GfQuath &dual)
Sets the dual part of the dual quaternion.
Definition: dualQuath.h:116
GF_API std::pair< GfHalf, GfHalf > Normalize(GfHalf eps=GF_MIN_VECTOR_LENGTH)
Normalizes this dual quaternion in place.
GF_API GfDualQuath GetNormalized(GfHalf eps=GF_MIN_VECTOR_LENGTH) const
Returns a normalized (unit-length) version of this dual quaternion.
friend GfDualQuath operator *(GfHalf s, const GfDualQuath &dq)
Returns the product of dual quaternion dq and scalar s.
Definition: dualQuath.h:254
GfDualQuath & operator *=(GfHalf s)
Scales this dual quaternion by s.
Definition: dualQuath.h:215
GfDualQuath(const GfQuath &rotation, const GfVec3h &translation)
This constructor initializes from a rotation and a translation components.
Definition: dualQuath.h:98
GF_API GfDualQuath & operator *=(const GfDualQuath &dq)
Post-multiplies dual quaternion dq into this dual quaternion.
bool operator==(const GfDualQuath &dq) const
Component-wise dual quaternion equality test.
Definition: dualQuath.h:185
GF_API std::ostream & operator<<(std::ostream &out, const GfDualQuath &dq)
Output a GfDualQuath using the format ((rw, rx, ry, rz), (dw, dx, dy, dz)).
GF_API GfDualQuath GetInverse() const
Returns the inverse 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:241
GF_API GfVec3h GetTranslation() const
Get the translation component of this dual quaternion.
static GfDualQuath GetIdentity()
Returns the identity dual quaternion, which has a real part of (1,0,0,0) and a dual part of (0,...
Definition: dualQuath.h:138
Basic type for a vector of 3 GfHalf components.
Definition: vec3h.h:64
friend GfDualQuath operator -(const GfDualQuath &dq1, const GfDualQuath &dq2)
Component-wise binary difference operator.
Definition: dualQuath.h:234
Basic type: a real part quaternion and a dual part quaternion.
Definition: dualQuath.h:68
#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