psycho-3D-proto.C

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-still.C $
00035 // $Id: psycho-still.C 10144 2008-08-27 01:16:43Z ilab19 $
00036 //
00037 
00038 
00039 #include "Component/ModelManager.H"
00040 #include "Image/Image.H"
00041 #include "Psycho/PsychoDisplay.H"
00042 #include "Psycho/EyeTrackerConfigurator.H"
00043 #include "Psycho/EyeTracker.H"
00044 #include "Psycho/PsychoOpts.H"
00045 #include "Component/EventLog.H"
00046 #include "Component/ComponentOpts.H"
00047 #include "Raster/Raster.H"
00048 #include "Util/MathFunctions.H"
00049 #include "Util/Types.H"
00050 #include "GameBoard/basic-graphics.H"
00051 #include <sys/types.h>
00052 #include <dirent.h>
00053 #include <errno.h>
00054 #include <vector>
00055 #include <string>
00056 #include <iostream>
00057 #include <SDL/SDL.h>
00058 #include <SDL/SDL_image.h>
00059 #include <SDL/SDL_mixer.h>
00060 #include <stdio.h>
00061 #include <stdlib.h>
00062 #include <sstream>
00063 #include <time.h>
00064 #include "Image/DrawOps.H"
00065 #include "GameBoard/resize.h"
00066 #include <iostream>
00067 #include <fstream>
00068 #include <set>
00069 #include <algorithm>
00070 #include <ctime>
00071 #include "Util/LEDcontroller.H"
00072 
00073 //////////////////////////////////////////////
00074 // a function for stringigying things
00075 //////////////////////////////////////////////
00076 
00077 using namespace std;
00078 template <class T> std::string stringify(T i)
00079 {
00080         ostringstream o ;
00081         o << i ;
00082         return o.str();
00083 }
00084 
00085 
00086 // ######################################################################
00087 extern "C" int main(const int argc, char** argv)
00088 {
00089   MYLOGVERB = LOG_INFO;  // suppress debug messages
00090 
00091   // Instantiate a ModelManager:
00092   ModelManager manager("Psycho 3D");
00093 
00094   // Instantiate our various ModelComponents:
00095   nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00096   manager.addSubComponent(d);
00097 
00098   nub::ref<LEDcontroller> itsledcon(new LEDcontroller(manager));
00099   manager.addSubComponent(itsledcon);
00100 
00101   nub::soft_ref<EyeTrackerConfigurator>
00102     etc(new EyeTrackerConfigurator(manager));
00103   manager.addSubComponent(etc);
00104 
00105   nub::soft_ref<EventLog> el(new EventLog(manager));
00106   manager.addSubComponent(el);
00107 
00108   manager.setOptionValString(&OPT_EventLogFileName, "psycho3DET.psy");
00109 
00110   manager.setOptionValString(&OPT_EyeTrackerType, "EL");
00111 
00112   // Parse command-line:
00113   if (manager.parseCommandLine(argc, argv,
00114                                " ", 0, 0)==false)
00115     return(1);
00116 
00117   // hook our various babies up and do post-command-line configs:
00118   nub::soft_ref<EyeTracker> et = etc->getET();
00119   d->setEyeTracker(et);
00120   d->setEventLog(el);
00121   et->setEventLog(el);
00122 
00123   // let's get all our ModelComponent instances started:
00124   manager.start();
00125 
00126   // let's do an eye tracker calibration:
00127  // 
00128   int eFlag = 0 ;
00129 
00130   d->clearScreen();
00131   d->displayText("<SPACE> for Eye-Link calibration; other key for skipping");
00132   int c = d->waitForKey();
00133 if (c == ' ') {et->calibrate(d);}
00134 
00135   d->clearScreen();
00136 //  d->displayText("<SPACE> on-display calibration; other key for skipping");
00137 //  c = d->waitForKey();
00138 //  if (c == ' ') {d->displayEyeTrackerCalibration(3,5,1 , true);}
00139 
00140   d->displayText("<SPACE> for off screen eye-trakin; other key for skipping");
00141   c = d->waitForKey();
00142   if (c == ' ') {eFlag=1;}
00143   // setup array of movie indices:
00144   
00145   // main loop:
00146 for (int j=0;j<1;j++){
00147 d->pushEvent("round: "+ stringify(j));
00148 d->clearScreen();
00149 if(eFlag==1) d->displayText("get ready for a round of LED calibration ");
00150 
00151 for(int i=1;i<5;i++){
00152         d->clearScreen();
00153         string s = stringify(i);
00154         d->displayText(s);
00155                 itsledcon -> setLED(i,true);
00156                 usleep(1000000);
00157         if(eFlag==1) {
00158           if(j==0){ 
00159             d->pushEvent("displayEvent start LEDCALIB" +s);
00160           }else{
00161              d->pushEvent("displayEvent start LEDVALID" +s+"_"+stringify(j));
00162           }
00163             et->track(true);
00164          
00165         }
00166         d->waitFrames(60);
00167         if(eFlag==1) {
00168           if(j==0){ 
00169             d->pushEvent("displayEvent stop LEDCALIB" +s);
00170           }else{
00171              d->pushEvent("displayEvent stop LEDVALID" +s+"_"+stringify(j));
00172           }
00173             et->track(false); 
00174         }
00175         itsledcon -> setLED(i,false);
00176                 d->waitForKey();
00177         }
00178 }
00179 
00180         d->clearScreen();
00181         d->displayText("get ready for first trial");
00182         d->waitForKey();
00183         d->clearScreen();
00184         //d->displayText("Start!");
00185         d->pushEvent("displayEvent start TRIAL1");
00186         et->track(true);
00187         d->waitForKey();
00188         d->pushEvent("displayEvent stop TRIAL1");
00189         et->track(false);
00190         d->clearScreen();
00191         d->displayText("get ready for second trial");
00192         d->waitForKey();
00193         d->clearScreen();
00194         //d->displayText("Start!");
00195         d->pushEvent("displayEvent start TRIAL2");
00196         et->track(true);
00197         d->waitForKey();
00198         d->pushEvent("displayEvent stop TRIAL2");
00199         et->track(false);
00200         d->clearScreen();
00201         d->displayText("get ready for third trial");
00202         d->waitForKey();
00203         d->clearScreen();
00204 //d->displayText("Start!");
00205         d->pushEvent("displayEvent start TRIAL3");
00206         et->track(true);
00207         d->waitForKey();
00208         d->pushEvent("displayEvent stop TRIAL3");
00209         et->track(false);
00210         d->clearScreen();
00211         d->displayText("get ready for third trial");
00212         d->waitForKey();
00213         d->clearScreen();
00214 //d->displayText("Start!");
00215         d->pushEvent("displayEvent start TRIAL4");
00216         et->track(true);
00217         d->waitForKey();
00218         d->pushEvent("displayEvent stop TRIAL4");
00219         et->track(false);
00220 
00221   d->clearScreen();
00222   d->displayText("Experiment is complete. Thank you!");
00223   d->waitForKey();
00224   
00225 
00226   // stop all our ModelComponents
00227   manager.stop();
00228 
00229   // all done!
00230   return 0;
00231 }
00232 
Generated on Sun May 8 08:40:06 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3