worldsim/include/worldsimconfig.h

00001 /********************************************************************************
00002  *  WorldSim -- library for robot simulations                                   *
00003  *  Copyright (C) 2008-2011 Gianluca Massera <emmegian@yahoo.it>                *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #ifndef WORLDSIMCONFIG_H
00021 #define WORLDSIMCONFIG_H
00022 
00023 // FARSA_WSIM_TEMPLATE is also for classes that are completely inline
00024 #ifdef WIN32
00025     #ifndef NOMINMAX
00026         //--- the min and max macros defined by window will conflicts with functions defined in YARP_math
00027         #define NOMINMAX
00028     #endif
00029     #ifdef FARSA_WSIM_BUILDING_DLL
00030         #define FARSA_WSIM_API __declspec(dllexport)
00031         #define FARSA_WSIM_TEMPLATE __declspec(dllexport)
00032     #else
00033         #define FARSA_WSIM_API __declspec(dllimport)
00034         #define FARSA_WSIM_TEMPLATE
00035     #endif
00036     #define FARSA_WSIM_INTERNAL
00037 #else
00038     #define FARSA_WSIM_API
00039     #define FARSA_WSIM_TEMPLATE
00040     #define FARSA_WSIM_INTERNAL __attribute__ ((visibility ("hidden")))
00041 #endif
00042 
00043 extern bool FARSA_WSIM_API initWorldSimLib();
00044 static const bool worldSimInitializer = initWorldSimLib();
00045 
00046 //--- read it as: x.yy.zz where
00047 //---  x  is major version
00048 //---  yy is minor version
00049 //---  zz is patch version
00050 //--- Example: version 2.4.6 is 20406
00051 #define FARSA_WSIM_VERSION 00600
00052 
00053 #include <QDebug>
00054 #include <QtGlobal>
00055 #include <QMetaType>
00056 
00058 #define UNUSED_PARAM( a ) ( (void) a );
00059 
00060 namespace farsa {
00061 
00065 typedef float real;
00066 
00067 #define PI_GRECO 3.14159265358979323846f
00068 
00077 inline real toRad( real x ) {
00078     return (x)*PI_GRECO/180.0f;
00079 };
00080 
00084 inline real toDegree( real x ) {
00085     return (x)*180.0f/PI_GRECO;
00086 };
00087 
00091 template<class T, class U>
00092 const T min( const T& t1, const U& t2 ) {
00093     if ( t1 < t2 ) {
00094         return t1;
00095     } else {
00096         return (T)t2;
00097     }
00098 }
00099 
00103 template<class T, class U>
00104 const T max( const T& t1, const U& t2 ) {
00105     if ( t1 > t2 ) {
00106         return t1;
00107     } else {
00108         return (T)t2;
00109     }
00110 }
00111 
00115 inline real ramp( real minv, real maxv, real value ) {
00116     if ( value > maxv ) return maxv;
00117     if ( value < minv ) return minv;
00118     return value;
00119 }
00120 
00130 inline float linearMap( float x, float min = -10, float max = 10,
00131                 float outMin = -1, float outMax = 1 ) {
00132     float m = ( outMax-outMin )/( max-min );
00133     float q = outMin - m*min;
00134     float ret = m*x+q;
00135     if (ret < outMin) return outMin;
00136     if (ret > outMax) return outMax;
00137     return ret;
00138 }
00139 
00149 inline float invLinearMap( float x, float min = -10, float max = 10,
00150                     float outMin = -1, float outMax = 1 ) {
00151     double m = - ( outMax-outMin )/( max-min );
00152     double q = outMax - m*min;
00153     double ret = m*x+q;
00154     if (ret < outMin) return outMin;
00155     if (ret > outMax) return outMax;
00156     return ret;
00157 }
00158 
00159 } // end namespace farsa
00160 
00161 #include "simpletimer.h"
00162 
00163 #endif