MRPT  2.0.3
CMatrixF.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-2020, 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/CMatrixF.h>
15 
16 using namespace mrpt;
17 using namespace mrpt::math;
18 using namespace mrpt::serialization;
19 
20 // This must be added to any CSerializable class implementation file.
22 
23 uint8_t CMatrixF::serializeGetVersion() const { return 0; }
25 {
26  // First, write the number of rows and columns:
27  out.WriteAs<uint32_t>(rows()).WriteAs<uint32_t>(cols());
28 
29  // Since mrpt-1.9.9, dynamic matrices are stored as a contiguous vector:
30  if (rows() > 0 && cols() > 0)
31  out.WriteBufferFixEndianness<value_type>(
32  &(*this)(0, 0), cols() * rows());
33 }
34 
36 {
37  switch (version)
38  {
39  case 0:
40  {
41  // Read the number of rows and columns:
42  const uint32_t nRows = in.ReadAs<uint32_t>();
43  const uint32_t nCols = in.ReadAs<uint32_t>();
44 
45  setSize(nRows, nCols);
46 
47  if (nRows > 0 && nCols > 0)
49  &(*this)(0, 0), nRows * nCols);
50  }
51  break;
52  default:
54  };
55 }
56 
57 /** Serialize CSerializable Object to CSchemeArchiveBase derived object*/
59 {
61  out["nrows"] = static_cast<uint32_t>(this->rows());
62  out["ncols"] = static_cast<uint32_t>(this->cols());
63  out["data"] = this->inMatlabFormat();
64 }
65 /** Serialize CSchemeArchiveBase derived object to CSerializable Object*/
67 {
68  uint8_t version;
70  switch (version)
71  {
72  case 1:
73  {
74  this->fromMatlabStringFormat(static_cast<std::string>(in["data"]));
75  }
76  break;
77  default:
79  }
80 }
mrpt::serialization::CSchemeArchiveBase
Virtual base class for "schematic archives" (JSON, XML,...)
Definition: CSchemeArchiveBase.h:75
math-precomp.h
mrpt::math::CMatrixDynamic::value_type
T value_type
The type of the matrix elements.
Definition: CMatrixDynamic.h:54
SCHEMA_DESERIALIZE_DATATYPE_VERSION
#define SCHEMA_DESERIALIZE_DATATYPE_VERSION()
For use inside serializeFrom(CSchemeArchiveBase) methods.
Definition: CSerializable.h:139
out
mrpt::vision::TStereoCalibResults out
Definition: chessboard_stereo_camera_calib_unittest.cpp:25
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
mrpt::math::CMatrixF::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Serialize CSerializable Object to CSchemeArchiveBase derived object.
Definition: CMatrixF.cpp:24
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::math::CMatrixF
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrixF.h:22
mrpt::serialization::CArchive::ReadAs
STORED_TYPE ReadAs()
De-serialize a variable and returns it by value.
Definition: CArchive.h:155
mrpt::math::CMatrixF::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Serialize CSchemeArchiveBase derived object to CSerializable Object.
Definition: CMatrixF.cpp:35
mrpt::serialization::CSerializable
The virtual base class which provides a unified interface for all persistent objects in MRPT.
Definition: CSerializable.h:30
CSchemeArchiveBase.h
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
Definition: CSerializable.h:166
mrpt::serialization
Definition: aligned_serialization.h:13
mrpt::serialization::CArchive::ReadBufferFixEndianness
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: CArchive.h:94
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:11
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
CMatrixF.h
SCHEMA_SERIALIZE_DATATYPE_VERSION
#define SCHEMA_SERIALIZE_DATATYPE_VERSION(ser_version)
For use inside all serializeTo(CSchemeArchiveBase) methods.
Definition: CSerializable.h:131



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 29 13:06:46 UTC 2020