MRPT  1.9.9
xsmatrix.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 XSMATRIX_H
10 #define XSMATRIX_H
11 
12 #include <stddef.h>
13 #include "xsmath.h"
14 
15 struct XsMatrix;
16 struct XsEuler;
17 struct XsQuaternion;
18 
19 #ifdef __cplusplus
20 extern "C"
21 {
22 #else
23 #define XSMATRIX_INITIALIZER \
24  { \
25  nullptr, 0, 0, 0, XSDF_Managed \
26  }
27 typedef struct XsMatrix XsMatrix;
28 #endif
29 
31  XsMatrix* thisPtr, XsSize rows, XsSize cols, XsSize stride,
32  XsReal* buffer, XsDataFlags flags);
34  XsMatrix* thisPtr, XsSize rows, XsSize cols, XsSize stride,
35  const XsReal* src, XsSize srcStride);
37  XsMatrix* thisPtr, XsSize rows, XsSize cols, XsSize stride,
38  const XsReal* src, XsSize srcStride);
42  XSTYPES_DLL_API int XsMatrix_empty(const XsMatrix* thisPtr);
44  const XsMatrix* thisPtr, XsReal scalar, XsMatrix* dest);
46  XsMatrix_offset(const XsMatrix* thisPtr, XsSize row, XsSize column);
48  XsMatrix_value(const XsMatrix* thisPtr, XsSize row, XsSize column);
52  const XsMatrix* thisPtr, XsSize rows, XsSize columns);
54  XsMatrix* thisPtr, const struct XsQuaternion* quat);
56 
57 #define XsMatrix_offsetM(thisPtr, row, column) \
58  (thisPtr->m_stride * row + column)
59 
60 #ifdef __cplusplus
61 } // extern "C"
62 #endif
63 #ifndef XSENS_NO_PACK
64 #pragma pack(push, 1)
65 #endif
66 struct XsMatrix
67 {
69  /** Contained data */
70  XsReal* const m_data;
71  /** Number of rows in the matrix */
72  const XsSize m_rows;
73  /** Number of columns in the matrix */
74  const XsSize m_cols;
75  /** Number of items per row in memory (usually equal to cols but not always)
76  */
78  /** Flags for data management */
79  const int m_flags;
80 
81 #ifdef __cplusplus
82  //! \brief Return the data management flags of the matrix.
83  inline int flags() { return m_flags; }
84 
85  public:
86  /*! \brief Initialize an XsMatrix object with the specified number of \a
87  * rows and \a cols */
88  inline explicit XsMatrix(
89  XsSize rows = 0, XsSize cols = 0, XsSize strde = 0,
90  const XsReal* dat = 0)
91  : m_data(0), m_rows(0), m_cols(0), m_stride(0), m_flags(0)
92  {
93  if (rows && cols)
94  XsMatrix_construct(this, rows, cols, strde ? strde : cols, dat, 0);
95  }
96 
97  /*! \brief Initialize an XsMatrix object from the \a other XsMatrix */
98  inline XsMatrix(const XsMatrix& other)
99  : m_data(0), m_rows(0), m_cols(0), m_stride(0), m_flags(0)
100  {
101  XsMatrix_copy(this, &other);
102  }
103 
104  /*! \brief Initialize an XsMatrix object that references the data passed in
105  * \a ref. \a rows, \a cols and \a stride can be used to specify the layout
106  * of the data */
107  inline explicit XsMatrix(
108  XsReal* ref, XsSize rows, XsSize cols, XsSize stride,
109  XsDataFlags flags = XSDF_None)
110  : m_data(ref),
111  m_rows(rows),
112  m_cols(cols),
113  m_stride(stride),
114  m_flags(flags)
115  {
116  }
117 
118  /*! \brief Initialize a copy of \a other in an XsMatrix object that
119  * references the data passed in \a ref. \a rows, \a cols and \a stride can
120  * be used to specify the layout of the data */
121  inline explicit XsMatrix(
122  const XsMatrix& other, XsReal* ref, XsSize rows, XsSize cols,
124  : m_data(ref),
125  m_rows(rows),
126  m_cols(cols),
127  m_stride(stride),
128  m_flags(flags)
129  {
130  XsMatrix_copy(this, &other);
131  }
132 
133  //! \brief \copybrief XsMatrix_fromQuaternion
134  inline explicit XsMatrix(const XsQuaternion& quat)
135  : m_data(0), m_rows(0), m_cols(0), m_stride(0), m_flags(0)
136  {
137  XsMatrix_fromQuaternion(this, &quat);
138  }
139 
140  //! \copydoc XsMatrix_destruct
141  inline ~XsMatrix() { XsMatrix_destruct(this); }
142  /*! \brief Resize the matrix to the specified number of \a rows and \a cols,
143  * destroying its current contents */
144  inline void setSize(XsSize rows, XsSize cols, XsSize stride = 0)
145  {
146  XsMatrix_assign(this, rows, cols, stride, 0, 0);
147  }
148 
149  /*! \brief \copybrief XsMatrix_copy */
150  inline XsMatrix& operator=(const XsMatrix& other)
151  {
152  XsMatrix_copy(this, &other);
153  return *this;
154  }
155 
156  //! \brief \copybrief XsMatrix_empty
157  inline bool empty() const { return 0 != XsMatrix_empty(this); }
158  //! \brief \copybrief XsMatrix_setZero
159  inline void setZero() { XsMatrix_setZero(this); }
160  //! \copydoc XsMatrix_offset */
161  inline XsSize offset(XsSize row, XsSize column) const
162  {
163  return XsMatrix_offset(this, row, column);
164  }
165 
166  /*! \brief Returns the value at \a row and \a column in the matrix */
167  inline XsReal value(XsSize row, XsSize column) const
168  {
169  return m_data[XsMatrix_offset(this, row, column)];
170  }
171 
172  /*! \brief Sets the \a value at \a row and \a column in the matrix */
173  inline void setValue(XsSize row, XsSize column, XsReal value)
174  {
176  }
177 
178  /*! \brief Returns a pointer to the data in \a row */
179  inline const XsReal* operator[](XsSize row) const
180  {
181  return &m_data[XsMatrix_offsetM(this, row, 0)];
182  }
183 
184  /*! \brief Returns a reference to the data in \a row */
185  inline XsReal* operator[](XsSize row)
186  {
187  return &m_data[XsMatrix_offsetM(this, row, 0)];
188  }
189 
190  /*! \brief \copybrief XsMatrix_multiplyScalar */
191  inline XsMatrix operator*(XsReal scalar) const
192  {
193  XsMatrix tmp(m_rows, m_cols);
194  XsMatrix_multiplyScalar(this, scalar, &tmp);
195  return tmp;
196  }
197 
198  /*! \brief \copybrief XsMatrix_fromQuaternion */
199  inline XsMatrix& fromQuaternion(const XsQuaternion& quat)
200  {
201  XsMatrix_fromQuaternion(this, &quat);
202  return *this;
203  }
204 
205  /*! \brief Fill the matrix with zeroes */
206  inline void zero()
207  {
208  for (XsSize r = 0; r < m_rows; ++r)
209  for (XsSize c = 0; c < m_cols; ++c)
211  }
212 
213  /*! \brief Return the number of rows in the matrix */
214  inline XsSize rows() const { return m_rows; }
215  /*! \brief Return the number of columns in the matrix */
216  inline XsSize cols() const { return m_cols; }
217  /*! \brief Return the stride of the matrix.
218  \details The stride of a matrix is for internal administration. It
219  defines the number of items
220  in a row in the data buffer. This is always greater than or equal to the
221  number of columns.
222  Especially for matrices that reference a part of another matrix this may
223  differ from the
224  cols() value.
225  \returns The stride of the matrix.
226  */
227  inline XsSize stride() const { return m_stride; }
228  //! \brief Return a const pointer to the internal data
229  inline const XsReal* data() const { return m_data; }
230  //! \brief Returns true if \a other is numerically identical to this
231  inline bool operator==(const XsMatrix& other) const
232  {
233  if (this == &other) return true;
234  if (m_rows != other.m_rows || m_cols != other.m_cols) return false;
235  for (XsSize r = 0; r < m_rows; ++r)
236  for (XsSize c = 0; c < m_cols; ++c)
237  if (m_data[XsMatrix_offsetM(this, r, c)] !=
238  other.m_data[XsMatrix_offsetM((&other), r, c)])
239  return false;
240  return true;
241  }
242 
243 #endif
244 };
245 #ifndef XSENS_NO_PACK
246 #pragma pack(pop)
247 #endif
248 
249 #ifdef __cplusplus
250 //! \brief Multiplies all values in the matrix \a m by \a scalar
251 inline XsMatrix operator*(XsReal scalar, const XsMatrix& m)
252 {
253  return (m * scalar);
254 }
255 #endif
256 
257 #endif // file guard
XSTYPES_DLL_API void XsMatrix_multiplyScalar(const XsMatrix *thisPtr, XsReal scalar, XsMatrix *dest)
const XsSize m_rows
Number of rows in the matrix.
Definition: xsmatrix.h:72
XSTYPES_DLL_API void XsMatrix_copy(XsMatrix *copy, XsMatrix const *src)
const int m_flags
Flags for data management.
Definition: xsmatrix.h:79
XSTYPES_DLL_API void XsMatrix_ref(XsMatrix *thisPtr, XsSize rows, XsSize cols, XsSize stride, XsReal *buffer, XsDataFlags flags)
XSTYPES_DLL_API const XsReal XsMath_zero
GLuint buffer
Definition: glext.h:3928
GLenum GLint ref
Definition: glext.h:4062
const XsSize m_stride
Number of items per row in memory (usually equal to cols but not always)
Definition: xsmatrix.h:77
XSTYPES_DLL_API void XsMatrix_assign(XsMatrix *thisPtr, XsSize rows, XsSize cols, XsSize stride, const XsReal *src, XsSize srcStride)
GLintptr offset
Definition: glext.h:3936
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:19
#define XsMatrix_offsetM(thisPtr, row, column)
Definition: xsmatrix.h:57
GLuint src
Definition: glext.h:7397
No flag set.
Definition: xstypedefs.h:44
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
XSTYPES_DLL_API void XsMatrix_construct(XsMatrix *thisPtr, XsSize rows, XsSize cols, XsSize stride, const XsReal *src, XsSize srcStride)
XSTYPES_DLL_API int XsMatrix_empty(const XsMatrix *thisPtr)
XSTYPES_DLL_API void XsMatrix_fromQuaternion(XsMatrix *thisPtr, const struct XsQuaternion *quat)
XSTYPES_DLL_API void XsMatrix_setValue(XsMatrix *thisPtr, XsSize row, XsSize column, XsReal value)
XSTYPES_DLL_API void XsMatrix_setZero(XsMatrix *thisPtr)
const GLubyte * c
Definition: glext.h:6406
GLsizei stride
Definition: glext.h:3831
GLubyte GLubyte b
Definition: glext.h:6372
XSCPPPROTECTED XsReal *const m_data
Contained data.
Definition: xsmatrix.h:70
#define XSCPPPROTECTED
Definition: xstypesconfig.h:57
XSTYPES_DLL_API int XsMatrix_dimensionsMatch(const XsMatrix *thisPtr, XsSize rows, XsSize columns)
XSTYPES_DLL_API void XsMatrix_destruct(XsMatrix *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 XsMatrix_swap(XsMatrix *a, XsMatrix *b)
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
XSTYPES_DLL_API XsReal XsMatrix_value(const XsMatrix *thisPtr, XsSize row, XsSize column)
GLenum GLenum GLvoid * row
Definition: glext.h:3580
double XsReal
Defines the floating point type used by the Xsens libraries.
Definition: xstypedefs.h:17
GLsizei const GLfloat * value
Definition: glext.h:4134
GLenum GLenum GLvoid GLvoid * column
Definition: glext.h:3580
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3550
GLubyte GLubyte GLubyte a
Definition: glext.h:6372
XsDataFlags
These flags define the behaviour of data contained by Xsens data structures.
Definition: xstypedefs.h:41
std::vector< T1 > operator*(const std::vector< T1 > &a, const std::vector< T2 > &b)
a*b (element-wise multiplication)
Definition: ops_vectors.h:50
XSTYPES_DLL_API XsSize XsMatrix_offset(const XsMatrix *thisPtr, XsSize row, XsSize column)
const XsSize m_cols
Number of columns in the matrix.
Definition: xsmatrix.h:74
struct XsMatrix XsMatrix
Definition: xsmatrix.h:27



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