00001 /*!@file AppPsycho/psycho-EyeDetect.C Psychophysics display to cause 00002 * stereotyped eye movements */ 00003 00004 // //////////////////////////////////////////////////////////////////// // 00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00006 // University of Southern California (USC) and the iLab at USC. // 00007 // See http://iLab.usc.edu for information about this project. // 00008 // //////////////////////////////////////////////////////////////////// // 00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00011 // in Visual Environments, and Applications'' by Christof Koch and // 00012 // Laurent Itti, California Institute of Technology, 2001 (patent // 00013 // pending; application number 09/912,225 filed July 23, 2001; see // 00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00015 // //////////////////////////////////////////////////////////////////// // 00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00017 // // 00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00019 // redistribute it and/or modify it under the terms of the GNU General // 00020 // Public License as published by the Free Software Foundation; either // 00021 // version 2 of the License, or (at your option) any later version. // 00022 // // 00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00026 // PURPOSE. See the GNU General Public License for more details. // 00027 // // 00028 // You should have received a copy of the GNU General Public License // 00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00031 // Boston, MA 02111-1307 USA. // 00032 // //////////////////////////////////////////////////////////////////// // 00033 // 00034 // Primary maintainer for this file: David Berg <dberg@usc.edu> 00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppPsycho/psycho-EyeDetect.C $ 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 "Util/MathFunctions.H" 00046 #include "Util/Types.H" 00047 #include "rutz/time.h" 00048 00049 #define TRIAL_LENGTH 15 00050 #define MIN_COUNT 10 00051 #define MAX_COUNT 10 00052 #define MIN_X 100 00053 #define MIN_Y 100 00054 #define MAX_X 540 00055 #define MAX_Y 380 00056 #define PPD 23 00057 #define RECALIB 8 00058 00059 //maybe add some spatial bluring so the pixilation isn't as noticible. 00060 //maybe add a 1/f background noise 00061 00062 // ###################################################################### 00063 static int submain(const int argc, char** argv) 00064 { 00065 MYLOGVERB = LOG_INFO; // suppress debug messages 00066 00067 // Instantiate a ModelManager: 00068 ModelManager manager("Psycho EyeDetect"); 00069 00070 nub::soft_ref<EventLog> el(new EventLog(manager)); 00071 manager.addSubComponent(el); 00072 00073 nub::soft_ref<EyeTrackerConfigurator> 00074 etc(new EyeTrackerConfigurator(manager)); 00075 manager.addSubComponent(etc); 00076 00077 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager)); 00078 manager.addSubComponent(d); 00079 00080 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy"); 00081 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN"); 00082 00083 00084 // Parse command-line: 00085 if (manager.parseCommandLine(argc, argv,"", 0, -1)==false) 00086 return(1); 00087 00088 // hook our various babies up and do post-command-line configs: 00089 nub::soft_ref<EyeTracker> et = etc->getET(); 00090 d->setEyeTracker(et); 00091 d->setEventLog(el); 00092 et->setEventLog(el); 00093 00094 // EyeLink opens the screen for us, so make sure SDLdisplay is slave: 00095 if (etc->getModelParamString("EyeTrackerType").compare("EL") == 0) 00096 d->setModelParamVal("SDLslaveMode", true); 00097 00098 //set our background color and text color to match our stim 00099 d->setModelParamVal("PsychoDisplayBackgroundColor", PixRGB<byte>(0,0,0)); 00100 d->setModelParamVal("PsychoDisplayTextColor", PixRGB<byte>(255,255,255)); 00101 d->setModelParamVal("PsychoDisplayFixSiz", 14); 00102 00103 // let's get all our ModelComponent instances started: 00104 manager.start(); 00105 00106 // let's do a standard eye tracker calibration: 00107 et->calibrate(d); 00108 00109 initRandomNumbers(); 00110 //create some stims before display 00111 int spdln = 12; 00112 float speeds[12] = {.01, 0.05, 0.1, 0.3, 0.7, 1.0, 1.0, 5.0, 5.0, 10.0, 10.0, 10.0}; 00113 int styln = 10; 00114 int stays[10] = {0,1,10,20,40,60,80,100,110,120}; 00115 00116 00117 LINFO("Load Our 1/f Background Noise Pre-Generated..."); 00118 FILE* f = fopen ("fnoise.bin", "r"); 00119 fseek (f , 0 , SEEK_END); 00120 long lSize = ftell (f); 00121 rewind (f); 00122 Uint8 * buf; 00123 buf = (Uint8*) malloc (sizeof(Uint8)*lSize); 00124 if (fread(buf,2,lSize,f) != (unsigned int)(lSize)) LFATAL("fread error"); 00125 fclose(f); 00126 lSize = lSize/(640*480); 00127 LINFO("LENGTH: %d\n",(int)lSize); 00128 00129 for (int trials = 0; trials < TRIAL_LENGTH; ++trials) 00130 { 00131 //give other processes else a chance 00132 sleep(1); if (system("/bin/sync")) LERROR("error in sync()"); 00133 00134 LINFO("Creating Random Background for Trial"); 00135 //create a new background image each time 00136 Image< PixRGB<byte> > img(640,480,ZEROS); 00137 00138 int count = 0; 00139 int index = (int)floor(randomDouble()*lSize); 00140 for (int xx = 0; xx < 640; ++xx) 00141 for (int yy = 0; yy < 480; ++yy) 00142 { 00143 // LINFO("X:%d Y:%d",xx,yy); 00144 img.setVal(xx,yy,PixRGB<byte>((byte)buf[(640*480)*index + count],0,0)); 00145 ++count; 00146 } 00147 00148 //randomize the number of moves for each trial 00149 int num_loc = (int)floor(MIN_COUNT + randomDouble()*(MAX_COUNT - MIN_COUNT)); 00150 00151 //generate some random locations before we get started 00152 int location[num_loc][2]; 00153 float speed[num_loc]; 00154 int stay[num_loc-1]; 00155 00156 for (int ii = 0; ii < num_loc; ++ii) 00157 { 00158 int x = (int)floor(MIN_X + randomDouble() * (MAX_X - MIN_X)); 00159 int y = (int)floor(MIN_Y + randomDouble() * (MAX_Y - MIN_Y)); 00160 location[ii][0] = x; 00161 location[ii][1] = y; 00162 float sp = speeds[(int)floor(randomDouble() * spdln)]*PPD; 00163 int st = stays[(int)floor(randomDouble() * (float)styln)]; 00164 speed[ii] = sp; 00165 if (ii < num_loc-1) 00166 stay[ii] = st; 00167 // LINFO(" Location X: %d, location Y: %d, Speed: %f, Fixation: %d\n",x,y,sp,st); 00168 } 00169 00170 00171 00172 char str[50]; 00173 sprintf(str,"Trial %d of %d: Follow the Red Dot <Space to Start>",trials+1,TRIAL_LENGTH); 00174 d->clearScreen(); 00175 d->clearScreen(); 00176 d->displayText(str); 00177 d->waitForKey(); 00178 d->clearScreen(); 00179 00180 d->displayImage(img); 00181 // display fixation to indicate that we are ready: 00182 d->displayRedDotFixation(); 00183 // ready to go whenever the user is ready: 00184 d->waitForKey(); 00185 d->waitNextRequestedVsync(false, true); 00186 sprintf(str,"==== Trial: %d ====",trials+1); 00187 d->pushEvent(str); 00188 // start the eye tracker: 00189 et->track(true); 00190 // blink the fixation: this is 1 second I think 00191 d->displayRedDotFixationBlink(img); 00192 //display our randomly created stimulus 00193 LINFO("Displaying Train\n"); 00194 d->waitNextRequestedVsync(false, true); 00195 d->displayMovingDotTrain(img,location, num_loc, speed, stay,PixRGB<byte>(255,0,0)); 00196 //now we are done with our one trial clear,sleep and recalibrate 00197 d->waitNextRequestedVsync(false, true); 00198 d->clearScreen(); 00199 d->clearScreen(); 00200 // stop the eye tracker: 00201 usleep(50000); 00202 et->track(false); 00203 // let's do a quickie eye tracker recalibration: 00204 if (((trials+1) % RECALIB) == 0) 00205 { 00206 LINFO("Calibrating\n"); 00207 et->recalibrate(d); 00208 } 00209 } 00210 00211 00212 d->clearScreen(); 00213 d->displayText("Experiment complete. Thank you!"); 00214 d->waitForKey(); 00215 00216 // stop all our ModelComponents 00217 manager.stop(); 00218 00219 // all done! 00220 return 0; 00221 } 00222 00223 // ###################################################################### 00224 extern "C" int main(const int argc, char** argv) 00225 { 00226 // simple wrapper around submain() to catch exceptions (because we 00227 // want to allow PsychoDisplay to shut down cleanly; otherwise if we 00228 // abort while SDL is in fullscreen mode, the X server won't return 00229 // to its original resolution) 00230 try 00231 { 00232 return submain(argc, argv); 00233 } 00234 catch (...) 00235 { 00236 REPORT_CURRENT_EXCEPTION; 00237 } 00238 00239 return 1; 00240 } 00241 00242 // ###################################################################### 00243 /* So things look consistent in everyone's emacs... */ 00244 /* Local Variables: */ 00245 /* indent-tabs-mode: nil */ 00246 /* End: */