Main MRPT website > C++ reference for MRPT 1.9.9
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-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 #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 */
20 namespace 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
31  * & CMatrixD */
32 template <size_t NROWS, size_t NCOLS>
35 {
36  CMatrix aux;
37  in.ReadObject(&aux);
38  ASSERTMSG_(
39  M.cols() == aux.cols() && M.rows() == aux.rows(),
40  format(
41  "Size mismatch: deserialized is %ux%u, expected is %ux%u",
42  (unsigned)aux.getRowCount(), (unsigned)aux.getColCount(),
43  (unsigned)NROWS, (unsigned)NCOLS))
44  M = aux;
45  return in;
46 }
47 /** Read operator from a CStream. The format is compatible with that of CMatrix
48  * & CMatrixD */
49 template <size_t NROWS, size_t NCOLS>
52 {
53  CMatrixD aux;
54  in.ReadObject(&aux);
55  ASSERTMSG_(
56  M.cols() == aux.cols() && M.rows() == aux.rows(),
57  format(
58  "Size mismatch: deserialized is %ux%u, expected is %ux%u",
59  (unsigned)aux.getRowCount(), (unsigned)aux.getColCount(),
60  (unsigned)NROWS, (unsigned)NCOLS))
61  M = aux;
62  return in;
63 }
64 
65 /** Write operator for writing into a CStream. The format is compatible with
66  * that of CMatrix & CMatrixD */
67 template <size_t NROWS, size_t NCOLS>
71 {
72  CMatrix aux = CMatrixFloat(M);
73  out.WriteObject(&aux);
74  return out;
75 }
76 /** Write operator for writing into a CStream. The format is compatible with
77  * that of CMatrix & CMatrixD */
78 template <size_t NROWS, size_t NCOLS>
82 {
83  CMatrixD aux = CMatrixDouble(M);
84  out.WriteObject(&aux);
85  return out;
86 }
87 
88 /** @} */ // end MRPT matrices stream operators
89 
90 /** @name Operators for text streaming of MRPT matrices
91  @{ */
92 
93 /** Dumps the matrix to a text ostream, adding a final "\n" to Eigen's default
94  * output. */
95 template <typename T, size_t NROWS, size_t NCOLS>
96 inline std::ostream& operator<<(
97  std::ostream& s, const CMatrixFixedNumeric<T, NROWS, NCOLS>& m)
98 {
99  Eigen::IOFormat fmt;
100  fmt.matSuffix = "\n";
101  return s << m.format(fmt);
102 }
103 
104 /** Dumps the matrix to a text ostream, adding a final "\n" to Eigen's default
105  * output. */
106 template <typename T>
107 inline std::ostream& operator<<(
108  std::ostream& s, const CMatrixTemplateNumeric<T>& m)
109 {
110  Eigen::IOFormat fmt;
111  fmt.matSuffix = "\n";
112  return s << m.format(fmt);
113 }
114 
115 /** @} */ // end MRPT matrices stream operators
116 
117 /** @} */ // end of grouping
118 } // End of math namespace
119 } // End of mrpt namespace
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
Definition: CMatrixD.h:25
GLdouble s
Definition: glext.h:3676
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
A numeric matrix of compile-time fixed size.
std::ostream & operator<<(std::ostream &o, const TPoint2D &p)
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
CMatrixTemplateNumeric< float > CMatrixFloat
Declares a matrix of float numbers (non serializable).
void WriteObject(const CSerializable *o)
Writes an object to the stream.
Definition: CStream.cpp:158
mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CMatrix::Ptr &pObj)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLuint in
Definition: glext.h:7274
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:25
#define ASSERTMSG_(f, __ERROR_MSG)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019