psycho-geon.C

Go to the documentation of this file.
00001 /*!@file AppPsycho/psycho-geon.C Psychophysics display of geon 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-geon.C $
00035 // $Id: psycho-geon.C 12962 2010-03-06 02:13:53Z irock $
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 <fstream>
00050 
00051 using namespace std;
00052 
00053 // ######################################################################
00054 extern "C" int main(const int argc, char** argv)
00055 {
00056   MYLOGVERB = LOG_INFO;  // suppress debug messages
00057 
00058   // Instantiate a ModelManager:
00059   ModelManager manager("Psycho Still");
00060 
00061   // Instantiate our various ModelComponents:
00062   nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00063   manager.addSubComponent(d);
00064 
00065   nub::soft_ref<EyeTrackerConfigurator>
00066     etc(new EyeTrackerConfigurator(manager));
00067   manager.addSubComponent(etc);
00068 
00069   nub::soft_ref<EventLog> el(new EventLog(manager));
00070   manager.addSubComponent(el);
00071 
00072 
00073 
00074 
00075   // Parse command-line:
00076   // Subject Run isAdapt(1or0) MaleOrFemale
00077   if (manager.parseCommandLine(argc, argv,
00078                                "<img1.ppm> ... <imgN.ppm>", 1, -1)==false){
00079         cout<<"please give the following arguments:\n Subject-Initials Run-Number Is-Adaptation(1 for adaptation 0 for control) PresentationTime(1 or 2 in secs) MaleOrFemale(M for Male, F you guessed it...) Handedness(R L)"<< endl;
00080     return(1);
00081         }
00082 
00083 
00084         string Sub=manager.getExtraArg(0);
00085         string Run=manager.getExtraArg(1);
00086         string IA=manager.getExtraArg(2);
00087         int IsAdapt=(int)IA[0]-48;//
00088         cout<<IsAdapt<<"is adaptation"<<endl;
00089         string PT=manager.getExtraArg(3);
00090         int PresentationTime=(int)PT[0]-48;//atoi(PT[0].c_str());
00091         cout<<"presentation time is:"<<PresentationTime<<endl;
00092         string Gender=manager.getExtraArg(4);
00093         string Handedness=manager.getExtraArg(5);
00094 
00095         string DataDir="/lab/ilab19/geonexp/stimuli/Data/";
00096         string psyFileName=DataDir + "BG_Run" + Run + "_Adapt" + IA +"_"+ Sub+"_StimONTime-"+PT+"_"+Gender+"_"+Handedness;
00097         manager.setOptionValString(&OPT_EventLogFileName, psyFileName);
00098         manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");
00099 
00100         d->pushEvent(std::string("Run=") + Run + "\n" + Sub +"\nGender="+ Gender);
00101         if (IsAdapt) {d->pushEvent("Adaptation");}
00102         else {d->pushEvent("Control");};
00103 
00104 
00105 
00106   // hook our various babies up and do post-command-line configs:
00107   nub::soft_ref<EyeTracker> et = etc->getET();
00108   d->setEyeTracker(et);
00109   d->setEventLog(el);
00110   et->setEventLog(el);
00111 
00112   // let's get all our ModelComponent instances started:
00113   manager.start();
00114 
00115   // let's do an eye tracker calibration:
00116   et->calibrate(d);
00117 
00118   d->clearScreen();
00119   d->displayText("<SPACE> for random play; other key for ordered");
00120   //int c = d->waitForKey();
00121 
00122   // setup array of movie indices:
00123   //uint nbimgs = manager.numExtraArgs(); int index[nbimgs];
00124   //for (uint i = 0; i < nbimgs; i ++) index[i] = i;
00125   //if (c == ' ') { LINFO("Randomizing images..."); randShuffle(index, nbimgs); }
00126 
00127   //Reads the Images sequence text file:
00128     string FileName;
00129 
00130     string ExpDir="/lab/ilab19/geonexp/stimuli/sequences/";
00131     string ImgDir="/lab/ilab19/geonexp/stimuli/images/";
00132 
00133     if (IsAdapt){
00134         FileName=ExpDir+"GRun_"+Run+"Adapt.txt";
00135     }else{
00136         FileName=ExpDir+"GRun_"+Run+"Control.txt";
00137     };
00138 
00139     cout<<FileName<<endl;
00140     const char *FileNameP=FileName.c_str();
00141 
00142 
00143   ifstream RunFile (FileNameP);
00144   string  u;
00145 
00146   int NumOfTrials, j;
00147 
00148   getline(RunFile, u);
00149   cout<<u;
00150   const char *p;
00151   p=u.c_str();
00152   NumOfTrials=atoi(p);
00153   string ImageSequence[NumOfTrials];
00154 
00155   for(j=0; j<NumOfTrials; j++){
00156     getline(RunFile, ImageSequence[j]);
00157     ImageSequence[j]= ImgDir +ImageSequence[j];
00158     cout <<ImageSequence[j]<<endl;
00159   }
00160 
00161   RunFile.close();
00162 
00163 
00164   LINFO("Ready to go");
00165 
00166   // main loop:
00167   for (int i = 0; i < NumOfTrials; i ++)
00168     {
00169       // load up the frame and show a fixation cross on a blank screen:
00170       d->clearScreen();
00171       LINFO("Loading '%s'...", ImageSequence[i].c_str());
00172       Image< PixRGB<byte> > image =
00173         Raster::ReadRGB(ImageSequence[i]);
00174 
00175       SDL_Surface *surf = d->makeBlittableSurface(image, true);
00176 
00177       LINFO("'%s' ready.", ImageSequence[i].c_str());
00178       d->displayFixation();
00179 
00180       // ready to go whenever the user is ready:
00181       d->waitForKey();
00182       d->waitNextRequestedVsync(false, true);
00183       d->pushEvent(std::string("===== Showing image: ") +
00184                    ImageSequence[i] + " =====");
00185 
00186       // start the eye tracker:
00187       et->track(true);
00188 
00189       // blink the fixation:
00190       d->displayFixationBlink();
00191 
00192       // show the image:
00193       d->displaySurface(surf, -2);
00194 
00195       // wait for key:
00196       d->waitFrames(PresentationTime*30);
00197 
00198       // free the image:
00199       SDL_FreeSurface(surf);
00200 
00201       // make sure display if off before we stop the tracker:
00202       d->clearScreen();
00203 
00204       // stop the eye tracker:
00205       usleep(50000);
00206       et->track(false);
00207     }
00208 
00209   d->clearScreen();
00210   d->displayText("Experiment complete. Thank you!");
00211   d->waitForKey();
00212 
00213   // stop all our ModelComponents
00214   manager.stop();
00215 
00216   // all done!
00217   return 0;
00218 }
00219 
00220 
00221 // ######################################################################
00222 /* So things look consistent in everyone's emacs... */
00223 /* Local Variables: */
00224 /* indent-tabs-mode: nil */
00225 /* End: */
Generated on Sun May 8 08:40:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3