ChannelBase.C

Go to the documentation of this file.
00001 /*!@file Channels/ChannelBase.C 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.C $
00035 // $Id: ChannelBase.C 10794 2009-02-08 06:21:09Z itti $
00036 //
00037 
00038 #include "Channels/ChannelBase.H"
00039 
00040 #include "Channels/ChannelVisitor.H"
00041 #include "Channels/InputFrame.H"
00042 #include "Channels/VisualFeatures.H"
00043 #include "Component/ParamMap.H"
00044 #include "Image/Image.H"
00045 #include "rutz/error_context.h"
00046 #include "rutz/sfmt.h"
00047 #include "rutz/trace.h"
00048 
00049 #include <string>
00050 
00051 // ######################################################################
00052 // ######################################################################
00053 // ChannelBase member definitions:
00054 // ######################################################################
00055 // ######################################################################
00056 
00057 ChannelBase::ChannelBase(OptionManager& mgr, const std::string& descrName,
00058                          const std::string& tag, const VisualFeature vs) :
00059   // ModelComponent::ModelComponent() auto called - virtual base
00060   itsVisFeature("VisualFeature", this, vs),
00061   itsInputDims()
00062 {
00063 GVX_TRACE(__PRETTY_FUNCTION__);
00064  ModelComponent::init(mgr, descrName, tag);
00065 }
00066 
00067 // ######################################################################
00068 ChannelBase::~ChannelBase()
00069 {
00070 GVX_TRACE(__PRETTY_FUNCTION__);
00071 }
00072 
00073 // ######################################################################
00074 void ChannelBase::reset1()
00075 {
00076 GVX_TRACE(__PRETTY_FUNCTION__);
00077   this->killCaches();
00078   itsInputDims = Dims();
00079   ModelComponent::reset1();
00080 }
00081 
00082 // ######################################################################
00083 void ChannelBase::accept(ChannelVisitor& v)
00084 {
00085 GVX_TRACE(__PRETTY_FUNCTION__);
00086   v.visitChannelBase(*this);
00087 }
00088 
00089 // ######################################################################
00090 VisualFeature ChannelBase::visualFeature() const
00091 {
00092 GVX_TRACE(__PRETTY_FUNCTION__);
00093   return itsVisFeature.getVal();
00094 }
00095 
00096 // ######################################################################
00097 bool ChannelBase::isHomogeneous() const
00098 {
00099 GVX_TRACE(__PRETTY_FUNCTION__);
00100   // default returns true; subclasses override if they want to return
00101   // something different
00102   return true;
00103 }
00104 
00105 // ######################################################################
00106 void ChannelBase::readFrom(const ParamMap& pmap)
00107 {
00108 GVX_TRACE(__PRETTY_FUNCTION__);
00109 
00110   killCaches();
00111 
00112   if (!pmap.hasParam("descriptivename"))
00113     LFATAL("Missing descriptivename parameter (expected %s)",
00114            descriptiveName().c_str());
00115   const std::string descriptive =
00116     pmap.getStringParam("descriptivename", "bug");
00117   if (descriptive.compare(descriptiveName()) != 0)
00118     LFATAL("Wrong descriptivename %s (expected %s)",
00119            descriptive.c_str(), descriptiveName().c_str());
00120 }
00121 
00122 // ######################################################################
00123 void ChannelBase::writeTo(ParamMap& pmap) const
00124 {
00125 GVX_TRACE(__PRETTY_FUNCTION__);
00126 
00127   pmap.putStringParam("descriptivename", descriptiveName());
00128 }
00129 
00130 // ######################################################################
00131 void ChannelBase::input(const InputFrame& inframe)
00132 {
00133 GVX_TRACE(__PRETTY_FUNCTION__);
00134   GVX_ERR_CONTEXT(rutz::sfmt("receiving input in channel %s",
00135                              this->tagName().c_str()));
00136 
00137   killCaches();
00138   itsInputDims = inframe.getDims();
00139   doInput(inframe);
00140 }
00141 
00142 // ######################################################################
00143 bool ChannelBase::hasInput() const
00144 {
00145 GVX_TRACE(__PRETTY_FUNCTION__);
00146   return itsInputDims.isNonEmpty();
00147 }
00148 
00149 // ######################################################################
00150 Dims ChannelBase::getInputDims() const
00151 {
00152 GVX_TRACE(__PRETTY_FUNCTION__);
00153   if (itsInputDims.isEmpty())
00154     CLFATAL("I haven't received any input yet");
00155 
00156   return itsInputDims;
00157 }
00158 
00159 // ######################################################################
00160 void ChannelBase::saveResults(const nub::ref<FrameOstream>& ofs)
00161 {
00162 GVX_TRACE(__PRETTY_FUNCTION__);
00163   // default is a no-op
00164 }
00165 
00166 // ######################################################################
00167 void ChannelBase::killCaches()
00168 {
00169 GVX_TRACE(__PRETTY_FUNCTION__);
00170   /* no caches to worry about here -- in particular, don't try to
00171      reset itsInputDims, since we still want to be able to retrieve
00172      that value in between frames, when caches might otherwise be
00173      killed */
00174 }
00175 
00176 // ######################################################################
00177 void ChannelBase::setInputDims(const Dims& dims)
00178 {
00179 GVX_TRACE(__PRETTY_FUNCTION__);
00180   if (dims.isEmpty())
00181     CLFATAL("input image must be non-empty!");
00182   itsInputDims = dims;
00183 }
00184 
00185 // ######################################################################
00186 /* So things look consistent in everyone's emacs... */
00187 /* Local Variables: */
00188 /* indent-tabs-mode: nil */
00189 /* End: */
Generated on Sun May 8 08:40:21 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3