Main MRPT website > C++ reference for MRPT 1.9.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
22  * operations (actually, just a wrapper on Eigen::Matrix<T,N,1>)
23  * \sa CArrayFloat, CArrayDouble, CArray
24  */
25 template <typename T, std::size_t N>
26 class CArrayNumeric : public Eigen::Matrix<T, N, 1>
27 {
28  public:
29  typedef T value_type;
30  typedef Eigen::Matrix<T, N, 1> Base;
31 
32  /** Default constructor */
34  /** Constructor from initial values ptr[0]-ptr[N-1] */
35  CArrayNumeric(const T* ptr) : Eigen::Matrix<T, N, 1>(ptr) {}
37 
38  /** Initialization from a vector-like source, that is, anything implementing
39  * operator[]. */
40  template <class ARRAYLIKE>
41  explicit CArrayNumeric(const ARRAYLIKE& obj) : Eigen::Matrix<T, N, 1>(obj)
42  {
43  }
44 
45  template <typename OtherDerived>
47  const Eigen::MatrixBase<OtherDerived>& other)
48  {
49  Base::operator=(other);
50  return *this;
51  }
52 };
53 
54 // -------------- Partial specializations of CArrayNumeric -----------
55 
56 /** A partial specialization of CArrayNumeric for float numbers.
57  * \sa CArrayNumeric, CArray */
58 template <std::size_t N>
59 class CArrayFloat : public CArrayNumeric<float, N>
60 {
61  public:
64 
65  /** Default constructor */
67  /** Constructor from initial values ptr[0]-ptr[N-1] */
68  CArrayFloat(const float* ptr) : CArrayNumeric<float, N>(ptr) {}
70 
71  /** Initialization from a vector-like source, that is, anything implementing
72  * operator[]. */
73  template <class ARRAYLIKE>
74  explicit CArrayFloat(const ARRAYLIKE& obj) : CArrayNumeric<float, N>(obj)
75  {
76  }
78  // ctor and
79  // "operator ="
80  // for any other
81  // Eigen class
82 };
83 
84 /** A partial specialization of CArrayNumeric for double numbers.
85  * \sa CArrayNumeric, CArray */
86 template <std::size_t N>
87 class CArrayDouble : public CArrayNumeric<double, N>
88 {
89  public:
92 
93  /** Default constructor */
95  /** Constructor from initial values ptr[0]-ptr[N-1] */
96  CArrayDouble(const double* ptr) : CArrayNumeric<double, N>(ptr) {}
98 
99  /** Initialization from a vector-like source, that is, anything implementing
100  * operator[]. */
101  template <class ARRAYLIKE>
102  explicit CArrayDouble(const ARRAYLIKE& obj) : CArrayNumeric<double, N>(obj)
103  {
104  }
106  // ctor and
107  // "operator ="
108  // for any other
109  // Eigen class
110 };
111 
112 /** A partial specialization of CArrayNumeric for int numbers.
113  * \sa CArrayNumeric, CArray */
114 template <std::size_t N>
115 class CArrayInt : public CArrayNumeric<int, N>
116 {
117  public:
120 
121  /** Default constructor */
123  /** Constructor from initial values ptr[0]-ptr[N-1] */
124  CArrayInt(const int* ptr) : CArrayNumeric<int, N>(ptr) {}
126  // and "operator ="
127  // for any other
128  // Eigen class
129 };
130 
131 /** A partial specialization of CArrayNumeric for unsigned int numbers.
132  * \sa CArrayNumeric, CArray */
133 template <std::size_t N>
134 class CArrayUInt : public CArrayNumeric<unsigned int, N>
135 {
136  public:
139 
140  /** Default constructor */
142  /** Constructor from initial values ptr[0]-ptr[N-1] */
143  CArrayUInt(const unsigned int* ptr) : CArrayNumeric<unsigned int, N>(ptr) {}
145  // and "operator
146  // =" for any
147  // other Eigen
148  // class
149 };
150 
151 } // End of namespace
152 
153 namespace utils
154 {
155 // Extensions to mrpt::utils::TTypeName for matrices:
156 template <typename T, size_t N>
158 {
159  static std::string get()
160  {
161  return mrpt::format(
162  "CArrayNumeric<%s,%u>", TTypeName<T>::get().c_str(),
163  static_cast<unsigned int>(N));
164  }
165 };
166 template <size_t N>
168 {
169  static std::string get()
170  {
171  return mrpt::format(
172  "CArrayNumeric<double,%u>", static_cast<unsigned int>(N));
173  }
174 };
175 template <size_t N>
177 {
178  static std::string get()
179  {
180  return mrpt::format(
181  "CArrayNumeric<float,%u>", static_cast<unsigned int>(N));
182  }
183 };
184 }
185 
186 } // End of namespace
187 
188 #endif
CArrayDouble(const double *ptr)
Constructor from initial values ptr[0]-ptr[N-1].
Definition: CArrayNumeric.h:96
CArrayNumeric()
Default constructor.
Definition: CArrayNumeric.h:33
CArrayNumeric< float, N > Base
Definition: CArrayNumeric.h:62
CArrayInt< N > mrpt_autotype
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
#define MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(_CLASS_)
Definition: types_math.h:46
A template to obtain the type of its argument as a string at compile time.
Definition: TTypeName.h:55
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually...
Definition: CArrayNumeric.h:26
A partial specialization of CArrayNumeric for unsigned int numbers.
CArrayNumeric< unsigned int, N > Base
CArrayNumeric(const ARRAYLIKE &obj)
Initialization from a vector-like source, that is, anything implementing operator[].
Definition: CArrayNumeric.h:41
CArrayInt(const int *ptr)
Constructor from initial values ptr[0]-ptr[N-1].
CArrayFloat()
Default constructor.
Definition: CArrayNumeric.h:66
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
CArrayFloat(const ARRAYLIKE &obj)
Initialization from a vector-like source, that is, anything implementing operator[].
Definition: CArrayNumeric.h:74
A partial specialization of CArrayNumeric for int numbers.
CArrayFloat(const float *ptr)
Constructor from initial values ptr[0]-ptr[N-1].
Definition: CArrayNumeric.h:68
A partial specialization of CArrayNumeric for float numbers.
Definition: CArrayNumeric.h:59
#define MRPT_MATRIX_CONSTRUCTORS_FROM_POSES(_CLASS_)
Definition: math_frwds.h:106
Eigen::Matrix< T, N, 1 > Base
Definition: CArrayNumeric.h:30
CArrayUInt< N > mrpt_autotype
GLsizei const GLchar ** string
Definition: glext.h:4101
CArrayDouble()
Default constructor.
Definition: CArrayNumeric.h:94
CArrayDouble< N > mrpt_autotype
Definition: CArrayNumeric.h:91
CArrayNumeric< T, N > & operator=(const Eigen::MatrixBase< OtherDerived > &other)
Definition: CArrayNumeric.h:46
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[].
CArrayUInt()
Default constructor.
CArrayNumeric(const T *ptr)
Constructor from initial values ptr[0]-ptr[N-1].
Definition: CArrayNumeric.h:35
A partial specialization of CArrayNumeric for double numbers.
Definition: CArrayNumeric.h:87
CArrayNumeric< double, N > Base
Definition: CArrayNumeric.h:90
CArrayNumeric< int, N > Base
CArrayInt()
Default constructor.
CArrayUInt(const unsigned int *ptr)
Constructor from initial values ptr[0]-ptr[N-1].
CArrayFloat< N > mrpt_autotype
Definition: CArrayNumeric.h:63



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019