psycho-calib.C
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "Component/ModelManager.H"
00038 #include "Image/Image.H"
00039 #include "Psycho/PsychoDisplay.H"
00040 #include "Psycho/EyeTrackerConfigurator.H"
00041 #include "Psycho/EyeTracker.H"
00042 #include "Psycho/PsychoOpts.H"
00043 #include "Component/EventLog.H"
00044 #include "Component/ComponentOpts.H"
00045 #include "Raster/Raster.H"
00046 #include "Util/MathFunctions.H"
00047 #include "Util/Types.H"
00048 #include "GameBoard/basic-graphics.H"
00049 #include <sys/types.h>
00050 #include <dirent.h>
00051 #include <errno.h>
00052 #include <vector>
00053 #include <string>
00054 #include <iostream>
00055 #include <SDL/SDL.h>
00056 #include <SDL/SDL_image.h>
00057 #include <stdio.h>
00058 #include <stdlib.h>
00059 #include <sstream>
00060 #include <time.h>
00061 #include "Image/DrawOps.H"
00062 #include "GameBoard/resize.h"
00063 #include <iostream>
00064 #include <fstream>
00065 #include <set>
00066 #include <algorithm>
00067 #include <ctime>
00068
00069 #ifndef INVT_HAVE_LIBSDL_IMAGE
00070 #include <cstdio>
00071 int main()
00072 {
00073 fprintf(stderr, "The SDL_image library must be installed to use this program\n");
00074 return 1;
00075 }
00076
00077 #else
00078
00079
00080
00081 using namespace std;
00082
00083
00084
00085 ModelManager manager("Psycho-Calib");
00086 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00087 map<uint,uint> testMap ;
00088 map<string,string> argMap ;
00089
00090
00091
00092
00093 template <class T> std::string stringify(T i)
00094 {
00095 ostringstream o ;
00096 o << i ;
00097 return o.str();
00098 }
00099
00100 bool itIsInThere(int x , vector<int> bag){
00101 for( uint i=0 ; i < bag.size(); i++ ){
00102 if(x == bag[i]) return true ;
00103 }
00104 return false ;
00105 }
00106
00107
00108
00109
00110
00111 int addArgument(const string st,const string delim="="){
00112 int i = st.find(delim) ;
00113 argMap[st.substr(0,i)] = st.substr(i+1);
00114
00115 return 0 ;
00116 }
00117
00118 std::string getArgumentValue(string arg){
00119 return argMap[arg] ;
00120 }
00121
00122 std::vector<int> getDigits(int n , string zs="n" , string rs="n" ){
00123 if(rs.compare("n")==0){
00124 if(zs.compare("n")==0 && n >9 ) {LINFO( "come on! what do you expect?!") ; exit(-1) ;}
00125 if(zs.compare("y")==0 && n >10 ) {LINFO( "come on! what do you expect?!") ; exit(-1) ;}
00126 }
00127 vector<int> digits ;
00128 int dig = 0 ;
00129 while( digits.size() < (uint)n ){
00130 if(zs.compare("n")==0) {dig = 1+(random()%9);}else{dig = random()%10;}
00131 if(rs.compare("y")==0){digits.push_back(dig);}else{if(!itIsInThere(dig,digits)) digits.push_back(dig);}
00132 }
00133 return digits ;
00134 }
00135
00136 std::string getUsageComment(){
00137
00138 string com = string("\nlist of arguments : \n");
00139
00140 com += "\nlogfile=[logfilename.psy] {default = psycho-stroop-concurrent.psy}\n" ;
00141 com += "\nmemo=[a_string_without_white_space]\n";
00142 com += "\nx-grid=[>0](num of grids along x direction){default=10} \n";
00143 com += "\ny-grid=[>0](num of grids along y direction){default=10} \n";
00144 com += "\nsubject=[subject_name] \n" ;
00145 return com ;
00146 }
00147
00148
00149 extern "C" int main(const int argc, char** argv)
00150 {
00151
00152 MYLOGVERB = LOG_INFO;
00153
00154 argMap["experiment"]="testing-calibration";
00155 argMap["logfile"]="psycho-calib.psy" ;
00156 argMap["subject"]="" ;
00157 argMap["memo"]="" ;
00158 argMap["x-grid"] = "10";
00159 argMap["y-grid"] = "10";
00160
00161 manager.addSubComponent(d);
00162 nub::soft_ref<EventLog> el(new EventLog(manager));
00163 manager.addSubComponent(el);
00164 d->setEventLog(el);
00165 nub::soft_ref<EyeTrackerConfigurator>
00166 etc(new EyeTrackerConfigurator(manager));
00167 manager.addSubComponent(etc);
00168
00169 if (manager.parseCommandLine(argc, argv,
00170 "at least one argument needed", 1, -1)==false){
00171 cout<<getUsageComment()<<endl;
00172 return(1);
00173 }
00174
00175 for(uint i = 0 ; i < manager.numExtraArgs() ; i++){
00176 addArgument(manager.getExtraArg(i),std::string("=")) ;
00177 }
00178
00179 manager.setOptionValString(&OPT_EventLogFileName, argMap["logfile"]);
00180 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");
00181 nub::soft_ref<EyeTracker> eyet = etc->getET();
00182 d->setEyeTracker(eyet);
00183 eyet->setEventLog(el);
00184 int x_g = atoi(argMap["x-grid"].c_str()) ;
00185 int y_g = atoi(argMap["y-grid"].c_str()) ;
00186 SDL_Rect offset ;
00187
00188 manager.start();
00189 for(map<string,string>::iterator it= argMap.begin(); it!= argMap.end() ; ++it) d->pushEvent("arg:"+ it->first+" value:"+it->second ) ;
00190
00191 d->clearScreen();
00192 d->displayISCANcalib();
00193 d->waitForMouseClick();
00194 d->displayText("CLICK LEFT button to calibrate; RIGHT to skip");
00195 int cl = d->waitForMouseClick();
00196 if (cl == 1) d->displayEyeTrackerCalibration(4,5,1 , true);
00197 d->clearScreen();
00198 d->displayText("Here the experiment starts! click to start!");
00199 d->waitForMouseClick() ;
00200 d->clearScreen();
00201 SDL_Surface* mark= getABlankSurface(5,5);
00202
00203 for(int i = 0 ; i <= x_g + 1 ; i++){
00204 for(int j = 0 ; j <= y_g +1 ; j++){
00205 int x = i* d->getWidth()/(x_g+1);
00206 int y = j* d->getHeight()/(y_g+1);
00207 if( x > d->getWidth()-5) x = d->getWidth() -5 ;
00208 if( y > d->getHeight()-5) y = d->getHeight() -5 ;
00209 offset.x = x;
00210 offset.y = y;
00211 d->displaySDLSurfacePatch(mark , &offset,NULL , -2,false, true);
00212 d->waitForMouseClick() ;
00213 std::string imst = "===== Showing image: im"+stringify(i)+"-"+stringify(j)+".png =====";
00214 d->pushEvent(imst);
00215 eyet->track(true);
00216 d->waitForMouseClick() ;
00217 eyet->track(false);
00218 d->clearScreen();
00219
00220 }
00221 }
00222
00223 d->waitForMouseClick();
00224 d->clearScreen();
00225
00226 d->clearScreen();
00227 d->displayText("Experiment complete. Thank you!");
00228 d->waitForMouseClick();
00229
00230
00231
00232 manager.stop();
00233
00234
00235 return 0;
00236 }
00237
00238 #endif // INVT_HAVE_LIBSDL_IMAGE
00239