SimulationViewerEyeMvtNeuro.H

Go to the documentation of this file.
00001 /*!@file Neuro/SimulationViewerEyeMvtNeuro.H get the saliency values at a
00002    proble location relative the the current eye position for comparing
00003    with a neural response*/
00004 
00005 // //////////////////////////////////////////////////////////////////// //
00006 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
00007 // by the University of Southern California (USC) and the iLab at USC.  //
00008 // See http://iLab.usc.edu for information about this project.          //
00009 // //////////////////////////////////////////////////////////////////// //
00010 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00011 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00012 // in Visual Environments, and Applications'' by Christof Koch and      //
00013 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00014 // pending; application number 09/912,225 filed July 23, 2001; see      //
00015 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00016 // //////////////////////////////////////////////////////////////////// //
00017 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00018 //                                                                      //
00019 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00020 // redistribute it and/or modify it under the terms of the GNU General  //
00021 // Public License as published by the Free Software Foundation; either  //
00022 // version 2 of the License, or (at your option) any later version.     //
00023 //                                                                      //
00024 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00025 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00026 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00027 // PURPOSE.  See the GNU General Public License for more details.       //
00028 //                                                                      //
00029 // You should have received a copy of the GNU General Public License    //
00030 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00031 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00032 // Boston, MA 02111-1307 USA.                                           //
00033 // //////////////////////////////////////////////////////////////////// //
00034 //
00035 // Primary maintainer for this file: David J Berg <dberg@usc.edu>
00036 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Neuro/SimulationViewerEyeMvtNeuro.H $
00037 
00038 #ifndef SIMULATIONVIEWEREYEMVTNEURO_H_DEFINED
00039 #define SIMULATIONVIEWEREYEMVTNERUO_H_DEFINED
00040 
00041 #include "Component/ModelParam.H"
00042 #include "Image/ImageCache.H"
00043 #include "Image/LevelSpec.H"
00044 #include "Image/Point2D.H"
00045 #include "Neuro/SimulationViewer.H"
00046 #include "Simulation/SimEvents.H"
00047 
00048 #include<deque>
00049 
00050 class ofstream;
00051 
00052 // ######################################################################
00053 //!a simple helper class to create 2d line plots
00054 // ######################################################################
00055 namespace SVEMNPlot
00056 {
00057   class PlotBuf 
00058   {
00059   public:
00060     //! constructure
00061     PlotBuf();
00062     
00063     //! constructure
00064     PlotBuf(const SimTime& buflength, const float scale, 
00065             const SimTime& sample_rate = SimTime::ZERO());
00066     
00067     //!!destructor
00068     ~PlotBuf() { };  
00069     
00070     //!push data onto the plot buffer
00071     void push(const SimTime& time, const float& data);
00072     
00073     //!reset the state to that just after construction
00074     void reset(const SimTime& buflength, const float scale,
00075                const SimTime& sample_rate = SimTime::ZERO());
00076 
00077     //!reset the state to that just after construction
00078     void reset();
00079     
00080     //!plot at specified size
00081     Image<PixRGB<byte> > draw(const uint w, const uint h, 
00082                               const char* title, const char* ylabel, 
00083                               const char* xlabel, const PixRGB<byte>& linecol, 
00084                               const int numticks, const bool reverse);
00085     
00086   private:
00087     SimTime itsBufLength;
00088     float itsScale;
00089     float itsMax;
00090     SimTime itsRate;
00091 
00092     std::deque<float> itsData;
00093     std::deque<SimTime> itsTimes;
00094   };
00095 }
00096 
00097 // ######################################################################
00098 //! Measure salience at receptive field center of a neuron
00099 // ######################################################################
00100 class SimulationViewerEyeMvtNeuro : public SimulationViewerAdapter {
00101 public:
00102   // ######################################################################
00103   /*! @name Constructors and destructors */
00104   //@{
00105 
00106   //! Constructor. See ModelComponent.H.
00107   SimulationViewerEyeMvtNeuro(OptionManager& mgr,
00108                               const std::string& descrName =
00109                               "EyeMvtNeuro Simulation Viewer",
00110                               const std::string& tagName =
00111                               "SimulationViewerEyeMvtNeuro");
00112   
00113   //! Destructor
00114   virtual ~SimulationViewerEyeMvtNeuro();
00115   
00116   //@}
00117   
00118 protected:
00119   //! Callback for every clock tick
00120   SIMCALLBACK_DECLARE(SimulationViewerEyeMvtNeuro, SimEventClockTick);
00121   
00122   //! Callback for every time we should save our outputs
00123   SIMCALLBACK_DECLARE(SimulationViewerEyeMvtNeuro, SimEventSaveOutput);
00124   
00125   //! Save our various results
00126   void save1(const ModelComponentSaveInfo& sinfo);
00127   
00128   //! Get the attention/eye/head trajectory image
00129   virtual Image< PixRGB<byte> > getTraj();
00130   
00131   OModelParam<bool> itsSaveTraj;      //!< save trajectory?
00132   OModelParam<bool> itsSaveMegaCombo; //!< save mega combo?
00133   OModelParam<int> itsDelayCacheSize; //!< size of our delay cache
00134   OModelParam<int> itsEyePatchSize;      //!< size of marker at eye position
00135   OModelParam<LevelSpec> itsLevelSpec; //!< our levelspec
00136   OModelParam<bool> itsUseDiagColor;//!< use eye movement diagnostic colors
00137   OModelParam<int> itsMaxComboWidth; //!< max width of getTraj()
00138   OModelParam<bool> itsShiftInput;   //! shift input to eye position?
00139   NModelParam<bool> itsUseSpaceVariantBoundary; //!< use space variant boundary
00140 
00141   //SimulationViewerEyeMvtNeuro specific options
00142   OModelParam<std::string> itsOutFname;  //!< Our results file
00143   OModelParam<Point2D<float> > itsProbe;//!location of virtual probe
00144   OModelParam<float> itsRFSize;//!size of the neurons receptive field
00145   OModelParam<std::string> itsRFMaskName;//!name of the rf weighting mask
00146   OModelParam<std::string> itsNeuronFileName;//!a text file with spike datax
00147   OModelParam<bool> itsDisplayTime;//!display the sample time
00148   OModelParam<int> itsDelaySpike;//!delay our neurons data by this # of samples
00149   OModelParam<SimTime> itsBufferLength;//!length of plotting buffer
00150   OModelParam<float> itsSalScale; //!< y-axis scale of 1D saliency plots
00151   OModelParam<float> itsNeuroScale; //!< y-axis scale of 1D saliency plots
00152   OModelParam<std::string> itsVisRFName; //!< name of visual rf output file
00153   OModelParam<std::string> itsMotRFName; //!< name of motor rf output file
00154   OModelParam<SimTime> itsMotWindow; //!< window for motor rf
00155   OModelParam<SimTime> itsVisWindow; //!< window for visual rf
00156   OModelParam<SimTime> itsVisOffset; //!< offset for visual rf
00157 
00158   virtual void start1(); //!< get started
00159   virtual void stop1(); //!< get stopped  
00160 
00161   //!process retinal images
00162   virtual void doEventRetinaImage(SimEventQueue& q, rutz::shared_ptr<SimEventRetinaImage>& e);
00163 
00164 
00165 private:
00166   //read an image set from disk
00167   void readImageSet(ImageSet<float>& set, const std::string filename);
00168 
00169   //write an image set to dsik
00170   void saveImageSet(const ImageSet<float>& set,
00171                     const int flags, std::string fname,
00172                     const RasterFileFormat ftype = RASFMT_AUTO);
00173 
00174   //prepare the file name for writing or reading image sets
00175   void prepFileName(const std::string& name,
00176                     std::string& base, std::string& ext);
00177 
00178   //set pixel locations of values originally given in degrees
00179   void setDegtoPixels(const float& ppdx, const float& ppdy);
00180 
00181   ImageCacheMinMax<float> itsDelayCache;//sliding image cache of sal maps
00182 
00183   Image<float> itsHeadSM;  // the saliency map at the head of the delay cache
00184   Image< PixRGB<byte> > itsDrawings;  // our drawings - black is transparent!
00185   Image<float> itsRFMask;//the RF weighting function if we set one
00186 
00187   ImageSet<float> itsVisRf, itsVisRfBuf;//for visual rf
00188   Image<float> itsMotRf; //for calculating  motor rf
00189   uint itsMotSamp;
00190   uint itsVisSamp;
00191   uint itsVisSampOff;
00192 
00193   std::ofstream *itsOutFile; //outout file
00194   std::ifstream *itsNeuronFile;//spike file
00195 
00196   SimTime itsRate; //!< the sampling rate
00197   float itsPpdx; //!<pixels per degree
00198   float itsPpdy; //!<pixels per degree
00199   Point2D<int> itsProbeP;//probe location in pixels
00200   Point2D<int> itsRawCenter;//center of raw input
00201   int itsRFSizeP;//rf size in pixels
00202   Dims itsInputDims; //our input image dims
00203   Dims itsOgInputDims; //input dims of input imagex
00204 
00205 
00206   std::deque<float> itsSpikeVals;//hold data values
00207   uint itsSpikePos; //position in our array
00208   SVEMNPlot::PlotBuf itsSalPb; //plot saliency values over a short interval
00209   SVEMNPlot::PlotBuf itsSpikePb; //plot spike  values over a short interval
00210   SVEMNPlot::PlotBuf itsHposPb; //plot horizontal eye position 
00211   SVEMNPlot::PlotBuf itsVposPb; //plot vertical eye position 
00212   std::string itsXlabel, itsTitle;  //labels for our plots
00213 };
00214 #endif
00215 
00216 // ######################################################################
00217 /* So things look consistent in everyone's emacs... */
00218 /* Local Variables: */
00219 /* indent-tabs-mode: nil */
00220 /* End: */
Generated on Sun May 8 08:05:25 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3