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 #ifndef TIGS_SCORE_MAP_VS_EYE_C_DEFINED
00039 #define TIGS_SCORE_MAP_VS_EYE_C_DEFINED
00040
00041 #include "Component/ModelManager.H"
00042 #include "Component/ModelOptionDef.H"
00043 #include "Media/FrameSeries.H"
00044 #include "Psycho/EyeSFile.H"
00045 #include "TIGS/Scorer.H"
00046 #include "TIGS/TigsOpts.H"
00047 #include "Util/Pause.H"
00048 #include "Util/csignals.H"
00049 #include "Util/sformat.H"
00050
00051 #include <fstream>
00052
00053
00054 static const ModelOptionDef OPT_MoviePeriod =
00055 { MODOPT_ARG(SimTime), "MoviePeriod", &MOC_TIGS, OPTEXP_CORE,
00056 "Inter-frame period (or rate) of input movie",
00057 "movie-period", '\0', "<float>{s|ms|us|ns|Hz}", "0.0s" };
00058
00059
00060 static const ModelOptionDef OPT_TimeShift =
00061 { MODOPT_ARG(SimTime), "TimeShift", &MOC_TIGS, OPTEXP_CORE,
00062 "Amount of time shift to use between visual input and eye position",
00063 "time-shift", '\0', "<float>{s|ms|us|ns|Hz}", "0.0s" };
00064
00065 static void writeStringToFile(const std::string& fname,
00066 const std::string& msg)
00067 {
00068 std::ofstream ofs(fname.c_str());
00069 if (!ofs.is_open())
00070 LFATAL("couldn't open %s for writing", fname.c_str());
00071 ofs << msg << '\n';
00072 ofs.close();
00073 }
00074
00075 int submain(int argc, const char** argv)
00076 {
00077 volatile int signum = 0;
00078 catchsignals(&signum);
00079
00080 ModelManager mgr("map-eye scorer");
00081 OModelParam<SimTime> moviePeriod(&OPT_MoviePeriod, &mgr);
00082 OModelParam<SimTime> timeShift(&OPT_TimeShift, &mgr);
00083
00084 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(mgr));
00085 mgr.addSubComponent(ifs);
00086
00087 nub::ref<EyeSFile> eyeS(new EyeSFile(mgr));
00088 mgr.addSubComponent(eyeS);
00089
00090 mgr.exportOptions(MC_RECURSE);
00091
00092 if (mgr.parseCommandLine(argc, argv, "outstem", 1, 1) == false)
00093 return 1;
00094
00095 mgr.start();
00096
00097 const std::string outstem = mgr.getExtraArg(0);
00098
00099 if (moviePeriod.getVal() == SimTime::ZERO())
00100 LFATAL("movie period must be non-zero");
00101
00102 PauseWaiter p;
00103
00104 int nframes = 0;
00105
00106 MulticastScorer scorer;
00107
00108 std::ofstream hist((outstem + ".hist").c_str());
00109 if (!hist.is_open())
00110 LFATAL("couldn't open %s.hist for writing", outstem.c_str());
00111
00112 while (1)
00113 {
00114 if (signum != 0)
00115 {
00116 LINFO("caught signal %s; quitting", signame(signum));
00117 break;
00118 }
00119
00120 if (p.checkPause())
00121 continue;
00122
00123 const SimTime stime =
00124 moviePeriod.getVal() * (nframes+1) - timeShift.getVal();
00125
00126 ifs->updateNext();
00127 Image<float> map = ifs->readFloat();
00128
00129 if (!map.initialized())
00130 {
00131 LINFO("input exhausted; quitting");
00132 break;
00133 }
00134
00135 if (stime > SimTime::ZERO())
00136 {
00137 const Point2D<int> eyepos = eyeS->readUpTo(stime);
00138
00139 LINFO("simtime %.6fs, movie frame %d, eye sample %d, ratio %f, "
00140 "eyepos (x=%d, y=%d)",
00141 stime.secs(), nframes+1, eyeS->lineNumber(),
00142 double(eyeS->lineNumber())/double(nframes+1),
00143 eyepos.i, eyepos.j);
00144
00145 const int p = (eyepos.j / 16) * map.getWidth() + (eyepos.i / 16);
00146
00147 scorer.score("scorer", map, p);
00148
00149 hist << scorer.itsNssScorer.getCurrentZscore() << ' '
00150 << scorer.itsPrctileScorer.getCurrentPrctile() << '\n';
00151 }
00152
00153 ++nframes;
00154 }
00155
00156 writeStringToFile(outstem + ".zscore",
00157 sformat("%.5f", scorer.itsNssScorer.getOverallZscore()));
00158
00159 writeStringToFile(outstem + ".prctile",
00160 sformat("%.5f", scorer.itsPrctileScorer.getOverallPrctile()));
00161
00162 mgr.stop();
00163
00164 return 0;
00165 }
00166
00167 int main(int argc, const char** argv)
00168 {
00169 try {
00170 submain(argc, argv);
00171 } catch(...) {
00172 REPORT_CURRENT_EXCEPTION;
00173 std::terminate();
00174 }
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184 #endif // TIGS_SCORE_MAP_VS_EYE_C_DEFINED