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  /// Default constructor leaves the quaternion undefined.
49  GfQuatd() {}
50 
51  /// Initialize the real coefficient to \p realVal and the imaginary
52  /// coefficients to zero.
53  ///
54  /// Since quaternions typically must be normalized, reasonable values for
55  /// \p realVal are -1, 0, or 1. Other values are legal but are likely to
56  /// be meaningless.
57  ///
58  explicit GfQuatd (double realVal) : _imaginary(0), _real(realVal) {}
59 
60  /// Initialize the real and imaginary coefficients.
61  GfQuatd(double real, double i, double j, double k)
62  : _imaginary(i, j, k), _real(real)
63  {
64  }
65 
66  /// Initialize the real and imaginary coefficients.
67  GfQuatd(double real, const GfVec3d &imaginary)
68  : _imaginary(imaginary), _real(real)
69  {
70  }
71 
72  /// Implicitly convert from GfQuatf.
73  GF_API
74  GfQuatd(class GfQuatf const &other);
75  /// Implicitly convert from GfQuath.
76  GF_API
77  GfQuatd(class GfQuath const &other);
78 
79  /// Return the zero quaternion, with real coefficient 0 and an
80  /// imaginary coefficients all zero.
81  static GfQuatd GetZero() { return GfQuatd(0.0); }
82 
83  /// Return the identity quaternion, with real coefficient 1 and an
84  /// imaginary coefficients all zero.
85  static GfQuatd GetIdentity() { return GfQuatd(1.0); }
86 
87  /// Return the real coefficient.
88  double GetReal() const { return _real; }
89 
90  /// Set the real coefficient.
91  void SetReal(double real) { _real = real; }
92 
93  /// Return the imaginary coefficient.
94  const GfVec3d &GetImaginary() const { return _imaginary; }
95 
96  /// Set the imaginary coefficients.
97  void SetImaginary(const GfVec3d &imaginary) {
98  _imaginary = imaginary;
99  }
100 
101  /// Set the imaginary coefficients.
102  void SetImaginary(double i, double j, double k) {
103  _imaginary.Set(i, j, k);
104  }
105 
106  /// Return geometric length of this quaternion.
107  double GetLength() const { return GfSqrt(_GetLengthSquared()); }
108 
109  /// length of this quaternion is smaller than \p eps, return the identity
110  /// quaternion.
111  GfQuatd
112  GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const {
113  GfQuatd ret(*this);
114  ret.Normalize(eps);
115  return ret;
116  }
117 
118  /// Normalizes this quaternion in place to unit length, returning the
119  /// length before normalization. If the length of this quaternion is
120  /// smaller than \p eps, this sets the quaternion to identity.
121  GF_API
122  double Normalize(double eps = GF_MIN_VECTOR_LENGTH);
123 
124  /// Return this quaternion's conjugate, which is the quaternion with the
125  /// same real coefficient and negated imaginary coefficients.
127  return GfQuatd(GetReal(), -GetImaginary());
128  }
129 
130  /// Return this quaternion's inverse, or reciprocal. This is the
131  /// quaternion's conjugate divided by it's squared length.
132  GfQuatd GetInverse() const {
133  return GetConjugate() / _GetLengthSquared();
134  }
135 
136  /// Transform the GfVec3d point. If the quaternion is normalized,
137  /// the transformation is a rotation. Given a GfQuatd q, q.Transform(point)
138  /// is equivalent to:
139  ///
140  /// (q * GfQuatd(0, point) * q.GetInverse()).GetImaginary()
141  ///
142  /// but is more efficient.
143  GF_API
144  GfVec3d Transform(const GfVec3d& point) const;
145 
146  /// Hash.
147  friend inline size_t hash_value(const GfQuatd &q) {
148  return TfHash::Combine(q.GetReal(), q.GetImaginary());
149  }
150 
151  /// Component-wise negation.
152  GfQuatd operator-() const {
153  return GfQuatd(-GetReal(), -GetImaginary());
154  }
155 
156  /// Component-wise quaternion equality test. The real and imaginary parts
157  /// must match exactly for quaternions to be considered equal.
158  bool operator==(const GfQuatd &q) const {
159  return (GetReal() == q.GetReal() &&
160  GetImaginary() == q.GetImaginary());
161  }
162 
163  /// Component-wise quaternion inequality test. The real and imaginary
164  /// parts must match exactly for quaternions to be considered equal.
165  bool operator!=(const GfQuatd &q) const {
166  return !(*this == q);
167  }
168 
169  /// Post-multiply quaternion \p q into this quaternion.
170  GF_API
171  GfQuatd &operator *=(const GfQuatd &q);
172 
173  /// Multiply this quaternion's coefficients by \p s.
174  GfQuatd &operator *=(double s) {
175  _real *= s;
176  _imaginary *= s;
177  return *this;
178  }
179 
180  /// Divide this quaternion's coefficients by \p s.
181  GfQuatd &operator /=(double s) {
182  _real /= s;
183  _imaginary /= s;
184  return *this;
185  }
186 
187  /// Add quaternion \p q to this quaternion.
189  _real += q._real;
190  _imaginary += q._imaginary;
191  return *this;
192  }
193 
194  /// Component-wise unary difference operator.
196  _real -= q._real;
197  _imaginary -= q._imaginary;
198  return *this;
199  }
200 
201  /// Component-wise binary sum operator.
202  friend GfQuatd
203  operator +(const GfQuatd &q1, const GfQuatd &q2) {
204  return GfQuatd(q1) += q2;
205  }
206 
207  /// Component-wise binary difference operator.
208  friend GfQuatd
209  operator -(const GfQuatd &q1, const GfQuatd &q2) {
210  return GfQuatd(q1) -= q2;
211  }
212 
213  /// Returns the product of quaternions \p q1 and \p q2.
214  friend GfQuatd
215  operator *(const GfQuatd &q1, const GfQuatd &q2) {
216  return GfQuatd(q1) *= q2;
217  }
218 
219  /// Returns the product of quaternion \p q and scalar \p s.
220  friend GfQuatd
221  operator *(const GfQuatd &q, double s) {
222  return GfQuatd(q) *= s;
223  }
224 
225  /// Returns the product of quaternion \p q and scalar \p s.
226  friend GfQuatd
227  operator *(double s, const GfQuatd &q) {
228  return GfQuatd(q) *= s;
229  }
230 
231  /// Returns the product of quaternion \p q and scalar 1 / \p s.
232  friend GfQuatd
233  operator /(const GfQuatd &q, double s) {
234  return GfQuatd(q) /= s;
235  }
236 
237  private:
238  /// Imaginary part
239  GfVec3d _imaginary;
240 
241  /// Real part
242  double _real;
243 
244  /// Returns the square of the length
245  double
246  _GetLengthSquared() const {
247  return GfDot(*this, *this);
248  }
249 };
250 
251 /// Spherically linearly interpolate between \p q0 and \p q1.
252 ///
253 /// If the interpolant \p alpha is zero, then the result is \p q0, while
254 /// \p alpha of one yields \p q1.
256 GfSlerp(double alpha, const GfQuatd& q0, const GfQuatd& q1);
257 
259 GfSlerp(const GfQuatd& q0, const GfQuatd& q1, double alpha);
260 
261 inline double
262 GfDot(GfQuatd const &q1, GfQuatd const &q2) {
263  return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
264  q1.GetReal()*q2.GetReal();
265 }
266 
267 /// Output a GfQuatd using the format (re, i, j, k)
268 /// \ingroup group_gf_DebuggingOutput
269 GF_API std::ostream& operator<<(std::ostream &, GfQuatd const &);
270 
272 
273 #endif // PXR_BASE_GF_QUATD_H
Definition: quath.h:43
const GfVec3d & GetImaginary() const
Return the imaginary coefficient.
Definition: quatd.h:94
GfQuatd GetNormalized(double eps=GF_MIN_VECTOR_LENGTH) const
Definition: quatd.h:112
GfQuatd & operator+=(const GfQuatd &q)
Add quaternion q to this quaternion.
Definition: quatd.h:188
GfQuatd()
Default constructor leaves the quaternion undefined.
Definition: quatd.h:49
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
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:262
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:195
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:107
static GfQuatd GetIdentity()
Definition: quatd.h:85
GF_API GfQuatd GfSlerp(double alpha, const GfQuatd &q0, const GfQuatd &q1)
double GetReal() const
Return the real coefficient.
Definition: quatd.h:88
GF_API GfQuatd & operator*=(const GfQuatd &q)
Post-multiply quaternion q into this quaternion.
GfQuatd GetInverse() const
Definition: quatd.h:132
GfQuatd GetConjugate() const
Definition: quatd.h:126
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:61
bool operator!=(const GfQuatd &q) const
Definition: quatd.h:165
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
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GfQuatd(double realVal)
Definition: quatd.h:58
GfQuatd & operator/=(double s)
Divide this quaternion's coefficients by s.
Definition: quatd.h:181
void SetImaginary(const GfVec3d &imaginary)
Set the imaginary coefficients.
Definition: quatd.h:97
GfVec3d & Set(double s0, double s1, double s2)
Set all elements with passed arguments.
Definition: vec3d.h:112
friend GfQuatd operator+(const GfQuatd &q1, const GfQuatd &q2)
Component-wise binary sum operator.
Definition: quatd.h:203
void SetImaginary(double i, double j, double k)
Set the imaginary coefficients.
Definition: quatd.h:102
void SetReal(double real)
Set the real coefficient.
Definition: quatd.h:91
Definition: vec3d.h:45
friend size_t hash_value(const GfQuatd &q)
Hash.
Definition: quatd.h:147
#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:215
GfQuatd operator-() const
Component-wise negation.
Definition: quatd.h:152
GF_API GfVec3d Transform(const GfVec3d &point) const
static GfQuatd GetZero()
Definition: quatd.h:81
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:67
bool operator==(const GfQuatd &q) const
Definition: quatd.h:158
#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:233
#define GF_API
Definition: api.h:23
GfVec3d ImaginaryType
Definition: quatd.h:46