SimulationViewer.C

Go to the documentation of this file.
00001 /*!@file Neuro/SimulationViewer.C visualize various model simulations */
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: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Neuro/SimulationViewer.C $
00035 // $Id: SimulationViewer.C 14508 2011-02-15 21:09:43Z dberg $
00036 //
00037 
00038 #include "Neuro/SimulationViewer.H"
00039 #include "Component/OptionManager.H"
00040 #include "Neuro/NeuroOpts.H"
00041 #include "Neuro/NeuroSimEvents.H"
00042 #include "Media/MediaSimEvents.H"
00043 #include "Simulation/SimEventQueue.H"
00044 
00045 // ######################################################################
00046 // implementation of SimulationViewer
00047 // ######################################################################
00048 SimulationViewer::SimulationViewer(OptionManager& mgr,
00049                                    const std::string& descrName,
00050                                    const std::string& tagName) :
00051   SimModule(mgr, descrName, tagName),
00052   SIMCALLBACK_INIT(SimEventSceneDescription),
00053   SIMCALLBACK_INIT(SimEventObjectDescription),
00054   itsDisplayInterp(&OPT_SVdisplayInterp, this),
00055   itsMapFactor(&OPT_SVdisplayMapFactor, this),
00056   itsMapType(&OPT_SVdisplayMapType, this)
00057 { }
00058 
00059 // ######################################################################
00060 SimulationViewer::~SimulationViewer()
00061 { }
00062 
00063 // ######################################################################
00064 void SimulationViewer::
00065 onSimEventSceneDescription(SimEventQueue& q, rutz::shared_ptr<SimEventSceneDescription>& e)
00066 {
00067   LINFO("Scene is: %s ", e->getSceneData()->description.c_str());
00068 }
00069 
00070 // ######################################################################
00071 void SimulationViewer::
00072 onSimEventObjectDescription(SimEventQueue& q, rutz::shared_ptr<SimEventObjectDescription>& e)
00073 {
00074   LINFO("Object is: %s id %i", e->getObjData()->description.c_str(), e->getObjData()->id);
00075 }
00076 
00077 // ######################################################################
00078 Image<float> SimulationViewer::getMap(SimEventQueue& q,
00079                                       const bool warn) const
00080 {
00081   const float fac = itsMapFactor.getVal();
00082   const std::string typ = itsMapType.getVal();
00083   Image<float> ret;
00084 
00085   if (typ.compare("SM") == 0)
00086     {
00087       if (SeC<SimEventSaliencyMapOutput> e =
00088           q.check<SimEventSaliencyMapOutput>(this, SEQ_ANY))
00089         ret = e->sm(fac);
00090       else if (warn) LERROR("Could not get a Saliency Map!");
00091     }
00092   else if  (typ.compare("TRM") == 0)
00093     {
00094       if (SeC<SimEventTaskRelevanceMapOutput> e =
00095           q.check<SimEventTaskRelevanceMapOutput>(this, SEQ_ANY))
00096         ret = e->trm(fac);
00097       else if (warn) LERROR("Could not get a Task Relevance Map!");
00098     }
00099   else if (typ.compare("AGM") == 0)
00100     {
00101       if (SeC<SimEventAttentionGuidanceMapOutput> e =
00102           q.check<SimEventAttentionGuidanceMapOutput>(this, SEQ_ANY))
00103         ret = e->agm(fac);
00104       else if (warn) LERROR("Could not get an Attention Guidance Map!");
00105     }
00106   else if  (typ.compare("VCO") == 0)
00107     {
00108       if (SeC<SimEventVisualCortexOutput> e =
00109           q.check<SimEventVisualCortexOutput>(this, SEQ_ANY))
00110         ret = e->vco(fac);
00111       else if (warn) LERROR("Could not get a Visual Cortex Output Map!");
00112     }
00113   else LFATAL("Unknown desired map type '%s'", typ.c_str());
00114 
00115   //inverse the map, will only happen if necessary default does nothing
00116   ret = inverseMap(ret);
00117   
00118   return ret;
00119 }
00120 
00121 // ######################################################################
00122 // implementation of SimulationViewerAdapter
00123 // ######################################################################
00124 SimulationViewerAdapter::SimulationViewerAdapter(OptionManager& mgr, 
00125                                                  const std::string& descrName, 
00126                                                  const std::string& tagName) :
00127   SimulationViewer(mgr, descrName, tagName),
00128   SIMCALLBACK_INIT(SimEventRetinaImage),
00129   SIMCALLBACK_INIT(SimEventWTAwinner),
00130   itsInverseRetinal(&OPT_SVInverseTransform, this),
00131   itsInput(),
00132   itsCurrFOA(WTAwinner::NONE()),
00133   itsPrevFOA(WTAwinner::NONE()),
00134   itsTransform(new SpaceVariantModule(mgr))
00135 {
00136   addSubComponent(itsTransform);
00137 }
00138 
00139 // ######################################################################
00140 void SimulationViewerAdapter::reset1()
00141 {
00142   itsInput.freeMem();
00143   itsCurrFOA = WTAwinner::NONE();
00144   itsPrevFOA = WTAwinner::NONE();
00145   itsTransform->clear();
00146   
00147  // propagate to our base class:
00148   SimulationViewer::reset1();
00149 }
00150 
00151 // ######################################################################
00152 void SimulationViewerAdapter::
00153 onSimEventRetinaImage(SimEventQueue& q, rutz::shared_ptr<SimEventRetinaImage>& e)
00154 {
00155   // keep a copy of the image
00156   itsInput = e->frame().colorByte();
00157   
00158   //if we are a retinal type that produces a transform, then lets invert the image if the flag is set
00159   if (e->getRetTransform().is_valid() && e->getMapTransform().is_valid())
00160     {
00161       //update the local versions of the transform
00162       itsTransform->setTransform(e->getRetTransform());
00163       itsTransform->setMapTransform(e->getMapTransform());
00164       
00165       //transform the retinal image
00166       if (itsInverseRetinal.getVal())
00167         itsInput = itsTransform->inverseTransform(itsInput);      
00168     }
00169 
00170   doEventRetinaImage(q, e);//derived classes can do there own thing
00171 }
00172 
00173 // ######################################################################
00174 void SimulationViewerAdapter::
00175 onSimEventWTAwinner(SimEventQueue& q, rutz::shared_ptr<SimEventWTAwinner>& e)
00176 {
00177   itsPrevFOA = itsCurrFOA;
00178   itsCurrFOA = e->winner();//get the current winner
00179   if (itsCurrFOA.isValid())
00180     {
00181       fromRetinal(itsCurrFOA.p);//inverse our retinal winner point if necessary
00182       fromRetinalMap(itsCurrFOA.smpos);//inverse the position in saliency map if necessary
00183     }
00184   doEventWTAwinner(q, e);//let derived classes do there own thing
00185 }
00186 
00187 // ######################################################################
00188 Image<float> SimulationViewerAdapter::inverseMap(const Image<float>& map_image) const
00189 {
00190   Image<float> map = map_image;
00191   
00192   //if we are a retinal type that produces a transform, then lets inverse the image if the flag is set
00193   if (itsTransform->validTransforms() && itsInverseRetinal.getVal())
00194     map = itsTransform->inverseMap(map);      
00195   return map;
00196 }
00197 
00198 // ######################################################################
00199 Image<float> SimulationViewerAdapter::inverseRetinal(const Image<float>& ret_image) const
00200 {
00201   Image<float> ret = ret_image;
00202 
00203   //if we are a retinal type that produces a transform, then lets inverse the image if the flag is set
00204   if (itsTransform->validTransforms() && itsInverseRetinal.getVal())
00205     ret = itsTransform->inverseTransform(ret);      
00206   return ret;
00207 }
00208 
00209 // ######################################################################
00210 void SimulationViewerAdapter::toRetinal(Point2D<int>& point) const
00211 {
00212   if (itsTransform->validTransforms())
00213     itsTransform->toSvCoords(point);
00214 }
00215 
00216 // ######################################################################
00217 void SimulationViewerAdapter::fromRetinal(Point2D<int>& point) const
00218 {
00219   if (itsTransform->validTransforms() && itsInverseRetinal.getVal())
00220     itsTransform->fromSvCoords(point);
00221 }
00222 
00223 // ######################################################################
00224 void SimulationViewerAdapter::fromRetinalMap(Point2D<int>& point) const
00225 {
00226   if (itsTransform->validTransforms() && itsInverseRetinal.getVal())
00227     itsTransform->fromSvCoordsMap(point);
00228 }
00229 
00230 // ######################################################################
00231 /* So things look consistent in everyone's emacs... */
00232 /* Local Variables: */
00233 /* indent-tabs-mode: nil */
00234 /* End: */
Generated on Sun May 8 08:41:04 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3