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



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020