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