EyeTracker.H

Go to the documentation of this file.
00001 /*!@file Psycho/EyeTracker.H Abstraction of an eye tracker device */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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/Psycho/EyeTracker.H $
00035 // $Id: EyeTracker.H 14176 2010-10-28 04:28:19Z ilink $
00036 //
00037 
00038 #ifndef PSYCHO_EYETRACKER_H_DEFINED
00039 #define PSYCHO_EYETRACKER_H_DEFINED
00040 #include "Psycho/PsychoDisplay.H"
00041 #include "Component/ModelComponent.H"
00042 #include "Image/Point2D.H"
00043 #include "Image/CalibrationTransform.H"
00044 #include "Image/AffineTransform.H"
00045 #include <string>
00046 class EventLog;
00047 class PsychoDisplay;
00048 
00049 //! Abstraction of an eye tracker device, virtual base class
00050 /*! This class specifies the common interface to all EyeTracker
00051   derivatives and provides a number of shared basic functions. This
00052   class cannot be instantiated directly since it contains some pure
00053   virtual methods. Instead, instantiate one of the EyeTrackerXXX
00054   objects which derive from the present EyeTracker common base. */
00055 
00056 class EyeTracker : public ModelComponent
00057 {
00058 public:
00059   // ######################################################################
00060   /*! @name Constructors and Destructors */
00061   //@{
00062 
00063   //! Constructor
00064   EyeTracker(OptionManager& mgr,
00065              const std::string& descrName = "Eye Tracker",
00066              const std::string& tagName = "EyeTracker");
00067 
00068   //! destructor
00069   virtual ~EyeTracker();
00070 
00071   //! Set an EventLog to use to keep a trace of what happens
00072   /*! If an EventLog component is registered with us, we will send it
00073     lots of event messages, each time we start or stop tracking, etc. */
00074   virtual void setEventLog(nub::soft_ref<EventLog> elog);
00075 
00076   //@}
00077 
00078   // ######################################################################
00079   /*! @name Eye-tracker control functions */
00080   //@{
00081 
00082   //! Calibrate the tracker, full calibration
00083   /*! This function will use the provided PsychoDisplay to display
00084     calibration images and wait for user input. Default implementation is
00085     to do nothing. */
00086   virtual void calibrate(nub::soft_ref<PsychoDisplay> d);
00087 
00088   //! Calibrate the tracker, quick re-calibration
00089   /*! This function will use the provided PsychoDisplay to display
00090     calibration images and wait for user input. Default implementation is
00091     to do nothing. */
00092   virtual void recalibrate(nub::soft_ref<PsychoDisplay> d,int repeats=5);
00093 
00094   virtual void setBackgroundColor(nub::soft_ref<PsychoDisplay> d);
00095 
00096         virtual void manualDriftCorrection(Point2D<double> eyepos, Point2D<double> targetpos);
00097 
00098         //! Run online calibration routine if available on the eyetracker
00099   virtual void calibrateOnline(nub::soft_ref<PsychoDisplay> d);
00100 
00101         /*! Close SDL from EyeLink library.  This function is designed when using
00102                  EyeLink eye tracker.  Ignore the function when using other eye tracker.
00103                 The purpose of opening and closing SDL from EyeLink library is to take back
00104                 full control of SDL from our own code.  Therefore, movies can be played
00105           smoothly (no slow frames).        */
00106   virtual void closeSDL();
00107 
00108         /*! Open SDL from EyeLink library.  This function is designed when using
00109                  EyeLink eye tracker.  Ignore the function when using other eye tracker.
00110                 The purpose of opening and closing SDL from EyeLink library is to take back
00111                 full control of SDL from our own code.  Therefore, movies can be played
00112           smoothly (no slow frames).        */
00113   virtual void openSDL();
00114 
00115   //! Start/stop tracking depending on a boolean parameter
00116   /*! If startstop is true, then StartTracking() will be called,
00117     otherwise StopTracking() will. Note that requests to start tracking
00118     will be ignored here (no call to startTracking()) if we are
00119     already tracking; idem for stopping. */
00120   virtual void track(const bool startstop);
00121 
00122   //! Are we tracking?
00123   virtual bool isTracking() const;
00124 
00125   //! Get current eye-tracking session number
00126   virtual int getSession() const;
00127 
00128   //!Get the calibration set
00129   virtual CalibrationTransform::Data getCalibrationSet(nub::soft_ref<PsychoDisplay> d) const = 0;
00130   //@}
00131 
00132 
00133 
00134   // ######################################################################
00135   /*! @name Eye-tracker monitoring functions */
00136   //@{
00137 
00138   //! Has the eye-tracker detected that the subject is fixating?
00139   /*! Depending on hardware, this may either rely on a built-in
00140     fixation detection in the eye-tracking device (e.g.,
00141     EyeTrackerDML, EyeTrackerUDP), or on monitoring getEyePos() over
00142     time (e.g., EyeTrackerISCAN). NOTE: this should be a non-blocking
00143     call as typically callers will also want to check for alternative
00144     triggers like keypresses while polling isFixating(). */
00145   virtual bool isFixating() = 0;
00146 
00147   //! Has the eye-tracker detected that the subject initiated a
00148   //! saccade?
00149   /*! Depending on hardware, this may either rely on a built-in
00150     saccade detection in the eye-tracking device (e.g. EyeTrackerUDP),
00151     or on monitoring getEyePos() over time. NOTE: this should be a
00152     non-blocking call as typically callers will also want to check for
00153     alternative triggers like keypresses while polling isSaccade(). */
00154   virtual bool isSaccade() = 0;
00155 
00156   //! Clear previosly triggered fixations and saccades. 
00157   /*! Clear all our eye status flags so that isFixating and isSaccade
00158     will not evaluate to true because of a previosly triggered but
00159     unchecked for fixation or saccde. Default behavior is to loop over
00160     isFixating and isSaccade, gobbling up any extra
00161     fixations. Depending on hardware, some eye trackers may have
00162     different requirements. */
00163   virtual void clearEyeStatus();
00164 
00165   //@}
00166 
00167   // ######################################################################
00168   /*! @name Eye position data streaming functions */
00169   //@{
00170 
00171   //! Get current eye position
00172   /*! Note: not all trackers support this! */
00173   virtual Point2D<int> getEyePos() const = 0;
00174 
00175   //! Get current fixation position (eliminates blink, saccade, etc.)
00176   /*! Note: not all trackers support this! */
00177   virtual Point2D<int> getFixationPos() const = 0;
00178 
00179   //@}
00180 
00181   //!get the current calibrated eye position
00182   virtual Point2D<int> getCalibEyePos();
00183 
00184   //!save a direct eyeS file using online calib
00185   virtual void requestQuickEyeS();
00186 
00187 //getter setter function for current stimulus filename used in online
00188 // calib type psycho progs
00189     virtual void setCurrentStimFile(std::string filename);
00190     virtual std::string getCurrentStimFile();
00191 
00192 
00193 protected:
00194   //! Start tracking
00195   /*! Derived classes need to implement this in a hardware-dependent manner. */
00196   virtual void startTracking() = 0;
00197 
00198   //! Stop tracking
00199   /*! Derived classes need to implement this in a hardware-dependent manner. */
00200   virtual void stopTracking() = 0;
00201 
00202   void start1(); //!< get started
00203 
00204   nub::soft_ref<EventLog> itsEventLog; //!< log stuff if desired
00205 
00206 private:
00207   bool itsIsTracking;  // true if we are currently tracking
00208   int itsSession; // tracking session number
00209   std::string itsCurrentStimFile; //name of current stimulus being shown
00210 
00211 };
00212 
00213 
00214 // ######################################################################
00215 /* So things look consistent in everyone's emacs... */
00216 /* Local Variables: */
00217 /* mode: c++ */
00218 /* indent-tabs-mode: nil */
00219 /* End: */
00220 
00221 #endif // PSYCHO_EYETRACKER_H_DEFINED
Generated on Sun May 8 08:05:32 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3