Main MRPT website > C++ reference for MRPT 1.5.6
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 & 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>
51  mrpt::utils::CStream &operator<<(mrpt::utils::CStream &out,const CMatrixFixedNumeric<float,NROWS,NCOLS> & M) {
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>
58  mrpt::utils::CStream &operator<<(mrpt::utils::CStream &out,const CMatrixFixedNumeric<double,NROWS,NCOLS> & M) {
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
CSerializablePtr ReadObject()
Reads an object from stream, its class determined at runtime, and returns a smart pointer to the obje...
Definition: CStream.cpp:486
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
Definition: CMatrixD.h:30
GLuint in
Definition: glew.h:7146
GLdouble s
Definition: glew.h:1295
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
A numeric matrix of compile-time fixed size.
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:21
CMatrixTemplateNumeric< float > CMatrixFloat
Declares a matrix of float numbers (non serializable).
BASE_IMPEXP::mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CMatrixPtr &pObj)
const GLdouble * m
Definition: glew.h:5094
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:30
#define ASSERTMSG_(f, __ERROR_MSG)



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