00001 /*!@file Neuro/SimulationViewerNerdCam.H entry interface between INVT and ASAC */ 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: T. Nathan Mundhenk <mundhenk@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Neuro/SimulationViewerNerdCam.H $ 00035 // $Id: SimulationViewerNerdCam.H 10714 2009-02-01 07:16:36Z itti $ 00036 // 00037 00038 #ifndef SIMULATIONVIEWERNERDCAM_H_DEFINED 00039 #define SIMULATIONVIEWERNERDCAM_H_DEFINED 00040 00041 #include "Component/ModelParam.H" 00042 #include "Component/OptionManager.H" 00043 #include "Image/ArrayData.H" // for Dims 00044 #include "Image/Image.H" // for Image 00045 #include "Image/ImageSet.H" 00046 #include "Image/Pixels.H" // for PixRGB<byte> 00047 #include "Image/Point2DT.H" // for Point2DT 00048 #include "Media/MediaSimEvents.H" 00049 #include "Neuro/NeuroSimEvents.H" 00050 #include "Neuro/Brain.H" 00051 #include "Neuro/SimulationViewer.H" 00052 #include "Neuro/SpatialMetrics.H" 00053 #include "Neuro/VisualCortex.H" 00054 #include "Neuro/WTAwinner.H" // for WTAwinner 00055 #include "Simulation/SimEvents.H" 00056 #include "Transport/FrameInfo.H" 00057 #include "Transport/FrameOstream.H" 00058 #include "Util/SimTime.H" 00059 #include "rutz/shared_ptr.h" // for rutz::shared_ptr 00060 #include <fstream> 00061 #include <fcntl.h> // for open() 00062 #include <cerrno> // for errno 00063 #include <cstdio> // for perror() 00064 00065 class Brain; 00066 class FrameOstream; 00067 00068 //! This class provides interface with vision and NerdCam 00069 /*! This simulation viewer is designed to take brain and VisualCortex 00070 information and process it for use with the nerd cam web page. For instance 00071 we can control file locking, motion noticing and file saving. We use 00072 a SimulationViewer to standardize its workings with ezvision. 00073 */ 00074 class SimulationViewerNerdCam : public SimulationViewer { 00075 public: 00076 // ###################################################################### 00077 /*! @name Constructors and destructors */ 00078 //@{ 00079 00080 //! Constructor. See ModelComponent.H. 00081 /*! @param mgr our ModelManager (see ModelManager.H) 00082 @param descrName descriptive name for human usage 00083 @param tagName name for ParamMap usage */ 00084 SimulationViewerNerdCam(OptionManager& mgr, 00085 const std::string& descrName = "NerdCam Interface", 00086 const std::string& tagName = "NerdCam"); 00087 //! Destructor 00088 virtual ~SimulationViewerNerdCam(); 00089 00090 //! Reset SimulationViewerNerdCam 00091 /*! See the base function in ModelComponent.H for info. */ 00092 virtual void reset1(); 00093 00094 //! basic init method 00095 void init(const ushort baseSizeX,const ushort baseSizeY); 00096 00097 //@} 00098 00099 protected: 00100 //! Callback for when a new input image is available 00101 SIMCALLBACK_DECLARE(SimulationViewerNerdCam, SimEventInputFrame); 00102 00103 //! Callback for every clock tick 00104 /*! Note: this is only being used by warp3d right now and should go away. */ 00105 SIMCALLBACK_DECLARE(SimulationViewerNerdCam, SimEventClockTick); 00106 00107 //! Callback for when a new attention shift occurs 00108 SIMCALLBACK_DECLARE(SimulationViewerNerdCam, SimEventWTAwinner); 00109 00110 //! Callback for every time we should save our outputs 00111 SIMCALLBACK_DECLARE(SimulationViewerNerdCam, SimEventSaveOutput); 00112 00113 //! Save our various results 00114 virtual void save1(const ModelComponentSaveInfo& sinfo); 00115 00116 //! Get the attention/eye/head trajectory image 00117 Image< PixRGB<byte> > getTraj(SimEventQueue& q); 00118 00119 //! Called by saveOutput() 00120 void saveResults(const nub::ref<FrameOstream>& ofs, SimEventQueue& q); 00121 00122 //! Get started: 00123 virtual void start2(); 00124 //! write a basic status page out 00125 void writeStatusPage() const; 00126 //! write a basic status page out 00127 void writeChannelPage() const; 00128 //! Draw current time onto given image 00129 void drawTime(Image< PixRGB<byte> >& image) const; 00130 //! apply an advisory lock on a file 00131 void lockFile(const std::string fileName, int &fd, struct flock &fl) const; 00132 //! remove an advisory lock on a file 00133 void unlockFile(const std::string fileName, const int fd, 00134 struct flock &fl) const; 00135 //! log data to standard log file 00136 void nlog(const std::string logData) const; 00137 //! Draw the date and time onto an image 00138 void drawDateTime(Image< PixRGB<byte> >& image) const; 00139 //! Draw the focus of covert attention 00140 void drawFOA(); 00141 //! Link previous focus of attention to current one 00142 void linkFOAs(); 00143 //! draw the mega combo 00144 Image< PixRGB<byte> > drawMegaCombo(SimEventQueue& q) const; 00145 //! Draw outline of a mask (used by drawFOA) 00146 void drawMaskOutline(Image< PixRGB<byte> >& traj, 00147 const Image<byte> mask, 00148 const PixRGB<byte>& col, 00149 const int thick, 00150 const Point2D<int>& pos, 00151 const int radius) const; 00152 00153 //! metrics that depend on the input size: 00154 nub::ref<SpatialMetrics> itsMetrics; 00155 00156 //! drawing color selection parameter 00157 NModelParam< PixRGB<byte> > itsColorBoring; 00158 //! drawing color selection parameter 00159 NModelParam< PixRGB<byte> > itsColorLink; 00160 //! drawing color selection parameter 00161 NModelParam< PixRGB<byte> > itsColorNormal ; 00162 //! config file to open 00163 OModelParam<std::string> itsConfigFile; 00164 00165 // ########## display selection parameters: 00166 OModelParam<Dims> itsCropFOA; 00167 OModelParam<bool> itsDisplayAdditive; 00168 OModelParam<bool> itsDisplayBoring; 00169 OModelParam<bool> itsDisplayFOA; 00170 OModelParam<bool> itsDisplayFOALinks; 00171 OModelParam<bool> itsDisplayHighlights; 00172 OModelParam<bool> itsDisplayPatch; 00173 OModelParam<bool> itsDisplaySMmodulate; 00174 OModelParam<bool> itsDisplayTime; 00175 00176 //! half-size of (filled square) FOA patch 00177 NModelParam<int> itsFOApsiz; 00178 //! line thickness for FOA outline 00179 NModelParam<int> itsFOAthick; 00180 //! line thickness for links bewteen FOAs 00181 NModelParam<int> itsFOAlinkThick; 00182 OModelParam<bool> itsMegaCombo; 00183 NModelParam<float> itsWarp3Dpitch; 00184 NModelParam<float> itsWarp3Dyaw; 00185 NModelParam<float> itsWarp3DpitchRate; 00186 NModelParam<float> itsWarp3DyawRate; 00187 NModelParam<float> itsWarp3DpitchMax; 00188 NModelParam<float> itsWarp3DyawMax; 00189 //! use larger drawings? 00190 OModelParam<bool> itsUseLargerDrawings; 00191 00192 private: 00193 //! cumulative FOA shape 00194 Image<byte> itsCumFOAmask; 00195 //! current attention position 00196 WTAwinner itsCurrFOA; 00197 //! current FOA shape 00198 Image<byte> itsCurrFOAmask; 00199 //! current time 00200 SimTime itsCurrTime; 00201 //! dims of 3D drawing 00202 Dims itsDims3D; 00203 //! used to foveate traj 00204 ImageSet< PixRGB<byte> > itsMultiTraj; 00205 // previous attention position 00206 WTAwinner itsPrevFOA; 00207 //! Some drawings go here 00208 Image< PixRGB<byte> > itsTraj; 00209 //! local copy of the input image 00210 Image< PixRGB<float> > itsInput; 00211 //! copy of saliency map 00212 Image<float> itsSalMap; 00213 //! what file to write output motion image file to 00214 std::string itsOutputMotionImage; 00215 //! what file to write output SalMap image file to 00216 std::string itsOutputSalMapImage; 00217 //! what file to write output 3D saliency image 00218 std::string itsOutput3DImage; 00219 //! what file to write output Mega saliency image 00220 std::string itsOutputMegaImage; 00221 //! what file to write a basic trajectory image to 00222 std::string itsOutputTrajImage; 00223 //! where is the base web page? 00224 std::string itsWebPageFile; 00225 //! status web page 00226 std::string itsStatusFile; 00227 //! status web page header 00228 std::string itsStatusHeader; 00229 //! status web page footer 00230 std::string itsStatusFooter; 00231 //! channel web page 00232 std::string itsChannelFile; 00233 //! URL of the web page 00234 std::string itsBaseURL; 00235 //! The name of this web page 00236 std::string itsBaseName; 00237 //! the file to log stuff to 00238 std::string itsLogFile; 00239 //! Time stamp for start up 00240 std::string itsStartTime; 00241 //! how many frames have we processed 00242 unsigned long itsTotalFrames; 00243 //! 3D drawing; mutable for testsuite 00244 mutable float itsPitch3D; 00245 //! 3D drawing; mutable for testsuite 00246 mutable float itsYaw3D; 00247 //! floating point threshold above which we spot moving things 00248 float itsMotionThreshold; 00249 //! the base image size in X 00250 ushort itsBaseSizeX; 00251 //! the base image size in Y 00252 ushort itsBaseSizeY; 00253 //! size of the mega combo image x 00254 ushort itsComboSizeX; 00255 //! size of the mega combo image y 00256 ushort itsComboSizeY; 00257 //! size of the mega combo image x 00258 ushort its3DSizeX; 00259 //! size of the mega combo image y 00260 ushort its3DSizeY; 00261 //! input changed since last getTraj() 00262 bool itsHasNewInput; 00263 //! tells us if we need to initialize ScaleSurpriseControl 00264 bool itsInit; 00265 }; 00266 00267 #endif 00268 00269 // ###################################################################### 00270 /* So things look consistent in everyone's emacs... */ 00271 /* Local Variables: */ 00272 /* indent-tabs-mode: nil */ 00273 /* End: */