Main MRPT website > C++ reference for MRPT 1.5.6
CMatrix.cpp
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 
10 #include "base-precomp.h" // Precompiled headers
11 
12 
13 #include <mrpt/math/CMatrix.h>
15 #include <mrpt/utils/CStream.h>
16 
17 using namespace mrpt;
18 using namespace mrpt::math;
19 using namespace mrpt::utils;
20 
21 
22 // This must be added to any CSerializable class implementation file.
24 
25 
26 /** Constructor from a TPose2D, which generates a 3x1 matrix \f$ [x y \phi]^T \f$ */
28 /** Constructor from a mrpt::poses::CPose6D, which generates a 6x1 matrix \f$ [x y z yaw pitch roll]^T \f$ */
30 /** Constructor from a TPoint2D, which generates a 2x1 matrix \f$ [x y]^T \f$ */
32 /** Constructor from a TPoint3D, which generates a 3x1 matrix \f$ [x y z]^T \f$ */
34 
35 /*---------------------------------------------------------------
36  writeToStream
37  ---------------------------------------------------------------*/
38 void CMatrix::writeToStream(mrpt::utils::CStream &out, int *out_Version) const
39 {
40  if (out_Version)
41  *out_Version = 0;
42  else
43  {
44  // First, write the number of rows and columns:
45  out << (uint32_t)rows() << (uint32_t)cols();
46 
47  if (rows()>0 && cols()>0)
48  for (Index i=0;i<rows();i++)
49  out.WriteBufferFixEndianness<Scalar>(&coeff(i,0),cols());
50  }
51 
52 }
53 
54 /*---------------------------------------------------------------
55  readFromStream
56  ---------------------------------------------------------------*/
58 {
59  switch(version)
60  {
61  case 0:
62  {
63  uint32_t nRows,nCols;
64 
65  // First, write the number of rows and columns:
66  in >> nRows >> nCols;
67 
68  setSize(nRows,nCols);
69 
70  if (nRows>0 && nCols>0)
71  for (Index i=0;i<rows();i++)
72  in.ReadBufferFixEndianness<Scalar>(&coeffRef(i,0),nCols);
73  } break;
74  default:
76 
77  };
78 }
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:39
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
CMatrix()
Constructor.
Definition: CMatrix.h:37
GLuint in
Definition: glew.h:7146
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
Definition: CStream.h:139
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
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...
int version
Definition: mrpt_jpeglib.h:898
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CMatrix.cpp:38
GLfloat GLfloat p
Definition: glew.h:10113
size_t ReadBufferFixEndianness(T *ptr, size_t ElementCount)
Reads a sequence of elemental datatypes, taking care of reordering their bytes from the MRPT stream s...
Definition: CStream.h:95
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Lightweight 2D pose.
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
Definition: CMatrix.cpp:57
Lightweight 3D point.
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:30
unsigned __int32 uint32_t
Definition: rptypes.h:49
Lightweight 2D point.
double Scalar
Definition: KmUtils.h:41



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018