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