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
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
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 <stdio.h>
00073 #include <stdlib.h>
00074 #include <map>
00075 #include <time.h>
00076 #include <sstream>
00077 #include "basic-graphics.H"
00078 #include "AppPsycho/psycho-skin-mapgenerator.h"
00079
00080
00081 using namespace std;
00082
00083 SDL_Surface* drawTheBoard(Matrix& bmap,map<int,Uint32>& colorMap , uint w , uint h ){
00084
00085 SDL_Surface* surface = getABlankSurface(w,h) ;
00086 uint nr = (uint)bmap.getNumOfRows() ;
00087 uint nc = (uint) bmap.getNumOfColumns() ;
00088 uint pw = w / ( 2* nc +1);
00089 uint ph = h / (2 * nr +1) ;
00090 uint offX = (w - pw*(2*nc-1))/2 ;
00091 uint offY = (h - ph*(2*nr-1))/2 ;
00092 for( uint r = 0 ; r < nr ; r++){
00093 for( uint c = 0 ; c < nc ; c++){
00094 fillRectangle(surface,colorMap[bmap.get(r,c)],offX+ (2*c )*pw,offY+ (2*r)*ph ,pw,ph) ;
00095
00096 }
00097 }
00098 return surface ;
00099 }
00100
00101 extern "C" int main(int argc, char* argv[] ){
00102
00103 ModelManager manager("Psycho Skin");
00104 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00105
00106 MYLOGVERB = LOG_INFO;
00107
00108 manager.addSubComponent(d);
00109 nub::soft_ref<EventLog> el(new EventLog(manager));
00110 manager.addSubComponent(el);
00111 d->setEventLog(el);
00112
00113 if (manager.parseCommandLine(argc, argv,"<logfilename>", 1 , 3)==false)
00114 return(1);
00115 manager.setOptionValString(&OPT_EventLogFileName,manager.getExtraArg(2).c_str() );
00116 manager.start();
00117
00118 SDL_Rect offset;
00119 SDL_Rect targetOffset ;
00120 targetOffset.x = (d->getWidth()-(d->getWidth())/10)/2 ;;
00121 targetOffset.y = (d->getHeight() - (d->getHeight())/10)/2 ;
00122 offset.x = 0 ;
00123 offset.y = 0 ;
00124 int k = -1 ;
00125 map<int,Uint32>* cm = new map<int , Uint32>() ;
00126 for( int i = 1 ; i <=10; i++){
00127 (*cm)[i] = d->getUint32color(PixRGB<byte>(0, 255-12.5*i, 0));
00128 }
00129
00130 do{
00131 d->clearScreen() ;
00132 srand ( time(NULL) );
00133 uint displacement = rand()%220 + 35 ;
00134 Matrix* bm = getARandomMap(30,30,5) ;
00135 Matrix* tm = getARandomMap(1,2,2) ;
00136 tm->set(0,0,12);
00137 tm->set(0,1,13);
00138 (*cm)[11] = d->getUint32color(PixRGB<byte>(displacement,20,displacement)) ;
00139 (*cm)[12] = d->getUint32color(PixRGB<byte>(displacement,20,0)) ;
00140 (*cm)[13] = d->getUint32color(PixRGB<byte>(0,20,displacement)) ;
00141
00142 SDL_Surface* target = drawTheBoard(*tm,*cm,(d->getWidth())/10,(d->getHeight())/10) ;
00143
00144 uint distractorNum = rand()%15 ;
00145
00146 for(uint i = 0 ; i < distractorNum ; i++){
00147 (*bm).set(rand()%(bm->getNumOfRows())+1,rand() % bm->getNumOfColumns()+1,11) ;
00148 }
00149 int targetFlag = rand()%3 ;
00150 switch( targetFlag ){
00151 case 0 : (*bm).set(rand()%(bm->getNumOfRows())+1,rand() % bm->getNumOfColumns()+1,12) ; break ;
00152 case 1 : (*bm).set(rand()%(bm->getNumOfRows())+1,rand() % bm->getNumOfColumns()+1,13) ; break ;
00153 default : break ;
00154 }
00155
00156 SDL_Surface* board = drawTheBoard(*bm,*cm,d->getWidth(),d->getHeight());
00157
00158 d->pushEvent("started showing target image");
00159 d->displaySDLSurfacePatch( target , &targetOffset ,NULL , -2,false, true);
00160 d->waitFrames(5);
00161 d->clearScreen();
00162
00163 d->pushEvent("started showing blink");
00164 d->displayFixationBlink(-1, -1, 3, 2);
00165 d->pushEvent("displaying the test image");
00166 d->displaySDLSurfacePatch(board , &offset,NULL , -2,false, true);
00167
00168 delete bm ;
00169 delete tm ;
00170 k = d->waitForKey() ;
00171 dumpSurface(board) ;
00172 dumpSurface(target);
00173
00174 }while(k!=32);
00175 delete cm ;
00176 manager.stop();
00177 return 0 ;
00178 }
00179
00180
00181 #endif // INVT_HAVE_LIBSDL_IMAGE
00182
00183