Main MRPT website > C++ reference for MRPT 1.4.0
matrix_serialization.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-2016, 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#pragma once
10
11#include <mrpt/utils/CStream.h>
12#include <mrpt/math/CMatrix.h>
13#include <mrpt/math/CMatrixD.h>
14
17
18/** \file matrix_serialization.h
19 * This file implements matrix/vector text and binary serialization */
20namespace mrpt
21{
22 namespace math
23 {
24 /** \addtogroup container_ops_grp
25 * @{ */
26
27 /** @name Operators for binary streaming of MRPT matrices
28 @{ */
29
30 /** Read operator from a CStream. The format is compatible with that of CMatrix & CMatrixD */
31 template <size_t NROWS,size_t NCOLS>
33 CMatrix aux;
34 in.ReadObject(&aux);
35 ASSERTMSG_(M.cols()==aux.cols() && M.rows()==aux.rows(), format("Size mismatch: deserialized is %ux%u, expected is %ux%u",(unsigned)aux.getRowCount(),(unsigned)aux.getColCount(),(unsigned)NROWS,(unsigned)NCOLS))
36 M = aux;
37 return in;
38 }
39 /** Read operator from a CStream. The format is compatible with that of CMatrix & CMatrixD */
40 template <size_t NROWS,size_t NCOLS>
42 CMatrixD aux;
43 in.ReadObject(&aux);
44 ASSERTMSG_(M.cols()==aux.cols() && M.rows()==aux.rows(), format("Size mismatch: deserialized is %ux%u, expected is %ux%u",(unsigned)aux.getRowCount(),(unsigned)aux.getColCount(),(unsigned)NROWS,(unsigned)NCOLS))
45 M = aux;
46 return in;
47 }
48
49 /** Write operator for writing into a CStream. The format is compatible with that of CMatrix & CMatrixD */
50 template <size_t NROWS,size_t NCOLS>
52 CMatrix aux = CMatrixFloat(M);
53 out.WriteObject(&aux);
54 return out;
55 }
56 /** Write operator for writing into a CStream. The format is compatible with that of CMatrix & CMatrixD */
57 template <size_t NROWS,size_t NCOLS>
59 CMatrixD aux = CMatrixDouble(M);
60 out.WriteObject(&aux);
61 return out;
62 }
63
64 /** @} */ // end MRPT matrices stream operators
65
66
67 /** @name Operators for text streaming of MRPT matrices
68 @{ */
69
70
71 /** Dumps the matrix to a text ostream, adding a final "\n" to Eigen's default output. */
72 template <typename T,size_t NROWS,size_t NCOLS>
73 inline std::ostream & operator << (std::ostream & s, const CMatrixFixedNumeric<T,NROWS,NCOLS>& m)
74 {
75 Eigen::IOFormat fmt; fmt.matSuffix="\n";
76 return s << m.format(fmt);
77 }
78
79 /** Dumps the matrix to a text ostream, adding a final "\n" to Eigen's default output. */
80 template<typename T>
81 inline std::ostream & operator << (std::ostream & s, const CMatrixTemplateNumeric<T>& m)
82 {
83 Eigen::IOFormat fmt; fmt.matSuffix="\n";
84 return s << m.format(fmt);
85 }
86
87 /** @} */ // end MRPT matrices stream operators
88
89 /** @} */ // end of grouping
90 } // End of math namespace
91} // End of mrpt namespace
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
Definition: CMatrixD.h:31
A numeric matrix of compile-time fixed size.
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:31
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:39
CSerializablePtr ReadObject()
Reads an object from stream, its class determined at runtime, and returns a smart pointer to the obje...
void WriteObject(const CSerializable *o)
Writes an object to the stream.
std::ostream BASE_IMPEXP & operator<<(std::ostream &o, const TPoint2D &p)
#define ASSERTMSG_(f, __ERROR_MSG)
Definition: mrpt_macros.h:260
BASE_IMPEXP::mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CMatrixPtr &pObj)
CMatrixTemplateNumeric< float > CMatrixFloat
Declares a matrix of float numbers (non serializable).
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.



Page generated by Doxygen 1.9.5 for MRPT 1.4.0 SVN: at Sun Nov 27 02:56:59 UTC 2022