Main MRPT website > C++ reference
MRPT logo
CMatrixFixedNumeric.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-2014, 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 #ifndef CMatrixFixedNumeric_H
10 #define CMatrixFixedNumeric_H
11 
12 #include <mrpt/math/CArray.h>
13 #include <mrpt/math/math_frwds.h> // Fordward declarations
15 
16 namespace mrpt
17 {
18  namespace math
19  {
20  using namespace mrpt::system;
21  using namespace mrpt::poses;
22 
23  /** A numeric matrix of compile-time fixed size.
24  * Basically, this class is a wrapper on Eigen::Matrix<T,NROWS,NCOLS>, but
25  * with a RowMajor element memory layout (except for column vectors).
26  *
27  * These matrices also have iterators to access all the elements in the matrix as a sequence, starting from the element (0,0), then row by row, from left to right.
28  *
29  * \note This class exists for backward compatibility of ancient times when MRPT didn't rely on Eigen, feel free to directly use Eigen::Matrix<> types instead.
30  * \sa CMatrixTemplateNumeric (for dynamic-size matrices)
31  * \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
32  * \ingroup mrpt_base_grp
33  */
34  template <typename T,size_t NROWS,size_t NCOLS>
36  public Eigen::Matrix<
37  T,
38  NROWS,
39  NCOLS,
40  // Use row major storage for backward compatibility with MRPT matrices in all cases, except in column vectors:
41  Eigen::AutoAlign |
42  ( (NCOLS==1 && NROWS!=1) ? Eigen::ColMajor : Eigen::RowMajor )
43  >
44  {
45  public:
46  typedef Eigen::Matrix<T,NROWS,NCOLS, Eigen::AutoAlign | ( (NCOLS==1 && NROWS!=1) ? Eigen::ColMajor : Eigen::RowMajor ) > Base;
48 
49  MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(CMatrixFixedNumeric) // Implements ctor and "operator =" for any other Eigen class
51 
52  /** Default constructor, initializes all elements to zero */
53  inline CMatrixFixedNumeric() : Base() { Base::setZero(); }
54 
55  /** Constructor from an array in row major */
56  inline CMatrixFixedNumeric(const T * vals) : Base(vals) { }
57 
58  /** Constructor which leaves the matrix uninitialized.
59  * Example of usage: CMatrixFixedNumeric<double,3,2> M(UNINITIALIZED_MATRIX);
60  */
61  inline CMatrixFixedNumeric(TConstructorFlags_Matrices constructor_flag) : Base() { }
62 
63  template<size_t N,typename ReturnType> inline ReturnType getVicinity(size_t c,size_t r) const {
64  return detail::getVicinity<CMatrixFixedNumeric<T,NROWS,NCOLS>,T,ReturnType,N>::get(c,r,*this);
65  }
66 
67  inline void loadFromArray(const T* vals)
68  {
69  Base b(vals);
70  *this = b;
71  }
72 
73  /** == comparison of two matrices; it differs from default Eigen operator in that returns false if matrices are of different sizes instead of raising an assert. */
74  template <typename Derived>
75  inline bool operator ==(const Eigen::MatrixBase<Derived>& m2) const
76  {
77  return Base::cols()==m2.cols() &&
78  Base::rows()==m2.rows() &&
79  Base::cwiseEqual(m2).all();
80  }
81  /** != comparison of two matrices; it differs from default Eigen operator in that returns true if matrices are of different sizes instead of raising an assert. */
82  template <typename Derived>
83  inline bool operator !=(const Eigen::MatrixBase<Derived>& m2) const { return !((*this)==m2); }
84 
85 
86  }; // end of class definition ------------------------------
87 
88  /** @name Typedefs for common sizes
89  @{ */
108 
126  /** @} */
127 
128 
129  namespace detail
130  {
131  /**
132  * Vicinity traits class specialization for fixed size matrices.
133  */
134  template<typename T,size_t D> class VicinityTraits<CMatrixFixedNumeric<T,D,D> > {
135  public:
136  inline static void initialize(CMatrixFixedNumeric<T,D,D> &mat,size_t N) {
137  ASSERT_(N==D);
138  }
139  inline static void insertInContainer(CMatrixFixedNumeric<T,D,D> &mat,size_t r,size_t c,const T &t) {
140  mat.get_unsafe(r,c)=t;
141  }
142  };
143  } //End of detail namespace.
144 
145 
146  } // End of namespace
147 
148  namespace utils
149  {
150  // Extensions to mrpt::utils::TTypeName for matrices:
151  template<typename T,size_t N,size_t M> struct TTypeName <mrpt::math::CMatrixFixedNumeric<T,N,M> > {
152  static std::string get() { return mrpt::format("CMatrixFixedNumeric<%s,%u,%u>",TTypeName<T>::get().c_str(),(unsigned int)N,(unsigned int)M); }
153  };
154  }
155 
156 } // End of namespace
157 
158 #endif
bool operator!=(const CArray< T, N > &x, const CArray< T, N > &y)
Definition: CArray.h:280
CMatrixFixedNumeric< float, 1, 5 > CMatrixFloat15
CMatrixFixedNumeric< double, 5, 1 > CMatrixDouble51
static void initialize(CMatrixFixedNumeric< T, D, D > &mat, size_t N)
CMatrixFixedNumeric< float, 1, 3 > CMatrixFloat13
TConstructorFlags_Matrices
For usage in one of the constructors of CMatrixFixedNumeric or CMatrixTemplate (and derived classes)...
Definition: math_frwds.h:81
CMatrixFixedNumeric< float, 2, 1 > CMatrixFloat21
CMatrixFixedNumeric< double, 3, 1 > CMatrixDouble31
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:32
A template to obtain the type of its argument as a string at compile time.
Definition: TTypeName.h:46
CMatrixFixedNumeric< float, 2, 2 > CMatrixFloat22
CMatrixFixedNumeric< float, 1, 2 > CMatrixFloat12
CMatrixFixedNumeric< float, 7, 1 > CMatrixFloat71
CMatrixFixedNumeric< float, 3, 2 > CMatrixFloat32
CMatrixFixedNumeric< double, 4, 4 > CMatrixDouble44
EIGEN_STRONG_INLINE const AdjointReturnType t() const
Transpose.
CMatrixFixedNumeric< T, NROWS, NCOLS > mrpt_autotype
CMatrixFixedNumeric< float, 6, 1 > CMatrixFloat61
CMatrixFixedNumeric< double, 2, 1 > CMatrixDouble21
Eigen::Matrix< T, NROWS, NCOLS, Eigen::AutoAlign|((NCOLS==1 &&NROWS!=1) ? Eigen::ColMajor :Eigen::RowMajor) > Base
CMatrixFixedNumeric< double, 1, 6 > CMatrixDouble16
MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(CMatrixFixedNumeric) inline CMatrixFixedNumeric()
Default constructor, initializes all elements to zero.
CMatrixFixedNumeric< double, 2, 3 > CMatrixDouble23
CMatrixFixedNumeric< float, 5, 1 > CMatrixFloat51
A numeric matrix of compile-time fixed size.
CMatrixFixedNumeric< float, 7, 7 > CMatrixFloat77
CMatrixFixedNumeric< double, 1, 2 > CMatrixDouble12
CMatrixFixedNumeric< double, 7, 7 > CMatrixDouble77
The purpose of this class is to model traits for containers, so that they can be used as return value...
Definition: math_frwds.h:153
static void insertInContainer(CMatrixFixedNumeric< T, D, D > &mat, size_t r, size_t c, const T &t)
bool operator==(const CArray< T, N > &x, const CArray< T, N > &y)
Definition: CArray.h:272
#define MRPT_MATRIX_CONSTRUCTORS_FROM_POSES(_CLASS_)
CMatrixFixedNumeric< double, 3, 3 > CMatrixDouble33
CMatrixFixedNumeric< double, 1, 7 > CMatrixDouble17
CMatrixFixedNumeric< double, 4, 1 > CMatrixDouble41
CMatrixFixedNumeric(const T *vals)
Constructor from an array in row major.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
CMatrixFixedNumeric< float, 2, 3 > CMatrixFloat23
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
CMatrixFixedNumeric< double, 1, 3 > CMatrixDouble13
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CMatrixFixedNumeric< float, 3, 1 > CMatrixFloat31
CMatrixFixedNumeric< double, 3, 2 > CMatrixDouble32
CMatrixFixedNumeric< double, 1, 5 > CMatrixDouble15
#define ASSERT_(f)
ReturnType getVicinity(size_t c, size_t r) const
This huge template encapsulates a function to get the vicinity of an element, with maximum genericity...
Definition: math_frwds.h:165
CMatrixFixedNumeric< float, 6, 6 > CMatrixFloat66
CMatrixFixedNumeric< double, 7, 1 > CMatrixDouble71
CMatrixFixedNumeric< float, 1, 7 > CMatrixFloat17
CMatrixFixedNumeric< double, 6, 6 > CMatrixDouble66
CMatrixFixedNumeric(TConstructorFlags_Matrices constructor_flag)
Constructor which leaves the matrix uninitialized.
CMatrixFixedNumeric< double, 6, 1 > CMatrixDouble61
CMatrixFixedNumeric< float, 3, 3 > CMatrixFloat33
CMatrixFixedNumeric< float, 1, 6 > CMatrixFloat16
CMatrixFixedNumeric< float, 4, 4 > CMatrixFloat44
CMatrixFixedNumeric< double, 2, 2 > CMatrixDouble22



Page generated by Doxygen 1.8.14 for MRPT 1.1.0 SVN: at lun oct 28 00:54:49 CET 2019 Hosted on:
SourceForge.net Logo