utils.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 #ifndef EGRAPH_UTILS_H
00027 #define EGRAPH_UTILS_H
00028 
00029 #include <libplayerc++/playerc++.h>
00030 #include <iostream>
00031 #include <vector>
00032 #include <assert.h>
00033 #include <math.h>
00034 
00035 
00036 using namespace PlayerCc;
00037 using namespace std;
00038 
00039 vector<player_color_t> gColorVec;
00040 
00041 player_color_t gColorFrontier;
00042 player_color_t gColorObstacle;
00043 player_color_t gColorFreeArc;
00044 player_color_t gColorCapture;
00045 player_color_t gColorRed;
00046 player_color_t gColorBlue;
00047 player_color_t gColorGreen;
00048 player_color_t gColorGray;
00049 player_color_t gColorOrange;
00050 
00051 int sign( const double num )
00052 {
00053     if( num > 0 )
00054         return 1;
00055     if( num < 0 )
00056         return -1;
00057     return 0;
00058 }
00059 
00060 int pickIndexInRange( int iMin, int iMax )
00061 {
00062     int iRand = rand();
00063     
00064     double fFrac = iRand/(RAND_MAX + 1.0);
00065     int iAdd = int((iMax - iMin)*fFrac);
00066 
00067     return (iMin + iAdd);
00068 }
00069 
00070 double angDistCCW( double angFrom, double angTo, bool bFixSmall )
00071 {
00072     double dist = (normalize(angTo) - normalize(angFrom));
00073     
00074     // Handle discretized raster lines
00075     if( bFixSmall && fabs(dist) < M_PI/10.0 )
00076     {
00077         dist = fabs(dist);
00078     }
00079     
00080     while( dist < 0 )
00081     {
00082         dist += 2*M_PI;
00083     }
00084     
00085     return dist;
00086 }
00087 
00088 void initColors( )
00089 {
00090     gColorFrontier.alpha = 255;
00091     gColorFrontier.red = 210;
00092     gColorFrontier.green = 0;
00093     gColorFrontier.blue = 0;
00094 
00095     gColorObstacle.alpha = 255;
00096     gColorObstacle.red = 170;
00097     gColorObstacle.green = 255;
00098     gColorObstacle.blue = 170;
00099 
00100     gColorFreeArc.alpha = 255;
00101     gColorFreeArc.red = 170;
00102     gColorFreeArc.green = 170;
00103     gColorFreeArc.blue = 255;
00104     
00105     gColorCapture.alpha = 255;
00106     gColorCapture.red = 0;
00107     gColorCapture.green = 0;
00108     gColorCapture.blue = 0;
00109     
00110     player_color_t color;
00111 
00112     // 0 Chartreuse
00113     color.alpha = 255;
00114     color.red = 127;
00115     color.green = 255;
00116     color.blue = 0;
00117     
00118     gColorGreen = color;
00119 
00120     gColorVec.push_back(color);
00121 
00122     // 1 Blue
00123     color.alpha = 255;
00124     color.red = 0;
00125     color.green = 0;
00126     color.blue = 255;
00127     
00128     gColorBlue = color;
00129 
00130     gColorVec.push_back(color);
00131 
00132     // 2 Coral
00133     color.alpha = 255;
00134     color.red = 255;
00135     color.green = 127;
00136     color.blue = 80;
00137 
00138     gColorVec.push_back(color);
00139 
00140     // 3 Cyan
00141     color.alpha = 255;
00142     color.red = 0;
00143     color.green = 255;
00144     color.blue = 255;
00145 
00146     gColorVec.push_back(color);
00147 
00148     // 4 Dark magenta
00149     color.alpha = 255;
00150     color.red = 139;
00151     color.green = 0;
00152     color.blue = 139;
00153 
00154     gColorVec.push_back(color);
00155 
00156     // 5 Dark cyan
00157     color.alpha = 255;
00158     color.red = 0;
00159     color.green = 139;
00160     color.blue = 139;
00161     
00162     gColorVec.push_back(color);
00163     
00164     // 6 Gold
00165     color.alpha = 255;
00166     color.red = 255;
00167     color.green = 215;
00168     color.blue = 0;
00169 
00170     gColorVec.push_back(color);
00171 
00172     // 7 Forest green
00173     color.alpha = 255;
00174     color.red = 34;
00175     color.green = 139;
00176     color.blue = 34;
00177 
00178     gColorVec.push_back(color);
00179 
00180     // 8 Deep pink
00181     color.alpha = 255;
00182     color.red = 255;
00183     color.green = 20;
00184     color.blue = 147;
00185     
00186     gColorRed = color;
00187 
00188     gColorVec.push_back(color);
00189 
00190     // 9 Peru
00191     color.alpha = 255;
00192     color.red = 205;
00193     color.green = 133;
00194     color.blue = 63;
00195 
00196     gColorVec.push_back(color);
00197 
00198     // 10 Dark Gray
00199     color.alpha = 255;
00200     color.red = 169;
00201     color.green = 169;
00202     color.blue = 169;
00203     
00204     gColorVec.push_back(color);
00205 
00206     // 11 Silver
00207     color.alpha = 255;
00208     color.red = 192;
00209     color.green = 192;
00210     color.blue = 192;
00211     
00212     gColorGray = color;
00213 
00214     gColorVec.push_back(color);
00215 }
00216 
00217 #endif    //UTILS_H

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6