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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020