SimulationViewerStd.H

Go to the documentation of this file.
00001 /*!@file Neuro/SimulationViewerStd.H visualize various model simulations */
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: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Neuro/SimulationViewerStd.H $
00035 // $Id: SimulationViewerStd.H 14468 2011-02-02 08:42:19Z dberg $
00036 //
00037 
00038 #ifndef SIMULATIONVIEWERSTD_H_DEFINED
00039 #define SIMULATIONVIEWERSTD_H_DEFINED
00040 
00041 #include "Component/ModelParam.H"
00042 #include "Image/ImageSet.H"
00043 #include "Image/LevelSpec.H"
00044 #include "Image/NamedImage.H"
00045 #include "Image/Pixels.H"      // for PixRGB<byte>
00046 #include "Image/SimpleFont.H"
00047 #include "Neuro/SimulationViewer.H"
00048 #include "Simulation/SimEvents.H"
00049 #include "rutz/shared_ptr.h"   // for rutz::shared_ptr
00050 
00051 class SpatialMetrics;
00052 
00053 //! This class provides a standard set of visualization tools
00054 /*! Its typical usage is with a model that generates shifts of
00055   attention, eye and head movements. This class will handle
00056   visualizing those events. There are three ways of customizing it to
00057   your specific needs: 1) by changing the values of some of its
00058   internal ModelParam parameters, either via the command-line or via a
00059   config file for those that do not have command-line options; 2) by
00060   overloading (in a derived class) the low-level drawing functions in
00061   the protected section of the class definition; 3) by overloading the
00062   trigger functions in the public section of the class definition. */
00063 class SimulationViewerStd : public SimulationViewerAdapter {
00064 public:
00065   // ######################################################################
00066   /*! @name Constructors and destructors */
00067   //@{
00068 
00069   //! Constructor. See ModelComponent.H.
00070   /*! @param mgr our ModelManager (see ModelManager.H)
00071       @param descrName descriptive name for human usage
00072       @param tagName name for ParamMap usage */
00073   SimulationViewerStd(OptionManager& mgr,
00074                       const std::string& descrName = "Simulation Viewer Std",
00075                       const std::string& tagName = "SimulationViewerStd");
00076   //! Destructor
00077   virtual ~SimulationViewerStd();
00078 
00079   //@}
00080 
00081 protected:
00082   //! Callback for when the eye moves
00083   SIMCALLBACK_DECLARE(SimulationViewerStd, SimEventSaccadeStatusEye);
00084 
00085   //! Callback for when the head moves
00086   SIMCALLBACK_DECLARE(SimulationViewerStd, SimEventSaccadeStatusHead);
00087 
00088   //! Callback for every time we should save our outputs
00089   SIMCALLBACK_DECLARE(SimulationViewerStd, SimEventSaveOutput);
00090 
00091   //! Callbacks for when a IT Output is available
00092   SIMCALLBACK_DECLARE(SimulationViewerStd, SimEventITOutput);
00093 
00094   //! Simulation time step
00095   OModelParam<SimTime> itsTimeStep;
00096 
00097   //! the model's LevelSpec
00098   OModelParam<LevelSpec> itsLevelSpec;
00099 
00100   //! metrics that depend on the input size:
00101   nub::ref<SpatialMetrics> itsMetrics;
00102 
00103   // ########## what to compute and show parameters:
00104   OModelParam<uint> itsFontSize;
00105   OModelParam<bool> itsSaveTraj;
00106   OModelParam<bool> itsSaveXcombo;
00107   OModelParam<bool> itsSaveYcombo;
00108   OModelParam<bool> itsSaveTRMXcombo;
00109   OModelParam<bool> itsSaveTRMYcombo;
00110   OModelParam<bool> itsSaveTRMmegaCombo;
00111   OModelParam<bool> itsWarp3D;
00112   OModelParam<bool> itsMegaCombo;
00113   OModelParam<uint> itsMegaComboZoom;
00114   OModelParam<bool> itsMegaComboTopCMapsOnly;
00115   OModelParam<Dims> itsCropFOA;
00116   OModelParam<bool> itsFoveateTraj;
00117 
00118   // ########## display selection parameters:
00119   OModelParam<bool> itsDisplayFOA;
00120   OModelParam<bool> itsDisplayPatch;
00121   OModelParam<bool> itsDisplayFOAnum;
00122   OModelParam<bool> itsDisplayFOALinks;
00123   OModelParam<bool> itsDisplayEye;
00124   OModelParam<bool> itsDisplayEyeLinks;
00125   OModelParam<bool> itsDisplayHead;
00126   OModelParam<bool> itsDisplayHeadLinks;
00127   OModelParam<bool> itsDisplayTime;
00128   OModelParam<bool> itsDisplayAdditive;
00129   OModelParam<bool> itsDisplayHighlights;
00130   OModelParam<bool> itsDisplaySMmodulate;
00131   OModelParam<bool> itsDisplayBoring;
00132   NModelParam<bool> itsDisplayShapeEstimator;
00133 
00134   // ########## drawing color selection parameters:
00135   NModelParam< PixRGB<byte> > itsColorNormal;
00136   NModelParam< PixRGB<byte> > itsColorBoring; //!< subtracted when boring
00137   NModelParam< PixRGB<byte> > itsColorBlink;
00138   NModelParam< PixRGB<byte> > itsColorSaccade;
00139   NModelParam< PixRGB<byte> > itsColorSmoothPursuit;
00140   NModelParam< PixRGB<byte> > itsColorLink;
00141   NModelParam< PixRGB<byte> > itsColorText;
00142 
00143   // ########## misc default values parameters:
00144   NModelParam<int> itsHighlightMax;
00145   NModelParam<float> itsShapeEstimatorBaseContrast;
00146   NModelParam<int> itsShapeEstimatorBaseBright;
00147 
00148   NModelParam<float> itsWarp3Dpitch;
00149   NModelParam<float> itsWarp3Dyaw;
00150   NModelParam<float> itsWarp3DpitchRate;
00151   NModelParam<float> itsWarp3DyawRate;
00152   NModelParam<float> itsWarp3DpitchMax;
00153   NModelParam<float> itsWarp3DyawMax;
00154 
00155   // ########## general model parameters, shared with other components:
00156   OModelParam<int> itsHeadRadius;
00157   OModelParam<int> itsMultiRetinaDepth;
00158 
00159   // ########## parameters for drawings (not exported as command-line opts):
00160   NModelParam<int> itsFOApsiz;     //!< half-size of (filled square) FOA patch
00161   NModelParam<int> itsFOAthick;    //!< line thickness for FOA outline
00162   NModelParam<int> itsFOAlinkThick;//!< line thickness for links bewteen FOAs
00163   NModelParam<int> itsFOVpsiz;     //!< half-size of (hollow square) FOV patch
00164   NModelParam<int> itsFOVpthick;   //!< line thickness for FOV patch
00165   NModelParam<int> itsFOVthick;    //!< line thickness for FOV outline
00166   NModelParam<int> itsFOVlinkThick;//!< line thickness for links btw FOVs
00167   NModelParam<int> itsHEDpsiz;     //!< half-size of (hollow-square) head patch
00168   NModelParam<int> itsHEDpthick;   //!< line thickness for head patch
00169   NModelParam<int> itsHEDthick;    //!< line thickness for head outline
00170   NModelParam<int> itsHEDlinkThick;//!< line thickness for links btw heads
00171 
00172   OModelParam<bool> itsUseLargerDrawings;  //!< use larger drawings?
00173 
00174   // ########## obsolete parameters, which we still keep around so
00175   // ########## that the user can get a helpful error message if they
00176   // ########## try to request the parameter on the command-line
00177   OModelParam<bool> itsObsolete1;
00178 
00179   //!process retinal images
00180   virtual void doEventRetinaImage(SimEventQueue& q, rutz::shared_ptr<SimEventRetinaImage>& e);
00181 
00182   //process wta winners
00183   virtual void doEventWTAwinner(SimEventQueue& q, rutz::shared_ptr<SimEventWTAwinner>& e);
00184 
00185   //! Get started:
00186   virtual void start2();
00187 
00188   //! Reset SimulationViewerStd
00189   /*! See the base function in ModelComponent.H for info. */
00190   virtual void reset1();
00191 
00192   //! Save our various results
00193   virtual void save1(const ModelComponentSaveInfo& sinfo);
00194 
00195   //! Get the attention/eye/head trajectory image
00196   Image< PixRGB<byte> > getTraj(SimEventQueue& q);
00197 
00198   // ######################################################################
00199   /*! @name Derived classes should overload those to fit their cosmetic needs*/
00200   //@{
00201 
00202   //! Draw the focus of covert attention
00203   void drawFOA();
00204 
00205   //! Link previous focus of attention to current one
00206   void linkFOAs();
00207 
00208   //! Draw current eye position
00209   void drawEye();
00210 
00211   //! Link previous eye position to current one
00212   void linkEyes();
00213 
00214   //! Draw current head position
00215   void drawHead();
00216 
00217   //! Link previous head position to current one
00218   void linkHeads();
00219 
00220   //! Draw current time onto given image
00221   void drawTime(Image< PixRGB<byte> >& image);
00222 
00223   //! Draw highlights around a given position
00224   void drawHighlights();
00225 
00226   //! Draw mega combo for X display
00227   Image< PixRGB<byte> > drawMegaCombo(SimEventQueue& q,
00228                                       const Image< PixRGB<byte> >& in);
00229 
00230   //! Draw motion sixpack
00231   Image< PixRGB<byte> > drawMotionSixPack(const Image< PixRGB<byte> >& in);
00232 
00233   //! Draw outline of a mask (used by drawFOA, drawEye, etc)
00234   /*! if the mask is initialized, revert to drawing a circle centered
00235     at "pos" an of radius "radius" */
00236   void drawMaskOutline(Image< PixRGB<byte> >& traj, const Image<byte> mask,
00237                        const PixRGB<byte>& col, const int thick,
00238                        const Point2D<int>& pos, const int radius);
00239 
00240   //! recurse to get all maps to display in a megacombo
00241   void getMegaComboMaps(const rutz::shared_ptr<ChannelMaps>& chm,
00242                         ImageSet< PixRGB<byte> >& cmaps, const uint depth = 0);
00243 
00244   //! Prepare a map for display
00245   Image< PixRGB<byte> > prepMapForDisplay(const NamedImage<float>& m) const;
00246 
00247   //@}
00248 
00249 private:
00250   friend class SimulationViewerEyeSim;
00251   Image< PixRGB<byte> > itsTraj;  // all our drawings go here
00252   uint itsFOAshiftNum;            // Attention shift number (0-based)
00253   Image<byte> itsCurrFOAmask;     // current FOA shape
00254   Image<byte> itsCumFOAmask;      // cumulative FOA shape
00255   Point2D<int> itsCurrEye;             // current eye position
00256   Image<byte> itsCurrFoveaMask;   // current fovea shape
00257   Image<byte> itsCumFoveaMask;    // cumulative fovea shape
00258   Point2D<int> itsCurrHead;            // current head position
00259   Image<byte> itsCurrHeadMask;    // current head shape
00260   Image<byte> itsCumHeadMask;     // cumulative head shape
00261 
00262   Point2D<int> itsPrevEye;             // previous eye position
00263   Point2D<int> itsPrevHead;            // previous head position
00264   SimTime itsCurrTime;            // time of last evolve()
00265   bool itsEyeSaccade;             // are we in eye saccade?
00266   bool itsEyeSmoothPursuit;       // are we in eye smooth pursuit?
00267   bool itsHeadSaccade;            // are we in head saccade?
00268   bool itsHeadSmoothPursuit;      // are we in head smooth pursuit?
00269   bool itsEyeBlink;               // are we in eye blink?
00270   ImageSet< PixRGB<byte> > itsMultiTraj; // used to foveate traj
00271   Dims itsDims3D;                 // dims of 3D drawing
00272   mutable float itsPitch3D, itsYaw3D; // 3D drawing; mutable for testsuite
00273   bool itsHasNewInput;            // input changed since last getTraj()
00274   SimpleFont itsFont;             // set from itsFontSize during start2()
00275 };
00276 
00277 #endif
00278 
00279 // ######################################################################
00280 /* So things look consistent in everyone's emacs... */
00281 /* Local Variables: */
00282 /* indent-tabs-mode: nil */
00283 /* End: */
Generated on Sun May 8 08:41:04 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3