MRPT  1.9.9
CMatrixD.cpp
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 
10 #include "math-precomp.h" // Precompiled headers
11 
12 #include <mrpt/math/CMatrixD.h>
15 
16 using namespace mrpt;
17 using namespace mrpt::math;
18 
19 // This must be added to any CSerializable class implementation file.
21 
22 uint8_t CMatrixD::serializeGetVersion() const { return 0; }
24 {
25  // First, write the number of rows and columns:
26  out << static_cast<uint32_t>(rows()) << static_cast<uint32_t>(cols());
27 
28  // Since mrpt-1.9.9, dynamic matrices are stored as a contiguous vector:
29  if (rows() > 0 && cols() > 0)
31  &(*this)(0, 0), cols() * rows());
32 }
34 {
35  switch (version)
36  {
37  case 0:
38  {
39  uint32_t nRows, nCols;
40 
41  // First, write the number of rows and columns:
42  in >> nRows >> nCols;
43 
44  setSize(nRows, nCols);
45 
46  if (nRows > 0 && nCols > 0)
47  in.ReadBufferFixEndianness<value_type>(
48  &(*this)(0, 0), nRows * nCols);
49  }
50  break;
51  default:
53  };
54 }
55 
56 /** Serialize CSerializable Object to CSchemeArchiveBase derived object*/
58 {
60  out["nrows"] = static_cast<uint32_t>(this->rows());
61  out["ncols"] = static_cast<uint32_t>(this->cols());
62  out["data"] = this->inMatlabFormat();
63 }
64 /** Serialize CSchemeArchiveBase derived object to CSerializable Object*/
66 {
67  uint8_t version;
69  switch (version)
70  {
71  case 1:
72  {
73  this->fromMatlabStringFormat(static_cast<std::string>(in["data"]));
74  }
75  break;
76  default:
78  }
79 }
This class is a "CSerializable" wrapper for "CMatrixDynamic<double>".
Definition: CMatrixD.h:23
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
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: CArchive.h:128
unsigned char uint8_t
Definition: rptypes.h:44
Virtual base class for "schematic archives" (JSON, XML,...)
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
This base provides a set of functions for maths stuff.
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Serialize CSchemeArchiveBase derived object to CSerializable Object.
Definition: CMatrixD.cpp:33
bool fromMatlabStringFormat(const std::string &s, mrpt::optional_ref< std::ostream > dump_errors_here=std::nullopt)
Reads a matrix from a string in Matlab-like format, for example: "[1 0 2; 0 4 -1]" The string must st...
double value_type
The type of the matrix elements.
size_type rows() const
Number of rows in the matrix.
size_type cols() const
Number of columns in the matrix.
#define SCHEMA_DESERIALIZE_DATATYPE_VERSION()
For use inside serializeFrom(CSchemeArchiveBase) methods.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:53
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
GLuint in
Definition: glext.h:7391
std::string inMatlabFormat(const std::size_t decimal_digits=6) const
Exports the matrix as a string compatible with Matlab/Octave.
void serializeTo(mrpt::serialization::CArchive &out) const override
Serialize CSerializable Object to CSchemeArchiveBase derived object.
Definition: CMatrixD.cpp:23
#define SCHEMA_SERIALIZE_DATATYPE_VERSION(ser_version)
For use inside all serializeTo(CSchemeArchiveBase) methods.
unsigned __int32 uint32_t
Definition: rptypes.h:50



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