Main MRPT website > C++ reference
MRPT logo
CMatrix.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CMATRIX_H
29 #define CMATRIX_H
30 
34 #include <mrpt/utils/CStream.h>
35 
36 namespace mrpt
37 {
38  namespace math
39  {
40  // This must be added to any CSerializable derived class:
41  // Note: instead of the standard "DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE", classes inheriting
42  // from templates need special nasty handling for MSVC DLL exports...
44  BASE_IMPEXP ::mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in, CMatrixPtr &pObj);
45 
46  /** This class is a "CSerializable" wrapper for "CMatrixFloat".
47  * \note For a complete introduction to Matrices and vectors in MRPT, see: http://www.mrpt.org/Matrices_vectors_arrays_and_Linear_Algebra_MRPT_and_Eigen_classes
48  * \ingroup mrpt_base_grp
49  */
50  class BASE_IMPEXP_TEMPL CMatrix : public mrpt::utils::CSerializable, public CMatrixFloat
51  {
52  // This must be added to any CSerializable derived class:
53  //DEFINE_SERIALIZABLE( CMatrix )
54  //DEFINE_MRPT_OBJECT(CMatrix)
55  protected:
56  static const mrpt::utils::TRuntimeClassId* _GetBaseClass();
58  public:
59  /*! A typedef for the associated smart pointer */
63  virtual BASE_IMPEXP const mrpt::utils::TRuntimeClassId* GetRuntimeClass() const;
64  static BASE_IMPEXP mrpt::utils::CObject* CreateObject();
65  static BASE_IMPEXP CMatrixPtr Create();
66  virtual BASE_IMPEXP mrpt::utils::CObject *duplicate() const;
67  protected:
68  /*! @name CSerializable virtual methods */
69  /*! @{ */
70  BASE_IMPEXP void writeToStream(mrpt::utils::CStream &out, int *getVersion) const;
71  BASE_IMPEXP void readFromStream(mrpt::utils::CStream &in, int version);
72  /*! @} */
73 
74  public:
75  /** Constructor */
76  CMatrix() : CMatrixFloat(1,1)
77  { }
78 
79  /** Constructor */
80  CMatrix(size_t row, size_t col) : CMatrixFloat(row,col)
81  { }
82 
83  /** Copy constructor
84  */
85  CMatrix( const CMatrixFloat &m ) : CMatrixFloat(m)
86  { }
87 
88  /** Copy constructor
89  */
90  CMatrix( const CMatrixTemplateNumeric<double> &m ) : CMatrixFloat(0,0)
91  {
92  *this = m.eval().cast<float>();
93  }
94 
95  /** Constructor from a TPose2D, which generates a 3x1 matrix \f$ [x y \phi]^T \f$
96  */
97  explicit CMatrix( const TPose2D &p) : CMatrixFloat(p) {}
98 
99  /** Constructor from a mrpt::poses::CPose6D, which generates a 6x1 matrix \f$ [x y z yaw pitch roll]^T \f$
100  */
101  explicit CMatrix( const TPose3D &p) : CMatrixFloat(p) {}
102 
103  /** Constructor from a TPoint2D, which generates a 2x1 matrix \f$ [x y]^T \f$
104  */
105  explicit CMatrix( const TPoint2D &p) : CMatrixFloat(p) {}
106 
107  /** Constructor from a TPoint3D, which generates a 3x1 matrix \f$ [x y z]^T \f$
108  */
109  explicit CMatrix( const TPoint3D &p) : CMatrixFloat(p) {}
110 
111  /** Assignment operator for float matrixes
112  */
113  template <class OTHERMAT>
114  inline CMatrix & operator = (const OTHERMAT& m)
115  {
116  CMatrixFloat::operator =(m);
117  return *this;
118  }
119 
120  /*! Assignment operator from any other Eigen class */
121  template<typename OtherDerived>
122  inline CMatrix & operator= (const Eigen::MatrixBase <OtherDerived>& other) {
124  return *this;
125  }
126  /*! Constructor from any other Eigen class */
127  template<typename OtherDerived>
128  inline CMatrix(const Eigen::MatrixBase <OtherDerived>& other) : CMatrixTemplateNumeric<float>(other) { }
129 
130  }; // end of class definition
131 
132  } // End of namespace
133 } // End of namespace
134 
135 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013