Beobot.C

Go to the documentation of this file.
00001 /*!@file Beobot/Beobot.C main Beobot class */
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: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/Beobot.C $
00035 // $Id: Beobot.C 9412 2008-03-10 23:10:15Z farhan $
00036 //
00037 
00038 #include "Beobot/Beobot.H"
00039 
00040 // ######################################################################
00041 Beobot::Beobot(const char *slaves, const int imgw, const int imgh,
00042                const int lev_min, const int lev_max,
00043                const int delta_min, const int delta_max,
00044                const int smlev, const int nborient, const MaxNormType normtype,
00045                const int jlev, const int jdepth, const int nbneig,
00046                const in_addr_t ip, const short int port)
00047 {
00048   if (slaves)
00049     {
00050       // parallel version:
00051       LINFO("Initializing Beowulf as master");
00052 
00053       LFATAL("THIS CODE IS TEMPORARILY BROKEN");
00054 
00055       visualCortex.init(imgw, imgh, lev_min, lev_max, delta_min, delta_max,
00056                         smlev, nborient, normtype, jlev, jdepth, nbneig, beo);
00057     }
00058   else
00059     // single-CPU version:
00060     visualCortex.init(imgw, imgh, lev_min, lev_max, delta_min, delta_max,
00061                       smlev, nborient, normtype, jlev, jdepth, nbneig,
00062                       nub::soft_ref<Beowulf>());
00063 }
00064 
00065 // ######################################################################
00066 void Beobot::newVisualInput(Image< PixRGB<byte> >& scene)
00067 { visualCortex.newVisualInput(scene); }
00068 
00069 // ######################################################################
00070 Image< PixRGB<byte> >* Beobot::getRetinaPtr()
00071 { return visualCortex.getScenePtr(); }
00072 
00073 // ######################################################################
00074 void Beobot::lowLevel(const int frame)
00075 { visualCortex.process(frame); }
00076 
00077 // ######################################################################
00078 void Beobot::lowLevelStart(const int frame)
00079 { visualCortex.processStart(frame); }
00080 
00081 // ######################################################################
00082 void Beobot::lowLevelEnd(const int frame)
00083 { visualCortex.processEnd(frame); }
00084 
00085 // ######################################################################
00086 void Beobot::getWinner(Point2D<int>& win) const
00087 { visualCortex.getWinner(win); }
00088 
00089 //###########################################################################
00090 void Beobot::intermediateLevel(bool initMasses)
00091 {
00092   visualCortex.initSprings(initMasses);
00093 
00094   const float dt = 0.1;
00095 
00096   int nbIter = 3; if (initMasses) nbIter=15;
00097 
00098   for (int t = 0; t < nbIter; t ++) visualCortex.iterateSprings(dt);
00099 
00100   Image< PixRGB<byte> > clusteredImage;
00101   Point2D<int> supposedTrackCentroid;
00102   Point2D<int> previousTrackCentroid;
00103 
00104   BeobotSensation sensa;
00105 
00106   // carefull : passedSensation( 0, sensa ) is the previous
00107   // sensation as we will update the memory only at the end
00108   // of this function...
00109 
00110   // the number of valid memories
00111   int nbMemories = 0;
00112 
00113   while (memory.passedSensation(nbMemories, sensa))
00114     {
00115       Point2D<int> pt;
00116       sensa.getCentroid(pt);
00117 
00118       previousTrackCentroid += pt;
00119       nbMemories ++;
00120 
00121       if (nbMemories >= BeobotMemory::memoryLength) break;
00122     }
00123 
00124   if (nbMemories > 0)
00125     // take the mean of previous centroids
00126     previousTrackCentroid /= nbMemories;
00127   else
00128     {
00129       // else, just pretend it was where it should be ;)
00130 
00131       visualCortex.getInputSize(previousTrackCentroid);
00132 
00133       previousTrackCentroid.i /= 2;
00134       // previousTrackCentroid.j *= 7/8
00135       previousTrackCentroid.j *= 7; previousTrackCentroid.j /= 8;
00136     }
00137 
00138   visualCortex.getClusteredImage(clusteredImage, supposedTrackCentroid,
00139                                  previousTrackCentroid);
00140 
00141   BeobotSensation sensation(clusteredImage, supposedTrackCentroid);
00142 
00143   memory.presentSensation(sensation);
00144 }
00145 
00146 //###########################################################################
00147 void Beobot::DEBUGgetClustered(Image< PixRGB<byte> >& im)
00148 {
00149   BeobotSensation sensa;
00150   memory.passedSensation(0, sensa);
00151 
00152   sensa.getQuickLayout(im);
00153 }
00154 
00155 //###########################################################################
00156 void Beobot::highLevel( void )
00157 {
00158   BeobotSensation s;
00159 
00160   memory.passedSensation(0, s);
00161   Image< PixRGB<byte> > ql;
00162 
00163   s.getQuickLayout(ql);
00164 
00165   // size of the image
00166   int w = ql.getWidth();
00167   int h = ql.getWidth();
00168 
00169   // 'point' is at the center of the bottom of the image
00170   int pointX = w / 2;
00171   int pointY = h * 7 / 8;
00172 
00173   Point2D<int> centroid;
00174   s.getCentroid(centroid);
00175 
00176   // create a new action
00177   BeobotAction action;
00178 
00179   // SPEED
00180   if (centroid.j > pointY)
00181     // not much visibility, go slow
00182     action.setSpeed(0.1);
00183   else if( centroid.j < h/2 )
00184     action.setSpeed(1.0);
00185   else
00186     // do something linear in between
00187     // note: centroid.j should be > h/2
00188     action.setSpeed( 1.0*( -(float)centroid.j+(float)h )/((float)h/2.0)  );
00189 
00190   // TURN
00191   // linear is beautiful
00192   action.setTurn( ((float)centroid.i-(float)pointX)/(float)pointX  );
00193 
00194   // GEAR
00195   action.setGear(1);
00196   // we'll think about this one later...
00197 
00198   memory.presentActionRecommendation( action );
00199 }
00200 
00201 //###########################################################################
00202 void Beobot::decision( void )
00203 { // all the work is done by memory
00204   memory.generatePresentAction(currentAction);
00205 }
00206 
00207 //###########################################################################
00208 void Beobot::action( void )
00209 {
00210   //LINFO("Beobot::act()");
00211 
00212 // all the work is done by effectors
00213   effectors->performAction(currentAction);
00214 }
00215 
00216 // ######################################################################
00217 /* So things look consistent in everyone's emacs... */
00218 /* Local Variables: */
00219 /* indent-tabs-mode: nil */
00220 /* End: */
Generated on Sun May 8 08:04:26 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3