HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HOM_Quaternion.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __HOM_Quaternion_h__
10 #define __HOM_Quaternion_h__
11 
12 #include "HOM_API.h"
13 #include "HOM_Defines.h"
14 #include "HOM_Errors.h"
15 #include "HOM_Module.h"
16 #include "HOM_Vector3.h"
17 #include "HOM_PtrOrNull.h"
18 #include <UT/UT_Quaternion.h>
19 #include <vector>
20 #include <stdexcept>
21 
22 class HOM_Matrix3;
23 class HOM_Matrix4;
24 
26 
28 {
29 public:
31  : myQuaternion(0.0, 0.0, 0.0, 1.0)
32  { HOM_CONSTRUCT_OBJECT(this) }
33 
34  HOM_Quaternion(const std::vector<double> &sequence)
35  {
37  setTo(sequence);
38  }
39 
40  HOM_Quaternion(double x, double y, double z, double w)
41  : myQuaternion(x, y, z, w)
42  { HOM_CONSTRUCT_OBJECT(this) }
43 
44  HOM_Quaternion(double angle_in_deg, const std::vector<double> &axis)
45  {
46  setToAngleAxis(angle_in_deg, axis);
48  }
49 
50  HOM_Quaternion(HOM_Matrix3 &matrix3);
51  HOM_Quaternion(HOM_Matrix4 &matrix4);
52 
54  HOM_Quaternion(const HOM_Quaternion &quaternion)
55  : myQuaternion(quaternion.myQuaternion)
56  { HOM_CONSTRUCT_OBJECT(this) }
57 
59  HOM_Quaternion(const UT_QuaternionD &quaternion)
60  : myQuaternion(quaternion)
61  { HOM_CONSTRUCT_OBJECT(this) }
62 
64  { HOM_DESTRUCT_OBJECT(this) }
65 
67  { return quaternion.myPointer &&
68  myQuaternion == quaternion.myPointer->myQuaternion; }
69 
71  { return !operator==(quaternion); }
72 
73  bool isAlmostEqual(HOM_Quaternion &quaternion, double tolerance=0.00001);
74 
75  // This method is deprecated.
76  bool almostEqual(HOM_Quaternion &quaternion, double tolerance=0.00001)
77  { return isAlmostEqual(quaternion, tolerance); }
78 
79  int __hash__();
82 
83  double __getitem__(int index);
84  void __setitem__(int index, double value);
85  int __len__()
86  { return 4; }
87 
88  void setTo(const std::vector<double> &tuple);
89 
90  void setToRotationMatrix(HOM_Matrix3 &matrix3);
91  void setToRotationMatrix(HOM_Matrix4 &matrix4);
92 
93  void setToAngleAxis(double angle_in_deg, const std::vector<double> &axis);
94 
95  void setToVectors(const HOM_Vector3 &v1, const HOM_Vector3 &v2);
96 
97  SWIGOUT(%kwargs setToEulerRotates;)
98  void setToEulerRotates(
99  const std::vector<double> &angles_in_deg,
100  const char *rotate_order="xyz");
101 
102  SWIGOUT(%ignore operator=;)
103  HOM_Quaternion &operator=(const HOM_Quaternion& quaternion)
104  {
105  myQuaternion = quaternion.myQuaternion;
106  return *this;
107  }
108 
109  HOM_Quaternion conjugate();
110  HOM_Quaternion inverse();
111  double dot(HOM_Quaternion &quaternion)
112  { return ::dot(myQuaternion, quaternion.myQuaternion); }
113 
115  { return HOM_Quaternion(myQuaternion + quaternion.myQuaternion); }
117  { return HOM_Quaternion(myQuaternion - quaternion.myQuaternion); }
118  HOM_Quaternion __mul__(double scalar)
119  { return HOM_Quaternion(myQuaternion * scalar); }
121 
122  HOM_Quaternion slerp(HOM_Quaternion &other, double fraction);
123 
124 
126 
127  double length()
128  { return myQuaternion.length(); }
129 
130 
131  SWIGOUT(%newobject extractRotationMatrix3;)
133 
134  std::pair<double, HOM_ElemPtr<HOM_Vector3> > extractAngleAxis();
135 
136  HOM_Vector3 extractEulerRotates(const char *rotate_order="xyz");
137 
139 
141  { return &myQuaternion; }
142 
143 
144  SWIGOUT(%ignore myQuaternion;)
145  UT_QuaternionD myQuaternion;
146 };
147 
148 #endif
bool almostEqual(HOM_Quaternion &quaternion, double tolerance=0.00001)
bool operator==(HOM_PtrOrNull< HOM_Quaternion > quaternion)
HOM_Quaternion(double x, double y, double z, double w)
double dot(HOM_Quaternion &quaternion)
#define HOM_DESTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1303
HOM_Quaternion __sub__(HOM_Quaternion &quaternion)
const GLdouble * v
Definition: glcorearb.h:837
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
#define SWIGOUT(x)
Definition: HOM_Defines.h:24
HOM_Quaternion(const HOM_Quaternion &quaternion)
string __repr__(VtArray< T > const &self)
Definition: wrapArray.h:349
GLint y
Definition: glcorearb.h:103
HOM_Quaternion(double angle_in_deg, const std::vector< double > &axis)
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
HOM_Quaternion(const std::vector< double > &sequence)
void * _asVoidPointer()
std::string __str__()
#define HOM_API
Definition: HOM_API.h:13
void ignore(T const &) VULKAN_HPP_NOEXCEPT
Definition: vulkan.hpp:6508
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
Definition: CE_Vector.h:140
#define HOM_CONSTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1302
HOM_Quaternion __add__(HOM_Quaternion &quaternion)
int __hash__()
HOM_Matrix3 * extractRotationMatrix3()
GLint GLenum GLboolean normalized
Definition: glcorearb.h:872
GLint GLenum GLint x
Definition: glcorearb.h:409
ImageBuf OIIO_API rotate(const ImageBuf &src, float angle, string_view filtername=string_view(), float filterwidth=0.0f, bool recompute_roi=false, ROI roi={}, int nthreads=0)
HOM_Quaternion __mul__(double scalar)
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Quat< T > slerp(const Quat< T > &q1, const Quat< T > &q2, T t) IMATH_NOEXCEPT
Definition: ImathQuat.h:531
void setTo(const std::vector< double > &sequence)
HOM_Matrix4 __mul__(HOM_Matrix4 &matrix4)
Definition: HOM_Matrix4.h:108
bool isAlmostEqual(HOM_Matrix4 &matrix4, double tolerance=0.00001)
OIIO_UTIL_API bool rename(string_view from, string_view to, std::string &err)
HOM_Quaternion(const UT_QuaternionD &quaternion)
GLuint index
Definition: glcorearb.h:786
GLfloat GLfloat v1
Definition: glcorearb.h:817
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
Definition: core.h:1131
UT_QuaternionD myQuaternion
bool operator!=(HOM_PtrOrNull< HOM_Quaternion > quaternion)
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542