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 #include "Component/ModelManager.H"
00040 #include "Image/Image.H"
00041 #include "Psycho/PsychoDisplay.H"
00042 #include "GUI/GUIOpts.H"
00043 #include "Psycho/EyeTrackerConfigurator.H"
00044 #include "Psycho/EyeTracker.H"
00045 #include "Psycho/PsychoOpts.H"
00046 #include "Component/EventLog.H"
00047 #include "Component/ComponentOpts.H"
00048 #include "Raster/Raster.H"
00049 #include "Util/Types.H"
00050 #include <fstream>
00051
00052
00053 extern "C" int main(const int argc, char** argv)
00054 {
00055 MYLOGVERB = LOG_INFO;
00056
00057
00058 ModelManager manager("Psycho no Cheating");
00059
00060
00061 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00062 manager.addSubComponent(d);
00063
00064 nub::soft_ref<EyeTrackerConfigurator>
00065 etc(new EyeTrackerConfigurator(manager));
00066 manager.addSubComponent(etc);
00067
00068 nub::soft_ref<EventLog> el(new EventLog(manager));
00069 manager.addSubComponent(el);
00070
00071
00072
00073 manager.setOptionValString(&OPT_SDLdisplayDims, "1024x768");
00074 d->setModelParamVal("PsychoDisplayBackgroundColor", PixRGB<byte>(0));
00075 d->setModelParamVal("PsychoDisplayTextColor", PixRGB<byte>(255));
00076 d->setModelParamVal("PsychoDisplayBlack", PixRGB<byte>(255));
00077 d->setModelParamVal("PsychoDisplayWhite", PixRGB<byte>(128));
00078 d->setModelParamVal("PsychoDisplayFixSiz", 5);
00079 d->setModelParamVal("PsychoDisplayFixThick", 5);
00080 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy");
00081 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");
00082
00083
00084 if (manager.parseCommandLine(argc, argv, "<fileList>", 1, -1)==false)
00085 return(1);
00086
00087
00088 nub::soft_ref<EyeTracker> et = etc->getET();
00089 d->setEyeTracker(et);
00090 d->setEventLog(el);
00091 et->setEventLog(el);
00092
00093
00094 manager.start();
00095
00096
00097 d->clearScreen();
00098 d->displayISCANcalib();
00099 d->waitForKey();
00100
00101
00102 d->displayText("<SPACE> to calibrate; other key to skip");
00103 int c = d->waitForKey();
00104 if (c == ' ') d->displayEyeTrackerCalibration(3, 3);
00105
00106 d->clearScreen();
00107
00108
00109 std::ifstream file(manager.getExtraArg(0).c_str());
00110 if (file == 0) LFATAL("Couldn't open object file: '%s'",
00111 manager.getExtraArg(0).c_str());
00112
00113 std::string line; int correct = 0, accuracy = 100, total = 0;
00114 while(getline(file, line))
00115 {
00116
00117
00118 std::string::size_type end = line.find_first_of(" ");
00119 std::string::size_type start = 0;
00120 int i = 0; std::string imageName, noCheatName, checkName, recoName;
00121 while (end != std::string::npos) {
00122 std::string token = line.substr(start, end-start);
00123 switch(i)
00124 {
00125 case 0:
00126 imageName = token;
00127 break;
00128 case 1:
00129 noCheatName = token;
00130 break;
00131 case 2:
00132 checkName = token;
00133 break;
00134 }
00135 start = end + 1;
00136 end = line.find_first_of(" ", start);
00137 i ++;
00138 }
00139
00140 recoName = line.substr(start);
00141
00142
00143 d->clearScreen();
00144 LINFO("Loading '%s'...", imageName.c_str());
00145 Image< PixRGB<byte> > image =
00146 Raster::ReadRGB(imageName);
00147
00148 SDL_Surface *surf = d->makeBlittableSurface(image, true);
00149
00150 LINFO("'%s' ready.", imageName.c_str());
00151
00152
00153 d->displayText("hit any key when ready");
00154 d->waitForKey();
00155 d->waitNextRequestedVsync(false, true);
00156
00157
00158 et->track(true);
00159 d->pushEvent(std::string("===== Showing image: ") +imageName + " =====");
00160
00161
00162 d->displayFixationBlink();
00163
00164
00165 d->displaySurface(surf, -2, true);
00166
00167
00168 c = d->waitForKey();
00169
00170
00171 SDL_FreeSurface(surf);
00172
00173
00174 usleep(50000);
00175 et->track(false);
00176
00177
00178
00179 LINFO("Loading '%s'...", noCheatName.c_str());
00180 Image< PixRGB<byte> > noCheat =
00181 Raster::ReadRGB(noCheatName);
00182
00183 surf = d->makeBlittableSurface(noCheat, true);
00184
00185 LINFO("'%s' ready.", noCheatName.c_str());
00186 d->pushEvent(std::string("===== Showing noCheat: ") + noCheatName
00187 + " =====");
00188
00189
00190 d->displaySurface(surf, -2, true);
00191 for (int j = 0; j < 3; j ++) d->waitNextRequestedVsync();
00192
00193
00194 SDL_FreeSurface(surf);
00195
00196
00197 d->displayText("Enter the number at the target location");
00198 c = d->waitForKey();
00199 int c2 = d->waitForKey();
00200 std::ifstream check (checkName.c_str());
00201 if (check == 0) LFATAL("Couldn't open check file: '%s'",
00202 checkName.c_str());
00203 std::string response;
00204 total ++;
00205 while (getline(check, response))
00206 {
00207 LINFO (" reading from %s", checkName.c_str());
00208 LINFO (" subject entered %d%d", c, c2);
00209 LINFO (" reading %c%c from %s", response[0], response[1],
00210 checkName.c_str());
00211
00212 char tmp[40];
00213 if (((int)response[0] == c) && ((int)response[1] == c2))
00214 {
00215 correct ++;
00216 accuracy = correct * 100 / total;
00217 sprintf(tmp, "Correct! Accuracy is %d%%", accuracy);
00218 d->displayText(tmp);
00219 d->pushEvent(std::string("===== Correct ====="));
00220 }
00221 else
00222 {
00223 accuracy = correct * 100 / total;
00224 sprintf(tmp, "Wrong! Accuracy is %d%%", accuracy);
00225 d->displayText(tmp);
00226 d->pushEvent(std::string("===== Wrong ====="));
00227 }
00228
00229
00230 for (int j = 0; j < 30; j ++) d->waitNextRequestedVsync();
00231 }
00232
00233 }
00234
00235 d->clearScreen();
00236 d->displayText("Experiment complete. Thank you!");
00237 d->waitForKey();
00238
00239
00240 manager.stop();
00241
00242
00243 return 0;
00244 }
00245
00246
00247
00248
00249
00250