00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef mrpt_utils_types_H
00030 #define mrpt_utils_types_H
00031
00032 #include <vector>
00033 #include <list>
00034 #include <set>
00035 #include <map>
00036 #include <string>
00037 #include <stdexcept>
00038
00039
00040 #include "pstdint.h"
00041
00042 #define __STDC_FORMAT_MACROS
00043 #if HAVE_INTTYPES_H
00044 # include <inttypes.h>
00045 #elif defined(_MSC_VER)
00046 # include <mrpt/utils/msvc_inttypes.h>
00047 #endif
00048
00049
00050 #if MRPT_HAS_SSE2
00051 #include <emmintrin.h>
00052 #include <mmintrin.h>
00053 #endif
00054
00055
00056 #define DECLARE_MRPT_CONTAINER_TYPES \
00057 template <class ANOTHERCONT> struct mrpt_container { \
00058 typedef void void_type; \
00059 typedef ANOTHERCONT dum_type; \
00060 typedef mrpt_autotype cont_type; \
00061 typedef typename mrpt_autotype::value_type element_type; \
00062 };
00063
00064 #define COMMON_DECLARE_MRPT_CONTAINER_IS_MATRIX \
00065 typedef void mrpt_matrix_tag; \
00066 template <class ANOTHERCONT> struct mrpt_matrix_tag_templ { typedef void void_type; typedef ANOTHERCONT dum_type; typedef mrpt_autotype cont_type; \
00067 };
00068
00069 #define DECLARE_MRPT_CONTAINER_IS_MATRIX \
00070 COMMON_DECLARE_MRPT_CONTAINER_IS_MATRIX \
00071 enum dummy_enum { mrpt_matrix_type_ncols = -1, \
00072 mrpt_matrix_type_nrows = -1 }; \
00073
00074 #define DECLARE_MRPT_CONTAINER_IS_MATRIX_FIXED(NROWS,NCOLS) \
00075 COMMON_DECLARE_MRPT_CONTAINER_IS_MATRIX \
00076 enum dummy_enum { mrpt_matrix_type_ncols = NCOLS, \
00077 mrpt_matrix_type_nrows = NROWS };
00078
00079
00080 #define DECLARE_MRPT_CONTAINER_IS_VECTOR \
00081 typedef void mrpt_vector_tag; \
00082 template <class ANOTHERCONT> struct mrpt_vector_tag_templ { typedef void void_type; typedef ANOTHERCONT dum_type; typedef mrpt_autotype cont_type; }; \
00083 enum dummy_enum { mrpt_vector_type_len = -1 }; \
00084
00085 #define DECLARE_MRPT_CONTAINER_IS_VECTOR_FIXED(LEN) \
00086 typedef void mrpt_vector_tag; \
00087 template <class ANOTHERCONT> struct mrpt_vector_tag_templ { typedef void void_type; typedef ANOTHERCONT dum_type; typedef mrpt_autotype cont_type; }; \
00088 enum dummy_enum { mrpt_vector_type_len = LEN }; \
00089
00090
00091
00092 #define RET_VOID_ASSERT_MRPTCONTAINER(_CONTAINER) \
00093 typename _CONTAINER::template mrpt_container<void>::void_type
00094
00095
00096
00097 #define RET_VOID_ASSERT_MRPTCONTAINERS(_CONTAINER1,_CONTAINER2) \
00098 typename _CONTAINER1::template mrpt_container<typename _CONTAINER2::mrpt_autotype>::void_type
00099
00100
00101
00102 #define RET_CONT1_ASSERT_MRPTCONTAINERS(_CONTAINER1,_CONTAINER2) \
00103 typename _CONTAINER1::template mrpt_container<typename _CONTAINER2::mrpt_autotype>::cont_type
00104
00105
00106
00107 #define RET_ELEMENT_ASSERT_MRPTCONTAINERS(_CONTAINER1,_CONTAINER2) \
00108 typename _CONTAINER1::template mrpt_container<typename _CONTAINER2::mrpt_autotype>::element_type
00109
00110
00111
00112 #define RET_CONT_ASSERT_MRPTCONTAINER(_CONTAINER) \
00113 typename _CONTAINER::mrpt_autotype
00114
00115
00116
00117 #define RET_ELEMENT_ASSERT_MRPTCONTAINER(_CONTAINER) \
00118 typename _CONTAINER::mrpt_autotype::value_type
00119
00120
00121
00122 #define RET_TYPE_ASSERT_MRPTCONTAINER(_CONTAINER,_RETTYPE) \
00123 typename _CONTAINER::template mrpt_container<_RETTYPE>::dum_type
00124
00125
00126
00127 #define RET_VOID_ASSERT_MRPTMATRIX(_MATRIX) \
00128 typename _MATRIX::template mrpt_matrix_tag_templ<void>::void_type
00129
00130
00131
00132 #define RET_TYPE_ASSERT_MRPTMATRIX(_MATRIX,_RETTYPE) \
00133 typename _MATRIX::template mrpt_matrix_tag_templ<_RETTYPE>::dum_type
00134
00135
00136
00137 #define RET_MAT_ASSERT_MRPTMATRIX(_MATRIX) \
00138 typename _MATRIX::template mrpt_matrix_tag_templ<void>::cont_type
00139
00140
00141
00142 #define RET_VOID_ASSERT_MRPTMATRICES(_MATRIX1,_MATRIX2) \
00143 typename _MATRIX1::template mrpt_matrix_tag_templ<typename _MATRIX2::mrpt_matrix_tag>::void_type
00144
00145
00146
00147 #define RET_MAT1_ASSERT_MRPTMATRICES(_MATRIX1,_MATRIX2) \
00148 typename _MATRIX1::template mrpt_matrix_tag_templ<typename _MATRIX2::mrpt_matrix_tag>::cont_type
00149
00150
00151
00152
00153
00154 #define RET_CONT1_ASSERT_MRPTVECTORS(_VECTOR1,_VECTOR2) \
00155 typename _VECTOR1::template mrpt_vector_tag_templ<typename _VECTOR2::mrpt_vector_tag>::cont_type
00156
00157
00158
00159 #include <mrpt/math/math_frwds.h>
00160
00161
00162 namespace mrpt
00163 {
00164
00165 template <typename _TYPE>
00166 struct mrpt_base_vector : public std::vector<_TYPE>
00167 {
00168 inline mrpt_base_vector() : std::vector<_TYPE>() {}
00169 inline mrpt_base_vector(const std::vector<_TYPE> &o) : std::vector<_TYPE>(o) {}
00170 inline mrpt_base_vector<_TYPE> & operator =(const std::vector<_TYPE> &o) { std::vector<_TYPE>::operator =(o); return *this; }
00171 inline mrpt_base_vector(size_t N) : std::vector<_TYPE>(N) { }
00172 inline mrpt_base_vector(size_t N,_TYPE val) : std::vector<_TYPE>(N,val) { }
00173 template<typename ITERATOR> inline mrpt_base_vector(const ITERATOR &b,const ITERATOR &e):std::vector<_TYPE>(b,e) {}
00174 typedef mrpt_base_vector<_TYPE> mrpt_autotype;
00175 DECLARE_MRPT_CONTAINER_TYPES
00176 DECLARE_MRPT_CONTAINER_IS_VECTOR
00177 DECLARE_COMMON_CONTAINERS_MEMBERS(_TYPE)
00178 };
00179
00180 typedef mrpt_base_vector<float> vector_float;
00181 typedef mrpt_base_vector<double> vector_double;
00182
00183 typedef mrpt_base_vector<int8_t> vector_signed_byte;
00184 typedef mrpt_base_vector<int16_t> vector_signed_word;
00185 typedef mrpt_base_vector<int32_t> vector_int;
00186 typedef mrpt_base_vector<int64_t> vector_long;
00187 typedef mrpt_base_vector<size_t> vector_size_t;
00188 typedef mrpt_base_vector<uint8_t> vector_byte;
00189 typedef mrpt_base_vector<uint16_t> vector_word;
00190 typedef mrpt_base_vector<uint32_t> vector_uint;
00191
00192 typedef std::vector<bool> vector_bool;
00193 typedef std::vector<std::string> vector_string;
00194
00195 namespace utils
00196 {
00197
00198 typedef void (*TFunctor_noRet_1inputs)(const void *);
00199 typedef void (*TFunctor_noRet_2inputs)(const void *,const void *);
00200 typedef void (*TFunctor_noRet_3inputs)(const void *,const void *,const void *);
00201
00202 typedef double (*TFunctor_retDouble_1inputs)(const void *);
00203 typedef double (*TFunctor_retDouble_2inputs)(const void *,const void *);
00204 typedef double (*TFunctor_retDouble_3inputs)(const void *,const void *,const void *);
00205
00206 typedef void (*TFunctor_retVecDbl_inpVecDbl)(const vector_double &in, vector_double &out);
00207 typedef void (*TFunctor_retVecFlt_inpVecFlt)(const vector_float &in, vector_float &out);
00208 typedef void (*TFunctor_retVecInt_inpVecInt)(const vector_int &in, vector_int &out);
00209
00210 typedef void (*TFunctor_retVecDbl_inp2VecDbl)(const vector_double &x,const vector_double &y, vector_double &out);
00211 typedef void (*TFunctor_retVecFlt_inp2VecFlt)(const vector_float &x,const vector_float &y, vector_float &out);
00212 typedef void (*TFunctor_retVecInt_inp2VecInt)(const vector_int &x,const vector_int &y, vector_int &out);
00213
00214 typedef double (*TFunctor_retDbl_inp1VecDbl)(const vector_double &in1);
00215 typedef double (*TFunctor_retDbl_inp2VecDbl)(const vector_double &in1,const vector_double &in2);
00216 typedef double (*TFunctor_retDbl_inp3VecDbl)(const vector_double &in1,const vector_double &in2,const vector_double &in3);
00217
00218
00219
00220 #if defined(_MSC_VER) && (_MSC_VER>=1300)
00221 typedef unsigned long long POINTER_TYPE;
00222 #else
00223 typedef unsigned long POINTER_TYPE;
00224 #endif
00225
00226
00227 struct BASE_IMPEXP TColor
00228 {
00229 TColor(uint8_t r=0,uint8_t g=0,uint8_t b=0, uint8_t alpha=255) : R(r),G(g),B(b),A(alpha) { }
00230 uint8_t R,G,B,A;
00231
00232 operator int(void) const { return (((int)R)<<16) | (((int)G)<<8) | B; }
00233
00234 static TColor red;
00235 static TColor green;
00236 static TColor blue;
00237 static TColor white;
00238 static TColor black;
00239 static TColor gray;
00240 };
00241
00242
00243 struct BASE_IMPEXP TColorf
00244 {
00245 TColorf(float r=0,float g=0,float b=0, float alpha=1.0f) : R(r),G(g),B(b),A(alpha) { }
00246 float R,G,B,A;
00247 };
00248
00249
00250 struct BASE_IMPEXP TPixelCoordf
00251 {
00252 double x,y;
00253
00254
00255 TPixelCoordf() : x(),y() {}
00256
00257
00258 TPixelCoordf(const double _x,const double _y) : x(_x), y(_y) { }
00259 };
00260
00261
00262 struct BASE_IMPEXP TPixelCoord
00263 {
00264 TPixelCoord() : x(0),y(0) { }
00265 TPixelCoord(const int _x,const int _y) : x(_x), y(_y) { }
00266
00267 int x,y;
00268 };
00269
00270 typedef TPixelCoord TImageSize;
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 template <typename T>
00281 struct TParameters : public std::map<std::string,T>
00282 {
00283 inline bool has(const std::string &s) const { return std::map<std::string,T>::end()!=std::map<std::string,T>::find(s); }
00284
00285
00286
00287 T operator[](const std::string &s) const {
00288 typename std::map<std::string,T>::const_iterator it =std::map<std::string,T>::find(s);
00289 if (std::map<std::string,T>::end()==it)
00290 throw std::logic_error(std::string("Parameter '")+s+std::string("' is not present.").c_str());
00291 return it->second;
00292 }
00293
00294 inline T & operator[](const std::string &s) { return std::map<std::string,T>::operator[](s); }
00295 };
00296 }
00297 }
00298
00299 #endif
00300