HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
quatd.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 ////////////////////////////////////////////////////////////////////////
8 // This file is generated by a script. Do not edit directly. Edit the
9 // quat.template.h file to make changes.
10 
11 #ifndef PXR_BASE_GF_QUATD_H
12 #define PXR_BASE_GF_QUATD_H
13 
14 /// \file gf/quatd.h
15 /// \ingroup group_gf_LinearAlgebra
16 
17 #include "pxr/pxr.h"
18 #include "pxr/base/gf/api.h"
19 #include "pxr/base/gf/declare.h"
20 #include "pxr/base/gf/vec3d.h"
21 #include "pxr/base/gf/traits.h"
22 #include "pxr/base/tf/hash.h"
23 
24 #include <iosfwd>
25 
27 
28 template <>
29 struct GfIsGfQuat<class GfQuatd> { static const bool value = true; };
30 
31 
32 /// Return the dot (inner) product of two quaternions.
33 double GfDot(const GfQuatd& q1, const GfQuatd& q2);
34 
35 
36 /// \class GfQuatd
37 /// \ingroup group_gf_LinearAlgebra
38 ///
39 /// Basic type: a quaternion, a complex number with a real coefficient and
40 /// three imaginary coefficients, stored as a 3-vector.
41 ///
42 class GfQuatd
43 {
44  public:
45  typedef double ScalarType;
47 
48  /// GfQuatd value-initializes to zero and performs no default
49  /// initialization, like float or double.
50  GfQuatd() = default;
51 
52  /// Initialize the real coefficient to \p realVal and the imaginary
53  /// coefficients to zero.
54  ///
55  /// Since quaternions typically must be normalized, reasonable values for
56  /// \p realVal are -1, 0, or 1. Other values are legal but are likely to
57  /// be meaningless.
58  ///
59  explicit GfQuatd (double realVal) : _imaginary(0), _real(realVal) {}
60 
61  /// Initialize the real and imaginary coefficients.
62  GfQuatd(double real, double i, double j, double k)
63  : _imaginary(i, j, k), _real(real)
64  {
65  }
66 
67  /// Initialize the real and imaginary coefficients.
68  GfQuatd(double real, const GfVec3d &imaginary)
69  : _imaginary(imaginary), _real(real)
70  {
71  }
72 
73  /// Implicitly convert from GfQuatf.
74  GF_API
75  GfQuatd(class GfQuatf const &other);
76  /// Implicitly convert from GfQuath.
77  GF_API
78  GfQuatd(class GfQuath const &other);
79 
80  /// Return the zero quaternion, with real coefficient 0 and an
81  /// imaginary coefficients all zero.
82  static GfQuatd GetZero() { return GfQuatd(0.0); }
83 
84  /// Return the identity quaternion, with real coefficient 1 and an
85  /// imaginary coefficients all zero.
86  static GfQuatd GetIdentity() { return GfQuatd(1.0); }
87 
88  /// Return the real coefficient.
89  double GetReal() const { return _real; }
90 
91  /// Set the real coefficient.
92  void SetReal(double real) { _real = real; }
93 
94  /// Return the imaginary coefficient.
95  const GfVec3d &GetImaginary() const { return _imaginary; }
96 
97  /// Set the imaginary coefficients.
98  void SetImaginary(const GfVec3d &imaginary) {
99  _imaginary = imaginary;
100  }
101 
102  /// Set the imaginary coefficients.
103  void SetImaginary(double i, double j, double k) {
104  _imaginary.Set(i, j, k);
105  }
106 
107  /// Return geometric length of this quaternion.
108  double GetLength() const { return GfSqrt(_GetLengthSquared()); }
109 
110  /// length of this quaternion is smaller than \p eps, return the identity
111  /// quaternion.
112  GfQuatd
113  GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const {
114  GfQuatd ret(*this);
115  ret.Normalize(eps);
116  return ret;
117  }
118 
119  /// Normalizes this quaternion in place to unit length, returning the
120  /// length before normalization. If the length of this quaternion is
121  /// smaller than \p eps, this sets the quaternion to identity.
122  GF_API
123  double Normalize(double eps = GF_MIN_VECTOR_LENGTH);
124 
125  /// Return this quaternion's conjugate, which is the quaternion with the
126  /// same real coefficient and negated imaginary coefficients.
128  return GfQuatd(GetReal(), -GetImaginary());
129  }
130 
131  /// Return this quaternion's inverse, or reciprocal. This is the
132  /// quaternion's conjugate divided by it's squared length.
133  GfQuatd GetInverse() const {
134  return GetConjugate() / _GetLengthSquared();
135  }
136 
137  /// Transform the GfVec3d point. If the quaternion is normalized,
138  /// the transformation is a rotation. Given a GfQuatd q, q.Transform(point)
139  /// is equivalent to:
140  ///
141  /// (q * GfQuatd(0, point) * q.GetInverse()).GetImaginary()
142  ///
143  /// but is more efficient.
144  GF_API
145  GfVec3d Transform(const GfVec3d& point) const;
146 
147  /// Hash.
148  friend inline size_t hash_value(const GfQuatd &q) {
149  return TfHash::Combine(q.GetReal(), q.GetImaginary());
150  }
151 
152  /// Component-wise negation.
153  GfQuatd operator-() const {
154  return GfQuatd(-GetReal(), -GetImaginary());
155  }
156 
157  /// Component-wise quaternion equality test. The real and imaginary parts
158  /// must match exactly for quaternions to be considered equal.
159  bool operator==(const GfQuatd &q) const {
160  return (GetReal() == q.GetReal() &&
161  GetImaginary() == q.GetImaginary());
162  }
163 
164  /// Component-wise quaternion inequality test. The real and imaginary
165  /// parts must match exactly for quaternions to be considered equal.
166  bool operator!=(const GfQuatd &q) const {
167  return !(*this == q);
168  }
169 
170  /// Post-multiply quaternion \p q into this quaternion.
171  GF_API
172  GfQuatd &operator *=(const GfQuatd &q);
173 
174  /// Multiply this quaternion's coefficients by \p s.
175  GfQuatd &operator *=(double s) {
176  _real *= s;
177  _imaginary *= s;
178  return *this;
179  }
180 
181  /// Divide this quaternion's coefficients by \p s.
182  GfQuatd &operator /=(double s) {
183  _real /= s;
184  _imaginary /= s;
185  return *this;
186  }
187 
188  /// Add quaternion \p q to this quaternion.
190  _real += q._real;
191  _imaginary += q._imaginary;
192  return *this;
193  }
194 
195  /// Component-wise unary difference operator.
197  _real -= q._real;
198  _imaginary -= q._imaginary;
199  return *this;
200  }
201 
202  /// Component-wise binary sum operator.
203  friend GfQuatd
204  operator +(const GfQuatd &q1, const GfQuatd &q2) {
205  return GfQuatd(q1) += q2;
206  }
207 
208  /// Component-wise binary difference operator.
209  friend GfQuatd
210  operator -(const GfQuatd &q1, const GfQuatd &q2) {
211  return GfQuatd(q1) -= q2;
212  }
213 
214  /// Returns the product of quaternions \p q1 and \p q2.
215  friend GfQuatd
216  operator *(const GfQuatd &q1, const GfQuatd &q2) {
217  return GfQuatd(q1) *= q2;
218  }
219 
220  /// Returns the product of quaternion \p q and scalar \p s.
221  friend GfQuatd
222  operator *(const GfQuatd &q, double s) {
223  return GfQuatd(q) *= s;
224  }
225 
226  /// Returns the product of quaternion \p q and scalar \p s.
227  friend GfQuatd
228  operator *(double s, const GfQuatd &q) {
229  return GfQuatd(q) *= s;
230  }
231 
232  /// Returns the product of quaternion \p q and scalar 1 / \p s.
233  friend GfQuatd
234  operator /(const GfQuatd &q, double s) {
235  return GfQuatd(q) /= s;
236  }
237 
238  private:
239  /// Imaginary part
240  GfVec3d _imaginary;
241 
242  /// Real part
243  double _real;
244 
245  /// Returns the square of the length
246  double
247  _GetLengthSquared() const {
248  return GfDot(*this, *this);
249  }
250 };
251 
252 /// Spherically linearly interpolate between \p q0 and \p q1.
253 ///
254 /// If the interpolant \p alpha is zero, then the result is \p q0, while
255 /// \p alpha of one yields \p q1.
257 GfSlerp(double alpha, const GfQuatd& q0, const GfQuatd& q1);
258 
260 GfSlerp(const GfQuatd& q0, const GfQuatd& q1, double alpha);
261 
262 inline double
263 GfDot(GfQuatd const &q1, GfQuatd const &q2) {
264  return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
265  q1.GetReal()*q2.GetReal();
266 }
267 
268 /// Output a GfQuatd using the format (re, i, j, k)
269 /// \ingroup group_gf_DebuggingOutput
270 GF_API std::ostream& operator<<(std::ostream &, GfQuatd const &);
271 
273 
274 #endif // PXR_BASE_GF_QUATD_H
Definition: quath.h:43
const GfVec3d & GetImaginary() const
Return the imaginary coefficient.
Definition: quatd.h:95
GfQuatd GetNormalized(double eps=GF_MIN_VECTOR_LENGTH) const
Definition: quatd.h:113
GfQuatd & operator+=(const GfQuatd &q)
Add quaternion q to this quaternion.
Definition: quatd.h:189
double GfSqrt(double f)
Definition: math.h:187
*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:632
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
double GfDot(const GfQuatd &q1, const GfQuatd &q2)
Return the dot (inner) product of two quaternions.
Definition: quatd.h:263
GF_API std::ostream & operator<<(std::ostream &, GfQuatd const &)
GLdouble s
Definition: glad.h:3009
GfQuatd & operator-=(const GfQuatd &q)
Component-wise unary difference operator.
Definition: quatd.h:196
GLdouble GLdouble GLdouble q
Definition: glad.h:2445
double ScalarType
Definition: quatd.h:45
Definition: quatf.h:42
double GetLength() const
Return geometric length of this quaternion.
Definition: quatd.h:108
static GfQuatd GetIdentity()
Definition: quatd.h:86
GF_API GfQuatd GfSlerp(double alpha, const GfQuatd &q0, const GfQuatd &q1)
double GetReal() const
Return the real coefficient.
Definition: quatd.h:89
GfQuatd()=default
GF_API GfQuatd & operator*=(const GfQuatd &q)
Post-multiply quaternion q into this quaternion.
GfQuatd GetInverse() const
Definition: quatd.h:133
GfQuatd GetConjugate() const
Definition: quatd.h:127
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
GfQuatd(double real, double i, double j, double k)
Initialize the real and imaginary coefficients.
Definition: quatd.h:62
bool operator!=(const GfQuatd &q) const
Definition: quatd.h:166
GLint j
Definition: glad.h:2733
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
GfQuatd(double realVal)
Definition: quatd.h:59
GfQuatd & operator/=(double s)
Divide this quaternion's coefficients by s.
Definition: quatd.h:182
void SetImaginary(const GfVec3d &imaginary)
Set the imaginary coefficients.
Definition: quatd.h:98
GfVec3d & Set(double s0, double s1, double s2)
Set all elements with passed arguments.
Definition: vec3d.h:113
friend GfQuatd operator+(const GfQuatd &q1, const GfQuatd &q2)
Component-wise binary sum operator.
Definition: quatd.h:204
void SetImaginary(double i, double j, double k)
Set the imaginary coefficients.
Definition: quatd.h:103
void SetReal(double real)
Set the real coefficient.
Definition: quatd.h:92
Definition: vec3d.h:45
friend size_t hash_value(const GfQuatd &q)
Hash.
Definition: quatd.h:148
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
friend GfQuatd operator*(const GfQuatd &q1, const GfQuatd &q2)
Returns the product of quaternions q1 and q2.
Definition: quatd.h:216
GfQuatd operator-() const
Component-wise negation.
Definition: quatd.h:153
GF_API GfVec3d Transform(const GfVec3d &point) const
static GfQuatd GetZero()
Definition: quatd.h:82
GF_API double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Definition: quatd.h:42
GfQuatd(double real, const GfVec3d &imaginary)
Initialize the real and imaginary coefficients.
Definition: quatd.h:68
bool operator==(const GfQuatd &q) const
Definition: quatd.h:159
#define GF_MIN_VECTOR_LENGTH
Definition: limits.h:17
friend GfQuatd operator/(const GfQuatd &q, double s)
Returns the product of quaternion q and scalar 1 / s.
Definition: quatd.h:234
#define GF_API
Definition: api.h:23
GfVec3d ImaginaryType
Definition: quatd.h:46