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 //
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 
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 <boost/functional/hash.hpp>
41 
42 #include <iosfwd>
43 
44 PXR_NAMESPACE_OPEN_SCOPE
45 
46 template <>
47 struct GfIsGfQuat<class GfQuatd> { static const bool value = true; };
48 
49 
51 double GfDot(const GfQuatd& q1, const GfQuatd& q2);
52 
53 
60 class GfQuatd
61 {
62  public:
63  typedef double ScalarType;
64  typedef GfVec3d ImaginaryType;
65 
67  GfQuatd() {}
68 
76  explicit GfQuatd (double realVal) : _imaginary(0), _real(realVal) {}
77 
79  GfQuatd(double real, double i, double j, double k)
80  : _imaginary(i, j, k), _real(real)
81  {
82  }
83 
85  GfQuatd(double real, const GfVec3d &imaginary)
86  : _imaginary(imaginary), _real(real)
87  {
88  }
89 
91  GF_API
92  GfQuatd(class GfQuatf const &other);
94  GF_API
95  GfQuatd(class GfQuath const &other);
96 
99  static GfQuatd GetIdentity() { return GfQuatd(1.0); }
100 
102  double GetReal() const { return _real; }
103 
105  void SetReal(double real) { _real = real; }
106 
108  const GfVec3d &GetImaginary() const { return _imaginary; }
109 
111  void SetImaginary(const GfVec3d &imaginary) {
112  _imaginary = imaginary;
113  }
114 
116  void SetImaginary(double i, double j, double k) {
117  _imaginary.Set(i, j, k);
118  }
119 
121  double GetLength() const { return GfSqrt(_GetLengthSquared()); }
122 
125  GfQuatd
126  GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const {
127  GfQuatd ret(*this);
128  ret.Normalize(eps);
129  return ret;
130  }
131 
135  GF_API
136  double Normalize(double eps = GF_MIN_VECTOR_LENGTH);
137 
141  return GfQuatd(GetReal(), -GetImaginary());
142  }
143 
146  GfQuatd GetInverse() const {
147  return GetConjugate() / _GetLengthSquared();
148  }
149 
157  GF_API
158  GfVec3d Transform(const GfVec3d& point) const;
159 
161  friend inline size_t hash_value(const GfQuatd &q) {
162  size_t h = boost::hash<ScalarType>()(q.GetReal());
163  boost::hash_combine(h, q.GetImaginary());
164  return h;
165  }
166 
168  GfQuatd operator-() const {
169  return GfQuatd(-GetReal(), -GetImaginary());
170  }
171 
174  bool operator==(const GfQuatd &q) const {
175  return (GetReal() == q.GetReal() &&
176  GetImaginary() == q.GetImaginary());
177  }
178 
181  bool operator!=(const GfQuatd &q) const {
182  return !(*this == q);
183  }
184 
186  GF_API
187  GfQuatd &operator *=(const GfQuatd &q);
188 
190  GfQuatd &operator *=(double s) {
191  _real *= s;
192  _imaginary *= s;
193  return *this;
194  }
195 
197  GfQuatd &operator /=(double s) {
198  _real /= s;
199  _imaginary /= s;
200  return *this;
201  }
202 
205  _real += q._real;
206  _imaginary += q._imaginary;
207  return *this;
208  }
209 
212  _real -= q._real;
213  _imaginary -= q._imaginary;
214  return *this;
215  }
216 
218  friend GfQuatd
219  operator +(const GfQuatd &q1, const GfQuatd &q2) {
220  return GfQuatd(q1) += q2;
221  }
222 
224  friend GfQuatd
225  operator -(const GfQuatd &q1, const GfQuatd &q2) {
226  return GfQuatd(q1) -= q2;
227  }
228 
230  friend GfQuatd
231  operator *(const GfQuatd &q1, const GfQuatd &q2) {
232  return GfQuatd(q1) *= q2;
233  }
234 
236  friend GfQuatd
237  operator *(const GfQuatd &q, double s) {
238  return GfQuatd(q) *= s;
239  }
240 
242  friend GfQuatd
243  operator *(double s, const GfQuatd &q) {
244  return GfQuatd(q) *= s;
245  }
246 
248  friend GfQuatd
249  operator /(const GfQuatd &q, double s) {
250  return GfQuatd(q) /= s;
251  }
252 
253  private:
255  GfVec3d _imaginary;
256 
258  double _real;
259 
261  double
262  _GetLengthSquared() const {
263  return GfDot(*this, *this);
264  }
265 };
266 
271 GF_API GfQuatd
272 GfSlerp(double alpha, const GfQuatd& q0, const GfQuatd& q1);
273 
274 GF_API GfQuatd
275 GfSlerp(const GfQuatd& q0, const GfQuatd& q1, double alpha);
276 
277 inline double
278 GfDot(GfQuatd const &q1, GfQuatd const &q2) {
279  return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
280  q1.GetReal()*q2.GetReal();
281 }
282 
285 GF_API std::ostream& operator<<(std::ostream &, GfQuatd const &);
286 
287 PXR_NAMESPACE_CLOSE_SCOPE
288 
289 #endif // PXR_BASE_GF_QUATD_H
GfQuatd()
Default constructor leaves the quaternion undefined.
Definition: quatd.h:67
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients...
Definition: quath.h:61
void SetImaginary(double i, double j, double k)
Set the imaginary coefficients.
Definition: quatd.h:116
double GetReal() const
Return the real coefficient.
Definition: quatd.h:102
GfQuatd GetConjugate() const
Return this quaternion&#39;s conjugate, which is the quaternion with the same real coefficient and negate...
Definition: quatd.h:140
bool operator==(const GfQuatd &q) const
Component-wise quaternion equality test.
Definition: quatd.h:174
GfQuatd GetNormalized(double eps=GF_MIN_VECTOR_LENGTH) const
length of this quaternion is smaller than eps, return the identity quaternion.
Definition: quatd.h:126
GF_API double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes this quaternion in place to unit length, returning the length before normalization.
const GfVec3d & GetImaginary() const
Return the imaginary coefficient.
Definition: quatd.h:108
GF_API GfQuatd & operator*=(const GfQuatd &q)
Post-multiply quaternion q into this quaternion.
void SetImaginary(const GfVec3d &imaginary)
Set the imaginary coefficients.
Definition: quatd.h:111
Declares Gf types.
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients...
Definition: quatf.h:60
GF_API GfQuatd GfSlerp(double alpha, const GfQuatd &q0, const GfQuatd &q1)
Spherically linearly interpolate between q0 and q1.
double GetLength() const
Return geometric length of this quaternion.
Definition: quatd.h:121
GfVec3d & Set(double s0, double s1, double s2)
Set all elements with passed arguments.
Definition: vec3d.h:130
static GfQuatd GetIdentity()
Return the identity quaternion, with real coefficient 1 and an imaginary coefficients all zero...
Definition: quatd.h:99
decltype(std::declval< Left >()*std::declval< Right >()) GfDot(Left left, Right right)
Returns the dot (inner) product of two vectors.
Definition: math.h:242
GfQuatd & operator+=(const GfQuatd &q)
Add quaternion q to this quaternion.
Definition: quatd.h:204
GfQuatd & operator-=(const GfQuatd &q)
Component-wise unary difference operator.
Definition: quatd.h:211
void SetReal(double real)
Set the real coefficient.
Definition: quatd.h:105
double GfSqrt(double f)
Return sqrt(f).
Definition: math.h:80
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
bool operator!=(const GfQuatd &q) const
Component-wise quaternion inequality test.
Definition: quatd.h:181
GfQuatd GetInverse() const
Return this quaternion&#39;s inverse, or reciprocal.
Definition: quatd.h:146
A metafunction with a static const bool member &#39;value&#39; that is true for GfQuat types and false for al...
Definition: traits.h:47
friend GfQuatd operator+(const GfQuatd &q1, const GfQuatd &q2)
Component-wise binary sum operator.
Definition: quatd.h:219
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
friend size_t hash_value(const GfQuatd &q)
Hash.
Definition: quatd.h:161
friend GfQuatd operator*(const GfQuatd &q1, const GfQuatd &q2)
Returns the product of quaternions q1 and q2.
Definition: quatd.h:231
GfQuatd operator-() const
Component-wise negation.
Definition: quatd.h:168
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients...
Definition: quatd.h:60
GfQuatd(double real, const GfVec3d &imaginary)
Initialize the real and imaginary coefficients.
Definition: quatd.h:85
GF_API GfVec3d Transform(const GfVec3d &point) const
Transform the GfVec3d point.
GfQuatd(double realVal)
Initialize the real coefficient to realVal and the imaginary coefficients to zero.
Definition: quatd.h:76
GfQuatd & operator/=(double s)
Divide this quaternion&#39;s coefficients by s.
Definition: quatd.h:197
friend GfQuatd operator/(const GfQuatd &q, double s)
Returns the product of quaternion q and scalar 1 / s.
Definition: quatd.h:249
GfQuatd(double real, double i, double j, double k)
Initialize the real and imaginary coefficients.
Definition: quatd.h:79
#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