Main MRPT website > C++ reference for MRPT 1.9.9
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-2018, 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/math/math_frwds.h> // Forward declarations
12 #include <mrpt/math/eigen_frwds.h>
13 #include <mrpt/math/types_math.h>
17 #include <mrpt/math/point_poses2vectors.h> // MRPT_MATRIX_CONSTRUCTORS_FROM_POSES()
18 
19 namespace mrpt
20 {
21 namespace math
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
28  * as a sequence, starting from the element (0,0), then row by row, from left to
29  * right.
30  *
31  * \note This class exists for backward compatibility of ancient times when MRPT
32  * didn't rely on Eigen, feel free to directly use Eigen::Matrix<> types
33  * instead.
34  * \sa CMatrixTemplateNumeric (for dynamic-size matrices)
35  * \note For a complete introduction to Matrices and vectors in MRPT, see:
36  * http://www.mrpt.org/Matrices_vectors_arrays_and_Linear_Algebra_MRPT_and_Eigen_classes
37  * \ingroup mrpt_math_grp
38  */
39 template <typename T, size_t NROWS, size_t NCOLS>
41  : public Eigen::Matrix<
42  T, NROWS, NCOLS,
43  // Use row major storage for backward compatibility with MRPT matrices
44  // in all cases, except in column vectors:
45  Eigen::AutoAlign |
46  ((NCOLS == 1 && NROWS != 1) ? Eigen::ColMajor : Eigen::RowMajor)>
47 {
48  public:
49  using Base = Eigen::Matrix<
50  T, NROWS, NCOLS,
51  Eigen::AutoAlign |
52  ((NCOLS == 1 && NROWS != 1) ? Eigen::ColMajor : Eigen::RowMajor)>;
56  CMatrixFixedNumeric) // Implements ctor and "operator =" for any other
57  // Eigen class
58 
59  /** Default constructor, initializes all elements to zero */
60  inline CMatrixFixedNumeric() : Base() { Base::setZero(); }
61  /** Constructor from an array in row major */
62  inline CMatrixFixedNumeric(const T* vals) : Base(vals) {}
63  /** Constructor which leaves the matrix uninitialized.
64  * Example of usage: CMatrixFixedNumeric<double,3,2>
65  * M(mrpt::math::UNINITIALIZED_MATRIX);
66  */
68  template <size_t N, typename ReturnType>
69  inline ReturnType getVicinity(size_t c, size_t r) const
70  {
71  return detail::getVicinity<
73  N>::get(c, r, *this);
74  }
75 
76  inline void loadFromArray(const T* vals)
77  {
78  Base b(vals);
79  *this = b;
80  }
81 
82  /** == comparison of two matrices; it differs from default Eigen operator in
83  * that returns false if matrices are of different sizes instead of raising
84  * an assert. */
85  template <typename Derived>
86  inline bool operator==(const Eigen::MatrixBase<Derived>& m2) const
87  {
88  return Base::cols() == m2.cols() && Base::rows() == m2.rows() &&
89  Base::cwiseEqual(m2).all();
90  }
91  /** != comparison of two matrices; it differs from default Eigen operator in
92  * that returns true if matrices are of different sizes instead of raising
93  * an assert. */
94  template <typename Derived>
95  inline bool operator!=(const Eigen::MatrixBase<Derived>& m2) const
96  {
97  return !((*this) == m2);
98  }
99 
100 }; // end of class definition ------------------------------
101 
102 namespace detail
103 {
104 /**
105  * Vicinity traits class specialization for fixed size matrices.
106  */
107 template <typename T, size_t D>
109 {
110  public:
111  inline static void initialize(CMatrixFixedNumeric<T, D, D>& mat, size_t N)
112  {
113  UNUSED(mat);
114  ASSERT_(N == D);
115  }
116  inline static void insertInContainer(
117  CMatrixFixedNumeric<T, D, D>& mat, size_t r, size_t c, const T& t)
118  {
119  mat.get_unsafe(r, c) = t;
120  }
121 };
122 } // namespace detail
123 
124 } // namespace math
125 
126 namespace typemeta
127 {
128 // Extensions to mrpt::typemeta::TTypeName for matrices:
129 template <typename T, size_t N, size_t M>
131 {
132  constexpr static auto get()
133  {
134  return literal("CMatrixFixedNumeric<") + TTypeName<T>::get() +
137  }
138 };
139 } // namespace typemeta
140 
141 } // namespace mrpt
mrpt::math::detail::getVicinity
This huge template encapsulates a function to get the vicinity of an element, with maximum genericity...
Definition: math_frwds.h:172
mrpt::typemeta::TTypeName< mrpt::math::CMatrixFixedNumeric< T, N, M > >::get
constexpr static auto get()
Definition: CMatrixFixedNumeric.h:132
t
GLdouble GLdouble t
Definition: glext.h:3689
point_poses2vectors.h
num_to_string.h
c
const GLubyte * c
Definition: glext.h:6313
mrpt::typemeta::TTypeName
A template to obtain the type of its argument as a string at compile time.
Definition: TTypeName.h:65
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::math::detail::VicinityTraits< CMatrixFixedNumeric< T, D, D > >::insertInContainer
static void insertInContainer(CMatrixFixedNumeric< T, D, D > &mat, size_t r, size_t c, const T &t)
Definition: CMatrixFixedNumeric.h:116
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::typemeta::num_to_string
constexpr string representation of a number.
Definition: num_to_string.h:44
mrpt::math::CMatrixFixedNumeric::operator!=
bool operator!=(const Eigen::MatrixBase< Derived > &m2) const
!= comparison of two matrices; it differs from default Eigen operator in that returns true if matrice...
Definition: CMatrixFixedNumeric.h:95
mrpt::math::CMatrixFixedNumeric::Base
Eigen::Matrix< T, NROWS, NCOLS, Eigen::AutoAlign|((NCOLS==1 &&NROWS !=1) ? Eigen::ColMajor :Eigen::RowMajor)> Base
Definition: CMatrixFixedNumeric.h:52
r
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
TTypeName.h
mrpt::math::CMatrixFixedNumeric::loadFromArray
void loadFromArray(const T *vals)
Definition: CMatrixFixedNumeric.h:76
mrpt::math::detail::VicinityTraits
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
mrpt::math::CMatrixFixedNumeric::MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL
MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(CMatrixFixedNumeric) inline CMatrixFixedNumeric()
Default constructor, initializes all elements to zero.
Definition: CMatrixFixedNumeric.h:55
mrpt::math::TConstructorFlags_Matrices
TConstructorFlags_Matrices
For usage in one of the constructors of CMatrixFixedNumeric or CMatrixTemplate (and derived classes),...
Definition: math_frwds.h:73
b
GLubyte GLubyte b
Definition: glext.h:6279
math_frwds.h
mrpt::typemeta::TTypeName::get
constexpr static auto get()
Definition: TTypeName.h:67
mrpt::math::CMatrixFixedNumeric
A numeric matrix of compile-time fixed size.
Definition: CMatrixFixedNumeric.h:40
eigen_frwds.h
mrpt::math::detail::VicinityTraits< CMatrixFixedNumeric< T, D, D > >::initialize
static void initialize(CMatrixFixedNumeric< T, D, D > &mat, size_t N)
Definition: CMatrixFixedNumeric.h:111
mrpt::math::CMatrixFixedNumeric::operator==
bool operator==(const Eigen::MatrixBase< Derived > &m2) const
== comparison of two matrices; it differs from default Eigen operator in that returns false if matric...
Definition: CMatrixFixedNumeric.h:86
MRPT_MATRIX_CONSTRUCTORS_FROM_POSES
#define MRPT_MATRIX_CONSTRUCTORS_FROM_POSES(_CLASS_)
Definition: math_frwds.h:95
Eigen::MatrixBase
Definition: eigen_frwds.h:20
mrpt::math::CMatrixFixedNumeric::CMatrixFixedNumeric
CMatrixFixedNumeric(const T *vals)
Constructor from an array in row major.
Definition: CMatrixFixedNumeric.h:62
CSerializable.h
mrpt::typemeta::literal
constexpr auto literal(const char(&lit)[N_PLUS_1]) -> string_literal< N_PLUS_1 - 1 >
Definition: static_string.h:43
types_math.h
mrpt::math::CMatrixFixedNumeric::CMatrixFixedNumeric
CMatrixFixedNumeric(TConstructorFlags_Matrices)
Constructor which leaves the matrix uninitialized.
Definition: CMatrixFixedNumeric.h:67
mrpt::math::CMatrixFixedNumeric::getVicinity
ReturnType getVicinity(size_t c, size_t r) const
Definition: CMatrixFixedNumeric.h:69



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST