HokuyoAIST  3.0.1
utils.h
Go to the documentation of this file.
00001 /* HokuyoAIST
00002  *
00003  * Header file for various utilities.
00004  *
00005  * Copyright 2008-2011 Geoffrey Biggs geoffrey.biggs@aist.go.jp
00006  *     RT-Synthesis Research Group
00007  *     Intelligent Systems Research Institute,
00008  *     National Institute of Advanced Industrial Science and Technology (AIST),
00009  *     Japan
00010  *     All rights reserved.
00011  *
00012  * This file is part of HokuyoAIST.
00013  *
00014  * HokuyoAIST is free software; you can redistribute it and/or modify it
00015  * under the terms of the GNU Lesser General Public License as published
00016  * by the Free Software Foundation; either version 2.1 of the License,
00017  * or (at your option) any later version.
00018  *
00019  * HokuyoAIST is distributed in the hope that it will be useful, but
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with HokuyoAIST. If not, see
00026  * <http://www.gnu.org/licenses/>.
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 // Convert radians to degrees
00065 #ifndef RTOD
00066     inline double RTOD(double rad)
00067     {
00068         return rad * 180.0 / M_PI;
00069     }
00070 #endif
00071 // Convert degrees to radians
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 } // namespace hokuyoaist
00091 
00094 #endif // UTILS_H__
00095