Main MRPT website > C++ reference
MRPT logo
CMatrixFixedNumeric.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (c) 2005-2013, Individual contributors, see AUTHORS file |
7  | Copyright (c) 2005-2013, MAPIR group, University of Malaga |
8  | Copyright (c) 2012-2013, University of Almeria |
9  | All rights reserved. |
10  | |
11  | Redistribution and use in source and binary forms, with or without |
12  | modification, are permitted provided that the following conditions are |
13  | met: |
14  | * Redistributions of source code must retain the above copyright |
15  | notice, this list of conditions and the following disclaimer. |
16  | * Redistributions in binary form must reproduce the above copyright |
17  | notice, this list of conditions and the following disclaimer in the |
18  | documentation and/or other materials provided with the distribution. |
19  | * Neither the name of the copyright holders nor the |
20  | names of its contributors may be used to endorse or promote products |
21  | derived from this software without specific prior written permission.|
22  | |
23  | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24  | 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
25  | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR|
26  | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE |
27  | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL|
28  | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR|
29  | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
30  | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
31  | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
32  | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33  | POSSIBILITY OF SUCH DAMAGE. |
34  +---------------------------------------------------------------------------+ */
35 #ifndef CMatrixFixedNumeric_H
36 #define CMatrixFixedNumeric_H
37 
38 #include <mrpt/math/CArray.h>
39 #include <mrpt/math/math_frwds.h> // Fordward declarations
41 
42 namespace mrpt
43 {
44  namespace math
45  {
46  using namespace mrpt::system;
47  using namespace mrpt::poses;
48 
49  /** A numeric matrix of compile-time fixed size.
50  * Basically, this class is a wrapper on Eigen::Matrix<T,NROWS,NCOLS>, but
51  * with a RowMajor element memory layout (except for column vectors).
52  *
53  * 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.
54  *
55  * \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.
56  * \sa CMatrixTemplateNumeric (for dynamic-size matrices)
57  * \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
58  * \ingroup mrpt_base_grp
59  */
60  template <typename T,size_t NROWS,size_t NCOLS>
62  public Eigen::Matrix<
63  T,
64  NROWS,
65  NCOLS,
66  // Use row major storage for backward compatibility with MRPT matrices in all cases, except in column vectors:
67  Eigen::AutoAlign |
68  ( (NCOLS==1 && NROWS!=1) ? Eigen::ColMajor : Eigen::RowMajor )
69  >
70  {
71  public:
72  typedef Eigen::Matrix<T,NROWS,NCOLS, Eigen::AutoAlign | ( (NCOLS==1 && NROWS!=1) ? Eigen::ColMajor : Eigen::RowMajor ) > Base;
74 
75  MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(CMatrixFixedNumeric) // Implements ctor and "operator =" for any other Eigen class
77 
78  /** Default constructor, initializes all elements to zero */
79  inline CMatrixFixedNumeric() : Base() { Base::setZero(); }
80 
81  /** Constructor from an array in row major */
82  inline CMatrixFixedNumeric(const T * vals) : Base(vals) { }
83 
84  /** Constructor which leaves the matrix uninitialized.
85  * Example of usage: CMatrixFixedNumeric<double,3,2> M(UNINITIALIZED_MATRIX);
86  */
87  inline CMatrixFixedNumeric(TConstructorFlags_Matrices constructor_flag) : Base() { }
88 
89  template<size_t N,typename ReturnType> inline ReturnType getVicinity(size_t c,size_t r) const {
90  return detail::getVicinity<CMatrixFixedNumeric<T,NROWS,NCOLS>,T,ReturnType,N>::get(c,r,*this);
91  }
92 
93  inline void loadFromArray(const T* vals)
94  {
95  Base b(vals);
96  *this = b;
97  }
98 
99  /** == 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. */
100  template <typename Derived>
101  inline bool operator ==(const Eigen::MatrixBase<Derived>& m2) const
102  {
103  return Base::cols()==m2.cols() &&
104  Base::rows()==m2.rows() &&
105  Base::cwiseEqual(m2).all();
106  }
107  /** != 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. */
108  template <typename Derived>
109  inline bool operator !=(const Eigen::MatrixBase<Derived>& m2) const { return !((*this)==m2); }
110 
111 
112  }; // end of class definition ------------------------------
113 
114  /** @name Typedefs for common sizes
115  @{ */
133 
151  /** @} */
152 
153 
154  namespace detail
155  {
156  /**
157  * Vicinity traits class specialization for fixed size matrices.
158  */
159  template<typename T,size_t D> class VicinityTraits<CMatrixFixedNumeric<T,D,D> > {
160  public:
161  inline static void initialize(CMatrixFixedNumeric<T,D,D> &mat,size_t N) {
162  ASSERT_(N==D);
163  }
164  inline static void insertInContainer(CMatrixFixedNumeric<T,D,D> &mat,size_t r,size_t c,const T &t) {
165  mat.get_unsafe(r,c)=t;
166  }
167  };
168  } //End of detail namespace.
169 
170 
171  } // End of namespace
172 
173  namespace utils
174  {
175  // Extensions to mrpt::utils::TTypeName for matrices:
176  template<typename T,size_t N,size_t M> struct TTypeName <mrpt::math::CMatrixFixedNumeric<T,N,M> > {
177  static std::string get() { return mrpt::format("CMatrixFixedNumeric<%s,%u,%u>",TTypeName<T>::get().c_str(),(unsigned int)N,(unsigned int)M); }
178  };
179  }
180 
181 } // End of namespace
182 
183 #endif
bool operator!=(const CArray< T, N > &x, const CArray< T, N > &y)
Definition: CArray.h:306
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:107
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:58
A template to obtain the type of its argument as a string at compile time.
Definition: TTypeName.h:72
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:179
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:298
#define MRPT_MATRIX_CONSTRUCTORS_FROM_POSES(_CLASS_)
CMatrixFixedNumeric< double, 3, 3 > CMatrixDouble33
CMatrixFixedNumeric< double, 1, 7 > CMatrixDouble17
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:191
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.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo