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 #include <cstdarg>
00039 #include <iostream>
00040 #include <sstream>
00041
00042 #include <ctime>
00043
00044
00045 #ifndef __STDC_FORMAT_MACROS
00046 # define __STDC_FORMAT_MACROS
00047 #endif
00048 #ifndef __STDC_CONSTANT_MACROS
00049 # define __STDC_CONSTANT_MACROS
00050 #endif
00051 #ifndef __STDC_LIMIT_MACROS
00052 # define __STDC_LIMIT_MACROS
00053 #endif
00054
00055
00056 #include "pstdint.h"
00057
00058 #if HAVE_INTTYPES_H
00059 # include <inttypes.h>
00060 #elif defined(_MSC_VER)
00061 # include <mrpt/utils/msvc_inttypes.h>
00062 #endif
00063
00064
00065 #if MRPT_HAS_SSE2
00066 #include <emmintrin.h>
00067 #include <mmintrin.h>
00068 #endif
00069
00070
00071 #include <mrpt/math/math_frwds.h>
00072
00073
00074
00075
00076
00077 #include <iostream>
00078 #include <fstream>
00079 #include <sstream>
00080 #ifdef EIGEN_MAJOR_VERSION
00081 # error **FATAL ERROR**: MRPT headers must be included before Eigen headers.
00082 #endif
00083 #define EIGEN_USE_NEW_STDVECTOR
00084 #include <Eigen/Dense>
00085 #include <Eigen/StdVector>
00086 #include <Eigen/StdDeque>
00087
00088 #if !EIGEN_VERSION_AT_LEAST(2,90,0)
00089 #error MRPT needs version 3.0.0-beta of Eigen or newer
00090 #endif
00091
00092
00093 #include EIGEN_MATRIXBASE_PLUGIN_POST_IMPL
00094
00095
00096
00097
00098
00099
00100 #define MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(_CLASS_) \
00101 \
00102 template<typename OtherDerived> \
00103 inline mrpt_autotype & operator= (const Eigen::MatrixBase <OtherDerived>& other) { \
00104 \
00105 Base::operator=(other); \
00106 return *this; \
00107 } \
00108 \
00109 template<typename OtherDerived> \
00110 inline _CLASS_(const Eigen::MatrixBase <OtherDerived>& other) : Base(other.template cast<typename Base::Scalar>()) { } \
00111
00112 namespace mrpt
00113 {
00114
00115 template <typename T>
00116 struct dynamicsize_vector : public Eigen::Matrix<T,Eigen::Dynamic,1>
00117 {
00118 typedef Eigen::Matrix<T,Eigen::Dynamic,1> Base;
00119 typedef dynamicsize_vector<T> mrpt_autotype;
00120 MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(dynamicsize_vector)
00121
00122
00123 inline dynamicsize_vector() : Base() {}
00124
00125 inline dynamicsize_vector(size_t N) : Base(N,1) { Base::derived().setZero(); }
00126
00127 inline dynamicsize_vector(size_t N, T init_val) : Base(N,1) { Base::derived().assign(init_val); }
00128
00129 template <typename R>
00130 inline dynamicsize_vector(const std::vector<R>& v) : Base(v.size(),1) { for (size_t i=0;i<v.size();i++) (*this)[i]=v[i]; }
00131
00132 inline void resize(const size_t N, const T default_val) { Base::derived().resize(N,1); Base::derived().setConstant(default_val); }
00133
00134 inline void resize(const size_t N) { Base::derived().conservativeResize(N); }
00135
00136 inline void clear() { *this = dynamicsize_vector<T>(); }
00137
00138 inline void reserve(size_t dummy_size) { }
00139 };
00140
00141 typedef dynamicsize_vector<float> vector_float;
00142 typedef dynamicsize_vector<double> vector_double;
00143
00144 typedef std::vector<int8_t> vector_signed_byte;
00145 typedef std::vector<int16_t> vector_signed_word;
00146 typedef std::vector<int32_t> vector_int;
00147 typedef std::vector<int64_t> vector_long;
00148 typedef std::vector<size_t> vector_size_t;
00149 typedef std::vector<uint8_t> vector_byte;
00150 typedef std::vector<uint16_t> vector_word;
00151 typedef std::vector<uint32_t> vector_uint;
00152 typedef std::vector<bool> vector_bool;
00153 typedef std::vector<std::string> vector_string;
00154
00155
00156 template <class TYPE1,class TYPE2=TYPE1>
00157 struct aligned_containers
00158 {
00159 typedef std::pair<TYPE1,TYPE2> pair_t;
00160 typedef std::vector<TYPE1, Eigen::aligned_allocator<TYPE1> > vector_t;
00161 typedef std::deque<TYPE1, Eigen::aligned_allocator<TYPE1> > deque_t;
00162 typedef std::map<TYPE1,TYPE2,std::less<TYPE1>,Eigen::aligned_allocator<std::pair<const TYPE1,TYPE2> > > map_t;
00163 typedef std::multimap<TYPE1,TYPE2,std::less<TYPE1>,Eigen::aligned_allocator<std::pair<const TYPE1,TYPE2> > > multimap_t;
00164 };
00165
00166 namespace utils
00167 {
00168
00169
00170 #if defined(_MSC_VER) && (_MSC_VER>=1300)
00171 typedef unsigned long long POINTER_TYPE;
00172 #else
00173 typedef unsigned long POINTER_TYPE;
00174 #endif
00175
00176
00177 struct BASE_IMPEXP TColor
00178 {
00179 inline TColor() : R(0),G(0),B(0),A(255) { }
00180 inline TColor(uint8_t r,uint8_t g,uint8_t b, uint8_t alpha=255) : R(r),G(g),B(b),A(alpha) { }
00181 inline explicit TColor(const unsigned int color_RGB_24bit) : R(uint8_t(color_RGB_24bit>>16)),G(uint8_t(color_RGB_24bit>>8)),B(uint8_t(color_RGB_24bit)),A(255) { }
00182 uint8_t R,G,B,A;
00183
00184 inline operator unsigned int(void) const { return (((unsigned int)R)<<16) | (((unsigned int)G)<<8) | B; }
00185
00186 static TColor red;
00187 static TColor green;
00188 static TColor blue;
00189 static TColor white;
00190 static TColor black;
00191 static TColor gray;
00192 };
00193
00194
00195 struct BASE_IMPEXP TColorf
00196 {
00197 TColorf(float r=0,float g=0,float b=0, float alpha=1.0f) : R(r),G(g),B(b),A(alpha) { }
00198 explicit TColorf(const TColor &col) : R(col.R*(1.f/255)),G(col.G*(1.f/255)),B(col.B*(1.f/255)),A(col.A*(1.f/255)) { }
00199 float R,G,B,A;
00200 };
00201
00202
00203 struct BASE_IMPEXP TPixelCoordf
00204 {
00205 float x,y;
00206
00207
00208 TPixelCoordf() : x(),y() {}
00209
00210
00211 TPixelCoordf(const float _x,const float _y) : x(_x), y(_y) { }
00212 };
00213
00214 std::ostream BASE_IMPEXP & operator <<(std::ostream& o, const TPixelCoordf& p);
00215
00216
00217 struct BASE_IMPEXP TPixelCoord
00218 {
00219 TPixelCoord() : x(0),y(0) { }
00220 TPixelCoord(const int _x,const int _y) : x(_x), y(_y) { }
00221
00222 int x,y;
00223 };
00224
00225 std::ostream BASE_IMPEXP & operator <<(std::ostream& o, const TPixelCoord& p);
00226
00227 typedef TPixelCoord TImageSize;
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 template <typename T>
00253 struct TParameters : public std::map<std::string,T>
00254 {
00255 typedef std::map<std::string,T> BASE;
00256
00257 TParameters() : BASE() { }
00258
00259 TParameters(const char *nam1,...) : BASE() {
00260 if (!nam1) return;
00261 T val;
00262 va_list args;
00263 va_start(args,nam1);
00264
00265 val = va_arg(args,T);
00266 BASE::operator[](std::string(nam1)) = val;
00267
00268 const char *nam;
00269 do{
00270 nam = va_arg(args,const char*);
00271 if (nam) {
00272 val = va_arg(args,T);
00273 BASE::operator[](std::string(nam)) = val;
00274 }
00275 } while (nam);
00276 va_end(args);
00277 }
00278 inline bool has(const std::string &s) const { return std::map<std::string,T>::end()!=BASE::find(s); }
00279
00280
00281
00282 inline T operator[](const std::string &s) const {
00283 typename BASE::const_iterator it =BASE::find(s);
00284 if (BASE::end()==it)
00285 throw std::logic_error(std::string("Parameter '")+s+std::string("' is not present.").c_str());
00286 return it->second;
00287 }
00288
00289
00290 inline T getWithDefaultVal(const std::string &s, const T& defaultVal) const {
00291 typename BASE::const_iterator it =BASE::find(s);
00292 if (BASE::end()==it)
00293 return defaultVal;
00294 else return it->second;
00295 }
00296
00297 inline T & operator[](const std::string &s) { return BASE::operator[](s); }
00298
00299
00300 inline void dumpToConsole() const { std::cout << getAsString(); }
00301
00302
00303 inline std::string getAsString() const { std::string s; getAsString(s); return s; }
00304
00305
00306 void getAsString(std::string &s) const {
00307 size_t maxStrLen = 10;
00308 for (typename BASE::const_iterator it=BASE::begin();it!=BASE::end();++it) maxStrLen = std::max(maxStrLen, it->first.size() );
00309 maxStrLen++;
00310 std::stringstream str;
00311 for (typename BASE::const_iterator it=BASE::begin();it!=BASE::end();++it)
00312 str << it->first << std::string(maxStrLen-it->first.size(),' ') << " = " << it->second << std::endl;
00313 s = str.str();
00314 }
00315 };
00316
00317 typedef TParameters<double> TParametersDouble;
00318 typedef TParameters<std::string> TParametersString;
00319
00320 typedef uint64_t TNodeID;
00321 typedef std::pair<TNodeID,TNodeID> TPairNodeIDs;
00322 #define INVALID_NODEID static_cast<TNodeID>(-1)
00323
00324 }
00325 }
00326
00327 #endif
00328