EyesalData.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 #ifndef PSYCHO_EYESALDATA_C_DEFINED
00036 #define PSYCHO_EYESALDATA_C_DEFINED
00037
00038 #include "Psycho/EyesalData.H"
00039 #include "Util/StringConversions.H"
00040 #include "Util/StringUtil.H"
00041
00042 #include <fstream>
00043
00044
00045
00046 EyesalData::EyesalData() :
00047 itsFilename(""), itsData()
00048 {
00049 }
00050
00051
00052 EyesalData::EyesalData(const std::string& filename) :
00053 itsFilename(filename), itsData()
00054 {
00055 setFile(filename);
00056 }
00057
00058
00059
00060
00061
00062
00063 void EyesalData::setFile(const std::string& filename)
00064 {
00065
00066 const char *fn = filename.c_str();
00067 std::ifstream fil(fn);
00068 if (fil.is_open() == false) PLFATAL("Cannot open '%s'", fn);
00069
00070 const std::string delim(" \t");
00071 std::string line; int linenum = -1;
00072
00073
00074 while (getline(fil, line))
00075 {
00076
00077 ++linenum;
00078
00079
00080 std::string::size_type pos = line.find_first_not_of(delim, 0);
00081 if (pos == line.npos) continue;
00082 RawEyesalData mydata;
00083
00084
00085 std::vector<std::string> tok;
00086 split(line, " \t", std::back_inserter(tok));
00087
00088
00089 mydata.Filename = tok[0];
00090 mydata.x = fromStr<int>(tok[1]);
00091 mydata.y = fromStr<int>(tok[2]);
00092 mydata.fovx = fromStr<int>(tok[3]);
00093 mydata.fovy = fromStr<int>(tok[4]);
00094 mydata.pupil = fromStr<float>(tok[5]);
00095 mydata.amp = fromStr<float>(tok[6]);
00096 mydata.duration = fromStr<float>(tok[7]);
00097 mydata.sactime = fromStr<float>(tok[8]);
00098 mydata.val = fromStr<float>(tok[9]);
00099 mydata.min = fromStr<float>(tok[10]);
00100 mydata.max = fromStr<float>(tok[11]);
00101 mydata.avg = fromStr<float>(tok[12]);
00102
00103 if (tok.size() != 313)
00104 LFATAL("Error parsing '%s', line %d", fn, linenum);
00105
00106 for (size_t jj = 13; jj < tok.size(); jj++){
00107 mydata.rand[jj-13] = fromStr<float>(tok[jj]);
00108 }
00109
00110 itsData.push_back(mydata);
00111
00112 }
00113
00114 }
00115
00116
00117 bool EyesalData::hasData(const size_t index) const
00118 {
00119 return index < itsData.size();
00120 }
00121
00122
00123 Point2D<int> EyesalData::getXYpos(const size_t index) const
00124 {
00125 Point2D<int> tmp(itsData[index].x,itsData[index].y);
00126 return tmp;
00127 }
00128
00129 std::vector<float> EyesalData::getNormSal() const
00130 {
00131 std::vector<float> normsal;
00132 for (std::vector<RawEyesalData>::const_iterator sal_iter = itsData.begin();
00133 sal_iter != itsData.end(); ++sal_iter)
00134 normsal.push_back(sal_iter->val/sal_iter->max);
00135 return normsal;
00136
00137
00138 }
00139
00140 std::vector<float> EyesalData::getNormRand(const size_t index) const
00141 {
00142 std::vector<float> normrnd;
00143 for (std::vector<RawEyesalData>::const_iterator rnd_iter = itsData.begin();
00144 rnd_iter != itsData.end(); ++rnd_iter)
00145 normrnd.push_back(rnd_iter->rand[index*3] / rnd_iter->max);
00146 return normrnd;
00147
00148 }
00149
00150 std::vector< std::vector<float> > EyesalData::getAllNormRand() const
00151 {
00152 std::vector< std::vector<float> > temp;
00153 for (size_t count = 0; count < 100; ++count)
00154 {
00155 std::vector<float> test = getNormRand(count);
00156 temp.push_back(test);
00157 }
00158 return temp;
00159 }
00160
00161 std::vector< std::vector<float> > EyesalData::getAllNormRandT() const
00162 {
00163 std::vector< std::vector<float> > temp = getAllNormRand();
00164 std::vector< std::vector<float> > out(temp[0].size());
00165 for (size_t count = 0; count < temp[0].size(); ++count){
00166 out[count].resize(100);
00167 for (size_t rndc = 0; rndc < 100; ++rndc){
00168 out[count][rndc] = temp[rndc][count];
00169 }
00170 }
00171
00172 return out;
00173 }
00174
00175 std::vector<Point2D<int> > EyesalData::getXYpos() const
00176 {
00177 std::vector<Point2D<int> > tmpv;
00178 for (size_t jj = 0; jj < size(); jj++)
00179 {
00180 Point2D<int> tmp(itsData[jj].x,itsData[jj].y);
00181 tmpv.push_back(tmp);
00182 }
00183 return tmpv;
00184 }
00185
00186 float EyesalData::getTime(const size_t index) const
00187 {
00188 return itsData[index].sactime;
00189 }
00190
00191
00192 std::vector<float> EyesalData::getTime() const
00193 {
00194 std::vector< float > tmpv;
00195 for (size_t jj = 0; jj < size(); jj++)
00196 {
00197 float tmp = itsData[jj].sactime;
00198 tmpv.push_back(tmp);
00199 }
00200 return tmpv;
00201
00202 }
00203
00204 std::string EyesalData::getFileName(const size_t index) const
00205 {
00206 return itsData[index].Filename;
00207 }
00208
00209 std::vector<std::string> EyesalData::getFileName() const
00210 {
00211 std::vector< std::string > tmpv;
00212 for (size_t jj = 0; jj < size(); jj++)
00213 {
00214 std::string tmp = itsData[jj].Filename;
00215 tmpv.push_back(tmp);
00216 }
00217 return tmpv;
00218
00219 }size_t EyesalData::size() const
00220 {
00221 return itsData.size();
00222
00223 }
00224
00225
00226 std::string EyesalData::filename() const
00227 {
00228 return itsFilename;
00229 }
00230
00231 std::string EyesalData::basename() const
00232 {
00233 size_t idx = itsFilename.rfind('.');
00234 size_t ids = itsFilename.rfind('/');
00235 if (idx == itsFilename.npos)
00236 idx = itsFilename.size();
00237 if (ids == itsFilename.npos)
00238 ids = 0;
00239 return itsFilename.substr(ids+1+2, itsFilename.size()-idx-1);
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 #endif // PSYCHO_EYESALDATA_C_DEFINED