quath.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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 // quat.template.h file to make changes.
27 
28 #ifndef PXR_BASE_GF_QUATH_H
29 #define PXR_BASE_GF_QUATH_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/vec3h.h"
38 #include "pxr/base/gf/traits.h"
39 #include "pxr/base/gf/half.h"
40 
41 #include <boost/functional/hash.hpp>
42 
43 #include <iosfwd>
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
47 template <>
48 struct GfIsGfQuat<class GfQuath> { static const bool value = true; };
49 
50 
52 GfHalf GfDot(const GfQuath& q1, const GfQuath& q2);
53 
54 
61 class GfQuath
62 {
63  public:
64  typedef GfHalf ScalarType;
65  typedef GfVec3h ImaginaryType;
66 
68  GfQuath() {}
69 
77  explicit GfQuath (GfHalf realVal) : _imaginary(0), _real(realVal) {}
78 
81  : _imaginary(i, j, k), _real(real)
82  {
83  }
84 
86  GfQuath(GfHalf real, const GfVec3h &imaginary)
87  : _imaginary(imaginary), _real(real)
88  {
89  }
90 
92  GF_API
93  explicit GfQuath(class GfQuatd const &other);
95  GF_API
96  explicit GfQuath(class GfQuatf const &other);
97 
100  static GfQuath GetZero() { return GfQuath(0.0); }
101 
104  static GfQuath GetIdentity() { return GfQuath(1.0); }
105 
107  GfHalf GetReal() const { return _real; }
108 
110  void SetReal(GfHalf real) { _real = real; }
111 
113  const GfVec3h &GetImaginary() const { return _imaginary; }
114 
116  void SetImaginary(const GfVec3h &imaginary) {
117  _imaginary = imaginary;
118  }
119 
122  _imaginary.Set(i, j, k);
123  }
124 
126  GfHalf GetLength() const { return GfSqrt(_GetLengthSquared()); }
127 
130  GfQuath
132  GfQuath ret(*this);
133  ret.Normalize(eps);
134  return ret;
135  }
136 
140  GF_API
142 
146  return GfQuath(GetReal(), -GetImaginary());
147  }
148 
151  GfQuath GetInverse() const {
152  return GetConjugate() / _GetLengthSquared();
153  }
154 
162  GF_API
163  GfVec3h Transform(const GfVec3h& point) const;
164 
166  friend inline size_t hash_value(const GfQuath &q) {
167  size_t h = boost::hash<ScalarType>()(q.GetReal());
168  boost::hash_combine(h, q.GetImaginary());
169  return h;
170  }
171 
173  GfQuath operator-() const {
174  return GfQuath(-GetReal(), -GetImaginary());
175  }
176 
179  bool operator==(const GfQuath &q) const {
180  return (GetReal() == q.GetReal() &&
181  GetImaginary() == q.GetImaginary());
182  }
183 
186  bool operator!=(const GfQuath &q) const {
187  return !(*this == q);
188  }
189 
191  GF_API
192  GfQuath &operator *=(const GfQuath &q);
193 
196  _real *= s;
197  _imaginary *= s;
198  return *this;
199  }
200 
203  _real /= s;
204  _imaginary /= s;
205  return *this;
206  }
207 
210  _real += q._real;
211  _imaginary += q._imaginary;
212  return *this;
213  }
214 
217  _real -= q._real;
218  _imaginary -= q._imaginary;
219  return *this;
220  }
221 
223  friend GfQuath
224  operator +(const GfQuath &q1, const GfQuath &q2) {
225  return GfQuath(q1) += q2;
226  }
227 
229  friend GfQuath
230  operator -(const GfQuath &q1, const GfQuath &q2) {
231  return GfQuath(q1) -= q2;
232  }
233 
235  friend GfQuath
236  operator *(const GfQuath &q1, const GfQuath &q2) {
237  return GfQuath(q1) *= q2;
238  }
239 
241  friend GfQuath
242  operator *(const GfQuath &q, GfHalf s) {
243  return GfQuath(q) *= s;
244  }
245 
247  friend GfQuath
248  operator *(GfHalf s, const GfQuath &q) {
249  return GfQuath(q) *= s;
250  }
251 
253  friend GfQuath
254  operator /(const GfQuath &q, GfHalf s) {
255  return GfQuath(q) /= s;
256  }
257 
258  private:
260  GfVec3h _imaginary;
261 
263  GfHalf _real;
264 
266  GfHalf
267  _GetLengthSquared() const {
268  return GfDot(*this, *this);
269  }
270 };
271 
276 GF_API GfQuath
277 GfSlerp(double alpha, const GfQuath& q0, const GfQuath& q1);
278 
279 GF_API GfQuath
280 GfSlerp(const GfQuath& q0, const GfQuath& q1, double alpha);
281 
282 inline GfHalf
283 GfDot(GfQuath const &q1, GfQuath const &q2) {
284  return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
285  q1.GetReal()*q2.GetReal();
286 }
287 
290 GF_API std::ostream& operator<<(std::ostream &, GfQuath const &);
291 
292 PXR_NAMESPACE_CLOSE_SCOPE
293 
294 #endif // PXR_BASE_GF_QUATH_H
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quath.h:61
GF_API GfHalf Normalize(GfHalf eps=GF_MIN_VECTOR_LENGTH)
Normalizes this quaternion in place to unit length, returning the length before normalization.
friend GfQuath operator+(const GfQuath &q1, const GfQuath &q2)
Component-wise binary sum operator.
Definition: quath.h:224
bool operator==(const GfQuath &q) const
Component-wise quaternion equality test.
Definition: quath.h:179
GfQuath & operator/=(GfHalf s)
Divide this quaternion's coefficients by s.
Definition: quath.h:202
pxr_half::half GfHalf
A 16-bit floating point data type.
Definition: half.h:43
void SetReal(GfHalf real)
Set the real coefficient.
Definition: quath.h:110
This header serves to simply bring in the half float datatype and provide a hash_value function.
void SetImaginary(GfHalf i, GfHalf j, GfHalf k)
Set the imaginary coefficients.
Definition: quath.h:121
GfQuath & operator *=(GfHalf s)
Multiply this quaternion's coefficients by s.
Definition: quath.h:195
Declares Gf types.
friend GfQuath operator *(const GfQuath &q, GfHalf s)
Returns the product of quaternion q and scalar s.
Definition: quath.h:242
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:60
GF_API GfVec3h Transform(const GfVec3h &point) const
Transform the GfVec3h point.
GfQuath & operator+=(const GfQuath &q)
Add quaternion q to this quaternion.
Definition: quath.h:209
GfQuath(GfHalf real, GfHalf i, GfHalf j, GfHalf k)
Initialize the real and imaginary coefficients.
Definition: quath.h:80
GF_API std::ostream & operator<<(std::ostream &, GfQuath const &)
Output a GfQuatd using the format (re, i, j, k)
static GfQuath GetIdentity()
Return the identity quaternion, with real coefficient 1 and an imaginary coefficients all zero.
Definition: quath.h:104
GfQuath GetInverse() const
Return this quaternion's inverse, or reciprocal.
Definition: quath.h:151
GfQuath operator-() const
Component-wise negation.
Definition: quath.h:173
GfHalf GetReal() const
Return the real coefficient.
Definition: quath.h:107
GfQuath()
Default constructor leaves the quaternion undefined.
Definition: quath.h:68
GfQuath(GfHalf real, const GfVec3h &imaginary)
Initialize the real and imaginary coefficients.
Definition: quath.h:86
GfQuath(GfHalf realVal)
Initialize the real coefficient to realVal and the imaginary coefficients to zero.
Definition: quath.h:77
friend size_t hash_value(const GfQuath &q)
Hash.
Definition: quath.h:166
friend GfQuath operator/(const GfQuath &q, GfHalf s)
Returns the product of quaternion q and scalar 1 / s.
Definition: quath.h:254
static GfQuath GetZero()
Return the zero quaternion, with real coefficient 0 and an imaginary coefficients all zero.
Definition: quath.h:100
double GfSqrt(double f)
Return sqrt(f).
Definition: math.h:80
GfQuath GetConjugate() const
Return this quaternion's conjugate, which is the quaternion with the same real coefficient and negate...
Definition: quath.h:145
GfVec3h & Set(GfHalf s0, GfHalf s1, GfHalf s2)
Set all elements with passed arguments.
Definition: vec3h.h:131
GfHalf GetLength() const
Return geometric length of this quaternion.
Definition: quath.h:126
friend GfQuath operator *(GfHalf s, const GfQuath &q)
Returns the product of quaternion q and scalar s.
Definition: quath.h:248
friend GfQuath operator *(const GfQuath &q1, const GfQuath &q2)
Returns the product of quaternions q1 and q2.
Definition: quath.h:236
const GfVec3h & GetImaginary() const
Return the imaginary coefficient.
Definition: quath.h:113
GfQuath & operator -=(const GfQuath &q)
Component-wise unary difference operator.
Definition: quath.h:216
bool operator!=(const GfQuath &q) const
Component-wise quaternion inequality test.
Definition: quath.h:186
A metafunction with a static const bool member 'value' that is true for GfQuat types and false for al...
Definition: traits.h:47
GfQuath GetNormalized(GfHalf eps=GF_MIN_VECTOR_LENGTH) const
length of this quaternion is smaller than eps, return the identity quaternion.
Definition: quath.h:131
GF_API GfQuath & operator *=(const GfQuath &q)
Post-multiply quaternion q into this quaternion.
GfHalf GfDot(const GfQuath &q1, const GfQuath &q2)
Return the dot (inner) product of two quaternions.
Definition: quath.h:283
GF_API GfQuath GfSlerp(double alpha, const GfQuath &q0, const GfQuath &q1)
Spherically linearly interpolate between q0 and q1.
friend GfQuath operator -(const GfQuath &q1, const GfQuath &q2)
Component-wise binary difference operator.
Definition: quath.h:230
void SetImaginary(const GfVec3h &imaginary)
Set the imaginary coefficients.
Definition: quath.h:116
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatd.h:60
Basic type for a vector of 3 GfHalf components.
Definition: vec3h.h:64
#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