00001 /*!@file AppPsycho/psycho-still.C Psychophysics display of still images */ 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-freeview.C $ 00035 // $Id: psycho-freeview.C 8521 2007-06-28 17:45:49Z rjpeters $ 00036 // 00037 00038 #include "Component/ModelManager.H" 00039 #include "Image/Image.H" 00040 #include "Psycho/PsychoDisplay.H" 00041 #include "Psycho/EyeTrackerConfigurator.H" 00042 #include "Psycho/EyeTracker.H" 00043 #include "Psycho/PsychoOpts.H" 00044 #include "Component/EventLog.H" 00045 #include "Component/ComponentOpts.H" 00046 #include "Raster/Raster.H" 00047 #include "Util/MathFunctions.H" 00048 #include "Util/Types.H" 00049 #include "Image/DrawOps.H" 00050 #include "Image/ImageSet.H" 00051 #include "Image/ShapeOps.H" 00052 #include "GUI/GUIOpts.H" 00053 #include "Util/StringUtil.H" 00054 #include "Util/MathFunctions.H" 00055 00056 // ###################################################################### 00057 extern "C" int main(const int argc, char** argv) 00058 { 00059 MYLOGVERB = LOG_INFO; // suppress debug messages 00060 00061 // Instantiate a ModelManager: 00062 ModelManager manager("Psycho Freeview"); 00063 00064 // Instantiate our various ModelComponents: 00065 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager)); 00066 manager.addSubComponent(d); 00067 00068 nub::soft_ref<EyeTrackerConfigurator> 00069 etc(new EyeTrackerConfigurator(manager)); 00070 manager.addSubComponent(etc); 00071 00072 nub::soft_ref<EventLog> el(new EventLog(manager)); 00073 manager.addSubComponent(el); 00074 00075 manager.exportOptions(MC_RECURSE); 00076 manager.setOptionValString(&OPT_SDLdisplayDims, "1920x1080"); 00077 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy"); 00078 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN"); 00079 00080 // Parse command-line: 00081 if (manager.parseCommandLine(argc, argv, 00082 "<img1.ppm> ... <imgN.ppm>", 1, -1)==false) 00083 return(1); 00084 00085 // hook our various babies up and do post-command-line configs: 00086 nub::soft_ref<EyeTracker> et = etc->getET(); 00087 d->setEyeTracker(et); 00088 d->setEventLog(el); 00089 et->setEventLog(el); 00090 00091 // let's get all our ModelComponent instances started: 00092 manager.start(); 00093 00094 // let's display an ISCAN calibration grid: 00095 d->clearScreen(); 00096 d->displayISCANcalib(); 00097 d->waitForKey(); 00098 00099 // let's do an eye tracker calibration: 00100 d->displayText("<SPACE> to calibrate; other key to skip"); 00101 int c = d->waitForKey(); 00102 if (c == ' ') d->displayEyeTrackerCalibration(); 00103 00104 d->clearScreen(); 00105 d->displayText("<SPACE> To Show Pictures"); 00106 c = d->waitForKey(); 00107 00108 // setup array of movie indices: 00109 uint nbimgs = manager.numExtraArgs(); int index[nbimgs]; 00110 for (uint i = 0; i < nbimgs; i ++) index[i] = i; 00111 if (c == ' ') { LINFO("Randomizing images..."); randShuffle(index, nbimgs); } 00112 00113 // main loop: 00114 for (uint i = 0; i < nbimgs; i ++) 00115 { 00116 // load up the frame and show a fixation cross on a blank screen: 00117 d->clearScreen(); 00118 LINFO("Loading '%s'...", manager.getExtraArg(index[i]).c_str()); 00119 Image< PixRGB<byte> > image = 00120 Raster::ReadRGB(manager.getExtraArg(index[i])); 00121 00122 SDL_Surface *surf = d->makeBlittableSurface(image, true); 00123 00124 LINFO("'%s' ready.", manager.getExtraArg(index[i]).c_str()); 00125 d->displayFixation(); 00126 00127 // ready to go whenever the user is ready: 00128 d->waitForKey(); 00129 d->waitNextRequestedVsync(false, true); 00130 d->pushEvent(std::string("===== Showing image: ") + 00131 manager.getExtraArg(index[i]) + " ====="); 00132 00133 // start the eye tracker: 00134 et->track(true); 00135 00136 // blink the fixation: 00137 d->displayFixationBlink(); 00138 00139 // show the image: 00140 d->displaySurface(surf, -2); 00141 00142 // fixed presentation time: 00143 usleep(2000000); 00144 00145 // free the image: 00146 SDL_FreeSurface(surf); 00147 00148 // make sure display if off before we stop the tracker: 00149 d->clearScreen(); 00150 00151 // stop the eye tracker: 00152 usleep(50000); 00153 et->track(false); 00154 00155 if ( ((int)(i+1)%46) == 0) 00156 00157 { 00158 00159 // let's display an ISCAN calibration grid: 00160 d->clearScreen(); 00161 d->displayISCANcalib(); 00162 d->waitForKey(); 00163 d->waitForKey(); 00164 00165 // let's do an eye tracker calibration: 00166 d->displayText("<SPACE> to calibrate; other key to skip"); 00167 int c = d->waitForKey(); 00168 if (c == ' ') d->displayEyeTrackerCalibration(); 00169 00170 d->clearScreen(); 00171 d->displayText("<SPACE> To Cotinue Experiment"); 00172 c = d->waitForKey(); 00173 } 00174 } 00175 00176 d->clearScreen(); 00177 d->displayText("Experiment complete. Thank you!"); 00178 d->waitForKey(); 00179 00180 // stop all our ModelComponents 00181 manager.stop(); 00182 00183 // all done! 00184 return 0; 00185 } 00186 00187 // ###################################################################### 00188 /* So things look consistent in everyone's emacs... */ 00189 /* Local Variables: */ 00190 /* indent-tabs-mode: nil */ 00191 /* End: */