SimStructure.H

Go to the documentation of this file.
00001 /*!@file ModelNeuron/SimStructure.H Class declarations for a
00002   structure module, a simulation unit that supports 2D image input and
00003   output. */
00004 
00005 // //////////////////////////////////////////////////////////////////// //
00006 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00007 // 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/ModelNeuron/SimStructure.H $
00037 
00038 #ifndef MODELNEURON_SIMSTRUCTURE_H_DEFINED
00039 #define MODELNEURON_SIMSTRUCTURE_H_DEFINED
00040 
00041 #include "Util/SimTime.H"
00042 #include "Image/Image.H"
00043 #include "ModelNeuron/Location.H"
00044 #include "GenericUtils/GenericFactory.H"
00045 #include "GenericUtils/CreateFunctor.H"
00046 #include "Image/LowPassLpt.H"
00047 
00048 #include <typeinfo>
00049 
00050 class SimUnit;
00051 // ######################################################################
00052 // SimStructure is an abstract container intended to serve as an interface
00053 // to collections of SimUnit's with 2D input and output. Most classes will 
00054 // derive from one of the partial implementations (see Structure.H and 
00055 // SimLayer.H) or from one of the full implementations (see Layer.H, SC.H 
00056 // and others for example).
00057 //######################################################################
00058 class SimStructure
00059 {
00060 public:
00061   //a typdef used to register classes
00062   typedef CreateFunctor<SimStructure, ParamList<BorderPolicy, SimTime, uint, uint> > Creator;
00063   typedef GenericFactory<SimStructure, std::string, Creator> Factory;
00064 
00065   //! constructor
00066   SimStructure(const uint width, const uint height, const std::string name = "", const std::string units = "");
00067   
00068   //!destructor 
00069   virtual ~SimStructure() { };
00070   
00071 // ######################################################################
00072 // i/o and simulation functions
00073 // ######################################################################  
00074 
00075   //!set the input
00076   virtual void input(const Image<double>& in, const int pos = -1) = 0;
00077 
00078   //!set the input
00079   virtual void inputExc(const Image<double>& in, const int pos = -1) = 0;
00080 
00081   //!set the input
00082   virtual void inputInh(const Image<double>& in, const int pos = -1) = 0;
00083 
00084   //!get the current output 
00085   virtual Image<double> getOutput(const int pos = -1) const = 0;
00086   
00087   //!get the current display output 
00088   virtual Image<double> getDisplayOutput(const int pos = -1) const;
00089   
00090   //!evolve up to specified time
00091   virtual void evolve(const SimTime& simtime) = 0;
00092 
00093 // ######################################################################
00094 // get/set unit functions
00095 // ######################################################################  
00096   
00097   //!get unit(s) at desired location
00098   virtual void getSimUnit(const Location& loc, std::vector<const SimUnit*>& units) = 0;
00099   
00100   //!edit unit(s) at the desired output position
00101   virtual void editSimUnit(const Location& loc, std::vector<SimUnit*>& units) = 0;
00102   
00103 // ######################################################################
00104 // sub-module functions
00105 // ######################################################################  
00106 
00107   //get the number of sub modules
00108   virtual const uint numSubs() const;
00109   
00110   //get a referene to a sub module const version
00111   virtual const SimStructure& getSub(const uint sub) const;  
00112   
00113   //get a referene to a sub module mutable version
00114   virtual SimStructure& editSub(const uint sub);  
00115 
00116 // ######################################################################
00117 // change state functions
00118 // ######################################################################  
00119 
00120   //!set units type
00121   void setName(const std::string& name);
00122   
00123   //!set units type
00124   void setUnits(const std::string& units);
00125   
00126   //reset all counters, output and call doInit() to reset all subclasses
00127   virtual void initialize() = 0;
00128 
00129   //!set simulation time step
00130   virtual void setTime(const SimTime& time, const bool recursive = true) = 0;  
00131 
00132 // ######################################################################
00133 // get state functions
00134 // ######################################################################  
00135 
00136   //!get name
00137   const std::string getName() const;
00138 
00139   //!get units
00140   const std::string getUnits() const;
00141 
00142   //!get output dimensions
00143   const Dims getOutDims() const;
00144 
00145   //!get the width
00146   const uint getOutWidth() const;
00147 
00148   //!get the height
00149   const uint getOutHeight() const;
00150   
00151   //!get the total output size
00152   const uint getOutSize() const;
00153 
00154   //!get simulation time step
00155   virtual const SimTime getTime() const = 0;
00156 
00157   //!get simulation time step
00158   virtual const SimTime getTimeStep() const = 0;
00159   
00160   //!clone the module
00161   virtual SimStructure* clone() const = 0;
00162   
00163 protected:
00164   //protect copy and asignment, use clone
00165   SimStructure(const SimStructure& nlc);
00166   SimStructure& operator=(const SimStructure& nlc);
00167 
00168   //split the positive and negative values of input into Exc and Inh
00169   static void splitExcInh(const Image<double>& input, Image<double>& Exc, Image<double>& Inh);
00170     
00171 private:
00172   std::string itsName, itsUnits;
00173   Dims itsOutDims;
00174 };
00175 
00176 // ######################################################################
00177 // SimStructure implementation
00178 // ######################################################################
00179 //! constructor
00180 inline
00181 SimStructure::SimStructure(const uint width, const uint height, const std::string name, const std::string units)
00182   : itsName(name), itsUnits(units), itsOutDims(width, height)
00183 { }
00184 
00185 // ######################################################################
00186 inline
00187 Image<double> SimStructure::getDisplayOutput(const int pos) const
00188 {
00189   return getOutput(pos);
00190 }
00191 
00192 // ######################################################################
00193 inline
00194 const uint SimStructure::numSubs() const
00195 {
00196   return 0;
00197 }
00198 
00199 // ######################################################################
00200 inline
00201 const SimStructure& SimStructure::getSub(const uint sub) const
00202 {
00203   LFATAL("No subcomponents, check numSubs before calling.");
00204   return *this;//will never execute
00205 }
00206 
00207 // ######################################################################
00208 inline
00209 SimStructure& SimStructure::editSub(const uint sub)
00210 {
00211   LFATAL("No subcomponents, check numSubs before calling.");
00212   return *this;//will never execute
00213 }
00214 
00215 // ######################################################################
00216 inline
00217 void SimStructure::setName(const std::string& name)
00218 {
00219   itsName = name;
00220 }
00221 
00222 // ######################################################################
00223 inline
00224 void SimStructure::setUnits(const std::string& units)
00225 {
00226   itsUnits = units;
00227 }
00228 
00229 // ######################################################################
00230 inline
00231 const std::string SimStructure::getName() const
00232 {
00233   return itsName;
00234 }
00235 
00236 // ######################################################################
00237 inline
00238 const std::string SimStructure::getUnits() const
00239 {
00240   return itsUnits;
00241 }
00242 
00243 // ######################################################################
00244 inline
00245 const Dims SimStructure::getOutDims() const
00246 {
00247   return itsOutDims;
00248 }
00249 
00250 // ######################################################################
00251 inline
00252 const uint SimStructure::getOutWidth() const
00253 {
00254   return itsOutDims.w();
00255 }
00256 
00257 // ######################################################################
00258 inline
00259 const uint SimStructure::getOutHeight() const
00260 {
00261   return itsOutDims.h();
00262 }
00263 
00264 // ######################################################################
00265 inline
00266 const uint SimStructure::getOutSize() const
00267 {
00268   return itsOutDims.h() * itsOutDims.w();
00269 }
00270 
00271 // ######################################################################
00272 inline
00273 SimStructure::SimStructure(const SimStructure& rhs) :
00274   itsName(rhs.itsName), itsUnits(rhs.itsUnits), itsOutDims(rhs.itsOutDims)
00275 { }
00276 
00277 // ######################################################################
00278 inline
00279 SimStructure& SimStructure::operator=(const SimStructure& rhs)
00280 { 
00281   if (this != &rhs)
00282     {
00283       itsName = rhs.itsName;
00284       itsUnits = rhs.itsUnits;
00285       itsOutDims = rhs.itsOutDims;
00286     }
00287   return *this;
00288 }
00289 
00290 // ######################################################################
00291 inline
00292 void SimStructure::splitExcInh(const Image<double>& input, Image<double>& Exc, Image<double>& Inh)
00293 {
00294   Image<double>::const_iterator in_iter(input.begin()), in_end(input.end());
00295   Image<double>::iterator oute_iter(Exc.beginw()), outi_iter(Inh.beginw());
00296   
00297   while (in_iter != in_end)
00298     {
00299       if (*in_iter < 0.0)
00300         *outi_iter += *in_iter;
00301       else 
00302         *oute_iter += *in_iter;
00303       
00304       ++in_iter; ++oute_iter; ++outi_iter; 
00305     }
00306 }
00307 
00308 #endif
00309 // ######################################################################
00310 /* So things look consistent in everyone's emacs... */
00311 /* Local Variables: */
00312 /* indent-tabs-mode: nil */
00313 /* End: */
Generated on Sun May 8 08:05:21 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3