SimulationViewerEyeHand.H

Go to the documentation of this file.
00001 /*!@file Neuro/SimulationViewerEyeHand.H combined human eye & hand movements*/
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
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: Dicky Nauli Sihite <sihite@usc.edu>
00034 // $HeadURL: 
00035 // $Id:
00036 //
00037 
00038 #ifndef SIMULATIONVIEWEREYEHAND_H_DEFINED
00039 #define SIMULATIONVIEWEREYEHAND_H_DEFINED
00040 
00041 #include "Component/ModelParam.H"
00042 #include "Image/ImageCache.H"
00043 #include "Image/ImageSet.H"
00044 #include "Image/LevelSpec.H"
00045 #include "Neuro/SimulationViewer.H"
00046 #include "Simulation/SimEvents.H"
00047 
00048 #include <map>
00049 #include<vector>
00050 
00051 class EyeData;
00052 class HandData;
00053 class SpatialMetrics;
00054 class ofstream;
00055 class SimTime;
00056 
00057 typedef Point2D<int> (*Point2DTransform)(Point2D<int> P);
00058 
00059 //! Measure salience at human eye positions
00060 class SimulationViewerEyeHand : public SimulationViewer {
00061 public:
00062   // ######################################################################
00063   /*! @name Constructors and destructors */
00064   //@{
00065 
00066   //! Constructor. See ModelComponent.H.
00067   SimulationViewerEyeHand(OptionManager& mgr,
00068                          const std::string& descrName =
00069                          "EyeHand Simulation Viewer",
00070                          const std::string& tagName =
00071                          "SimulationViewerEyeHand");
00072 
00073   //! Destructor
00074   virtual ~SimulationViewerEyeHand();
00075 
00076   //@}
00077 
00078 protected:
00079   //! Callback for every clock tick
00080   SIMCALLBACK_DECLARE(SimulationViewerEyeHand, SimEventClockTick);
00081 
00082   //! Callback for every time we should save our outputs
00083   SIMCALLBACK_DECLARE(SimulationViewerEyeHand, SimEventSaveOutput);
00084 
00085   //! Save our various results
00086   void save1(const ModelComponentSaveInfo& sinfo);
00087 
00088   //! Get the attention/eye/head trajectory image
00089   virtual Image< PixRGB<byte> > getTraj(SimEventQueue& q);
00090 
00091   nub::ref<SpatialMetrics> itsMetrics;//!< metrics that depend on input size
00092 
00093   // EyeMvt params
00094   OModelParam<bool> itsSaveTraj;      //!< save trajectory?
00095   OModelParam<int> itsDelayCacheSize; //!< size of our delay cache
00096   OModelParam<int> itsMaxCacheSize;   //!< size of our max cache
00097   OModelParam<bool> itsSampleAtStart; //!< take samples at start or end of sac
00098   OModelParam<bool> itsDisplaySacNum; //!< display saccade number?
00099   OModelParam<bool> itsDisplayPatch;  //!< display eye position
00100   OModelParam<int> itsPatchSize;      //!< size of marker at eye position
00101   OModelParam<bool> itsEraseMarker;   //!< erase marker at each frame
00102   OModelParam<bool> itsDisplayFOA; //!< display saccade targets?
00103   OModelParam<LevelSpec> itsLevelSpec; //!< our levelspec
00104   OModelParam<std::string> itsOutFname;  //!< Our results file
00105   OModelParam<std::string> itsPriorRandomDistro; //!< Uniform or from File
00106   OModelParam<bool> itsUseSaccadeInBlink;//!< use saccade during blink?
00107   OModelParam<bool> itsUseDiagColor;//!< use saccade during blink?
00108   OModelParam<bool> itsLabelEyePatch; //!< label eyetraces on video
00109   OModelParam<int> itsNumRandomSamples; //!< number of random samples
00110   OModelParam<int> itsMaxComboWidth; //!< max width of getTraj()
00111   OModelParam<uint> itsSMhistoryQlen; //!< queue len for Sm history
00112   // Hand params
00113   OModelParam<bool> itsDisplayHand;  //!< display Hand position
00114   OModelParam<bool> itsSaveCombo; //!< save combo?
00115 
00116   virtual void start1(); //!< get started
00117   virtual void stop1(); //!< get stopped
00118 
00119   virtual void drawEye(const rutz::shared_ptr<EyeData> data,
00120                        const uint trackerNum);  // overloaded by EyeRegion
00121   virtual void drawHand(const rutz::shared_ptr<HandData> data,
00122                         const uint trackerNum);
00123   virtual void drawFOA(const Point2D<int> target,
00124                        const uint trackerNum); // overloaded by EyeRegion
00125 
00126   // where the SVEM output is all put together
00127   virtual std::string craftSVEMOutput(const std::string TrackerNum,
00128                                       const rutz::shared_ptr<EyeData> data);
00129 
00130   // overloaded by EyeRegion to do its output
00131   virtual void extraSampleProcessing(const rutz::shared_ptr<EyeData>);
00132   virtual void extraSampleProcessing(const rutz::shared_ptr<HandData>);
00133   
00134   // auxiliaries for file I/O
00135   std::string craftModelFreeOutput(const rutz::shared_ptr<EyeData> data);
00136   std::string craftSMSamples(const rutz::shared_ptr<EyeData> data,
00137                              Image<float> smap);
00138   std::string craftSMHistory(const rutz::shared_ptr<EyeData> data,
00139                              Image<float> smap);
00140   void writeHeader();
00141 
00142   // use a sliding image cache for salience computations:
00143   ImageCacheMinMax<float> itsDelayCache;
00144   ImageCacheMinMax<float> itsMaxCache;
00145 
00146   // the saliency map at the head of the delay cache;
00147   Image<float> itsHeadSM;
00148 
00149   Image< PixRGB<byte> > itsDrawings;  // our drawings - black is transparent!
00150   // these drawings include, from SVEyeHand: the eyetrace
00151   // from SVEyeRegion: the names and borders of regions
00152 
00153   SimTime itsCurrTime;
00154   uint itsFrameNumber;     // this member is never used in SVEyeHand
00155 
00156   bool itsHeaderCrafted;
00157   std::vector<std::string> itsOutFields;
00158 
00159   // based on SimEventRetinaImage::rawToRetinal()
00160   // wraps the rawToRetinal transform for inherited functions to use
00161   Point2D<int> rawToRet(Point2D<int> P) const {return P+itsRawToRetOffset;}
00162 
00163   // EyeMvt
00164   struct GEyeFormat {
00165     PixRGB<byte> col;
00166     std::string label; // depends on OModelParam
00167     int pSize; // patch size
00168     // shape? other aspects?
00169   };
00170   std::vector<GEyeFormat> itsEyeStyles;
00171 
00172   // Hand
00173   struct GHandFormat {
00174     PixRGB<byte> col;
00175     std::string label; // depends on OModelParam
00176     int pSize; // patch size
00177     // shape? other aspects?
00178   };
00179   std::vector<GHandFormat> itsHandStyles;
00180 
00181 private:
00182   // Special stuffs for hand, using some coord-based system
00183   inline Dims getGridCoord(Dims src, int W_, int H_) {
00184     Dims dst (src.w() * W_, src.h() * H_);
00185     return dst; 
00186   };
00187 
00188   std::map<int, rutz::shared_ptr<EyeData> > itsEyeTargets;
00189   std::map<int, rutz::shared_ptr<HandData> > itsHandTargets;
00190   std::vector<Point2D<int> > randPoints;
00191   ImageCache<float> itsSMhistory;
00192 
00193   std::ofstream *itsOutFile;
00194   std::ifstream *itsRandFile;
00195   Point2D<int> itsRawToRetOffset;
00196 };
00197 
00198 #endif
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:41:04 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3