
00001 /*!@file Channels/ChannelBase.H The base class for all channel classes */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // 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: Rob Peters <rjpeters@klab.caltech.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Channels/ChannelBase.H $ 00035 // $Id: ChannelBase.H 10746 2009-02-03 07:09:00Z itti $ 00036 // 00037 00038 #ifndef CHANNELBASE_H_DEFINED 00039 #define CHANNELBASE_H_DEFINED 00040 00041 #include "Channels/InputFrame.H" 00042 #include "Channels/VisualFeatures.H" 00043 #include "Component/ModelComponent.H" 00044 #include "Component/ModelParam.H" 00045 #include "Image/Image.H" 00046 #include "Image/PixelsTypes.H" 00047 #include "Util/Assert.H" 00048 00049 #include <vector> 00050 00051 class ChannelBase; 00052 class ChannelVisitor; 00053 class Dims; 00054 class FrameOstream; 00055 class ParamMap; 00056 template <class T> class Point2D; 00057 class Rectangle; 00058 class SimTime; 00059 template <class T> class PixRGB; 00060 00061 // ###################################################################### 00062 //! ChannelBase represents the various computational modules in VisualCortex. 00063 class ChannelBase : virtual public ModelComponent 00064 { 00065 public: 00066 //! Default constructor. See ModelComponent.H 00067 /*! @param mgr our ModelManager (see ModelManager.H) 00068 @param descrName descriptive name for human usage 00069 @param tagName name for ParamMap usage 00070 @param vs The VisualFeature implemented by the channel */ 00071 ChannelBase(OptionManager& mgr, const std::string& descrName, 00072 const std::string& tagName, const VisualFeature vs); 00073 00074 //! Virtual destructor ensures proper destruction of derived classes. 00075 virtual ~ChannelBase(); 00076 00077 //! Kill our caches 00078 virtual void reset1(); 00079 00080 /// Default version calls visitChannelBase() on the ChannelVisitor. 00081 virtual void accept(ChannelVisitor& v); 00082 00083 // ###################################################################### 00084 /*! @name VisualFeature functions */ 00085 //@{ 00086 00087 //! Get the visual feature 00088 VisualFeature visualFeature() const; 00089 00090 //! Is the channel homogeneous? 00091 /*! A homogeneous channel is one whose subchannels (and their subs) 00092 have identical VisualFeatures, and those are also identical to 00093 our VisualFeature. Default implementation returns true. */ 00094 virtual bool isHomogeneous() const; 00095 //@} 00096 00097 // ###################################################################### 00098 /*! @name ParamMap functions 00099 00100 Subclasses should be sure to call ChannelBase's version of these 00101 functions within their own implementations, so that 00102 ChannelBase's parameters (such as its weights) are properly 00103 handled. 00104 00105 This interface is different from that provided by 00106 ModelComponent, as here we only save a subset of all of the 00107 Channel's parameters, that are useful, e.g., for object 00108 recognition or feature-based attention biasing. Some of the 00109 values saved here may not even be ModelParam parameters. */ 00110 //@{ 00111 00112 //! Read params from the ParamMap. 00113 virtual void readFrom(const ParamMap& pmap); 00114 00115 //! Write params to the ParamMap. 00116 virtual void writeTo(ParamMap& pmap) const; 00117 00118 //@} 00119 00120 // ###################################################################### 00121 /*! @name Input functions 00122 00123 See documentation on InputFrame for multiple ways in which an 00124 InputFrame can be constructed. */ 00125 //@{ 00126 00127 //! Send a full-blown InputFrame to the channel 00128 void input(const InputFrame& inframe); 00129 00130 //@} 00131 00132 // ###################################################################### 00133 /*! @name Access functions */ 00134 //@{ 00135 00136 //! Query whether the channel is ready to give yield valid output. 00137 /*! In some cases (e.g. with motion channels), it may take several 00138 input frames before the channel is fully initialized. */ 00139 virtual bool outputAvailable() const = 0; 00140 00141 //! Return the dimensions of the output image. 00142 virtual Dims getMapDims() const = 0; 00143 00144 //! Check if we've received any input images yet. 00145 bool hasInput() const; 00146 00147 //! Return the dimensions of the most recent input image. 00148 /*! Will LFATAL() if hasInput() is false. */ 00149 Dims getInputDims() const; 00150 00151 //! Return the number of feature maps represented by this channel. 00152 virtual uint numSubmaps() const = 0; 00153 00154 //! Get the feature map at the given index. 00155 /*! This function is intended to be implemented by subclasses so 00156 that it recurses into any nested channels, mapping nested 00157 submaps into a linear sequence of indices. */ 00158 virtual Image<float> getSubmap(const uint index) const = 0; 00159 00160 //! get raw CS map; part of getSubmap() 00161 virtual Image<float> getRawCSmap(const uint idx) const {LFATAL("Not implemented yet."); return Image<float>();} 00162 00163 //! Get the name/description of the feature map at the given index. 00164 /*! This function is intended to be implemented by subclasses so 00165 that it recurses into any nested channels, mapping nested 00166 submaps into a linear sequence of indices. The output of this 00167 function is intended only to be human-readable (e.g. for 00168 labeling image displays), and does not have to follow any 00169 particular parseable syntax. */ 00170 virtual std::string getSubmapName(const uint index) const = 0; 00171 00172 00173 virtual void getFeatures(const Point2D<int>& locn, 00174 std::vector<float>& mean) const = 0; 00175 00176 virtual void getFeaturesBatch(std::vector<Point2D<int>*> *locn, 00177 std::vector<std::vector<float> > *mean, 00178 int *count) const = 0; 00179 00180 //! The output will be the size of the feature map level in the pyramid. 00181 /*! (I.e., the size of the output is given by getMapDims(). */ 00182 virtual Image<float> getOutput() = 0; 00183 00184 //! Save our various maps using a FrameOstream 00185 /*! The default implementation is a no-op; subclasses can override 00186 to do something interesting */ 00187 virtual void saveResults(const nub::ref<FrameOstream>& ofs); 00188 00189 //! Subclasses override this to clear any caches they may maintain. 00190 /*! <b>Subclasses must be sure to explicitly call their base class's 00191 version of this function!</b>. This function will be called by 00192 ChannelBase when a new input image is received, or when new 00193 parameters are read from a ParamMap, etc. Subclasses may also 00194 call this function when they know that caches may have become 00195 invalid. Calling this explicitly after you have obtained the 00196 output from a channel may save you some memory. */ 00197 virtual void killCaches(); 00198 00199 //@} 00200 00201 protected: 00202 //! Subclasses override this implementation of the input() function. 00203 /*! This will be called by one of the input() methods. For 00204 efficiency reasons (e.g. network bandwidth in parallel code), it 00205 is possible that the color or luminance input may be null, 00206 although the code should be wired up properly so that given 00207 subclasses do not receive a null input that they in fact 00208 need. Subclasses should be sure to ASSERT that any used inputs 00209 are non-null. */ 00210 virtual void doInput(const InputFrame& inframe) = 0; 00211 00212 // This is used only by SingleOpponentChannel::singleOpponentInput() 00213 void setInputDims(const Dims& dims); 00214 00215 private: 00216 ChannelBase(const ChannelBase&); // not allowed 00217 ChannelBase& operator=(const ChannelBase&); // not allowed 00218 00219 NModelParam<VisualFeature> itsVisFeature; 00220 00221 Dims itsInputDims; 00222 }; 00223 00224 00225 /* So things look consistent in everyone's emacs... */ 00226 /* Local Variables: */ 00227 /* indent-tabs-mode: nil */ 00228 /* End: */ 00229 00230 #endif // !CHANNELBASE_H_DEFINED
1.4.4