Main MRPT website > C++ reference for MRPT 1.5.7
xsquaternion.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://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 #else
22 #define XSQUATERNION_INITIALIZER { { { XsMath_zero, XsMath_zero, XsMath_zero, XsMath_zero } } }
23 typedef struct XsQuaternion XsQuaternion;
24 #endif
25 
34 XSTYPES_DLL_API void XsQuaternion_multiply(const XsQuaternion* left, const XsQuaternion* right, XsQuaternion* dest);
38 
39 #ifdef __cplusplus
40 } // extern "C"
41 #endif
42 
43 struct XsQuaternion {
45  union {
46  struct {
47  XsReal m_w; //!< Stores the w component of the quaternion
48  XsReal m_x; //!< Stores the x component of the quaternion
49  XsReal m_y; //!< Stores the y component of the quaternion
50  XsReal m_z; //!< Stores the z component of the quaternion
51  };
52  XsReal m_data[4]; //!< Stores the quaternion in an array of four elements
53  };
54 #ifdef __cplusplus
55 public:
56  //! \brief Construct a quaternion with the supplied values, or zero's by default
58  : m_w(w)
59  , m_x(x)
60  , m_y(y)
61  , m_z(z)
62  {}
63 
64  //! \brief Construct a quaternion with the supplied values from the \a other Quaternion
65  inline XsQuaternion(const XsQuaternion& other)
66  : m_w(other.m_w)
67  , m_x(other.m_x)
68  , m_y(other.m_y)
69  , m_z(other.m_z)
70  {}
71 
72  //! \brief Construct a quaternion by converting from an XsEuler object
73  inline explicit XsQuaternion(const XsEuler& euler)
74  {
75  XsQuaternion_fromEulerAngles(this, &euler);
76  }
77 
78  //! \brief Construct a quaternion by converting from an XsMatrix rotation matrix object
79  inline explicit XsQuaternion(const XsMatrix& ori)
80  {
82  }
83 
84  //! \brief Assigns the \a other quaternion to this quaternion
85  inline XsQuaternion& operator=(const XsQuaternion& other)
86  {
87  m_w = other.m_w;
88  m_x = other.m_x;
89  m_y = other.m_y;
90  m_z = other.m_z;
91  return *this;
92  }
93 
94  /*! \brief Set the Quaternion to these specific values
95  */
96  inline void assign(XsReal w, XsReal x, XsReal y, XsReal z)
97  {
98  m_w = w;
99  m_x = x;
100  m_y = y;
101  m_z = z;
102  }
103 
104  /*! \brief Set the Quaternion to the specific values in the supplied array.
105  \param values An array that contains at least 4 items. The first four will be interpreted as w,x,y,z
106  */
107  inline void assign(const XsReal* values)
108  {
109  for (int i = 0; i < 4; ++i)
110  m_data[i] = values[i];
111  }
112 
113  //! \brief Returns a reference to the \a index'th component of the quaternion
114  inline XsReal& operator[](XsSize index)
115  {
116  assert(index < 4);
117  return m_data[index];
118  }
119 
120  //! \brief Returns the \a index'th component of the quaternion
121  inline XsReal const& operator[](XsSize index) const
122  {
123  assert(index < 4);
124  return m_data[index];
125  }
126 
127  //! \brief Return a const pointer to the internal data
128  inline const XsReal* data() const
129  {
130  return m_data;
131  }
132 
133  //! \brief \copybrief XsQuaternion_inverse \returns The inverse/conjugate of the quaternion
134  inline XsQuaternion inverse() const
135  {
136  XsQuaternion tmp;
137  XsQuaternion_inverse(this, &tmp);
138  return tmp;
139  }
140 
141  //! \brief \copybrief XsQuaternion_inverse \returns The inverse/conjugate of the quaternion
142  inline XsQuaternion conjugate() const
143  {
144  XsQuaternion tmp;
145  XsQuaternion_inverse(this, &tmp);
146  return tmp;
147  }
148 
149  //! \brief Return a normalized version of the quaternion \sa XsQuaternion_normalized \returns The normalized quaternion
150  XsQuaternion normalized() const
151  {
152  XsQuaternion tmp;
153  XsQuaternion_normalized(this, &tmp);
154  return tmp;
155  }
156 
157  //! \brief Normalized the quaternion \sa XsQuaternion_normalized \returns The cartesian length of the quaternion before normalization
158  inline XsReal normalize()
159  {
160  return XsQuaternion_normalized(this, this);
161  }
162 
163  //! \brief \copybrief XsQuaternion_empty
164  inline bool empty() const
165  {
166  return 0 != XsQuaternion_empty(this);
167  }
168 
169  //! \brief \copybrief XsQuaternion_fromEulerAngles
170  inline XsQuaternion& fromEulerAngles(const XsEuler& src)
171  {
173  return *this;
174  }
175 
176  //! \brief \copybrief XsQuaternion_fromRotationMatrix
177  inline XsQuaternion& fromRotationMatrix(const XsMatrix& ori)
178  {
180  return *this;
181  }
182 
183  //! \brief \copybrief XsQuaternion_identity
184  inline static const XsQuaternion& identity()
185  {
186  return *XsQuaternion_identity();
187  }
188 
189  /*! \brief In-place multiplication of this quaternion with \a other quaternion
190  \param other The other quaternion to multiply with (right side of multiplication)
191  \sa XsQuaternion_multiply()
192  */
193  inline void operator*=(const XsQuaternion& other)
194  {
195  XsQuaternion_multiply(this, &other, this);
196  }
197 
198  //! \brief Return the w component of the quaternion
199  inline XsReal w() const { return m_w; }
200  //! \brief Return the x component of the quaternion
201  inline XsReal x() const { return m_x; }
202  //! \brief Return the y component of the quaternion
203  inline XsReal y() const { return m_y; }
204  //! \brief Return the z component of the quaternion
205  inline XsReal z() const { return m_z; }
206  //! \brief Return a reference to the w component of the quaternion
207  inline XsReal& w() { return m_w; }
208  //! \brief Return a reference to the x component of the quaternion
209  inline XsReal& x() { return m_x; }
210  //! \brief Return a reference to the y component of the quaternion
211  inline XsReal& y() { return m_y; }
212  //! \brief Return a reference to the z component of the quaternion
213  inline XsReal& z() { return m_z; }
214 
215  //! \brief Swap the contents with \a other
216  inline void swap(XsQuaternion& other)
217  {
218  XsQuaternion_swap(this, &other);
219  }
220 
221  //! \brief Returns true if \a other is numerically identical to this
222  inline bool operator ==(const XsQuaternion& other) const
223  {
224  return m_w == other.m_w &&
225  m_x == other.m_x &&
226  m_y == other.m_y &&
227  m_z == other.m_z;
228  }
229 
230 #endif
231 };
232 
233 #ifdef __cplusplus
234 //! \brief Return the negated version of the Quaternion \a q (w,-x,-y,-z)
235 inline XsQuaternion operator-(const XsQuaternion &q)
236 {
237  return XsQuaternion(q.w(), -q.x(), -q.y(), -q.z());
238 }
239 
240 //! \brief Multiply \a lhs by \a rhs and return the result
241 inline XsQuaternion operator *(const XsQuaternion& lhs, const XsQuaternion &rhs)
242 {
243  XsQuaternion tmp(lhs);
244  tmp *= rhs;
245  return tmp;
246 }
247 #endif
248 
249 #endif // file guard
XSTYPES_DLL_API XsReal XsQuaternion_normalized(const XsQuaternion *thisPtr, XsQuaternion *dest)
bool operator==(const TPoint2D &p1, const TPoint2D &p2)
Exact comparison between 2D points.
EIGEN_STRONG_INLINE bool empty() const
GLdouble GLdouble z
Definition: glext.h:3734
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:3535
XSTYPES_DLL_API const XsReal XsMath_zero
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:3626
XsReal m_z
Stores the z component of the quaternion.
Definition: xsquaternion.h:50
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:17
GLuint src
Definition: glext.h:6303
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3962
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:52
GLuint index
Definition: glext.h:3891
XsReal m_y
Stores the y component of the quaternion.
Definition: xsquaternion.h:49
XSTYPES_DLL_API void XsQuaternion_copy(XsQuaternion *copy, XsQuaternion const *src)
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:123
XSTYPES_DLL_API void XsQuaternion_inverse(const XsQuaternion *thisPtr, XsQuaternion *dest)
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
Definition: Miscellaneous.h:74
GLubyte GLubyte b
Definition: glext.h:5575
struct XsQuaternion XsQuaternion
Definition: xsquaternion.h:23
#define XSCPPPROTECTED
Definition: xstypesconfig.h:56
EIGEN_STRONG_INLINE void assign(const Scalar v)
Definition: eigen_plugins.h:41
XSTYPES_DLL_API void XsQuaternion_swap(XsQuaternion *a, XsQuaternion *b)
XSTYPES_DLL_API int XsQuaternion_empty(const XsQuaternion *thisPtr)
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:9
void normalize(Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
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:16
GLenum GLint GLint y
Definition: glext.h:3516
XSTYPES_DLL_API XsReal XsQuaternion_normalize(XsQuaternion *thisPtr)
XsReal m_w
Stores the w component of the quaternion.
Definition: xsquaternion.h:47
GLenum GLint x
Definition: glext.h:3516
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3520
GLubyte GLubyte GLubyte a
Definition: glext.h:5575
TPoint3D operator-(const TPoint3D &p1)
Unary minus operator for 3D points.
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:40
XsReal m_x
Stores the x component of the quaternion.
Definition: xsquaternion.h:48
std::vector< T1 > operator*(const std::vector< T1 > &a, const std::vector< T2 > &b)
a*b (element-wise multiplication)
Definition: ops_vectors.h:59
GLint GLenum GLboolean normalized
Definition: glext.h:3977
XSTYPES_DLL_API const XsQuaternion * XsQuaternion_identity(void)



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019