psycho-stillRTI.C

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