psycho-constellation.C

00001 /*!@file AppPsycho/psycho-skin-bsindexing.c Psychophysics main application for indexing experiment */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu>
00034 //
00035 // 2008-02-20 16:14:27Z nnoori $
00036 //
00037 
00038 #ifndef INVT_HAVE_LIBSDL_IMAGE
00039 
00040 #include <cstdio>
00041 int main()
00042 {
00043         fprintf(stderr, "The SDL_image library must be installed to use this program\n");
00044         return 1;
00045 }
00046 
00047 #else
00048 
00049 
00050 
00051 /*
00052 Attention: SDL_image is needed for linking
00053 
00054 */
00055 
00056 #include "Component/ModelManager.H"
00057 #include "Image/Image.H"
00058 #include "Psycho/PsychoDisplay.H"
00059 #include "Psycho/EyeTrackerConfigurator.H"
00060 #include "Psycho/EyeTracker.H"
00061 #include "Psycho/PsychoOpts.H"
00062 #include "Component/EventLog.H"
00063 #include "Component/ComponentOpts.H"
00064 #include "Raster/Raster.H"
00065 #include "Util/MathFunctions.H"
00066 #include "Util/Types.H"
00067 #include <iostream>
00068 #include <fstream>
00069 #include <SDL/SDL.h>
00070 #include <SDL/SDL_image.h>
00071 #include "AppPsycho/psycho-skin-resize.h"
00072 #include <stdio.h>
00073 #include <stdlib.h>
00074 #include <map>
00075 #include <time.h>
00076 #include "AppPsycho/psycho-skin-mapgenerator.h"
00077 #include <sstream>
00078 #include "GameBoard/basic-graphics.H"
00079 
00080 
00081 using namespace std;
00082 
00083 
00084 ModelManager manager("Psycho Constellation");
00085 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00086 bool programQuit = false ;
00087 map<string,Uint32> colorMap ;
00088 map<string,string> starColorMap ;
00089 map<string,int> starRadiusMap ;
00090 map<string,string> starTypeMap ;
00091 map<string,int> starDensityMap ;
00092 map<string,int> starFlickingMap ;
00093 int vx , vy ;
00094 int sw=800 ;
00095 int sh=600 ;
00096 
00097 
00098 //////////////////////////////////////////
00099 
00100 void startExperiment(){
00101         cout<<" experiment started "<< starColorMap.size()<<endl;
00102         SDL_Surface* blankSurface = getABlankSurface(sw,sh) ;
00103         int screenSize = sw * sh ;
00104 
00105         for( map<string,string>:: iterator it = starColorMap.begin() ; it != starColorMap.end() ; ++it ){
00106                 string starName = it->first ;
00107                 int starCount = screenSize*starDensityMap[starName]/300000 ;
00108                 for(int i = 0 ; i < starCount ; i++){
00109                         int x = rand()% (sw-150);
00110                         int y = rand()% (sh-150);
00111                         //cout<<"starcolor: "<< colorMap[starColorMap[starName]]<<"    "<<x<<"  "<<y<<endl;
00112                         //fillOval(blankSurface,colorMap[starColorMap[starName]],x,y,2,2) ;
00113                         fillQuadricRadiant(blankSurface,colorMap[starColorMap[starName]],x+50,y+50,starRadiusMap[starName]) ;
00114                 }
00115 
00116 
00117         }
00118 
00119         SDL_Rect offset;
00120         d->clearScreen() ;
00121         //Give the offsets to the rectangle
00122         for (int i = 0 ; i < 100 ; i++){
00123                 offset.x = i + (d->getWidth() - blankSurface->w) /2;
00124                 offset.y = i+ (d-> getHeight() - blankSurface->h) /2;
00125                 d->displaySDLSurfacePatch(blankSurface , &offset,NULL , -2,false, true);
00126                 d->waitFrames(1);
00127         }
00128 
00129 
00130 
00131         d->waitForKey() ;
00132 }
00133 
00134 //////////////////////////////////////////
00135 int emergencyExit(){
00136         time_t rawtime;
00137         time ( &rawtime );
00138         LINFO("...emergencyExit called @%s .", ctime( &rawtime ));
00139         d->pushEvent(std::string("experiment ended at ")+ ctime( &rawtime ) );
00140         manager.stop();
00141         return -1;
00142 }
00143 
00144 
00145 ////////////////////////////////////
00146 
00147 template <class T>
00148                 string stringify(T &i)
00149 {
00150         ostringstream o ;
00151         o << i ;
00152         return o.str();
00153 }
00154 
00155 
00156 /////////////////////////////////////////////
00157 int readTop(ifstream& inFile){
00158         char ch[1000] ;
00159         while( inFile.getline(ch , 1000) ){
00160                 string line  = ch ;
00161                 LINFO("reads : %s" , line.c_str()) ;
00162                 if( line.compare("end_top") == 0 ) break;
00163 
00164                 if( line.substr(0,6).compare("color:")==0 ){
00165                         char rf[3] ;
00166                         string::size_type colPos = line.find(":") ;
00167                         string::size_type eqPos = line.find("=") ;
00168                         string colorName = line.substr(colPos+1,eqPos-colPos-1) ;
00169                         string colorString = line.substr(eqPos+1);
00170                         string::size_type  _Pos = colorString.find("_") ;
00171                         strcpy(rf,colorString.substr(0,_Pos).c_str()) ;
00172                         int rL = atoi(rf) ;
00173                         colorString = colorString.substr(_Pos+1) ;
00174                         _Pos = colorString.find("_") ;
00175                         strcpy(rf,colorString.substr(0,_Pos).c_str()) ;
00176                         int gL = atoi(rf) ;
00177                         colorString = colorString.substr(_Pos+1) ;
00178                         strcpy(rf,colorString.c_str()) ;
00179                         int bL = atoi(rf) ;
00180                         Uint32 color = d->getUint32color(PixRGB<byte>(rL, gL, bL));
00181                         colorMap[colorName] = color ;
00182                 }
00183                 if( line.substr(0,2).compare("vx")==0 ){
00184                         string::size_type position = line.find("=");
00185                         char rf[10] ;
00186                         strcpy(rf,line.substr(position+1).c_str());
00187                         vx = atoi(rf);
00188                         d->pushEvent(line.c_str());
00189                 }
00190                 if( line.substr(0,2).compare("vy")==0 ){
00191                         string::size_type position = line.find("=");
00192                         char rf[10] ;
00193                         strcpy(rf,line.substr(position+1).c_str());
00194                         vy = atoi(rf);
00195                         d->pushEvent(line.c_str());
00196                 }
00197 
00198         }
00199         return 0 ;
00200 }
00201 
00202 /////////////////////////////////////////////
00203 
00204 int readStarBlock(ifstream& inFile){
00205         char ch[1000] ;
00206         string starName = "" ;
00207         while( inFile.getline(ch , 1000) ){
00208                 string line  = ch ;
00209                 LINFO("reads : %s" , line.c_str()) ;
00210                 if(line.compare("end_star")==0) {
00211                         d -> pushEvent("ended reading star block ");
00212                         break ;
00213                 }
00214 
00215                 if(line.substr(0,8).compare("starname")== 0 ) {
00216                         string::size_type eqPos = line.find("=");
00217                         starName =line.substr(eqPos+1) ;
00218                 }
00219                 if(line.substr(0,6).compare("color=")==0){
00220                         string::size_type eqPos = line.find("=");
00221                         string colorStr = line.substr(eqPos+1) ;
00222                         starColorMap[starName] = colorStr ;
00223                         cout<<"local star Name :" <<starName<<" and color:"<< colorStr<<endl ;
00224                 }
00225                 if(line.substr(0,4).compare("type")==0){
00226                         string::size_type eqPos = line.find("=");
00227                         string starType = line.substr(eqPos+1) ;
00228                         starTypeMap[starName] = starType ;
00229                 }
00230 
00231                 if( line.substr(0,6).compare("radius")==0 ){
00232                         string::size_type position = line.find("=");
00233                         char rf[10] ;
00234                         strcpy(rf,line.substr(position+1).c_str());
00235                         int s = atoi(rf);
00236                         starRadiusMap[starName] = s ;
00237                 }
00238                 if( line.substr(0,7).compare("density")==0 ){
00239                         string::size_type position = line.find("=");
00240                         char rf[10] ;
00241                         strcpy(rf,line.substr(position+1).c_str());
00242                         int s = atoi(rf);
00243                         starDensityMap[starName] = s ;
00244                 }
00245                 if( line.substr(0,8).compare("flicking")==0 ){
00246                         string::size_type position = line.find("=");
00247                         char rf[10] ;
00248                         strcpy(rf,line.substr(position+1).c_str());
00249                         int s = atoi(rf);
00250                         starFlickingMap[starName] = s ;
00251                 }
00252 
00253 
00254         }
00255         return 0 ;
00256 }
00257 
00258 
00259 
00260 /////////////////////////////////////////////
00261 int readBlock(ifstream& inFile){
00262         char ch[1000] ;
00263         while( inFile.getline(ch,1000) ){
00264                 string line = ch ;
00265                 LINFO("reads :  %s" , line.c_str());
00266                 if(line.compare("end_block")== 0) {
00267                         d -> pushEvent("ended reading block") ;
00268                         break ;
00269                 }
00270                 if( line.compare("start_star")==0 ){
00271                         readStarBlock(inFile) ;
00272                 }
00273         }
00274         return 0;
00275 }
00276 /////////////////////////////////////////////
00277 int readprofile(const char* filename){
00278         ifstream inFile(filename, ios::in);
00279         if (! inFile)
00280         {
00281                 LINFO("profile '%s' not found!" , filename);
00282                 return -1;
00283         }
00284 
00285         char ch[1000];
00286         while (inFile.getline(ch , 1000)){
00287                 string line = ch;
00288                 LINFO("reads : %s", line.c_str());
00289                 if( line.substr(0,11).compare("profilename") == 0 ){
00290                         string::size_type position = line.find("=");
00291                         d -> pushEvent("profile  "+line.substr(position+1)+" started reading" ) ;
00292                 }
00293                 if(line.compare("start_top")==0 ) readTop(inFile);
00294                 if(line.compare("start_block")==0) readBlock(inFile);
00295                 if(programQuit == true) break ;
00296         }
00297 
00298         return 0 ;
00299 }
00300 /////////////////////////////////////////////
00301 
00302 
00303 extern "C" int main( int argc, char* argv[] )
00304 
00305 {
00306 
00307         MYLOGVERB = LOG_INFO;  // suppress debug messages
00308 
00309         manager.addSubComponent(d);
00310         nub::soft_ref<EventLog> el(new EventLog(manager));
00311         manager.addSubComponent(el);
00312         d->setEventLog(el);
00313 // Parse command-line:
00314         if (manager.parseCommandLine(argc, argv,"<profile.prf> <logfileName.psy>", 2, 2)==false)
00315                 return(1);
00316         manager.setOptionValString(&OPT_EventLogFileName,manager.getExtraArg(1).c_str() );
00317         manager.start();
00318         d->clearScreen() ;
00319         if(readprofile(manager.getExtraArg(0).c_str())== 0 ) startExperiment();
00320         d->displayText("Experiment is done! Thanks for participating! ") ;
00321         d->waitForKey() ;
00322         manager.stop();
00323         return(0) ;
00324 //         time_t rawtime;
00325 //         time ( &rawtime );
00326 //         LINFO("@%s psycho-skin-bsindexing started:...", ctime(&rawtime));
00327 //         manager.start();
00328 //         d->pushEvent(std::string("started the experiment at ")+ ctime( &rawtime ) );
00329 //         SDL_Surface* free = getAFreshSurface(40,80) ;
00330 //         SDL_Rect offset;
00331 //             //Give the offsets to the rectangle
00332 //         d->clearScreen();
00333 //             offset.x = 100;
00334 //             offset.y = 60;
00335 //         d->displaySDLSurfacePatch(free,&offset,NULL , -2,false, true);
00336 //         d->waitFrames(10);
00337                 //         ////////////////////////////
00338 //         d->clearScreen();
00339 //         offset.x = 100;
00340 //             offset.y = 160;
00341 //         d->displaySDLSurfacePatch(free , &offset,NULL , -2,false, true);
00342 //         d->waitFrames(10);
00343 //           d->displayText("Experiment complete. Thank you!");
00344 //         //d->waitFrames(1);
00345 //           //d->waitForKey();
00346 //         time ( &rawtime );
00347 //         LINFO("...psycho-skin-bsindexing ended @%s .", ctime( &rawtime ));
00348 //         d->pushEvent(std::string("experiment ended at ")+ ctime( &rawtime ) );
00349 //         manager.stop();
00350                 //
00351 //         return 0 ;
00352 }
00353 
00354 #endif // INVT_HAVE_LIBSDL_IMAGE
00355 
Generated on Sun May 8 08:40:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3