Main MRPT website > C++ reference for MRPT 1.4.0
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-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#ifndef CMatrixFixedNumeric_H
10#define CMatrixFixedNumeric_H
11
12#include <mrpt/math/math_frwds.h> // Forward declarations
16#include <mrpt/math/point_poses2vectors.h> // MRPT_MATRIX_CONSTRUCTORS_FROM_POSES()
17
18namespace mrpt
19{
20 namespace math
21 {
22 /** A numeric matrix of compile-time fixed size.
23 * Basically, this class is a wrapper on Eigen::Matrix<T,NROWS,NCOLS>, but
24 * with a RowMajor element memory layout (except for column vectors).
25 *
26 * 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.
27 *
28 * \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.
29 * \sa CMatrixTemplateNumeric (for dynamic-size matrices)
30 * \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
31 * \ingroup mrpt_base_grp
32 */
33 template <typename T,size_t NROWS,size_t NCOLS>
35 public Eigen::Matrix<
36 T,
37 NROWS,
38 NCOLS,
39 // Use row major storage for backward compatibility with MRPT matrices in all cases, except in column vectors:
40 Eigen::AutoAlign |
41 ( (NCOLS==1 && NROWS!=1) ? Eigen::ColMajor : Eigen::RowMajor )
42 >
43 {
44 public:
45 typedef Eigen::Matrix<T,NROWS,NCOLS, Eigen::AutoAlign | ( (NCOLS==1 && NROWS!=1) ? Eigen::ColMajor : Eigen::RowMajor ) > Base;
47
48 MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(CMatrixFixedNumeric) // Implements ctor and "operator =" for any other Eigen class
50
51 /** Default constructor, initializes all elements to zero */
52 inline CMatrixFixedNumeric() : Base() { Base::setZero(); }
53
54 /** Constructor from an array in row major */
55 inline CMatrixFixedNumeric(const T * vals) : Base(vals) { }
56
57 /** Constructor which leaves the matrix uninitialized.
58 * Example of usage: CMatrixFixedNumeric<double,3,2> M(mrpt::math::UNINITIALIZED_MATRIX);
59 */
61
62 template<size_t N,typename ReturnType> inline ReturnType getVicinity(size_t c,size_t r) const {
63 return detail::getVicinity<CMatrixFixedNumeric<T,NROWS,NCOLS>,T,ReturnType,N>::get(c,r,*this);
64 }
65
66 inline void loadFromArray(const T* vals)
67 {
68 Base b(vals);
69 *this = b;
70 }
71
72 /** == 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. */
73 template <typename Derived>
74 inline bool operator ==(const Eigen::MatrixBase<Derived>& m2) const
75 {
76 return Base::cols()==m2.cols() &&
77 Base::rows()==m2.rows() &&
78 Base::cwiseEqual(m2).all();
79 }
80 /** != 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. */
81 template <typename Derived>
82 inline bool operator !=(const Eigen::MatrixBase<Derived>& m2) const { return !((*this)==m2); }
83
84
85 }; // end of class definition ------------------------------
86
87 namespace detail
88 {
89 /**
90 * Vicinity traits class specialization for fixed size matrices.
91 */
92 template<typename T,size_t D> class VicinityTraits<CMatrixFixedNumeric<T,D,D> > {
93 public:
94 inline static void initialize(CMatrixFixedNumeric<T,D,D> &mat,size_t N) {
95 UNUSED(mat);
96 ASSERT_(N==D);
97 }
98 inline static void insertInContainer(CMatrixFixedNumeric<T,D,D> &mat,size_t r,size_t c,const T &t) {
99 mat.get_unsafe(r,c)=t;
100 }
101 };
102 } //End of detail namespace.
103
104
105 } // End of namespace
106
107 namespace utils
108 {
109 // Extensions to mrpt::utils::TTypeName for matrices:
110 template<typename T,size_t N,size_t M> struct TTypeName <mrpt::math::CMatrixFixedNumeric<T,N,M> > {
111 static std::string get() { return mrpt::format("CMatrixFixedNumeric<%s,%u,%u>",TTypeName<T>::get().c_str(),(unsigned int)N,(unsigned int)M); }
112 };
113 }
114
115} // End of namespace
116
117#endif
A numeric matrix of compile-time fixed size.
CMatrixFixedNumeric(TConstructorFlags_Matrices)
Constructor which leaves the matrix uninitialized.
Eigen::Matrix< T, NROWS, NCOLS, Eigen::AutoAlign|((NCOLS==1 &&NROWS!=1) ? Eigen::ColMajor :Eigen::RowMajor) > Base
CMatrixFixedNumeric(const T *vals)
Constructor from an array in row major.
CMatrixFixedNumeric< T, NROWS, NCOLS > mrpt_autotype
bool operator!=(const Eigen::MatrixBase< Derived > &m2) const
!= comparison of two matrices; it differs from default Eigen operator in that returns true if matrice...
bool operator==(const Eigen::MatrixBase< Derived > &m2) const
== comparison of two matrices; it differs from default Eigen operator in that returns false if matric...
ReturnType getVicinity(size_t c, size_t r) const
static void initialize(CMatrixFixedNumeric< T, D, D > &mat, size_t N)
static void insertInContainer(CMatrixFixedNumeric< T, D, D > &mat, size_t r, size_t c, const T &t)
The purpose of this class is to model traits for containers, so that they can be used as return value...
Definition: math_frwds.h:141
EIGEN_STRONG_INLINE const AdjointReturnType t() const
Transpose.
#define MRPT_MATRIX_CONSTRUCTORS_FROM_POSES(_CLASS_)
Definition: math_frwds.h:88
#define ASSERT_(f)
Definition: mrpt_macros.h:261
TConstructorFlags_Matrices
For usage in one of the constructors of CMatrixFixedNumeric or CMatrixTemplate (and derived classes),...
Definition: math_frwds.h:74
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.
This huge template encapsulates a function to get the vicinity of an element, with maximum genericity...
Definition: math_frwds.h:153
A template to obtain the type of its argument as a string at compile time.
Definition: TTypeName.h:48
#define MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(_CLASS_)
Definition: types_math.h:47



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Thu Jan 19 22:37:47 UTC 2023