Main MRPT website > C++ reference for MRPT 1.5.9
CArrayNumeric.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-2017, 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 _MRPT_CArrayNumeric_H
10 #define _MRPT_CArrayNumeric_H
11 
12 #include <mrpt/utils/core_defs.h>
13 #include <mrpt/utils/types_math.h> // Eigen
14 #include <mrpt/utils/TTypeName.h>
15 #include <mrpt/math/point_poses2vectors.h> // MRPT_MATRIX_CONSTRUCTORS_FROM_POSES()
16 
17 namespace mrpt
18 {
19 namespace math
20 {
21  /** CArrayNumeric is an array for numeric types supporting several mathematical operations (actually, just a wrapper on Eigen::Matrix<T,N,1>)
22  * \sa CArrayFloat, CArrayDouble, CArray
23  */
24  template <typename T, std::size_t N>
25  class CArrayNumeric : public Eigen::Matrix<T,N,1>
26  {
27  public:
28  typedef T value_type;
29  typedef Eigen::Matrix<T,N,1> Base;
30 
31  CArrayNumeric() {} //!< Default constructor
32  /** Constructor from initial values ptr[0]-ptr[N-1] */
33  CArrayNumeric(const T*ptr) : Eigen::Matrix<T,N,1>(ptr) {}
34 
36 
37  /** Initialization from a vector-like source, that is, anything implementing operator[]. */
38  template <class ARRAYLIKE>
39  explicit CArrayNumeric(const ARRAYLIKE &obj) : Eigen::Matrix<T,N,1>(obj) {}
40 
41  template<typename OtherDerived>
42  inline CArrayNumeric<T,N> & operator= (const Eigen::MatrixBase <OtherDerived>& other) {
43  Base::operator=(other);
44  return *this;
45  }
46 
47  };
48 
49  // -------------- Partial specializations of CArrayNumeric -----------
50 
51  /** A partial specialization of CArrayNumeric for float numbers.
52  * \sa CArrayNumeric, CArray */
53  template <std::size_t N>
54  class CArrayFloat : public CArrayNumeric<float,N>
55  {
56  public:
59 
60  CArrayFloat() {} //!< Default constructor
61  CArrayFloat(const float*ptr) : CArrayNumeric<float,N>(ptr) {} //!< Constructor from initial values ptr[0]-ptr[N-1]
62 
64 
65  /** Initialization from a vector-like source, that is, anything implementing operator[]. */
66  template <class ARRAYLIKE>
67  explicit CArrayFloat(const ARRAYLIKE &obj) : CArrayNumeric<float,N>(obj) {}
68  MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(CArrayFloat) // Implements ctor and "operator =" for any other Eigen class
69  };
70 
71  /** A partial specialization of CArrayNumeric for double numbers.
72  * \sa CArrayNumeric, CArray */
73  template <std::size_t N>
74  class CArrayDouble : public CArrayNumeric<double,N>
75  {
76  public:
79 
80  CArrayDouble() {} //!< Default constructor
81  CArrayDouble(const double*ptr) : CArrayNumeric<double,N>(ptr) {} //!< Constructor from initial values ptr[0]-ptr[N-1]
82 
84 
85  /** Initialization from a vector-like source, that is, anything implementing operator[]. */
86  template <class ARRAYLIKE>
87  explicit CArrayDouble(const ARRAYLIKE &obj) : CArrayNumeric<double,N>(obj) {}
88  MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(CArrayDouble) // Implements ctor and "operator =" for any other Eigen class
89  };
90 
91  /** A partial specialization of CArrayNumeric for int numbers.
92  * \sa CArrayNumeric, CArray */
93  template <std::size_t N>
94  class CArrayInt : public CArrayNumeric<int,N>
95  {
96  public:
99 
100  CArrayInt() {} //!< Default constructor
101  CArrayInt(const int*ptr) : CArrayNumeric<int,N>(ptr) {} //!< Constructor from initial values ptr[0]-ptr[N-1]
102  MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(CArrayInt) // Implements ctor and "operator =" for any other Eigen class
103  };
104 
105  /** A partial specialization of CArrayNumeric for unsigned int numbers.
106  * \sa CArrayNumeric, CArray */
107  template <std::size_t N>
108  class CArrayUInt : public CArrayNumeric<unsigned int,N>
109  {
110  public:
113 
114  CArrayUInt() {} //!< Default constructor
115  CArrayUInt(const unsigned int*ptr) : CArrayNumeric<unsigned int,N>(ptr) {} //!< Constructor from initial values ptr[0]-ptr[N-1]
116  MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(CArrayUInt) // Implements ctor and "operator =" for any other Eigen class
117  };
118 
119 } // End of namespace
120 
121 namespace utils
122 {
123  // Extensions to mrpt::utils::TTypeName for matrices:
124  template<typename T,size_t N> struct TTypeName <mrpt::math::CArrayNumeric<T,N> > {
125  static std::string get() { return mrpt::format("CArrayNumeric<%s,%u>",TTypeName<T>::get().c_str(),static_cast<unsigned int>(N)); } };
126  template<size_t N> struct TTypeName <mrpt::math::CArrayDouble<N> > {
127  static std::string get() { return mrpt::format("CArrayNumeric<double,%u>",static_cast<unsigned int>(N)); } };
128  template<size_t N> struct TTypeName <mrpt::math::CArrayFloat<N> > {
129  static std::string get() { return mrpt::format("CArrayNumeric<float,%u>",static_cast<unsigned int>(N)); } };
130 }
131 
132 } // End of namespace
133 
134 
135 #endif
CArrayDouble(const double *ptr)
Constructor from initial values ptr[0]-ptr[N-1].
Definition: CArrayNumeric.h:81
CArrayNumeric()
Default constructor.
Definition: CArrayNumeric.h:31
CArrayInt< N > mrpt_autotype
Definition: CArrayNumeric.h:98
#define MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(_CLASS_)
Definition: types_math.h:47
A template to obtain the type of its argument as a string at compile time.
Definition: TTypeName.h:47
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually...
Definition: CArrayNumeric.h:25
A partial specialization of CArrayNumeric for unsigned int numbers.
CArrayNumeric(const ARRAYLIKE &obj)
Initialization from a vector-like source, that is, anything implementing operator[].
Definition: CArrayNumeric.h:39
CArrayInt(const int *ptr)
Constructor from initial values ptr[0]-ptr[N-1].
CArrayFloat()
Default constructor.
Definition: CArrayNumeric.h:60
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
CArrayFloat(const ARRAYLIKE &obj)
Initialization from a vector-like source, that is, anything implementing operator[].
Definition: CArrayNumeric.h:67
A partial specialization of CArrayNumeric for int numbers.
Definition: CArrayNumeric.h:94
CArrayFloat(const float *ptr)
Constructor from initial values ptr[0]-ptr[N-1].
Definition: CArrayNumeric.h:61
A partial specialization of CArrayNumeric for float numbers.
Definition: CArrayNumeric.h:54
#define MRPT_MATRIX_CONSTRUCTORS_FROM_POSES(_CLASS_)
Definition: math_frwds.h:88
CArrayUInt< N > mrpt_autotype
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLsizei const GLchar ** string
Definition: glext.h:3919
CArrayNumeric< T, N > & operator=(const Eigen::MatrixBase< OtherDerived > &other)
Definition: CArrayNumeric.h:42
CArrayNumeric< unsigned int, N > Base
CArrayNumeric< double, N > Base
Definition: CArrayNumeric.h:77
CArrayDouble()
Default constructor.
Definition: CArrayNumeric.h:80
CArrayDouble< N > mrpt_autotype
Definition: CArrayNumeric.h:78
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CArrayDouble(const ARRAYLIKE &obj)
Initialization from a vector-like source, that is, anything implementing operator[].
Definition: CArrayNumeric.h:87
CArrayUInt()
Default constructor.
CArrayNumeric(const T *ptr)
Constructor from initial values ptr[0]-ptr[N-1].
Definition: CArrayNumeric.h:33
A partial specialization of CArrayNumeric for double numbers.
Definition: CArrayNumeric.h:74
CArrayNumeric< float, N > Base
Definition: CArrayNumeric.h:57
Eigen::Matrix< T, N, 1 > Base
Definition: CArrayNumeric.h:29
CArrayInt()
Default constructor.
CArrayNumeric< int, N > Base
Definition: CArrayNumeric.h:97
CArrayUInt(const unsigned int *ptr)
Constructor from initial values ptr[0]-ptr[N-1].
CArrayFloat< N > mrpt_autotype
Definition: CArrayNumeric.h:58



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020