00001 /*!@file Psycho/EyesalData.C */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: David Berg <dberg@usc.edu> 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 //Access functions 00060 // ###################################################################### 00061 00062 00063 void EyesalData::setFile(const std::string& filename) 00064 { 00065 // let's read the entire file: 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 //ok, we have opened a file so lets read some data lines 00074 while (getline(fil, line)) 00075 { 00076 // one more line that we have read: 00077 ++linenum; 00078 00079 // skip initial whitespace: 00080 std::string::size_type pos = line.find_first_not_of(delim, 0); 00081 if (pos == line.npos) continue; // line was all whitespace 00082 RawEyesalData mydata; 00083 00084 // let's tokenize the line: 00085 std::vector<std::string> tok; 00086 split(line, " \t", std::back_inserter(tok)); 00087 00088 //get our saccade data 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);//we got all the data so store it 00111 00112 }//end while getlines 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();//no extension 00237 if (ids == itsFilename.npos) 00238 ids = 0;//no path 00239 return itsFilename.substr(ids+1+2, itsFilename.size()-idx-1); 00240 } 00241 00242 // ###################################################################### 00243 //some simple computations 00244 // ###################################################################### 00245 00246 00247 // ###################################################################### 00248 /* So things look consistent in everyone's emacs... */ 00249 /* Local Variables: */ 00250 /* mode: c++ */ 00251 /* indent-tabs-mode: nil */ 00252 /* End: */ 00253 00254 #endif // PSYCHO_EYESALDATA_C_DEFINED