00001 /*!@file AppPsycho/psycho-math-op.C Psychophysics test to measure the influence of eyemovement on memory task performance */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // 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: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppPsycho/psycho-energy-calib.C $ 00035 00036 00037 #include "Component/ModelManager.H" 00038 #include "Image/Image.H" 00039 #include "Psycho/PsychoDisplay.H" 00040 #include "Psycho/EyeTrackerConfigurator.H" 00041 #include "Psycho/EyeTracker.H" 00042 #include "Psycho/PsychoOpts.H" 00043 #include "Component/EventLog.H" 00044 #include "Component/ComponentOpts.H" 00045 #include "Raster/Raster.H" 00046 #include "Util/MathFunctions.H" 00047 #include "Util/Types.H" 00048 #include "GameBoard/basic-graphics.H" 00049 #include <sys/types.h> 00050 #include <dirent.h> 00051 #include <errno.h> 00052 #include <vector> 00053 #include <string> 00054 #include <iostream> 00055 #include <SDL/SDL.h> 00056 #include <SDL/SDL_image.h> 00057 #include <stdio.h> 00058 #include <stdlib.h> 00059 #include <sstream> 00060 #include <time.h> 00061 #include "Image/DrawOps.H" 00062 #include "GameBoard/resize.h" 00063 #include <iostream> 00064 #include <fstream> 00065 #include <set> 00066 #include <algorithm> 00067 #include <ctime> 00068 00069 #ifndef INVT_HAVE_LIBSDL_IMAGE 00070 #include <cstdio> 00071 int main() 00072 { 00073 fprintf(stderr, "The SDL_image library must be installed to use this program\n"); 00074 return 1; 00075 } 00076 00077 #else 00078 00079 00080 00081 using namespace std; 00082 00083 // ###################################################################### 00084 00085 ModelManager manager("Psycho-Calib"); 00086 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager)); 00087 map<uint,uint> testMap ; 00088 map<string,string> argMap ; 00089 00090 ////////////////////////////////////////////// 00091 // a functionf for stringigying things 00092 ////////////////////////////////////////////// 00093 template <class T> std::string stringify(T i) 00094 { 00095 ostringstream o ; 00096 o << i ; 00097 return o.str(); 00098 } 00099 00100 bool itIsInThere(int x , vector<int> bag){ 00101 for( uint i=0 ; i < bag.size(); i++ ){ 00102 if(x == bag[i]) return true ; 00103 } 00104 return false ; 00105 } 00106 00107 00108 00109 00110 00111 int addArgument(const string st,const string delim="="){ 00112 int i = st.find(delim) ; 00113 argMap[st.substr(0,i)] = st.substr(i+1); 00114 00115 return 0 ; 00116 } 00117 00118 std::string getArgumentValue(string arg){ 00119 return argMap[arg] ; 00120 } 00121 00122 std::vector<int> getDigits(int n , string zs="n" , string rs="n" ){ 00123 if(rs.compare("n")==0){ 00124 if(zs.compare("n")==0 && n >9 ) {LINFO( "come on! what do you expect?!") ; exit(-1) ;} 00125 if(zs.compare("y")==0 && n >10 ) {LINFO( "come on! what do you expect?!") ; exit(-1) ;} 00126 } 00127 vector<int> digits ; 00128 int dig = 0 ; 00129 while( digits.size() < (uint)n ){ 00130 if(zs.compare("n")==0) {dig = 1+(random()%9);}else{dig = random()%10;} 00131 if(rs.compare("y")==0){digits.push_back(dig);}else{if(!itIsInThere(dig,digits)) digits.push_back(dig);} 00132 } 00133 return digits ; 00134 } 00135 00136 std::string getUsageComment(){ 00137 00138 string com = string("\nlist of arguments : \n"); 00139 00140 com += "\nlogfile=[logfilename.psy] {default = psycho-stroop-concurrent.psy}\n" ; 00141 com += "\nmemo=[a_string_without_white_space]\n"; 00142 com += "\nx-grid=[>0](half minus one of num of points along x direction){default=5} \n"; 00143 com += "\nsaccade=[>0](half minus one of number of saccades to be made at each point){default=5} \n"; 00144 com += "\nsubject=[subject_name] \n" ; 00145 return com ; 00146 } 00147 00148 00149 extern "C" int main(const int argc, char** argv) 00150 { 00151 00152 MYLOGVERB = LOG_INFO; // suppress debug messages 00153 //let's push the initial value for the parameters 00154 argMap["experiment"]="testing-calibration-for-energy-distribution"; 00155 argMap["logfile"]="psycho-energy-calib.psy" ; 00156 argMap["subject"]="" ; 00157 argMap["memo"]="" ; 00158 argMap["x-grid"] = "5"; 00159 argMap["saccade"] = "5"; 00160 00161 manager.addSubComponent(d); 00162 nub::soft_ref<EventLog> el(new EventLog(manager)); 00163 manager.addSubComponent(el); 00164 d->setEventLog(el); 00165 nub::soft_ref<EyeTrackerConfigurator> 00166 etc(new EyeTrackerConfigurator(manager)); 00167 manager.addSubComponent(etc); 00168 00169 if (manager.parseCommandLine(argc, argv, 00170 "at least one argument needed", 1, -1)==false){ 00171 cout<<getUsageComment()<<endl; 00172 return(1); 00173 } 00174 00175 for(uint i = 0 ; i < manager.numExtraArgs() ; i++){ 00176 addArgument(manager.getExtraArg(i),std::string("=")) ; 00177 } 00178 00179 manager.setOptionValString(&OPT_EventLogFileName, argMap["logfile"]); 00180 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN"); 00181 nub::soft_ref<EyeTracker> eyet = etc->getET(); 00182 d->setEyeTracker(eyet); 00183 eyet->setEventLog(el); 00184 int x_g = atoi(argMap["x-grid"].c_str()) ; 00185 int y_g = atoi(argMap["saccade"].c_str()) ; 00186 // SDL_Rect offset ; 00187 // let's get all our ModelComponent instances started: 00188 manager.start(); 00189 for(map<string,string>::iterator it= argMap.begin(); it!= argMap.end() ; ++it) d->pushEvent("arg:"+ it->first+" value:"+it->second ) ; 00190 // let's display an ISCAN calibration grid: 00191 d->clearScreen(); 00192 d->displayISCANcalib(); 00193 d->waitForMouseClick(); 00194 d->displayText("CLICK LEFT button to calibrate; RIGHT to skip"); 00195 int cl = d->waitForMouseClick(); 00196 if (cl == 1) d->displayEyeTrackerCalibration(3,5,1 , true); 00197 d->clearScreen(); 00198 d->displayText("Here the experiment starts! click to start!"); 00199 d->waitForMouseClick() ; 00200 d->clearScreen(); 00201 //SDL_Surface* mark= getABlankSurface(5,5); 00202 int x0 = d->getWidth(); 00203 for(int i = - x_g ; i < x_g + 1 ; i++){ 00204 for(int j = -y_g ; j < y_g +1 ; j++){ 00205 int y = d->getHeight()/2; 00206 int x1 = x0+ i*32; 00207 int x2 = x1 + j*32; 00208 d->displayFixation(); 00209 d->waitForMouseClick() ; 00210 std::string imst = "===== Showing image: im"+stringify(x_g)+"-"+stringify(y_g)+".png ====="; 00211 d->pushEvent(imst); 00212 d->displayFixationBlink(x1,y,3,2); 00213 eyet->track(true); 00214 d->displayFixationBlink(x1,y,16,2); 00215 d->displayFixationBlink(x2,y,16,2); 00216 eyet->track(false); 00217 d->clearScreen(); 00218 00219 } 00220 } 00221 00222 d->waitForMouseClick(); 00223 d->clearScreen(); 00224 00225 d->clearScreen(); 00226 d->displayText("Experiment complete. Thank you!"); 00227 d->waitForMouseClick(); 00228 00229 00230 // stop all our ModelComponents 00231 manager.stop(); 00232 00233 00234 return 0; 00235 } 00236 00237 #endif // INVT_HAVE_LIBSDL_IMAGE 00238