MRPT  1.9.9
xsquaternion.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef XSQUATERNION_H
10 #define XSQUATERNION_H
11 
12 #include "xsmath.h"
13 
14 struct XsEuler;
15 struct XsMatrix;
16 struct XsVector;
17 struct XsQuaternion;
18 
19 #ifdef __cplusplus
20 extern "C"
21 {
22 #else
23 #define XSQUATERNION_INITIALIZER \
24  { \
25  { \
26  { \
27  XsMath_zero, XsMath_zero, XsMath_zero, XsMath_zero \
28  } \
29  } \
30  }
31 typedef struct XsQuaternion XsQuaternion;
32 #endif
33 
37  const XsQuaternion* thisPtr, XsQuaternion* dest);
39  const XsQuaternion* thisPtr, XsQuaternion* dest);
42  XsQuaternion* thisPtr, const struct XsEuler* src);
44  XsQuaternion* thisPtr, const struct XsMatrix* ori);
47  const XsQuaternion* left, const XsQuaternion* right,
48  XsQuaternion* dest);
51  XsQuaternion* copy, XsQuaternion const* src);
53  XsQuaternion const* a, XsQuaternion const* b);
54 
55 #ifdef __cplusplus
56 } // extern "C"
57 #endif
58 
60 {
62  union {
63  struct
64  {
65  /** Stores the w component of the quaternion */
67  /** Stores the x component of the quaternion */
69  /** Stores the y component of the quaternion */
71  /** Stores the z component of the quaternion */
73  };
74  /** Stores the quaternion in an array of four elements */
76  };
77 #ifdef __cplusplus
78  public:
79  //! \brief Construct a quaternion with the supplied values, or zero's by
80  //! default
81  inline explicit XsQuaternion(
84  : m_w(w), m_x(x), m_y(y), m_z(z)
85  {
86  }
87 
88  //! \brief Construct a quaternion with the supplied values from the \a other
89  //! Quaternion
90  inline XsQuaternion(const XsQuaternion& other)
91  : m_w(other.m_w), m_x(other.m_x), m_y(other.m_y), m_z(other.m_z)
92  {
93  }
94 
95  //! \brief Construct a quaternion by converting from an XsEuler object
96  inline explicit XsQuaternion(const XsEuler& euler)
97  {
98  XsQuaternion_fromEulerAngles(this, &euler);
99  }
100 
101  //! \brief Construct a quaternion by converting from an XsMatrix rotation
102  //! matrix object
103  inline explicit XsQuaternion(const XsMatrix& ori)
104  {
106  }
107 
108  //! \brief Assigns the \a other quaternion to this quaternion
109  inline XsQuaternion& operator=(const XsQuaternion& other)
110  {
111  m_w = other.m_w;
112  m_x = other.m_x;
113  m_y = other.m_y;
114  m_z = other.m_z;
115  return *this;
116  }
117 
118  /*! \brief Set the Quaternion to these specific values
119  */
120  inline void assign(XsReal w, XsReal x, XsReal y, XsReal z)
121  {
122  m_w = w;
123  m_x = x;
124  m_y = y;
125  m_z = z;
126  }
127 
128  /*! \brief Set the Quaternion to the specific values in the supplied array.
129  \param values An array that contains at least 4 items. The first four
130  will be interpreted as w,x,y,z
131  */
132  inline void assign(const XsReal* values)
133  {
134  for (int i = 0; i < 4; ++i) m_data[i] = values[i];
135  }
136 
137  //! \brief Returns a reference to the \a index'th component of the
138  //! quaternion
139  inline XsReal& operator[](XsSize index)
140  {
141  assert(index < 4);
142  return m_data[index];
143  }
144 
145  //! \brief Returns the \a index'th component of the quaternion
146  inline XsReal const& operator[](XsSize index) const
147  {
148  assert(index < 4);
149  return m_data[index];
150  }
151 
152  //! \brief Return a const pointer to the internal data
153  inline const XsReal* data() const { return m_data; }
154  //! \brief \copybrief XsQuaternion_inverse \returns The inverse/conjugate of
155  //! the quaternion
156  inline XsQuaternion inverse() const
157  {
158  XsQuaternion tmp;
159  XsQuaternion_inverse(this, &tmp);
160  return tmp;
161  }
162 
163  //! \brief \copybrief XsQuaternion_inverse \returns The inverse/conjugate of
164  //! the quaternion
165  inline XsQuaternion conjugate() const
166  {
167  XsQuaternion tmp;
168  XsQuaternion_inverse(this, &tmp);
169  return tmp;
170  }
171 
172  //! \brief Return a normalized version of the quaternion \sa
173  //! XsQuaternion_normalized \returns The normalized quaternion
174  XsQuaternion normalized() const
175  {
176  XsQuaternion tmp;
177  XsQuaternion_normalized(this, &tmp);
178  return tmp;
179  }
180 
181  //! \brief Normalized the quaternion \sa XsQuaternion_normalized \returns
182  //! The cartesian length of the quaternion before normalization
183  inline XsReal normalize() { return XsQuaternion_normalized(this, this); }
184  //! \brief \copybrief XsQuaternion_empty
185  inline bool empty() const { return 0 != XsQuaternion_empty(this); }
186  //! \brief \copybrief XsQuaternion_fromEulerAngles
187  inline XsQuaternion& fromEulerAngles(const XsEuler& src)
188  {
190  return *this;
191  }
192 
193  //! \brief \copybrief XsQuaternion_fromRotationMatrix
194  inline XsQuaternion& fromRotationMatrix(const XsMatrix& ori)
195  {
197  return *this;
198  }
199 
200  //! \brief \copybrief XsQuaternion_identity
201  inline static const XsQuaternion& identity()
202  {
203  return *XsQuaternion_identity();
204  }
205 
206  /*! \brief In-place multiplication of this quaternion with \a other
207  quaternion
208  \param other The other quaternion to multiply with (right side of
209  multiplication)
210  \sa XsQuaternion_multiply()
211  */
212  inline void operator*=(const XsQuaternion& other)
213  {
214  XsQuaternion_multiply(this, &other, this);
215  }
216 
217  //! \brief Return the w component of the quaternion
218  inline XsReal w() const { return m_w; }
219  //! \brief Return the x component of the quaternion
220  inline XsReal x() const { return m_x; }
221  //! \brief Return the y component of the quaternion
222  inline XsReal y() const { return m_y; }
223  //! \brief Return the z component of the quaternion
224  inline XsReal z() const { return m_z; }
225  //! \brief Return a reference to the w component of the quaternion
226  inline XsReal& w() { return m_w; }
227  //! \brief Return a reference to the x component of the quaternion
228  inline XsReal& x() { return m_x; }
229  //! \brief Return a reference to the y component of the quaternion
230  inline XsReal& y() { return m_y; }
231  //! \brief Return a reference to the z component of the quaternion
232  inline XsReal& z() { return m_z; }
233  //! \brief Swap the contents with \a other
234  inline void swap(XsQuaternion& other) { XsQuaternion_swap(this, &other); }
235  //! \brief Returns true if \a other is numerically identical to this
236  inline bool operator==(const XsQuaternion& other) const
237  {
238  return m_w == other.m_w && m_x == other.m_x && m_y == other.m_y &&
239  m_z == other.m_z;
240  }
241 
242 #endif
243 };
244 
245 #ifdef __cplusplus
246 //! \brief Return the negated version of the Quaternion \a q (w,-x,-y,-z)
247 inline XsQuaternion operator-(const XsQuaternion& q)
248 {
249  return XsQuaternion(q.w(), -q.x(), -q.y(), -q.z());
250 }
251 
252 //! \brief Multiply \a lhs by \a rhs and return the result
253 inline XsQuaternion operator*(const XsQuaternion& lhs, const XsQuaternion& rhs)
254 {
255  XsQuaternion tmp(lhs);
256  tmp *= rhs;
257  return tmp;
258 }
259 #endif
260 
261 #endif // file guard
XSTYPES_DLL_API XsReal XsQuaternion_normalized(const XsQuaternion *thisPtr, XsQuaternion *dest)
GLdouble GLdouble z
Definition: glext.h:3879
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:3586
XSTYPES_DLL_API const XsReal XsMath_zero
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:3727
XsReal m_z
Stores the z component of the quaternion.
Definition: xsquaternion.h:72
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:19
GLuint src
Definition: glext.h:7397
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn&#39;t exist already.
Definition: ts_hash_map.h:193
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4199
XSTYPES_DLL_API int XsQuaternion_equal(XsQuaternion const *a, XsQuaternion const *b)
XsReal m_data[4]
Stores the quaternion in an array of four elements.
Definition: xsquaternion.h:75
void normalize(CONTAINER &c, Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
GLuint index
Definition: glext.h:4068
XsReal m_y
Stores the y component of the quaternion.
Definition: xsquaternion.h:70
XSTYPES_DLL_API void XsQuaternion_copy(XsQuaternion *copy, XsQuaternion const *src)
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
Definition: Miscellaneous.h:81
XSTYPES_DLL_API void XsQuaternion_inverse(const XsQuaternion *thisPtr, XsQuaternion *dest)
GLubyte GLubyte b
Definition: glext.h:6372
struct XsQuaternion XsQuaternion
Definition: xsquaternion.h:31
#define XSCPPPROTECTED
Definition: xstypesconfig.h:57
XSTYPES_DLL_API void XsQuaternion_swap(XsQuaternion *a, XsQuaternion *b)
XSTYPES_DLL_API int XsQuaternion_empty(const XsQuaternion *thisPtr)
bool empty() const
Definition: ts_hash_map.h:190
bool operator==(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
Definition: TCamera.cpp:202
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:9
XSTYPES_DLL_API void XsQuaternion_fromRotationMatrix(XsQuaternion *thisPtr, const struct XsMatrix *ori)
XSTYPES_DLL_API void XsQuaternion_destruct(XsQuaternion *thisPtr)
XSTYPES_DLL_API void XsQuaternion_multiply(const XsQuaternion *left, const XsQuaternion *right, XsQuaternion *dest)
double XsReal
Defines the floating point type used by the Xsens libraries.
Definition: xstypedefs.h:17
TColor operator-(const TColor &first, const TColor &second)
Pairwise substraction of their corresponding RGBA members.
Definition: TColor.cpp:30
GLenum GLint GLint y
Definition: glext.h:3542
XSTYPES_DLL_API XsReal XsQuaternion_normalize(XsQuaternion *thisPtr)
XsReal m_w
Stores the w component of the quaternion.
Definition: xsquaternion.h:66
GLenum GLint x
Definition: glext.h:3542
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3550
GLubyte GLubyte GLubyte a
Definition: glext.h:6372
XSTYPES_DLL_API void XsQuaternion_fromEulerAngles(XsQuaternion *thisPtr, const struct XsEuler *src)
std::vector< T1 > & operator*=(std::vector< T1 > &a, const std::vector< T2 > &b)
a*=b (element-wise multiplication)
Definition: ops_vectors.h:31
XsReal m_x
Stores the x component of the quaternion.
Definition: xsquaternion.h:68
std::vector< T1 > operator*(const std::vector< T1 > &a, const std::vector< T2 > &b)
a*b (element-wise multiplication)
Definition: ops_vectors.h:50
GLint GLenum GLboolean normalized
Definition: glext.h:4229
XSTYPES_DLL_API const XsQuaternion * XsQuaternion_identity(void)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019