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/ColorOps.H"
00041 #include "Image/CutPaste.H"
00042 #include "Image/Image.H"
00043 #include "Image/MathOps.H"
00044 #include "Psycho/PsychoDisplay.H"
00045 #include "Psycho/EyeTrackerConfigurator.H"
00046 #include "Psycho/EyeTracker.H"
00047 #include "Psycho/PsychoOpts.H"
00048 #include "GUI/GUIOpts.H"
00049 #include "Component/EventLog.H"
00050 #include "Component/ComponentOpts.H"
00051 #include "GUI/SDLdisplay.H"
00052 #include "Raster/Raster.H"
00053 #include "Util/MathFunctions.H"
00054 #include "Util/Types.H"
00055
00056 #include <ctype.h>
00057 #include <vector>
00058
00059
00060 #define NMASK 10
00061
00062
00063 extern "C" int main(const int argc, char** argv)
00064 {
00065 MYLOGVERB = LOG_INFO;
00066
00067
00068 ModelManager manager("Psycho Double Search");
00069
00070
00071 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00072 manager.addSubComponent(d);
00073
00074 nub::soft_ref<EyeTrackerConfigurator>
00075 etc(new EyeTrackerConfigurator(manager));
00076 manager.addSubComponent(etc);
00077
00078 nub::soft_ref<EventLog> el(new EventLog(manager));
00079 manager.addSubComponent(el);
00080
00081 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy");
00082 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");
00083 manager.setOptionValString(&OPT_SDLdisplayDims, "1280x1024");
00084 d->setModelParamVal("PsychoDisplayBackgroundColor", PixRGB<byte>(0));
00085 d->setModelParamVal("PsychoDisplayTextColor", PixRGB<byte>(255));
00086 d->setModelParamVal("PsychoDisplayBlack", PixRGB<byte>(255));
00087 d->setModelParamVal("PsychoDisplayWhite", PixRGB<byte>(128));
00088 d->setModelParamVal("PsychoDisplayFixSiz", 5);
00089 d->setModelParamVal("PsychoDisplayFixThick", 5);
00090
00091
00092 if (manager.parseCommandLine(argc, argv, "<imagelist.txt>", 1, 1) == false)
00093 return(1);
00094
00095
00096 nub::soft_ref<EyeTracker> et = etc->getET();
00097 d->setEyeTracker(et);
00098 d->setEventLog(el);
00099 et->setEventLog(el);
00100
00101
00102 manager.start();
00103
00104
00105 SDL_Surface *mask[NMASK]; int mindex[NMASK]; Dims ddims = d->getDims();
00106
00107 for (int i = 0; i < NMASK; i ++) {
00108 Image<byte> n(ddims, ZEROS);
00109 inplaceSpeckleNoise(n, 1.0F, i+1, 255, true);
00110 mask[i] = d->makeBlittableSurface(makeRGB(n, n, n), false);
00111
00112
00113 mindex[i] = i;
00114 }
00115
00116
00117 FILE *f = fopen(manager.getExtraArg(0).c_str(), "r");
00118 if (f == NULL) LFATAL("Cannot read stimulus file");
00119 char line[1024];
00120 std::vector<std::string> ilist, t1list, t2list;
00121 while(fgets(line, 1024, f))
00122 {
00123
00124
00125
00126 char *line2 = line; while(*line2 != '\0' && !isspace(*line2)) line2 ++;
00127 *line2++ = '\0';
00128 char *line3 = line2; while(*line3 != '\0' && !isspace(*line3)) line3 ++;
00129 *line3++ = '\0'; line3[strlen(line3) - 1] = '\0';
00130
00131
00132 t1list.push_back(std::string(line));
00133 t2list.push_back(std::string(line2));
00134 ilist.push_back(std::string(line3));
00135 }
00136 fclose(f);
00137
00138
00139 int nimg = ilist.size(); int imindex[nimg];
00140 for (int i = 0; i < nimg; i ++) imindex[i] = i;
00141 randShuffle(imindex, nimg);
00142
00143
00144 d->clearScreen();
00145 d->displayISCANcalib();
00146 d->waitForKey();
00147
00148
00149 d->displayText("<SPACE> to calibrate; other key to skip");
00150 int c = d->waitForKey();
00151 if (c == ' ') d->displayEyeTrackerCalibration(3, 3);
00152
00153
00154 d->clearScreen();
00155 d->displayText("<SPACE> to start experiment");
00156 d->waitForKey();
00157 d->waitNextRequestedVsync(false, true);
00158
00159
00160 for (int im = 0; im < nimg; im ++) {
00161 int imnum = imindex[im];
00162
00163
00164 d->clearScreen();
00165 LINFO("Loading '%s' / '%s'/ '%s'...",
00166 ilist[imnum].c_str(), t1list[imnum].c_str(), t2list[imnum].c_str());
00167
00168
00169 Image< PixRGB<byte> > img1 = Raster::ReadRGB(t1list[imnum]);
00170 Image< PixRGB<byte> > img2 = Raster::ReadRGB(t2list[imnum]);
00171 Image< PixRGB<byte> > img(d->getDims(), NO_INIT);
00172 img.clear(d->getGrey());
00173 inplacePaste(img, img1, Point2D<int>(img.getWidth() / 2 - img1.getWidth() * 2,
00174 (img.getHeight() - img1.getHeight()) / 2));
00175 inplacePaste(img, img2, Point2D<int>(img.getWidth() / 2 + img2.getWidth(),
00176 (img.getHeight() - img2.getHeight()) / 2));
00177 SDL_Surface *surf1 = d->makeBlittableSurface(img, false);
00178 char buf[256];
00179 sprintf(buf, "===== Showing imagelets: %s %s =====",
00180 t1list[imnum].c_str(), t1list[imnum].c_str());
00181
00182
00183 img = Raster::ReadRGB(ilist[imnum]);
00184 SDL_Surface *surf2 = d->makeBlittableSurface(img, false);
00185
00186
00187 randShuffle(mindex, NMASK);
00188
00189
00190 usleep(200000);
00191
00192
00193 d->displayText("Press <SPACE> when you are ready");
00194 d->waitForKey();
00195 d->pushEvent(buf);
00196
00197
00198 d->displaySurface(surf1, 0, true);
00199
00200
00201 sleep(5);
00202
00203
00204 d->pushEvent("===== Showing mask =====");
00205 for (int j = 0; j < NMASK; j ++)
00206 d->displaySurface(mask[mindex[j]], j+1, true);
00207
00208
00209 d->clearScreen();
00210 d->displayFixation();
00211 for (int i = 0; i < 40; i ++) d->waitNextRequestedVsync();
00212
00213
00214 et->track(true);
00215
00216
00217 d->displayFixationBlink();
00218
00219
00220 d->pushEvent(std::string("===== Showing search image: ") + ilist[imnum] +
00221 std::string(" ====="));
00222 d->displaySurface(surf2, 0, true);
00223
00224
00225 d->waitForKey();
00226 d->waitForKey();
00227
00228
00229 SDL_FreeSurface(surf1); SDL_FreeSurface(surf2);
00230
00231
00232 usleep(150000);
00233 et->track(false);
00234
00235
00236 if ((im + 1) % 5 == 0) {
00237 d->displayText("press <SPACE> when you are ready for recalibration");
00238 d->waitForKey();
00239 d->displayEyeTrackerCalibration(3, 3);
00240 d->clearScreen();
00241 d->displayText("Press <SPACE> to continue with the movies");
00242 d->waitForKey();
00243 }
00244 }
00245
00246 d->clearScreen();
00247 d->displayText("Experiment complete. Thank you!");
00248 d->waitForKey();
00249
00250
00251 manager.stop();
00252
00253
00254 for (int i = 0; i < NMASK; i++) SDL_FreeSurface(mask[i]);
00255
00256
00257 return 0;
00258 }
00259
00260
00261
00262
00263
00264