utils.h
Go to the documentation of this file.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 UTILS_H__
00030 #define UTILS_H__
00031
00032 #include <algorithm>
00033 #include <cassert>
00034 #include <flexiport/port.h>
00035 #include <iostream>
00036 #include <string>
00037 #include <vector>
00038
00039 #if defined(WIN32)
00040 typedef unsigned char uint8_t;
00041 typedef unsigned int uint32_t;
00042 #if defined(HOKUYOAIST_STATIC)
00043 #define HOKUYOAIST_EXPORT
00044 #elif defined(hokuyoaist_EXPORTS)
00045 #define HOKUYOAIST_EXPORT __declspec(dllexport)
00046 #else
00047 #define HOKUYOAIST_EXPORT __declspec(dllimport)
00048 #endif
00049 #else
00050 #include <stdint.h>
00051 #define HOKUYOAIST_EXPORT
00052 #endif
00053
00058 namespace hokuyoaist
00059 {
00060
00061 #ifndef M_PI
00062 double const M_PI = 3.14159265358979323846;
00063 #endif
00064
00065 #ifndef RTOD
00066 inline double RTOD(double rad)
00067 {
00068 return rad * 180.0 / M_PI;
00069 }
00070 #endif
00071
00072 #ifndef DTOR
00073 inline double DTOR(double deg)
00074 {
00075 return deg * M_PI / 180.0;
00076 }
00077 #endif
00078
00079
00081 template<typename T>
00082 inline T median(std::vector<T>& v)
00083 {
00084 typename std::vector<T>::iterator first(v.begin());
00085 typename std::vector<T>::iterator median(first + (v.end() - first) / 2);
00086 std::nth_element(first, median, v.end());
00087 return *median;
00088 }
00089
00090 }
00091
00094 #endif // UTILS_H__
00095