psycho-searchArray.C
Go to the documentation of this file.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 "Image/DrawOps.H"
00042 #include "Psycho/PsychoDisplay.H"
00043 #include "Psycho/EyeTrackerConfigurator.H"
00044 #include "Psycho/EyeTracker.H"
00045 #include "Psycho/PsychoOpts.H"
00046 #include "Psycho/ArrayCreator.H"
00047 #include "Component/EventLog.H"
00048 #include "Component/ComponentOpts.H"
00049 #include "Raster/Raster.H"
00050 #include "Util/MathFunctions.H"
00051 #include "Util/Types.H"
00052 #include "Util/SimTime.H"
00053 #include "Util/Timer.H"
00054 #include "rutz/rand.h"
00055
00056 #include <vector>
00057
00058
00059 static const ModelOptionDef OPT_ACTrials =
00060 { MODOPT_ARG(int), "ACTrials", &MOC_PSYCHOARRAYCREATOR,
00061 OPTEXP_CORE, "number of times to repeat the sequnce",
00062 "trials", '\0', "<int>", "1" };
00063
00064
00065 extern "C" int main(const int argc, char** argv)
00066 {
00067 MYLOGVERB = LOG_INFO;
00068
00069
00070 ModelManager manager("Psycho Search Array");
00071 OModelParam<std::string> itsConfigFile(&OPT_ACFileName, &manager);
00072 OModelParam<uint> itsItemRadius(&OPT_ACItemRadius, &manager);
00073 OModelParam<float> itsJitter(&OPT_ACJitterLevel, &manager);
00074 OModelParam<float> itsPpdx(&OPT_ACPpdX, &manager);
00075 OModelParam<float> itsPpdy(&OPT_ACPpdY, &manager);
00076 OModelParam<PixRGB<byte> > itsBgCol(&OPT_ACBackgroundColor, &manager);
00077 OModelParam<SimTime> itsDur(&OPT_DisplayTime, &manager);
00078 OModelParam<float> itsFixSize(&OPT_FixSize, &manager);
00079 OModelParam<bool> itsKeepFix(&OPT_KeepFix, &manager);
00080 OModelParam<int> itsTrials(&OPT_ACTrials, &manager);
00081 OModelParam<Range<int> > itsWait(&OPT_TrialWait, &manager);
00082 OModelParam<bool> itsPermTargs(&OPT_ACPermuteTargs, &manager);
00083 OModelParam<bool> testrun(&OPT_Testrun, &manager);
00084
00085
00086 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00087 manager.addSubComponent(d);
00088
00089 nub::soft_ref<EyeTrackerConfigurator>
00090 etc(new EyeTrackerConfigurator(manager));
00091 manager.addSubComponent(etc);
00092
00093 nub::soft_ref<EventLog> el(new EventLog(manager));
00094 manager.addSubComponent(el);
00095
00096 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy");
00097 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");
00098
00099
00100 if (manager.parseCommandLine(argc, argv,"", 0, 0)==false)
00101 return(1);
00102
00103
00104 ArrayCreator ac(itsConfigFile.getVal(),
00105 itsItemRadius.getVal(), itsJitter.getVal(),
00106 d->getDims(), itsPpdx.getVal(),itsPpdy.getVal(),
00107 itsBgCol.getVal(),
00108 int(itsKeepFix.getVal())*itsFixSize.getVal(),
00109 itsPermTargs.getVal());
00110
00111 LINFO("Array list created with %d trials", ac.size());
00112
00113
00114 nub::soft_ref<EyeTracker> et = etc->getET();
00115 d->setEyeTracker(et);
00116 d->setEventLog(el);
00117 et->setEventLog(el);
00118
00119 initRandomNumbers();
00120
00121
00122 manager.start();
00123
00124 d->SDLdisplay::clearScreen(itsBgCol.getVal());
00125
00126
00127 const float ppd = sqrt(itsPpdx.getVal()*itsPpdx.getVal() +
00128 itsPpdy.getVal()*itsPpdy.getVal());
00129 const int size = int(ppd * itsFixSize.getVal());
00130 d->setFixationSize(size*2);
00131
00132
00133 uint nbimgs = ac.size()*itsTrials.getVal(); int index[nbimgs];
00134 for (uint i = 0; i < nbimgs; ++i) index[i] = i % ac.size();
00135 randShuffle(index, nbimgs);
00136 std::vector<int> vindex(index, index + nbimgs);
00137
00138 try {
00139
00140 for (uint i = 0; i < vindex.size(); i ++)
00141 {
00142
00143 d->SDLdisplay::clearScreen(itsBgCol.getVal());
00144 Image< PixRGB<byte> > image = ac.draw(vindex[i]);
00145
00146 SDL_Surface *surf = d->makeBlittableSurface(image, true);
00147 LINFO("Array ready. %d trial", i);
00148
00149
00150 sleep(1); if (system("/bin/sync")) LERROR("error in sync");
00151 LINFO("sync command complete");
00152
00153
00154
00155 et->clearEyeStatus();
00156 while (d->checkForKey() != -1) ;
00157
00158
00159 d->displayWhiteDotFixation();
00160
00161
00162 d->checkForKey();
00163
00164
00165 if (!testrun.getVal())
00166 while(true)
00167 {
00168 if (et->isFixating()) break;
00169 if (d->checkForKey() != -1) break;
00170 }
00171
00172
00173 et->clearEyeStatus();
00174
00175
00176 d->pushEvent(std::string("===== Showing Array: ") +
00177 ac.toString(index[i]) + " =====");
00178
00179
00180 d->waitNextRequestedVsync(false, true);
00181
00182
00183 et->track(true);
00184
00185
00186 d->displaySurface(surf, -2);
00187
00188
00189 Timer itsTimer;
00190
00191
00192 while ( itsTimer.getSimTime() < itsDur.getVal() )
00193 {
00194 if (itsKeepFix.getVal())
00195 if (et->isSaccade())
00196 {
00197 LINFO("Trial Aborted: Broke fixation");
00198 d->pushEvent("Trial Aborted: Broke fixation");
00199
00200
00201 int temp = vindex[i];
00202 vindex.push_back(temp);
00203 break;
00204 }
00205 }
00206
00207
00208 SDL_FreeSurface(surf);
00209
00210
00211 d->SDLdisplay::clearScreen(itsBgCol.getVal());
00212
00213
00214 usleep(50000);
00215 et->track(false);
00216
00217
00218 usleep(rutz::rand_range<int>(itsWait.getVal().min(),
00219 itsWait.getVal().max()) * 1000);
00220 }
00221
00222 d->SDLdisplay::clearScreen(itsBgCol.getVal());;
00223 LINFO("Experiment complete");
00224 }
00225 catch(...)
00226 {
00227 REPORT_CURRENT_EXCEPTION;
00228 }
00229
00230
00231 manager.stop();
00232
00233
00234 return 0;
00235 }
00236
00237
00238
00239
00240
00241