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 "Util/MathFunctions.H"
00046 #include "Util/Types.H"
00047 #include "rutz/time.h"
00048
00049 #define TRIAL_LENGTH 15
00050 #define MIN_COUNT 10
00051 #define MAX_COUNT 10
00052 #define MIN_X 100
00053 #define MIN_Y 100
00054 #define MAX_X 540
00055 #define MAX_Y 380
00056 #define PPD 23
00057 #define RECALIB 8
00058
00059
00060
00061
00062
00063 static int submain(const int argc, char** argv)
00064 {
00065 MYLOGVERB = LOG_INFO;
00066
00067
00068 ModelManager manager("Psycho EyeDetect");
00069
00070 nub::soft_ref<EventLog> el(new EventLog(manager));
00071 manager.addSubComponent(el);
00072
00073 nub::soft_ref<EyeTrackerConfigurator>
00074 etc(new EyeTrackerConfigurator(manager));
00075 manager.addSubComponent(etc);
00076
00077 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00078 manager.addSubComponent(d);
00079
00080 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy");
00081 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");
00082
00083
00084
00085 if (manager.parseCommandLine(argc, argv,"", 0, -1)==false)
00086 return(1);
00087
00088
00089 nub::soft_ref<EyeTracker> et = etc->getET();
00090 d->setEyeTracker(et);
00091 d->setEventLog(el);
00092 et->setEventLog(el);
00093
00094
00095 if (etc->getModelParamString("EyeTrackerType").compare("EL") == 0)
00096 d->setModelParamVal("SDLslaveMode", true);
00097
00098
00099 d->setModelParamVal("PsychoDisplayBackgroundColor", PixRGB<byte>(0,0,0));
00100 d->setModelParamVal("PsychoDisplayTextColor", PixRGB<byte>(255,255,255));
00101 d->setModelParamVal("PsychoDisplayFixSiz", 14);
00102
00103
00104 manager.start();
00105
00106
00107 et->calibrate(d);
00108
00109 initRandomNumbers();
00110
00111 int spdln = 12;
00112 float speeds[12] = {.01, 0.05, 0.1, 0.3, 0.7, 1.0, 1.0, 5.0, 5.0, 10.0, 10.0, 10.0};
00113 int styln = 10;
00114 int stays[10] = {0,1,10,20,40,60,80,100,110,120};
00115
00116
00117 LINFO("Load Our 1/f Background Noise Pre-Generated...");
00118 FILE* f = fopen ("fnoise.bin", "r");
00119 fseek (f , 0 , SEEK_END);
00120 long lSize = ftell (f);
00121 rewind (f);
00122 Uint8 * buf;
00123 buf = (Uint8*) malloc (sizeof(Uint8)*lSize);
00124 if (fread(buf,2,lSize,f) != (unsigned int)(lSize)) LFATAL("fread error");
00125 fclose(f);
00126 lSize = lSize/(640*480);
00127 LINFO("LENGTH: %d\n",(int)lSize);
00128
00129 for (int trials = 0; trials < TRIAL_LENGTH; ++trials)
00130 {
00131
00132 sleep(1); if (system("/bin/sync")) LERROR("error in sync()");
00133
00134 LINFO("Creating Random Background for Trial");
00135
00136 Image< PixRGB<byte> > img(640,480,ZEROS);
00137
00138 int count = 0;
00139 int index = (int)floor(randomDouble()*lSize);
00140 for (int xx = 0; xx < 640; ++xx)
00141 for (int yy = 0; yy < 480; ++yy)
00142 {
00143
00144 img.setVal(xx,yy,PixRGB<byte>((byte)buf[(640*480)*index + count],0,0));
00145 ++count;
00146 }
00147
00148
00149 int num_loc = (int)floor(MIN_COUNT + randomDouble()*(MAX_COUNT - MIN_COUNT));
00150
00151
00152 int location[num_loc][2];
00153 float speed[num_loc];
00154 int stay[num_loc-1];
00155
00156 for (int ii = 0; ii < num_loc; ++ii)
00157 {
00158 int x = (int)floor(MIN_X + randomDouble() * (MAX_X - MIN_X));
00159 int y = (int)floor(MIN_Y + randomDouble() * (MAX_Y - MIN_Y));
00160 location[ii][0] = x;
00161 location[ii][1] = y;
00162 float sp = speeds[(int)floor(randomDouble() * spdln)]*PPD;
00163 int st = stays[(int)floor(randomDouble() * (float)styln)];
00164 speed[ii] = sp;
00165 if (ii < num_loc-1)
00166 stay[ii] = st;
00167
00168 }
00169
00170
00171
00172 char str[50];
00173 sprintf(str,"Trial %d of %d: Follow the Red Dot <Space to Start>",trials+1,TRIAL_LENGTH);
00174 d->clearScreen();
00175 d->clearScreen();
00176 d->displayText(str);
00177 d->waitForKey();
00178 d->clearScreen();
00179
00180 d->displayImage(img);
00181
00182 d->displayRedDotFixation();
00183
00184 d->waitForKey();
00185 d->waitNextRequestedVsync(false, true);
00186 sprintf(str,"==== Trial: %d ====",trials+1);
00187 d->pushEvent(str);
00188
00189 et->track(true);
00190
00191 d->displayRedDotFixationBlink(img);
00192
00193 LINFO("Displaying Train\n");
00194 d->waitNextRequestedVsync(false, true);
00195 d->displayMovingDotTrain(img,location, num_loc, speed, stay,PixRGB<byte>(255,0,0));
00196
00197 d->waitNextRequestedVsync(false, true);
00198 d->clearScreen();
00199 d->clearScreen();
00200
00201 usleep(50000);
00202 et->track(false);
00203
00204 if (((trials+1) % RECALIB) == 0)
00205 {
00206 LINFO("Calibrating\n");
00207 et->recalibrate(d);
00208 }
00209 }
00210
00211
00212 d->clearScreen();
00213 d->displayText("Experiment complete. Thank you!");
00214 d->waitForKey();
00215
00216
00217 manager.stop();
00218
00219
00220 return 0;
00221 }
00222
00223
00224 extern "C" int main(const int argc, char** argv)
00225 {
00226
00227
00228
00229
00230 try
00231 {
00232 return submain(argc, argv);
00233 }
00234 catch (...)
00235 {
00236 REPORT_CURRENT_EXCEPTION;
00237 }
00238
00239 return 1;
00240 }
00241
00242
00243
00244
00245
00246