00001 /*!@file GameBoard/psycho-constellation.C Psychophysics main application for constellation concept learning 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-06-16 16:14:27Z nnoori $ 00036 //written by Nader Noori 00037 00038 // 00039 #ifndef INVT_HAVE_LIBSDL_IMAGE 00040 00041 #include <cstdio> 00042 int main() 00043 { 00044 fprintf(stderr, "The SDL_image library must be installed to use this program\n"); 00045 return 1; 00046 } 00047 00048 #else 00049 00050 00051 00052 /* 00053 Attention: SDL_image is needed for linking 00054 00055 */ 00056 00057 #include "Component/ModelManager.H" 00058 #include "Image/Image.H" 00059 #include "Psycho/PsychoDisplay.H" 00060 #include "Psycho/EyeTrackerConfigurator.H" 00061 #include "Psycho/EyeTracker.H" 00062 #include "Psycho/PsychoOpts.H" 00063 #include "Component/EventLog.H" 00064 #include "Component/ComponentOpts.H" 00065 #include "Raster/Raster.H" 00066 #include "Util/MathFunctions.H" 00067 #include "Util/Types.H" 00068 #include <iostream> 00069 #include <fstream> 00070 #include <SDL/SDL.h> 00071 #include <SDL/SDL_image.h> 00072 //#include "psycho-skin-resize.h" 00073 #include <stdio.h> 00074 #include <stdlib.h> 00075 #include <map> 00076 #include <time.h> 00077 #include "AppPsycho/psycho-skin-mapgenerator.h" 00078 #include <sstream> 00079 #include "basic-graphics.H" 00080 00081 using namespace std; 00082 00083 ModelManager manager("Psycho Parallel Search"); 00084 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager)); 00085 bool programQuit = false ; 00086 map<string,Uint32> colorMap ; 00087 int targetExposure ; 00088 int emptyTime ; 00089 int vx , vy ; 00090 ////////////////////////////////////////// 00091 int emergencyExit(){ 00092 time_t rawtime; 00093 time ( &rawtime ); 00094 LINFO("...emergencyExit called @%s .", ctime( &rawtime )); 00095 d->pushEvent(std::string("experiment ended at ")+ ctime( &rawtime ) ); 00096 manager.stop(); 00097 return -1; 00098 } 00099 00100 00101 ////////////////////////////////////////// 00102 // Here we collect subjects response 00103 uint getStaticResponse(){ 00104 00105 // int c = -1; 00106 // int conf = -1 ; 00107 // int quit = -1 ; 00108 // do{ 00109 // // 00110 // c = -1 ; 00111 // while( c!=49 && c!=50 ){ 00112 // c = d->waitForKey(); 00113 // d->pushEvent("subject decided to report"); 00114 // d->clearScreen() ; 00115 // if(c!=49 && c!=50 ){ 00116 // d-> displayText("Press 1 for 'yes', 2 for 'no'"); 00117 // } 00118 // } 00119 // if( c == 49){ 00120 // d-> displayText("You chose 'yes' press space-bar to confirm"); 00121 // } else { 00122 // d-> displayText("You chose 'no' press space-bar to confirm"); 00123 // } 00124 // conf = d-> waitForKey() ; 00125 // if( conf == 127){ 00126 // quit = d-> waitForKey() ; 00127 // if( quit == 127 ){ 00128 // emergencyExit() ; 00129 // } 00130 // } 00131 // }while(conf!=32) ; 00132 // 00133 // if( c == 49 ){ 00134 // d->pushEvent("positive identification confirmed"); 00135 // return 1 ; 00136 // } else { 00137 // d->pushEvent("negative identification confirmed"); 00138 // return 0 ; 00139 // } 00140 return 0 ; 00141 00142 } 00143 00144 00145 ////////////////////////////////////////// 00146 // Here we collect subjects response 00147 uint getDynamicResponse(int c = -1){ 00148 00149 // //d->clearScreen(); 00150 // int conf = -1 ; 00151 // int quit = -1 ; 00152 // do{ 00153 // 00154 // while( c!=49 && c!=50 ){ 00155 // d-> displayText("Press 1 for 'yes', 2 for 'no'"); 00156 // c = d->waitForKey(); 00157 // d->pushEvent("subject decided to report"); 00158 // } 00159 // if( c == 49){ 00160 // d-> displayText("You chose 'yes' press space-bar to confirm"); 00161 // } else { 00162 // d-> displayText("You chose 'no' press space-bar to confirm"); 00163 // } 00164 // conf = d-> waitForKey() ; 00165 // if( conf == 127){ 00166 // quit = d-> waitForKey() ; 00167 // if( quit == 127 ){ 00168 // emergencyExit() ; 00169 // } 00170 // } 00171 // c = -1 ; 00172 // }while(conf!=32) ; 00173 // 00174 // if( c == 49 ){ 00175 // d->pushEvent("positive identification confirmed"); 00176 // return 1 ; 00177 // } else { 00178 // d->pushEvent("negative identification confirmed"); 00179 // return 0 ; 00180 // } 00181 return 0 ; 00182 } 00183 00184 //////////////////////////////////// 00185 00186 template <class T> 00187 string stringify(T &i) 00188 { 00189 ostringstream o ; 00190 o << i ; 00191 return o.str(); 00192 } 00193 00194 00195 ///////////////////////////////////////////// 00196 int readTop(ifstream& inFile){ 00197 // char ch[1000] ; 00198 // while( inFile.getline(ch , 1000) ){ 00199 // string line = ch ; 00200 // LINFO("reads : %s" , line.c_str()) ; 00201 // if( line.compare("end_top") == 0 ) break; 00202 // if( line.substr(0,2).compare("vx")==0 ){ 00203 // string::size_type position = line.find("=") ; 00204 // char rf[10] ; 00205 // strcpy(rf,line.substr(position+1).c_str()); 00206 // vx = atoi(rf); 00207 // } 00208 // if( line.substr(0,2).compare("vy")==0 ){ 00209 // string::size_type position = line.find("=") ; 00210 // char rf[10] ; 00211 // strcpy(rf,line.substr(position+1).c_str()); 00212 // vy = atoi(rf); 00213 // } 00214 // 00215 // if( line.substr(0,4).compare("color:")==0 ){ 00216 // string::size_type colPos = line.find(":") ; 00217 // string::size_type eqPos = line.find("=") ; 00218 // string colorName = line.substr(colPos+1,eqPos-colPos-1) ; 00219 // string colorStr = line.substr(eqPos+1); 00220 // string::size_type uPos = colorStr.find("_"); 00221 // string redString = colorStr.substr(0,) ; 00222 // skinFileMap[skinName] = path ; 00223 // } 00224 // 00225 // } 00226 // return 0 ; 00227 return 0 ; 00228 } 00229 ///////////////////////////////////////////// 00230 void showStaticTarget(Matrix& pattern , SDL_Surface* classSkin){ 00231 // int pw = classSkin->w; 00232 // int ph = classSkin->h ; 00233 // SDL_Rect theClip ; 00234 // theClip.x = 0 ; 00235 // theClip.y = 0 ; 00236 // theClip.w = pw ; 00237 // theClip.h = pw ; 00238 // SDL_Surface* blankSurface = getAFreshSurface(pw*pattern.getNumOfColumns(),pw*pattern.getNumOfRows()); 00239 // int nv = ph / pw ; 00240 // for( int r = 0 ; r < pattern.getNumOfRows() ; r++){ 00241 // for( int c = 0 ; c < pattern.getNumOfColumns() ; c++){ 00242 // if( pattern.get(r,c)== 1 ){ 00243 // theClip.y = (rand()%nv)*pw ; 00244 // apply_surface(c*pw,r*pw, *classSkin , *blankSurface ,theClip) ; 00245 // } 00246 // } 00247 // } 00248 // d->clearScreen(); 00249 // SDL_Rect offset; 00250 // 00251 // //Give the offsets to the rectangle 00252 // offset.x = (d->getWidth() - blankSurface->w) /2; 00253 // offset.y = (d-> getHeight() - blankSurface->h) /2; 00254 // d->displaySDLSurfacePatch(blankSurface , &offset,NULL , -2,false, true); 00255 // d->waitFrames(targetExposure); 00256 // SDL_FreeSurface(blankSurface); 00257 // theClip.~SDL_Rect(); 00258 } 00259 ///////////////////////////////////////// 00260 void showDynamicTarget(Matrix& pattern , SDL_Surface* classSkin){ 00261 // int pw = classSkin->w; 00262 // int ph = classSkin->h ; 00263 // SDL_Rect theClip ; 00264 // theClip.x = 0 ; 00265 // theClip.y = 0 ; 00266 // theClip.w = pw ; 00267 // theClip.h = pw ; 00268 // SDL_Surface* blankSurface = getAFreshSurface(pw*pattern.getNumOfColumns(),pw*pattern.getNumOfRows()); 00269 // int nv = ph / pw ; 00270 // Matrix* phaseMatrix = getARandomMap(pattern.getNumOfRows(),pattern.getNumOfColumns(),nv) ; 00271 // int counter = 0 ; 00272 // while(counter < targetExposure ){ 00273 // for( int r = 0 ; r < pattern.getNumOfRows() ; r++){ 00274 // for( int c = 0 ; c < pattern.getNumOfColumns() ; c++){ 00275 // if( pattern.get(r,c)== 1 ){ 00276 // theClip.y = ((counter+phaseMatrix->get(r,c)) %nv)*pw ; 00277 // apply_surface(c*pw,r*pw, *classSkin , *blankSurface ,theClip) ; 00278 // } 00279 // } 00280 // } 00281 // 00282 // 00283 // SDL_Rect offset; 00284 // 00285 // //Give the offsets to the rectangle 00286 // offset.x = (d->getWidth() - blankSurface->w) /2; 00287 // offset.y = (d-> getHeight() - blankSurface->h) /2; 00288 // d->displaySDLSurfacePatch(blankSurface , &offset,NULL , -2,true, true); 00289 // counter++; 00290 // } 00291 // 00292 // SDL_FreeSurface(blankSurface); 00293 // phaseMatrix->~Matrix(); 00294 // theClip.~SDL_Rect(); 00295 } 00296 ///////////////////////////////////////// 00297 uint showDynamicSlide(Matrix& theMap , map<string,SDL_Surface*>& cmap ){ 00298 // int cs = theMap.getNumOfColumns(); 00299 // int rs = theMap.getNumOfRows() ; 00300 // map<string , int> clipNumMap; 00301 // int imageWidth = -1 ; 00302 // int imageHeigth = -1 ; 00303 // int pw = 0 ; 00304 // int maxForPhase = 0; 00305 // //int sT = 100 ; 00306 // for( map<string,SDL_Surface*>:: iterator it = cmap.begin() ; it != cmap.end() ; ++it ){ 00307 // string clName = it->first ; 00308 // SDL_Surface* surf = it->second; 00309 // int numOfClips = (surf->h) / (surf->w); 00310 // clipNumMap[clName] = numOfClips; 00311 // maxForPhase = max(maxForPhase,numOfClips); 00312 // if(imageWidth == -1){ 00313 // pw = surf->w ; 00314 // imageWidth = theMap.getNumOfColumns()*pw ; 00315 // imageHeigth = theMap.getNumOfRows()*pw ; 00316 // } 00317 // 00318 // } 00319 // Matrix* phaseMatrix = getARandomMap(rs,cs,maxForPhase) ; 00320 // 00321 // SDL_Rect* theClip = new SDL_Rect(); 00322 // theClip->x = 0 ; 00323 // theClip->y = 0 ; 00324 // theClip->w = pw ; 00325 // theClip->h = pw ; 00326 // // 00327 // SDL_Surface* nbg = getAFreshSurface(imageWidth,imageHeigth); 00328 // string cname("") ; 00329 // int key = -1 ; 00330 // int counter = 0 ; 00331 // while( key < 0 ){ 00332 // for( int r = 0 ; r < rs ; r++){ 00333 // for( int c = 0 ; c < cs ; c++){ 00334 // switch( theMap.get(r,c) ){ 00335 // case 1 : cname = "class1" ;break ; 00336 // case 2 : cname = "class2" ; break ; 00337 // case 3 : cname = "class3" ; break ; 00338 // case 4 : cname = "class4" ; break ; 00339 // case 5 : cname = "class5" ; break ; 00340 // case 6 : cname = "class6" ; break ; 00341 // } 00342 // SDL_Surface* csurf = cmap[cname] ; 00343 // int y = ( (counter+phaseMatrix->get(r,c)) % clipNumMap[cname])*pw; 00344 // theClip->y = y ; 00345 // apply_surface(c*pw,r*pw, *csurf , *nbg ,*theClip) ; 00346 // } 00347 // } 00348 // //d->clearScreen(); 00349 // SDL_Rect offset; 00350 // offset.x = (d->getWidth() - nbg->w) /2; 00351 // offset.y = (d-> getHeight() - nbg->h) /2; 00352 // d->pushEvent("displaying frame "+ stringify(counter)); 00353 // d->displaySDLSurfacePatch(nbg , &offset,NULL , -2,true, true); 00354 // counter++; 00355 // key = d->checkForKey(); 00356 // if( key!=-1 ) { 00357 // d->pushEvent("subject decided to report"); 00358 // d->clearScreen(); 00359 // break ; 00360 // } 00361 // } 00362 // 00363 // delete phaseMatrix; 00364 // delete theClip; 00365 // SDL_FreeSurface(nbg); 00366 // return key ; 00367 return 0 ; 00368 } 00369 00370 ///////////////////////////////////////// 00371 void showStaticSlide(Matrix& theMap , map<string,SDL_Surface*>& cmap ){ 00372 // int cs = theMap.getNumOfColumns(); 00373 // int rs = theMap.getNumOfRows() ; 00374 // map<string , int> clipNumMap; 00375 // int imageWidth = -1 ; 00376 // int imageHeigth = -1 ; 00377 // int pw = 0 ; 00378 // 00379 // for( map<string,SDL_Surface*>:: iterator it = cmap.begin() ; it != cmap.end() ; ++it ){ 00380 // string clName = it->first ; 00381 // SDL_Surface* surf = it->second; 00382 // int numOfClips = (surf->h) / (surf->w); 00383 // clipNumMap[clName] = numOfClips; 00384 // if(imageWidth == -1){ 00385 // pw = surf->w ; 00386 // imageWidth = theMap.getNumOfColumns()*pw ; 00387 // imageHeigth = theMap.getNumOfRows()*pw ; 00388 // 00389 // } 00390 // 00391 // } 00392 // SDL_Rect* theClip = new SDL_Rect(); 00393 // theClip->x = 0 ; 00394 // theClip->y = 0 ; 00395 // theClip->w = pw ; 00396 // theClip->h = pw ; 00397 // // 00398 // SDL_Surface* nbg = getAFreshSurface(imageWidth,imageHeigth); 00399 // for( int r = 0 ; r < rs ; r++){ 00400 // for( int c = 0 ; c < cs ; c++){ 00401 // const int ti = theMap.get(r,c); 00402 // string cname = "class"+stringify(ti); 00403 // SDL_Surface* csurf = cmap[cname] ; 00404 // int y = (rand() % clipNumMap[cname])*pw; 00405 // theClip->y = y ; 00406 // apply_surface(c*pw,r*pw, *csurf , *nbg ,*theClip) ; 00407 // } 00408 // } 00409 // d->clearScreen(); 00410 // SDL_Rect offset; 00411 // offset.x = (d->getWidth() - nbg->w) /2; 00412 // offset.y = (d-> getHeight() - nbg->h) /2; 00413 // d->clearScreen(); 00414 // d->pushEvent("displaying the test image"); 00415 // d->displaySDLSurfacePatch(nbg , &offset,NULL , -2,false, true); 00416 // SDL_FreeSurface(nbg); 00417 // delete theClip; 00418 } 00419 ///////////////////////////////////////////// 00420 void doStaticTraining( map<string,SDL_Surface*>& cmap,vector<string>& messages){ 00421 // d->pushEvent("training starts") ; 00422 // d->displayText("Training Time! Press any key to start"); 00423 // d->showCursor(true); 00424 // d->waitForKey() ; 00425 // ////// 00426 // for( uint i = 0 ; i< messages.size() ; i++){ 00427 // d->displayText(messages[i]); 00428 // d->pushEvent("displayed training message : " + messages[i]); 00429 // d->waitFrames(300); 00430 // } 00431 // 00432 // ///// 00433 // d->pushEvent("training ends"); 00434 // //d->pushEvent("Congradulations! You are ready for the real test"); 00435 // d->waitFrames(45); 00436 // d->displayText("Press any key to start!") ; 00437 // d->waitForKey(); 00438 //d->showCursor(false); 00439 } 00440 00441 void doDynamicTraining( map<string,SDL_Surface*>& cmap,vector<string>& messages){ 00442 // d->pushEvent("training starts") ; 00443 // d->displayText("Training Time! Press any key to start"); 00444 // d->showCursor(true); 00445 // d->waitForKey() ; 00446 // ////// 00447 // for( uint i = 0 ; i< messages.size() ; i++){ 00448 // d->pushEvent(messages[i]); 00449 // } 00450 // 00451 // ///// 00452 // d->pushEvent("training ends"); 00453 // //d->pushEvent("Congradulations! You are ready for the real test"); 00454 // d->waitFrames(45); 00455 // d->displayText("Press any key to start!") ; 00456 // d->waitForKey(); 00457 // d->showCursor(false); 00458 } 00459 ///////////////////////////////////////////// 00460 int readBlock(ifstream& inFile){ 00461 // string block_name("") ; 00462 // string pattern("") ; 00463 // string skin_name("") ; 00464 // int px = 0 ; 00465 // int py = 0 ; 00466 // int rows = 0 ; 00467 // int columns = 0 ; 00468 // float rf = 1.0f ; 00469 // float prb = 0.5f ; 00470 // bool staticFlag = true ; 00471 // bool pureFlag = true ; 00472 // char ch[1000]; 00473 // bool trainingFlag = false ; 00474 // bool pureFlag = true ; 00475 // string trainingMessage("") ; 00476 // vector<string>* messages = new vector<string>() ; 00477 // vector<string>* exclusionList = new vector<string>(); 00478 // float minAccuracy = 0 ; 00479 // float minSensitivity = 0 ; 00480 // int minPositiveCase = 75; 00481 // 00482 // /*let's read attributes of the block*/ 00483 // while( inFile.getline(ch , 1000) ){ 00484 // string line = ch ; 00485 // LINFO("reads : %s" , line.c_str()) ; 00486 // 00487 // if(line.compare("dynamic")==0) { 00488 // staticFlag = false ; 00489 // } 00490 // 00491 // if(line.compare("mixed")==0) { 00492 // pureFlag = false ; 00493 // d ->pushEvent("mixed stimuli"); 00494 // } 00495 // 00496 // if(line.compare("end_block")==0) { 00497 // d -> pushEvent("ended reading block "+ block_name); 00498 // break ; 00499 // } 00500 // if( line.substr(0,10).compare("block_name") == 0 ){ 00501 // string::size_type position = line.find("=") ; 00502 // block_name = line.substr(position+1) ; 00503 // d -> pushEvent("started reading block "+block_name) ; 00504 // } 00505 // 00506 // if( line.substr(0,14).compare("target_pattern") == 0 ){ 00507 // string::size_type position = line.find("=") ; 00508 // pattern = line.substr(position+1) ; 00509 // d -> pushEvent("target pattern "+pattern) ; 00510 // } 00511 // 00512 // if( line.substr(0,16).compare("excluded_pattern") == 0 ){ 00513 // string::size_type position = line.find("=") ; 00514 // string exPattern = line.substr(position+1); 00515 // exclusionList->push_back(exPattern ) ; 00516 // d -> pushEvent("excluded pattern "+exPattern) ; 00517 // } 00518 // 00519 // if( line.substr(0,4).compare("skin") == 0 ){ 00520 // string::size_type position = line.find("=") ; 00521 // skin_name = line.substr(position+1) ; 00522 // } 00523 // 00524 // if(line.substr(0,2).compare("rf")==0){ 00525 // string::size_type position = line.find("="); 00526 // char x[10] ; 00527 // strcpy(x,line.substr(position+1).c_str()); 00528 // rf = atof(x); 00529 // } 00530 // if(line.substr(0,11).compare("probability")==0){ 00531 // string::size_type position = line.find("="); 00532 // char rf[10] ; 00533 // strcpy(rf,line.substr(position+1).c_str()); 00534 // prb = atof(rf); 00535 // } 00536 // if(line.substr(0,2).compare("px")==0){ 00537 // string::size_type position = line.find("="); 00538 // char rf[10] ; 00539 // strcpy(rf,line.substr(position+1).c_str()); 00540 // px = atoi(rf); 00541 // } 00542 // if(line.substr(0,2).compare("py")==0){ 00543 // string::size_type position = line.find("="); 00544 // char rf[10] ; 00545 // strcpy(rf,line.substr(position+1).c_str()); 00546 // py = atoi(rf); 00547 // } 00548 // if(line.substr(0,2).compare("rs")==0){ 00549 // string::size_type position = line.find("="); 00550 // char rf[10] ; 00551 // strcpy(rf,line.substr(position+1).c_str()); 00552 // rows = atoi(rf); 00553 // } 00554 // if(line.substr(0,2).compare("cs")==0){ 00555 // string::size_type position = line.find("="); 00556 // char rf[10] ; 00557 // strcpy(rf,line.substr(position+1).c_str()); 00558 // columns = atoi(rf); 00559 // } 00560 // if(line.substr(0,16).compare("minimum_positive")==0){ 00561 // string::size_type position = line.find("="); 00562 // char rf[10] ; 00563 // strcpy(rf,line.substr(position+1).c_str()); 00564 // minPositiveCase = atoi(rf); 00565 // } 00566 // 00567 // if( line.substr(0,12).compare("min_accuracy")==0 ){ 00568 // string::size_type position = line.find("="); 00569 // char rf[10] ; 00570 // strcpy(rf,line.substr(position + 1 ).c_str()); 00571 // minAccuracy = atof(rf); 00572 // } 00573 // if( line.substr(0,15).compare("min_sensitivity")==0 ){ 00574 // string::size_type position = line.find("="); 00575 // char rf[10] ; 00576 // strcpy(rf,line.substr(position + 1 ).c_str()); 00577 // minSensitivity = atof(rf); 00578 // } 00579 // if( line.substr(0,16).compare("training_message")==0 ){ 00580 // string::size_type position = line.find("="); 00581 // trainingFlag = true ; 00582 // trainingMessage = line.substr(position +1) ; 00583 // messages->push_back(trainingMessage); 00584 // } 00585 // 00586 // } 00587 // 00588 // /*let's load up the sprites associated with the skin and resize them and store them in a map*/ 00589 // map<string,SDL_Surface*>* classesMap = new map<string,SDL_Surface*>(); 00590 // for( int i = 0 ; i < 6 ; i++ ){ 00591 // string filepath ; 00592 // filepath += skinFileMap[skin_name]+"/"+classes[i]+"/ball.png" ; 00593 // SDL_Surface* tmpSurface = load_image(filepath) ; 00594 // tmpSurface = SDL_Resize(tmpSurface , rf , 6 ); 00595 // (*classesMap)[classes[i]] = tmpSurface; 00596 // } 00597 // 00598 // /*now we find all Euclidean transormations of the patten and store them in a vector 00599 // in every trial one of these pattens will be used (either included or excluded) 00600 // */ 00601 // Matrix *rawPattenMatrix = getPattenByString(pattern) ; 00602 // vector<Matrix*>* vars = getAllVariations(*rawPattenMatrix); 00603 // int vs = vars->size() ; 00604 // 00605 // /*Let's start training the subject*/ 00606 // d->displayText("Press any key to start!") ; 00607 // d->waitForKey() ; 00608 // if( trainingFlag ){ 00609 // if( staticFlag ){ 00610 // doStaticTraining(*classesMap,*messages) ; 00611 // } else { 00612 // doDynamicTraining(*classesMap,*messages) ; 00613 // } 00614 // 00615 // } 00616 // 00617 // /*the real test starts here and unless the required sensitivity is reached or prbability of having 00618 // positive cases it will continue 00619 // */ 00620 // int positiveCases = 0 ; 00621 // vector<int>* experiment = new vector<int>(); 00622 // vector<int>* report = new vector<int>(); 00623 // float sensitivity = 0.0f; 00624 // float accuracy = 0.0f ; 00625 // do{ 00626 // 00627 // 00628 // /*here we start different trials and we will have as many as block_size trials*/ 00629 // d->clearScreen(); 00630 // d->displayText("Please wait!") ; 00631 // srand ( time(NULL) ); 00632 // int patternChannel = rand()%NUMBER_OF_CLASSES ; 00633 // string targetClass = classes[patternChannel]; 00634 // srand ( time(NULL) ); 00635 // /*here we pick one of the transformed pattern to be used*/ 00636 // Matrix *patternMatrix = (*vars)[rand()%vs] ; 00637 // vector<Matrix*>* mapsVector ; 00638 // bool positiveFalg = true ; 00639 // 00640 // /*here we filp a coin to see if we include the pattern or exclude it*/ 00641 // if( rand()%10000 < prb*10000 ){ 00642 // 00643 // if(pureFlag){ 00644 // mapsVector = getPureMapsWithExactPatternAndExactChannel(rows,columns,NUMBER_OF_CLASSES , patternChannel+1,*patternMatrix,1,1); 00645 // }else{ 00646 // mapsVector = getMapsWithExactPattenAndExactChannel(rows,columns,NUMBER_OF_CLASSES , patternChannel+1,*patternMatrix,1,1); 00647 // } 00648 // 00649 // 00650 // /*we keep in mind that we chose to include the target in the board*/ 00651 // experiment-> push_back(1) ; 00652 // }else{ 00653 // mapsVector = getMapsWithExactPattenAndExactChannel(rows,columns,NUMBER_OF_CLASSES , patternChannel+1,*patternMatrix,0,1); 00654 // /*we keep in mind that we chose to exclude the target from the board*/ 00655 // experiment -> push_back(0) ; 00656 // positiveFalg = false ; 00657 // } 00658 // if( positiveFalg ) positiveCases++ ; 00659 // Matrix *map = (*mapsVector)[0] ; 00660 // d->pushEvent("class picked : " + targetClass) ; 00661 // d->pushEvent("pattern picked : "+patternMatrix->toFormattedString()) ; 00662 // d->pushEvent("map picked :" +map->toFormattedString()); 00663 // 00664 // /*now that we have picked the target patten and the board map let's start showing the 00665 // target 00666 // */ 00667 // d->clearScreen(); 00668 // d->pushEvent("started showing target image"); 00669 // if( staticFlag ){ 00670 // showStaticTarget(*patternMatrix,(*classesMap)[targetClass]) ; 00671 // } else { 00672 // showDynamicTarget(*patternMatrix,(*classesMap)[targetClass]) ; 00673 // } 00674 // /*we let's delay showing the board after the target*/ 00675 // d->pushEvent("started showing blink"); 00676 // d->displayFixationBlink(-1, -1, emptyTime/2, 2); 00677 // /*now that the target is shown we can show the board*/ 00678 // 00679 // if( staticFlag ){ 00680 // showStaticSlide(*map,*classesMap ); 00681 // report->push_back(getStaticResponse()); 00682 // } else { 00683 // int resp = showDynamicSlide(*map,*classesMap); 00684 // report->push_back(getDynamicResponse(resp)); 00685 // } 00686 // 00687 // 00688 // /*now that we are done with trials let's do some book keeping and see what was subject's sensitivity and 00689 // accuracy 00690 // */ 00691 // 00692 // float truePositives = 0.0f ; 00693 // float trueNegatives = 0.0f ; 00694 // float falsePositives = 0.0f ; 00695 // float falseNegatives = 0.0f ; 00696 // float positives = 0.0f ; 00697 // float negatives = 0.0f ; 00698 // vector<int>::size_type trialSize = experiment->size() ; 00699 // for( uint i = 0 ; i < trialSize ; i++ ){ 00700 // if( (*experiment)[i]==1 && (*report)[i]==1 ) {truePositives++ ; positives++ ; } 00701 // if( (*experiment)[i]==1 && (*report)[i]==0 ) {falseNegatives++ ; positives++ ; } 00702 // if( (*experiment)[i]==0 && (*report)[i]==1 ) {falsePositives++ ;negatives++ ; } 00703 // if( (*experiment)[i]==0 && (*report)[i]==0 ) {trueNegatives++ ; negatives++ ;} 00704 // } 00705 // if( positives != 0 ){ 00706 // sensitivity = truePositives / positives ; 00707 // } 00708 // accuracy = (truePositives + trueNegatives) / (positives+negatives) ; 00709 // 00710 // 00711 // d->pushEvent("positiveCases:%s"+stringify(positiveCases)+" minPositiveCase:"+stringify(minPositiveCase)); 00712 // d->pushEvent("accuracy:%s"+stringify(accuracy)+" minAccuracy:"+stringify(minAccuracy)) ; 00713 // d->pushEvent("sensitivity:%s"+stringify(sensitivity)+" minSensitivity"+stringify(minSensitivity)); 00714 // 00715 // }while( sensitivity < minSensitivity || accuracy < minAccuracy || positiveCases < minPositiveCase ); 00716 // 00717 // string reportString("") ; 00718 // string experimentString(""); 00719 // for(uint i = 0 ; i < experiment->size() ; i++){ 00720 // experimentString += stringify((*experiment)[i]) ; 00721 // reportString += stringify((*report)[i]) ; 00722 // } 00723 // d->pushEvent("experiment string :" + experimentString); 00724 // d->pushEvent("report string:" + reportString) ; 00725 // 00726 // /*and here we do necessary cleanups before finishing up the block*/ 00727 // for( map<string,SDL_Surface*>::iterator it=classesMap->begin() ; it!= classesMap->end() ; ++it){ 00728 // SDL_FreeSurface(it->second); 00729 // } 00730 // delete classesMap; 00731 // delete rawPattenMatrix; 00732 // delete vars; 00733 // delete messages; 00734 // delete exclusionList; 00735 // d-> displayText("You may take a short break!") ; 00736 // d->waitForKey() ; 00737 // return 0 ; 00738 // } 00739 // ///////////////////////////////////////////// 00740 // int readprofile(const char* filename){ 00741 // ifstream inFile(filename, ios::in); 00742 // if (! inFile) 00743 // { 00744 // LINFO("profile '%s' not found!" , filename); 00745 // return -1; 00746 // } 00747 // 00748 // char ch[1000]; 00749 // while (inFile.getline(ch , 1000)){ 00750 // string line = ch; 00751 // LINFO("reads : %s", line.c_str()); 00752 // if( line.substr(0,11).compare("profilename") == 0 ){ 00753 // string::size_type position = line.find("="); 00754 // d -> pushEvent("profile "+line.substr(position+1)+" started reading" ) ; 00755 // } 00756 // if(line.compare("start_top")==0 ) readTop(inFile); 00757 // if(line.compare("start_block")==0) readBlock(inFile); 00758 // if(programQuit == true) break ; 00759 // } 00760 00761 return 0 ; 00762 } 00763 ///////////////////////////////////////////// 00764 00765 00766 extern "C" int main( int argc, char* argv[] ) 00767 00768 { 00769 00770 MYLOGVERB = LOG_INFO; 00771 manager.addSubComponent(d); 00772 nub::soft_ref<EventLog> el(new EventLog(manager)); 00773 manager.addSubComponent(el); 00774 d->setEventLog(el); 00775 // Parse command-line: 00776 if (manager.parseCommandLine(argc, argv,"<profile.prf> <logfileName.psy>", 2, 2)==false) 00777 return(1); 00778 manager.setOptionValString(&OPT_EventLogFileName,manager.getExtraArg(1).c_str() ); 00779 manager.start(); 00780 d->clearScreen() ; 00781 //readprofile(manager.getExtraArg(0).c_str()); 00782 d->displayText("Experiment is done! Thanks for participating! ") ; 00783 d->waitForKey() ; 00784 manager.stop(); 00785 return(0) ; 00786 } 00787 00788 #endif // INVT_HAVE_LIBSDL_IMAGE 00789 00790