HokuyoAIST  3.0.2
utils.h
Go to the documentation of this file.
1 /* HokuyoAIST
2  *
3  * Header file for various utilities.
4  *
5  * Copyright 2008-2011 Geoffrey Biggs geoffrey.biggs@aist.go.jp
6  * RT-Synthesis Research Group
7  * Intelligent Systems Research Institute,
8  * National Institute of Advanced Industrial Science and Technology (AIST),
9  * Japan
10  * All rights reserved.
11  *
12  * This file is part of HokuyoAIST.
13  *
14  * HokuyoAIST is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU Lesser General Public License as published
16  * by the Free Software Foundation; either version 2.1 of the License,
17  * or (at your option) any later version.
18  *
19  * HokuyoAIST is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with HokuyoAIST. If not, see
26  * <http://www.gnu.org/licenses/>.
27  */
28 
29 #ifndef INCLUDE_HOKUYOAIST_UTILS_H__
30 #define INCLUDE_HOKUYOAIST_UTILS_H__
31 
32 #include <algorithm>
33 #include <cassert>
34 #include <flexiport/port.h>
35 #include <iostream>
36 #include <string>
37 #include <vector>
38 
39 #if defined(WIN32)
40  typedef unsigned char uint8_t;
41  typedef unsigned int uint32_t;
42  #if defined(HOKUYOAIST_STATIC)
43  #define HOKUYOAIST_EXPORT
44  #elif defined(hokuyoaist_EXPORTS)
45  #define HOKUYOAIST_EXPORT __declspec(dllexport)
46  #else
47  #define HOKUYOAIST_EXPORT __declspec(dllimport)
48  #endif
49 #else
50  #include <stdint.h>
51  #define HOKUYOAIST_EXPORT
52 #endif
53 
58 namespace hokuyoaist {
59 
60 #ifndef M_PI
61  double const M_PI = 3.14159265358979323846;
62 #endif
63 // Convert radians to degrees
64 #ifndef RTOD
65  inline double RTOD(double rad)
66  {
67  return rad * 180.0 / M_PI;
68  }
69 #endif
70 // Convert degrees to radians
71 #ifndef DTOR
72  inline double DTOR(double deg)
73  {
74  return deg * M_PI / 180.0;
75  }
76 #endif
77 
78 
80 template<typename T>
81 inline T median(std::vector<T>& v)
82 {
83  typename std::vector<T>::iterator first(v.begin());
84  typename std::vector<T>::iterator median(first + (v.end() - first) / 2);
85  std::nth_element(first, median, v.end());
86  return *median;
87 }
88 
89 } // namespace hokuyoaist
90 
93 #endif // INCLUDE_HOKUYOAIST_UTILS_H__
double RTOD(double rad)
Definition: utils.h:65
double const M_PI
Definition: utils.h:61
T median(std::vector< T > &v)
Find the median value of a std::vector.
Definition: utils.h:81
double DTOR(double deg)
Definition: utils.h:72