psycho-still-monkey.C
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 "Component/ModelOptionDef.H"
00039 #include "Image/Image.H"
00040 #include "Image/Range.H"
00041 #include "Psycho/PsychoDisplay.H"
00042 #include "Psycho/EyeTrackerConfigurator.H"
00043 #include "Psycho/EyeTracker.H"
00044 #include "Psycho/PsychoOpts.H"
00045 #include "Component/EventLog.H"
00046 #include "Component/ComponentOpts.H"
00047 #include "Raster/Raster.H"
00048 #include "Util/SimTime.H"
00049 #include "Util/MathFunctions.H"
00050 #include "Util/Types.H"
00051 #include "rutz/rand.h"
00052
00053
00054 extern "C" int main(const int argc, char** argv)
00055 {
00056 MYLOGVERB = LOG_INFO;
00057
00058
00059 ModelManager manager("Psycho Still");
00060 OModelParam<bool> keepfix(&OPT_KeepFix, &manager);
00061 OModelParam<float> fixsize(&OPT_FixSize, &manager);
00062 OModelParam<float> ppd(&OPT_Ppd, &manager);
00063 OModelParam<SimTime> itsDur(&OPT_DisplayTime, &manager);
00064 OModelParam<Range<int> > itsWait(&OPT_TrialWait, &manager);
00065 OModelParam<bool> testrun(&OPT_Testrun, &manager);
00066
00067
00068 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00069 manager.addSubComponent(d);
00070
00071 nub::soft_ref<EyeTrackerConfigurator>
00072 etc(new EyeTrackerConfigurator(manager));
00073 manager.addSubComponent(etc);
00074
00075 nub::soft_ref<EventLog> el(new EventLog(manager));
00076 manager.addSubComponent(el);
00077
00078 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy");
00079 manager.setOptionValString(&OPT_EyeTrackerType, "DML");
00080
00081
00082 if (manager.parseCommandLine(argc, argv,
00083 "<img1.ppm> ... <imgN.ppm>", 1, -1)==false)
00084 return(1);
00085
00086
00087 nub::soft_ref<EyeTracker> et = etc->getET();
00088 d->setEyeTracker(et);
00089 d->setEventLog(el);
00090 et->setEventLog(el);
00091
00092
00093 int fixrad = int(ppd.getVal() * fixsize.getVal());
00094 if ((fixrad % 2) != 0)
00095 --fixrad;
00096 d->setFixationSize(fixrad*2);
00097
00098
00099 SDL_Rect rect;
00100 const int siz2 = (fixrad - 1) / 2;
00101 const int w = d->getDims().w(), h = d->getDims().h();
00102 const int i = w / 2 - 1;
00103 const int j = h / 2 - 1;
00104 rect.x = i - siz2; rect.y = j - siz2; rect.w = fixrad; rect.h = fixrad;
00105
00106
00107 manager.start();
00108 d->clearScreen();
00109
00110
00111 uint nbimgs = manager.numExtraArgs(); int index[nbimgs];
00112 for (uint i = 0; i < nbimgs; i ++)
00113 index[i] = i;
00114
00115 LINFO("Randomizing images...");
00116 randShuffle(index, nbimgs);
00117
00118 try {
00119
00120 for (uint i = 0; i < nbimgs; i ++)
00121 {
00122
00123 d->clearScreen();
00124 LINFO("Loading '%s'...", manager.getExtraArg(index[i]).c_str());
00125 Image< PixRGB<byte> > image =
00126 Raster::ReadRGB(manager.getExtraArg(index[i]));
00127
00128 SDL_Surface *surf = d->makeBlittableSurface(image, true);
00129
00130
00131 if (keepfix.getVal())
00132 SDL_FillRect(surf, &rect, d->getUint32color(PixRGB<byte>(255, 0, 0)));
00133
00134 LINFO("'%s' ready.", manager.getExtraArg(index[i]).c_str());
00135
00136
00137
00138 while(et->isFixating()) ;
00139 while(d->checkForKey() != -1) ;
00140
00141
00142 d->displayRedDotFixation();
00143
00144
00145 d->checkForKey();
00146
00147
00148 if (!testrun.getVal())
00149 while(true)
00150 {
00151 if (et->isFixating()) break;
00152 if (d->checkForKey() != -1) break;
00153 }
00154
00155 d->waitNextRequestedVsync(false, true);
00156 d->pushEvent(std::string("===== Showing image: ") +
00157 manager.getExtraArg(index[i]) + " =====");
00158
00159
00160 et->track(true);
00161
00162
00163 d->displaySurface(surf, -2);
00164
00165
00166 usleep(itsDur.getVal().usecs());
00167
00168
00169 SDL_FreeSurface(surf);
00170
00171
00172 d->clearScreen();
00173
00174
00175 usleep(50000);
00176 et->track(false);
00177
00178
00179 usleep(rutz::rand_range<int>(itsWait.getVal().min(),
00180 itsWait.getVal().max()) * 1000);
00181 }
00182
00183 d->clearScreen();
00184 d->displayText("Experiment complete. Thank you!");
00185 d->waitForKey();
00186 }
00187 catch (...)
00188 {
00189 REPORT_CURRENT_EXCEPTION;
00190 };
00191
00192
00193 manager.stop();
00194
00195
00196 return 0;
00197 }
00198
00199
00200
00201
00202
00203