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 };
00084
00085
00086
00087 #define RET_VOID_ASSERT_MRPTCONTAINER(_CONTAINER) \
00088 typename _CONTAINER::template mrpt_container<void>::void_type
00089
00090
00091
00092 #define RET_VOID_ASSERT_MRPTCONTAINERS(_CONTAINER1,_CONTAINER2) \
00093 typename _CONTAINER1::template mrpt_container<typename _CONTAINER2::mrpt_autotype>::void_type
00094
00095
00096
00097 #define RET_CONT1_ASSERT_MRPTCONTAINERS(_CONTAINER1,_CONTAINER2) \
00098 typename _CONTAINER1::template mrpt_container<typename _CONTAINER2::mrpt_autotype>::cont_type
00099
00100
00101
00102 #define RET_ELEMENT_ASSERT_MRPTCONTAINERS(_CONTAINER1,_CONTAINER2) \
00103 typename _CONTAINER1::template mrpt_container<typename _CONTAINER2::mrpt_autotype>::element_type
00104
00105
00106
00107 #define RET_CONT_ASSERT_MRPTCONTAINER(_CONTAINER) \
00108 typename _CONTAINER::mrpt_autotype
00109
00110
00111
00112 #define RET_ELEMENT_ASSERT_MRPTCONTAINER(_CONTAINER) \
00113 typename _CONTAINER::mrpt_autotype::value_type
00114
00115
00116
00117 #define RET_TYPE_ASSERT_MRPTCONTAINER(_CONTAINER,_RETTYPE) \
00118 typename _CONTAINER::template mrpt_container<_RETTYPE>::dum_type
00119
00120
00121
00122 #define RET_VOID_ASSERT_MRPTMATRIX(_MATRIX) \
00123 typename _MATRIX::template mrpt_matrix_tag_templ<void>::void_type
00124
00125
00126
00127 #define RET_TYPE_ASSERT_MRPTMATRIX(_MATRIX,_RETTYPE) \
00128 typename _MATRIX::template mrpt_matrix_tag_templ<_RETTYPE>::dum_type
00129
00130
00131
00132 #define RET_MAT_ASSERT_MRPTMATRIX(_MATRIX) \
00133 typename _MATRIX::template mrpt_matrix_tag_templ<void>::cont_type
00134
00135
00136
00137 #define RET_VOID_ASSERT_MRPTMATRICES(_MATRIX1,_MATRIX2) \
00138 typename _MATRIX1::template mrpt_matrix_tag_templ<typename _MATRIX2::mrpt_matrix_tag>::void_type
00139
00140
00141
00142 #define RET_MAT1_ASSERT_MRPTMATRICES(_MATRIX1,_MATRIX2) \
00143 typename _MATRIX1::template mrpt_matrix_tag_templ<typename _MATRIX2::mrpt_matrix_tag>::cont_type
00144
00145
00146
00147
00148
00149 #define RET_CONT1_ASSERT_MRPTVECTORS(_VECTOR1,_VECTOR2) \
00150 typename _VECTOR1::template mrpt_vector_tag_templ<typename _VECTOR2::mrpt_vector_tag>::cont_type
00151
00152
00153
00154 #include <mrpt/math/math_frwds.h>
00155
00156
00157 namespace mrpt
00158 {
00159
00160 template <typename _TYPE>
00161 struct mrpt_base_vector : public std::vector<_TYPE>
00162 {
00163 inline mrpt_base_vector() : std::vector<_TYPE>() {}
00164 inline mrpt_base_vector(const std::vector<_TYPE> &o) : std::vector<_TYPE>(o) {}
00165 inline mrpt_base_vector<_TYPE> & operator =(const std::vector<_TYPE> &o) { std::vector<_TYPE>::operator =(o); return *this; }
00166 inline mrpt_base_vector(size_t N) : std::vector<_TYPE>(N) { }
00167 inline mrpt_base_vector(size_t N,_TYPE val) : std::vector<_TYPE>(N,val) { }
00168 typedef mrpt_base_vector<_TYPE> mrpt_autotype;
00169 DECLARE_MRPT_CONTAINER_TYPES
00170 DECLARE_MRPT_CONTAINER_IS_VECTOR
00171 DECLARE_COMMON_CONTAINERS_MEMBERS(_TYPE)
00172 };
00173
00174 typedef mrpt_base_vector<float> vector_float;
00175 typedef mrpt_base_vector<double> vector_double;
00176
00177 typedef mrpt_base_vector<int8_t> vector_signed_byte;
00178 typedef mrpt_base_vector<int16_t> vector_signed_word;
00179 typedef mrpt_base_vector<int32_t> vector_int;
00180 typedef mrpt_base_vector<int64_t> vector_long;
00181 typedef mrpt_base_vector<size_t> vector_size_t;
00182 typedef mrpt_base_vector<uint8_t> vector_byte;
00183 typedef mrpt_base_vector<uint16_t> vector_word;
00184 typedef mrpt_base_vector<uint32_t> vector_uint;
00185
00186 typedef std::vector<bool> vector_bool;
00187 typedef std::vector<std::string> vector_string;
00188
00189 namespace utils
00190 {
00191
00192 typedef void (*TFunctor_noRet_1inputs)(const void *);
00193 typedef void (*TFunctor_noRet_2inputs)(const void *,const void *);
00194 typedef void (*TFunctor_noRet_3inputs)(const void *,const void *,const void *);
00195
00196 typedef double (*TFunctor_retDouble_1inputs)(const void *);
00197 typedef double (*TFunctor_retDouble_2inputs)(const void *,const void *);
00198 typedef double (*TFunctor_retDouble_3inputs)(const void *,const void *,const void *);
00199
00200 typedef void (*TFunctor_retVecDbl_inpVecDbl)(const vector_double &in, vector_double &out);
00201 typedef void (*TFunctor_retVecFlt_inpVecFlt)(const vector_float &in, vector_float &out);
00202 typedef void (*TFunctor_retVecInt_inpVecInt)(const vector_int &in, vector_int &out);
00203
00204 typedef void (*TFunctor_retVecDbl_inp2VecDbl)(const vector_double &x,const vector_double &y, vector_double &out);
00205 typedef void (*TFunctor_retVecFlt_inp2VecFlt)(const vector_float &x,const vector_float &y, vector_float &out);
00206 typedef void (*TFunctor_retVecInt_inp2VecInt)(const vector_int &x,const vector_int &y, vector_int &out);
00207
00208 typedef double (*TFunctor_retDbl_inp1VecDbl)(const vector_double &in1);
00209 typedef double (*TFunctor_retDbl_inp2VecDbl)(const vector_double &in1,const vector_double &in2);
00210 typedef double (*TFunctor_retDbl_inp3VecDbl)(const vector_double &in1,const vector_double &in2,const vector_double &in3);
00211
00212
00213
00214 #if defined(_MSC_VER) && (_MSC_VER>=1300)
00215 typedef unsigned long long POINTER_TYPE;
00216 #else
00217 typedef unsigned long POINTER_TYPE;
00218 #endif
00219
00220
00221 struct MRPTDLLIMPEXP TColor
00222 {
00223 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) { }
00224 uint8_t R,G,B,A;
00225
00226 operator int(void) const { return (((int)R)<<16) | (((int)G)<<8) | B; }
00227
00228 static TColor red;
00229 static TColor green;
00230 static TColor blue;
00231 static TColor white;
00232 static TColor black;
00233 static TColor gray;
00234 };
00235
00236
00237 struct MRPTDLLIMPEXP TColorf
00238 {
00239 TColorf(float r=0,float g=0,float b=0, float alpha=1.0f) : R(r),G(g),B(b),A(alpha) { }
00240 float R,G,B,A;
00241 };
00242
00243
00244 struct MRPTDLLIMPEXP TPixelCoordf
00245 {
00246 double x,y;
00247
00248
00249 TPixelCoordf() : x(),y() {}
00250
00251
00252 TPixelCoordf(const double _x,const double _y) : x(_x), y(_y) { }
00253 };
00254
00255
00256 struct MRPTDLLIMPEXP TPixelCoord
00257 {
00258 TPixelCoord() : x(0),y(0) { }
00259 TPixelCoord(const int _x,const int _y) : x(_x), y(_y) { }
00260
00261 int x,y;
00262 };
00263
00264 typedef TPixelCoord TImageSize;
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 template <typename T>
00275 struct TParameters : public std::map<std::string,T>
00276 {
00277 inline bool has(const std::string &s) const { return std::map<std::string,T>::end()!=std::map<std::string,T>::find(s); }
00278
00279
00280
00281 T operator[](const std::string &s) const {
00282 typename std::map<std::string,T>::const_iterator it =std::map<std::string,T>::find(s);
00283 if (std::map<std::string,T>::end()==it)
00284 throw std::logic_error(std::string("Parameter '")+s+std::string("' is not present.").c_str());
00285 return it->second;
00286 }
00287
00288 inline T & operator[](const std::string &s) { return std::map<std::string,T>::operator[](s); }
00289 };
00290 }
00291 }
00292
00293 #endif
00294