INTRODUCTION Overview Download and Install Documentation Publications REPOSITORY Libraries DEVELOPER Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
utils.h00001 /* 00002 * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics 00003 * http://gearbox.sf.net/ 00004 * Copyright (c) 2008-2010 Geoffrey Biggs 00005 * 00006 * hokuyo_aist Hokuyo laser scanner driver. 00007 * 00008 * This distribution is licensed to you under the terms described in the 00009 * LICENSE file included in this distribution. 00010 * 00011 * This work is a product of the National Institute of Advanced Industrial 00012 * Science and Technology, Japan. Registration number: H22PRO-1086. 00013 * 00014 * This file is part of hokuyo_aist. 00015 * 00016 * This software is licensed under the Eclipse Public License -v 1.0 (EPL). See 00017 * http://www.opensource.org/licenses/eclipse-1.0.txt 00018 */ 00019 00020 #ifndef UTILS_H__ 00021 #define UTILS_H__ 00022 00023 #include <flexiport/port.h> 00024 #include <string> 00025 #include <vector> 00026 #include <algorithm> 00027 #include <cassert> 00028 00029 #include <iostream> 00030 00031 #if defined(WIN32) 00032 typedef unsigned char uint8_t; 00033 typedef unsigned int uint32_t; 00034 #if defined(HOKUYO_AIST_STATIC) 00035 #define HOKUYO_AIST_EXPORT 00036 #elif defined(HOKUYO_AIST_EXPORTS) 00037 #define HOKUYO_AIST_EXPORT __declspec(dllexport) 00038 #else 00039 #define HOKUYO_AIST_EXPORT __declspec(dllimport) 00040 #endif 00041 #else 00042 #include <stdint.h> 00043 #define HOKUYO_AIST_EXPORT 00044 #endif 00045 00050 namespace hokuyo_aist 00051 { 00052 00053 #ifndef M_PI 00054 double const M_PI = 3.14159265358979323846; 00055 #endif 00056 // Convert radians to degrees 00057 #ifndef RTOD 00058 inline double RTOD(double rad) 00059 { 00060 return rad * 180.0 / M_PI; 00061 } 00062 #endif 00063 // Convert degrees to radians 00064 #ifndef DTOR 00065 inline double DTOR(double deg) 00066 { 00067 return deg * M_PI / 180.0; 00068 } 00069 #endif 00070 00071 00073 template<typename T> 00074 inline T median(std::vector<T>& v) 00075 { 00076 typename std::vector<T>::iterator first(v.begin()); 00077 typename std::vector<T>::iterator median(first + (v.end() - first) / 2); 00078 std::nth_element(first, median, v.end()); 00079 return *median; 00080 } 00081 00082 } // namespace hokuyo_aist 00083 00086 #endif // UTILS_H__ 00087 |