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
00038 #include "Component/ModelManager.H"
00039 #include "Image/Image.H"
00040 #include "Psycho/PsychoDisplay.H"
00041 #include "Psycho/EyeTrackerConfigurator.H"
00042 #include "Psycho/EyeTracker.H"
00043 #include "Psycho/PsychoOpts.H"
00044 #include "Component/EventLog.H"
00045 #include "Component/ComponentOpts.H"
00046 #include "Raster/Raster.H"
00047 #include "Util/MathFunctions.H"
00048 #include "Util/Types.H"
00049 #include "GameBoard/basic-graphics.H"
00050 #include <sys/types.h>
00051 #include <dirent.h>
00052 #include <errno.h>
00053 #include <vector>
00054 #include <string>
00055 #include <iostream>
00056 #include <SDL/SDL.h>
00057 #include <SDL/SDL_image.h>
00058 #include <SDL/SDL_mixer.h>
00059 #include <stdio.h>
00060 #include <stdlib.h>
00061 #include <sstream>
00062 #include <time.h>
00063 #include "Image/DrawOps.H"
00064 #include "GameBoard/resize.h"
00065 #include <iostream>
00066 #include <fstream>
00067 #include <set>
00068 #include <algorithm>
00069 #include <ctime>
00070
00071 #ifndef INVT_HAVE_LIBSDL_IMAGE
00072 #include <cstdio>
00073 int main()
00074 {
00075 fprintf(stderr, "The SDL_image library must be installed to use this program\n");
00076 return 1;
00077 }
00078
00079 #else
00080
00081
00082
00083 using namespace std;
00084
00085
00086
00087 ModelManager manager("Psycho-Concurrent-Digit");
00088 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00089 map<uint,uint> testMap ;
00090 map<string,string> argMap ;
00091 map<string,vector<SDL_Rect*>*> clipsmap;
00092
00093
00094
00095
00096 template <class T> std::string stringify(T i)
00097 {
00098 ostringstream o ;
00099 o << i ;
00100 return o.str();
00101 }
00102
00103
00104 double getAvarage(vector<long> v){
00105 double f = 0.0 ;
00106 for( uint i = 0 ; i < v.size() ; i++ ){
00107 f += v[i] ;
00108 }
00109 if (v.size()!=0) return f/v.size() ;
00110 return -1 ;
00111 }
00112
00113 double getVariance(vector<long> v){
00114 double m = getAvarage(v);
00115 double var = 0.0 ;
00116 for( uint i = 0 ; i < v.size(); i++ ){
00117 var += (v[i]-m)*(v[i]-m) ;
00118 }
00119 if (v.size()!=0) return var/v.size() ;
00120 return -1 ;
00121 }
00122
00123 bool itIsInThere(int x , vector<int> bag){
00124 for( uint i=0 ; i < bag.size(); i++ ){
00125 if(x == bag[i]) return true ;
00126 }
00127 return false ;
00128 }
00129
00130
00131
00132
00133
00134
00135 string ascSort(string st)
00136 {
00137 string res = "" ;
00138 vector<string> v = vector<string>();
00139 for(uint i = 0 ; i < st.size() ; i++) v.push_back(st.substr(i,1)) ;
00140
00141 std::sort(v.begin(), v.end());
00142
00143 for ( uint i = 0 ; i < v.size() ; i++ ){
00144 res += v[i] ;
00145 }
00146 return res;
00147 }
00148
00149
00150
00151
00152
00153
00154
00155 string desSort(string st)
00156 {
00157 string res = "" ;
00158 vector<string> v = vector<string>();
00159 for(uint i = 0 ; i < st.size() ; i++) v.push_back(st.substr(i,1)) ;
00160 std::sort(v.begin(), v.end());
00161 std::reverse(v.begin(), v.end());
00162 for ( uint i = 0 ; i < v.size() ; i++ ){
00163 res += v[i] ;
00164 }
00165 return res;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174 int mydist(string str , string sorted){
00175 size_t found;
00176 int m = 0 ;
00177 for(uint i = 2 ; i <= sorted.size() ; i++ ){
00178 for(uint j = 0 ; j <= sorted.size()-i ; j++ ) {
00179 found = str.find(sorted.substr(j,i));
00180 if (found!=string::npos) m += i ;
00181 }
00182 }
00183 return m ;
00184 }
00185
00186
00187
00188
00189
00190
00191 int getDisMetric(string st){
00192 int m = 0 ;
00193 size_t found;
00194 string asString = ascSort(st) ;
00195 for(uint i = 0 ; i < st.size() ; i++ ){
00196 found = asString.find(st.substr(i,1));
00197 m += abs((int)i-int(found)) ;
00198 }
00199
00200 return m- 2*mydist(st,asString) ;
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210 string getARandomString(uint l, string alphabet="0123456789" , int thresh=0){
00211
00212 string test = string("") ;
00213 string retString ;
00214 int maxDist = -1000000;
00215 int it = 0 ;
00216 int d = 0 ;
00217 do{
00218 test = "" ;
00219 string tp = string("") ;
00220 vector<int> pickedones = vector<int>() ;
00221 for(uint i = 0 ; i < l ; i++){
00222 int nd;
00223 do{ nd= rand()% alphabet.size() ; }while(itIsInThere(nd,pickedones) && pickedones.size() <= alphabet.size()) ;
00224 pickedones.push_back(nd);
00225 tp = alphabet.substr(nd,1) ;
00226 test += tp ;
00227 }
00228 it++ ;
00229 d = getDisMetric(test);
00230 maxDist=max(maxDist,d) ;
00231 if (d==maxDist) retString = test ;
00232
00233 }while( maxDist<thresh && it < 1000000);
00234
00235 return retString ;
00236 }
00237
00238
00239
00240
00241
00242 string digitMemorizationTask(uint l, string alphabet="0123456789" , int displayFrame = 10 ){
00243 d->clearScreen() ;
00244 vector<int> pickedones = vector<int>() ;
00245 string test = string("") ;
00246 string tp = string("") ;
00247 for(uint i = 0 ; i < l ; i++){
00248 int nd;
00249 do{ nd= rand()% alphabet.size() ; }while(itIsInThere(nd,pickedones) && pickedones.size() <= alphabet.size()) ;
00250 pickedones.push_back(nd);
00251 tp = alphabet.substr(nd,1) ;
00252 test += tp ;
00253 }
00254 d->displayText(test,true,0) ;
00255 d->waitFrames(displayFrame) ;
00256 d->clearScreen() ;
00257 return test ;
00258 }
00259
00260
00261
00262
00263
00264 void scramble(vector<string>& v){
00265 vector<string> tv = vector<string>() ;
00266 while(v.size()>0){
00267 tv.push_back(v[0]);
00268 v.erase(v.begin());
00269 }
00270 int i = 0 ;
00271 while(tv.size()>0){
00272 i = rand()%tv.size() ;
00273 v.push_back(tv[i]);
00274 tv.erase(tv.begin()+i);
00275 }
00276 }
00277
00278
00279
00280
00281
00282 SDL_Surface* getButtonImage(string label , PixRGB<byte> txtcolor=PixRGB<byte>(0,0,0) , PixRGB<byte> bgcolor=PixRGB<byte>(255,255,255) ,Point2D<int> size = Point2D<int>(100,100) ,PixRGB<byte> bordercolor=PixRGB<byte>(0,0,0) , int border=3){
00283 Image<PixRGB<byte> > textIm(d->getWidth(),d->getHeight(),ZEROS);
00284 textIm.clear(bgcolor);
00285 writeText(textIm, Point2D<int>((size.i - label.length()*10)/2,(size.j-20) /2),label.c_str(),txtcolor,bgcolor);
00286 SDL_Surface *surf = d->makeBlittableSurface(textIm , true);
00287 Uint32 bc = d->getUint32color(bordercolor);
00288 drawRectangle(surf,bc,0,0,size.i -1,size.j -1 ,border);
00289 SDL_Surface* blank =getABlankSurface(size.i , size.j);
00290 SDL_Rect clip;
00291 clip.x = 0 ;
00292 clip.y = 0 ;
00293 clip.w = size.i ;
00294 clip.h = size.j ;
00295 apply_surface(0,0,*surf,*blank,clip);
00296 dumpSurface(surf) ;
00297 return blank ;
00298 }
00299
00300
00301
00302
00303
00304
00305 SDL_Surface* getKeyPad(string alphabet,map<string , SDL_Rect>& buttmap){
00306 SDL_Surface* pad= getABlankSurface(d->getWidth()/4,d->getHeight()/3);
00307 SDL_Rect clip;
00308 clip.x=0;
00309 clip.y=0;
00310 int numofrows = alphabet.size()/3 +1;
00311 if(alphabet.size()%3 != 0 ) numofrows++ ;
00312 int numofcolumns = 3 ;
00313 clip.w= pad->w / numofcolumns ;
00314 clip.h = pad->h / numofrows ;
00315
00316
00317 for( int i = 0 ; i < numofrows*3 ; i++){
00318 SDL_Surface* but ;
00319 if((uint)i < alphabet.size()){
00320 but = getButtonImage(alphabet.substr(i,1),PixRGB<byte>(0,0,0),PixRGB<byte>(255,255,255),Point2D<int>(pad->w / numofcolumns , pad->h / numofrows),PixRGB<byte>(255, 98 , 25),3);
00321 }else{
00322 but = getButtonImage(" ",PixRGB<byte>(0,0,0),PixRGB<byte>(255,255,255),Point2D<int>(pad->w / numofcolumns , pad->h / numofrows),PixRGB<byte>(255, 98 , 25),3);
00323 }
00324
00325 SDL_Rect cl ;
00326 cl.x = ((i)%numofcolumns)*(pad->w)/numofcolumns ; cl.y= ((i)/numofcolumns)*((pad->h)/numofrows) ;
00327 cl.w = clip.w ;
00328 cl.h = clip.h ;
00329 apply_surface( cl.x , cl.y ,*but,*pad,clip);
00330 if((uint)i < alphabet.size()) buttmap[alphabet.substr(i,1)] = cl ;
00331 dumpSurface(but);
00332 }
00333 SDL_Rect cl1 ;
00334 cl1.x = 0 ; cl1.y= (numofrows-1)*((pad->h)/numofrows) ;
00335 cl1.w = clip.w ;
00336 cl1.h = clip.h ;
00337 buttmap["!"] = cl1 ;
00338 SDL_Surface* but = getButtonImage(string("<-"),PixRGB<byte>(0,0,0),PixRGB<byte>(255,255,255),Point2D<int>(pad->w / numofcolumns , pad->h / numofrows),PixRGB<byte>(255, 98 , 25),3);
00339 apply_surface(0, (numofrows-1)*((pad->h)/numofrows),*but,*pad,clip);
00340 dumpSurface(but);
00341 SDL_Rect cl2 ;
00342 cl2.x = (pad->w)/numofcolumns ; cl2.y= (numofrows-1)*((pad->h)/numofrows) ;
00343 cl2.w = clip.w ;
00344 cl2.h = clip.h ;
00345 buttmap[" "] = cl2 ;
00346 but = getButtonImage(string("spc"),PixRGB<byte>(0,0,0),PixRGB<byte>(255,255,255),Point2D<int>(pad->w / numofcolumns , pad->h / numofrows),PixRGB<byte>(255, 98 , 25),3);
00347 apply_surface((pad->w)/numofcolumns, (numofrows-1)*((pad->h)/numofrows),*but,*pad,clip);
00348 dumpSurface(but);
00349 SDL_Rect cl3 ;
00350 cl3.x = 2*(pad->w)/numofcolumns ; cl3.y= (numofrows-1)*((pad->h)/numofrows) ;
00351 cl3.w = clip.w ;
00352 cl3.h = clip.h ;
00353 buttmap["*"] = cl3 ;
00354 but = getButtonImage(string("Ok"),PixRGB<byte>(0,0,0),PixRGB<byte>(255,255,255),Point2D<int>(pad->w / numofcolumns , pad->h / numofrows),PixRGB<byte>(255, 98 , 25),3);
00355 apply_surface(2*(pad->w)/numofcolumns, (numofrows-1)*((pad->h)/numofrows),*but,*pad,clip);
00356 dumpSurface(but);
00357 return pad ;
00358 }
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 string getPressedButtonCommand(map<string , SDL_Rect>& buttmap,Point2D<int> offset=Point2D<int>(0,0)){
00369 int quit = 0 ;
00370 string s ;
00371 SDL_Event event ;
00372 while( quit!=2 ){
00373 while( SDL_PollEvent( &event ) ) {
00374 if(event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT ){
00375 for( map<string , SDL_Rect>::iterator it = buttmap.begin() ; it!=buttmap.end() ; ++it){
00376 if(event.button.x >= (it->second).x + offset.i && event.button.x <= (it->second).x + (it->second).w + offset.i && event.button.y >= (it->second).y+ offset.j && event.button.y <= (it->second).y + (it->second).h + offset.j) {
00377 quit = 2 ;
00378 s = it->first ;
00379 break;
00380 }
00381
00382 }
00383 }
00384
00385 }
00386 }
00387 return s ;
00388
00389 }
00390
00391
00392
00393
00394
00395
00396
00397 string getDigitSequenceFromSubject(string alphabet="0123456789" , uint maxl = 7 ){
00398 d->showCursor(true) ;
00399
00400 map<string , SDL_Rect>* buttmap = new map<string , SDL_Rect>();
00401
00402 SDL_Surface * keypad = getKeyPad(alphabet,*buttmap);
00403
00404 SDL_Rect offset ;
00405 offset.x = (d->getWidth() - keypad->w) /2;
00406 offset.y = (d-> getHeight() - keypad->h) /2;
00407
00408 d->displaySDLSurfacePatch(keypad , &offset,NULL , -2,false, true);
00409
00410 string p = string("") ;
00411
00412 string tp = string("");
00413
00414 while( tp.compare("*")!=0 ){
00415
00416 SDL_Surface* dp = getButtonImage(p ,PixRGB<byte>(195,60,12) ,PixRGB<byte>(255,255,255) ,Point2D<int>(d->getWidth()/6,d->getHeight() /15) ,PixRGB<byte>(0,25,180) , 4) ;
00417 SDL_Rect offs ; offs.x = (d->getWidth() - dp->w) /2 ; offs.y = d->getHeight()/6 ;
00418 d->displaySDLSurfacePatch(dp , &offs , NULL , -2 , false ,true ) ;
00419
00420 tp = getPressedButtonCommand(*buttmap,Point2D<int>(offset.x,offset.y)) ;
00421 dumpSurface(dp) ;
00422 if(tp.compare("!")==0 && p.size()>=0 ) {
00423 if (p.size()>0) p = p.substr(0,p.size()-1) ;
00424 }else{
00425 if(p.size() < maxl && tp.compare("*")!=0) {
00426 p +=tp ;
00427 }
00428
00429 }
00430
00431 }
00432 buttmap = 0 ;
00433 dumpSurface(keypad) ;
00434 d->clearScreen() ;
00435 return p ;
00436
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449 bool isAnswerCorrect(string test , string answer , int mode){
00450
00451 if(mode == 0 && answer.compare(test)==0) return true ;
00452
00453 if(mode == 1 && answer.compare(ascSort(test))==0) return true ;
00454
00455 if(mode == 2 && answer.compare(desSort(test))==0) return true ;
00456
00457 return false;
00458 }
00459
00460
00461
00462 int addArgument(const string st,const string delim="="){
00463 int i = st.find(delim) ;
00464 argMap[st.substr(0,i)] = st.substr(i+1);
00465
00466 return 0 ;
00467 }
00468
00469 std::string getArgumentValue(string arg){
00470 return argMap[arg] ;
00471 }
00472
00473 std::string getUsageComment(){
00474
00475 string com = string("\nlist of arguments : \n");
00476
00477 com += "\nlogfile=[logfilename.psy] {default = psycho-stroop-concurrent.psy}\n" ;
00478 com += "\nmemo=[a_string_without_white_space]\n";
00479 com += "\nstring-size=[>0](the size of string){default=5} \n";
00480 com += "\nsubject=[subject_name] \n" ;
00481 com += "\ntest-rounds=[>1] (number of tests ) {default=10}\n";
00482 com += "\ndigit-onset=[>1] (number of frames that the string will remain onset ){default=10}\n";
00483 com += "\nalphabet=[a string of characters](a string of characters){default=0123456789}\n";
00484 com += "\nmetric-threshold=[>-30 for string of lenght of 5](a string of characters){default=10}\n";
00485 com += "\nmaintain-prb=[a number between 0 to 1], probability of challenging the subject with a memorization task, default=0.5\n" ;
00486 com += "\nmode=[1,2,3,4](1 for displaying the whole number, 2 for random display , 3 for linear flashing disply , 4 for linear reverse flashing){default=1}\n";
00487 com += "\ncue-wait-frames=[<0](number of frames to show the cue){default=0}\n";
00488 com += "\ncue-onset-frames=[<0](number of frames to show the cue onset){default=3}\n";
00489 com += "\nmask=[y/n](whether present a mask after presentation, n for no, y for yes ){default=n}\n" ;
00490 com += "\nmask-onset-frames=[<0](number of frames that mask will be onset){default=0}\n";
00491 com += "\nwhite-space=[>0](the distance between digits in display){default=20}\n" ;
00492 com += "\ncue-type=[a/v](a for audio v for visual){default=v}\n";
00493 com += "\nsound-dir=[path to wav files directory]{default=..}\n";
00494
00495 return com ;
00496 }
00497
00498
00499 void displayWholeNumber(string s , int onsetTime , int wsd){
00500 int x = (d->getWidth()-s.size()*wsd)/2 ;
00501 int y = (d->getHeight())/2 -10;
00502 Image<PixRGB<byte> > textIm(d->getWidth(),d->getHeight(),ZEROS);
00503 textIm.clear(PixRGB<byte>(128,128,128));
00504 for( uint k = 0 ; k < s.size() ; k++ ){
00505
00506 writeText(textIm, Point2D<int>(x+k*wsd,y),s.substr(k,1).c_str(),PixRGB<byte>(0,0,0),PixRGB<byte>(128,128,128));
00507 }
00508 SDL_Surface *surf = d->makeBlittableSurface(textIm , true);
00509 SDL_Rect offs ; offs.x = 0 ; offs.y = 0 ;
00510 d->displaySDLSurfacePatch(surf , &offs , NULL , -2 , false ,true ) ;
00511 dumpSurface(surf);
00512 d->waitFrames(onsetTime);
00513 d->clearScreen() ;
00514 }
00515
00516 void displayWholeNumberVertically(string s , int onsetTime , int wsd){
00517 int x = (d->getWidth())/2 ;
00518 int y = (d->getHeight()-s.size()*wsd)/2 ;
00519 Image<PixRGB<byte> > textIm(d->getWidth(),d->getHeight(),ZEROS);
00520 textIm.clear(PixRGB<byte>(128,128,128));
00521 for( uint k = 0 ; k < s.size() ; k++ ){
00522
00523 writeText(textIm, Point2D<int>(x,y+k*wsd),s.substr(k,1).c_str(),PixRGB<byte>(0,0,0),PixRGB<byte>(128,128,128));
00524 }
00525 SDL_Surface *surf = d->makeBlittableSurface(textIm , true);
00526 SDL_Rect offs ; offs.x = 0 ; offs.y = 0 ;
00527 d->displaySDLSurfacePatch(surf , &offs , NULL , -2 , false ,true ) ;
00528 dumpSurface(surf);
00529 d->waitFrames(onsetTime);
00530 d->clearScreen() ;
00531 }
00532
00533 void displayRandom(string s , int onsetTime){
00534 for( uint k = 0 ; k < s.size() ; k++ ){
00535 int x = 9*d->getWidth()/20 + rand()%(d->getWidth()/10);
00536 int y = 9*d->getHeight()/20 + rand()%(d->getHeight()/10) ;
00537 d->displayText(s.substr(k,1),Point2D<int>(x,y),PixRGB<byte>(0,0,0),PixRGB<byte>(128,128,128),true) ;
00538 d->waitFrames(onsetTime);
00539 d->clearScreen() ;
00540 }
00541 }
00542
00543 void displayLinear(string s , int onsetTime){
00544 int x = (d->getWidth()-s.size()*10)/2 ;
00545 int y = d->getHeight()/2 - 10;
00546 for( uint k = 0 ; k < s.size() ; k++ ){
00547 d->displayText(s.substr(k,1),Point2D<int>(x+k*10,y),PixRGB<byte>(0,0,0),PixRGB<byte>(128,128,128),true) ;
00548 d->waitFrames(onsetTime);
00549 d->clearScreen() ;
00550 }
00551 }
00552
00553 void displayLinearReverse(string s , int onsetTime){
00554 int x = (d->getWidth()-s.size()*10)/2 ;
00555 int y = d->getHeight()/2 - 10;
00556 for( uint k = 0 ; k < s.size() ; k++ ){
00557 d->displayText(s.substr(k,1),Point2D<int>(x+(s.size()-k)*10,y),PixRGB<byte>(0,0,0),PixRGB<byte>(128,128,128),true) ;
00558 d->waitFrames(onsetTime);
00559 d->clearScreen() ;
00560 }
00561 }
00562 void displayLinearRandom(string s , int onsetTime){
00563 int x = (d->getWidth()-s.size()*10)/2 ;
00564 int y = d->getHeight()/2 - 10;
00565 for( uint k = 0 ; k < s.size() ; k++ ){
00566 d->displayText(s.substr(k,1),Point2D<int>(x+ (random()%s.size())*10,y),PixRGB<byte>(0,0,0),PixRGB<byte>(128,128,128),true) ;
00567 d->waitFrames(onsetTime);
00568 d->clearScreen() ;
00569 }
00570 }
00571
00572 void displayLinearRandomVertically(string s , int onsetTime){
00573 int x = (d->getWidth())/2 ;
00574 int y = (d->getHeight()-s.size()*10)/2 - 10;
00575 for( uint k = 0 ; k < s.size() ; k++ ){
00576 d->displayText(s.substr(k,1),Point2D<int>(x, (random()%s.size())*10+y),PixRGB<byte>(0,0,0),PixRGB<byte>(128,128,128),true) ;
00577 d->waitFrames(onsetTime);
00578 d->clearScreen() ;
00579 }
00580 }
00581
00582 void displayLinearRandomNoRepeating(string s , int onsetTime){
00583 int x = (d->getWidth()-s.size()*10)/2 ;
00584 int y = d->getHeight()/2 - 10;
00585 for( uint k = 0 ; k < s.size() ; k++ ){
00586 d->displayText(s.substr(k,1),Point2D<int>(x+ (random()%s.size())*10,y),PixRGB<byte>(0,0,0),PixRGB<byte>(128,128,128),true) ;
00587 d->waitFrames(onsetTime);
00588 d->clearScreen() ;
00589 }
00590 }
00591
00592
00593 void showMask(int frames, string alphabet="0123456789"){
00594 Image<PixRGB<byte> > textIm(d->getWidth(),d->getHeight(),ZEROS);
00595 PixRGB<byte> bgcolor = PixRGB<byte>(128,128,128);
00596 PixRGB<byte> txtcolor = PixRGB<byte>(0,0,0);
00597 textIm.clear(bgcolor);
00598 for(int i = 0 ; i < 200 ; i++)
00599 writeText(textIm, Point2D<int>((int)random()%(d->getWidth()),(int)random()%(d->getHeight())),alphabet.substr(random()%(int)alphabet.size(),1).c_str(),txtcolor,bgcolor);
00600 SDL_Surface *surf = d->makeBlittableSurface(textIm , true);
00601 SDL_Rect offs ; offs.x = 0 ; offs.y = 0 ;
00602 d->displaySDLSurfacePatch(surf , &offs , NULL , -2 , false ,true ) ;
00603 d->waitFrames(frames) ;
00604 d->clearScreen();
00605 dumpSurface(surf) ;
00606 }
00607
00608 extern "C" int main(const int argc, char** argv)
00609 {
00610
00611 MYLOGVERB = LOG_INFO;
00612
00613 argMap["experiment"]="working memory single task - sorting";
00614 argMap["logfile"]="psycho-wm.psy" ;
00615 argMap["string-size"]="5" ;
00616 argMap["test-rounds"]="10";
00617 argMap["subject"]="" ;
00618 argMap["memo"]="" ;
00619 argMap["digit-onset"]="10" ;
00620 argMap["alphabet"]="0123456789";
00621 argMap["metric-threshold"]="10" ;
00622 argMap["mode"]="1" ;
00623 argMap["cue-wait-frames"]="0" ;
00624 argMap["mask"]="n" ;
00625 argMap["mask-onset-frames"]="0";
00626 argMap["cue-onset-frames"] = "3" ;
00627 argMap["white-space"] = "20" ;
00628 argMap["cue-type"] = "v" ;
00629 argMap["sound-dir"]="..";
00630 argMap["min-wait-frames"] = "150" ;
00631 argMap["max-wait-frames"] = "240" ;
00632 manager.addSubComponent(d);
00633 nub::soft_ref<EventLog> el(new EventLog(manager));
00634 manager.addSubComponent(el);
00635 d->setEventLog(el);
00636 nub::soft_ref<EyeTrackerConfigurator>
00637 etc(new EyeTrackerConfigurator(manager));
00638 manager.addSubComponent(etc);
00639
00640 if (manager.parseCommandLine(argc, argv,
00641 "at least one argument needed", 1, -1)==false){
00642 cout<<getUsageComment()<<endl;
00643 return(1);
00644 }
00645
00646 for(uint i = 0 ; i < manager.numExtraArgs() ; i++){
00647 addArgument(manager.getExtraArg(i),std::string("=")) ;
00648 }
00649
00650 manager.setOptionValString(&OPT_EventLogFileName, argMap["logfile"]);
00651 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");
00652 nub::soft_ref<EyeTracker> eyet = etc->getET();
00653 d->setEyeTracker(eyet);
00654 eyet->setEventLog(el);
00655
00656
00657
00658 manager.start();
00659 for(map<string,string>::iterator it= argMap.begin(); it!= argMap.end() ; ++it) d->pushEvent("arg:"+ it->first+" value:"+it->second ) ;
00660
00661 d->clearScreen();
00662 d->displayISCANcalib();
00663 d->waitForMouseClick();
00664 d->displayText("Here the experiment starts! click to start!");
00665 d->waitForMouseClick();
00666 d->clearScreen();
00667
00668 int mode = atoi(argMap["mode"].c_str());
00669 vector<long> correctAnswersTiming;
00670 vector<long> incorrectAnswersTiming;
00671 vector<long> allTiming ;
00672 int correctMemory = 0 ;
00673 int incorrectMemory = 0 ;
00674 int numOfTests = atoi(argMap["test-rounds"].c_str()) ;
00675 int stringSize = atoi(argMap["string-size"].c_str());
00676 int meticThreshold = atoi(argMap["metric-threshold"].c_str()) ;
00677 int onsetDel = atoi(argMap["digit-onset"].c_str()) ;
00678 int cue_onset_frames = atoi(argMap["cue-onset-frames"].c_str()) ;
00679 int cue_wait_frames = atoi(argMap["cue-wait-frames"].c_str()) ;
00680 int mask_onset_frames = atoi(argMap["mask-onset-frames"].c_str()) ;
00681 int white_sapece_distance = atoi(argMap["white-space"].c_str());
00682 int md = atoi(argMap["min-wait-frames"].c_str());
00683 int Md = atoi(argMap["max-wait-frames"].c_str());
00684
00685 d->displayText("CLICK LEFT button to calibrate; RIGHT to skip");
00686 int cl = d->waitForMouseClick();
00687 if (cl == 1) d->displayEyeTrackerCalibration(3,5,1 , true);
00688 d->clearScreen();
00689
00690 int cr = 0 ;
00691
00692 Mix_Music* recallCueMusic = NULL;
00693 Mix_Music* sortCueMusic = NULL;
00694 if(argMap["cue-type"].compare("a")==0){
00695
00696 if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ){
00697 LINFO( "did not open the mix-audio") ;
00698 return -1 ;
00699 }
00700
00701 string str = argMap["sound-dir"]+"/recall.wav" ;
00702 recallCueMusic = Mix_LoadMUS(str.c_str());
00703 str = argMap["sound-dir"]+"/sort.wav" ;
00704 sortCueMusic = Mix_LoadMUS(str.c_str());
00705 }
00706 while( cr <numOfTests ){
00707
00708 cr++;
00709 d->pushEvent("**************************************") ;
00710 d->showCursor(true);
00711 d->displayText("click one of the mouse buttons to start!");
00712 d->waitForMouseClick() ;
00713 d->showCursor(false) ;
00714 string testString ;
00715 testString = getARandomString(stringSize, argMap["alphabet"] , meticThreshold);
00716 d->clearScreen() ;
00717 d->displayFixationBlink();
00718 switch( mode ){
00719 case 1 : displayWholeNumber(testString,onsetDel,white_sapece_distance);break ;
00720 case 2 : displayRandom(testString,onsetDel) ; break ;
00721 case 3 : displayLinear(testString,onsetDel) ; break ;
00722 case 4 : displayLinearRandom(testString,onsetDel) ; break ;
00723 case 5 : displayLinearReverse(testString,onsetDel) ; break ;
00724 case 6 : displayLinearRandomVertically(testString,onsetDel) ; break ;
00725 case 7 : displayWholeNumberVertically(testString,onsetDel,white_sapece_distance) ; break ;
00726 }
00727 if(argMap["mask"].compare("y")==0) showMask(mask_onset_frames,argMap["alphabet"]);
00728 std::string imst = "===== Showing image: tst"+ stringify(cr)+ ".png =====";
00729 d->pushEvent(imst);
00730 eyet->track(true);
00731 if(cue_wait_frames != 0) d->waitFrames(cue_wait_frames) ;
00732 eyet->track(false);
00733 if(argMap["cue-type"].compare("v")==0){
00734 d->displayRedDotFixation();
00735 }else{
00736 if( Mix_PlayMusic( sortCueMusic, 0 ) == -1 ) { return 1; }
00737 while( Mix_PlayingMusic() == 1 ){}
00738 }
00739
00740 imst = "===== Showing image: def"+ stringify(cr)+ ".png =====";
00741 d->pushEvent(imst);
00742 eyet->track(true);
00743 d->waitFrames(cue_onset_frames);
00744 long st = d->getTimerValue() ;
00745 d->clearScreen() ;
00746 d->pushEvent("second recording starts");
00747 d->pushEvent("the sequence for memorization is : "+testString) ;
00748 d->waitFrames(rand()%(Md-md) + md) ;
00749 long et = d->getTimerValue();
00750 eyet->track(false);
00751 d->pushEvent("task ends") ;
00752 d->pushEvent("second part time:"+stringify(et-st));
00753 allTiming.push_back(et-st);
00754
00755 string answer = getDigitSequenceFromSubject(argMap["alphabet"] , testString.size());
00756 d->pushEvent("subject keyed : "+answer);
00757
00758
00759 if(answer.compare(testString)==0){
00760 d->pushEvent("answer was correct");
00761 correctAnswersTiming.push_back(et-st) ;
00762 }else{
00763 d->pushEvent("answer was incorrect");
00764 incorrectAnswersTiming.push_back(et-st);
00765 }
00766
00767
00768 }
00769 d->pushEvent("total number of memory trials :"+stringify(correctMemory+incorrectMemory)) ;
00770 d->pushEvent("number of correct memory recall : "+ stringify(correctMemory)) ;
00771 d->pushEvent("total number of trials :"+ stringify(allTiming.size())) ;
00772 d->pushEvent("number of correct answers :" + stringify(correctAnswersTiming.size()));
00773 d->pushEvent("number of incorrect answers :"+ stringify(incorrectAnswersTiming.size())) ;
00774 d->pushEvent("avarage time for respond :"+ stringify(getAvarage(allTiming)));
00775 d->pushEvent("variance of respond :"+ stringify(getVariance(allTiming)));
00776 d->pushEvent("avarage time for correct answers "+stringify(getAvarage(correctAnswersTiming))) ;
00777 d->pushEvent("variance of correct responds :"+ stringify(getVariance(correctAnswersTiming)));
00778 d->clearScreen();
00779 d->displayText("Experiment complete. Thank you!");
00780 d->waitForMouseClick();
00781
00782
00783 manager.stop();
00784
00785
00786
00787 return 0;
00788 }
00789
00790 #endif // INVT_HAVE_LIBSDL_IMAGE
00791