AgentManagerA.H

00001 /*!@file SeaBee/AgentManager.H management class for agents on COM-A    */
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: Michael Montalbo <montalbo@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/SeaBee/AgentManagerA.H $
00035 // $Id: AgentManagerA.H 10794 2009-02-08 06:21:09Z itti $
00036 //
00037 
00038 #ifndef __SEABEE_AGENT_MANAGER_H__
00039 #define __SEABEE_AGENT_MANAGER_H__
00040 
00041 #include "Component/ModelComponent.H"
00042 #include "Component/ModelParam.H"
00043 
00044 #include "Raster/Raster.H"
00045 #include "Image/Image.H"
00046 #include "Image/Pixels.H"
00047 #include "Image/CutPaste.H"
00048 
00049 #include "Neuro/EnvVisualCortex.H"
00050 
00051 #include "GUI/XWinManaged.H"
00052 
00053 #include "Globals.H"
00054 #include "AgentManagerCommand.H"
00055 
00056 #include "ForwardVision.H"
00057 #include "Captain.H"
00058 #include "Movement.H"
00059 #include "SubController.H"
00060 #include "SensorResult.H"
00061 #include "DownwardVision.H"
00062 #include "SonarListen.H"
00063 
00064 
00065 #include "Util/Timer.H"
00066 #include <pthread.h>
00067 
00068 class CaptainAgent;
00069 class MovementAgent;
00070 class ForwardVisionAgent;
00071 class DownwardVisionAgent;
00072 class SonarListenAgent;
00073 
00074 class AgentManagerA : public ModelComponent
00075 {
00076 public:
00077 
00078   // ######################################################################
00079   /*! @name Constructors and Destructors */
00080   //@{
00081 
00082   //! Constructor
00083   AgentManagerA(nub::soft_ref<SubController> subController,
00084                 nub::soft_ref<EnvVisualCortex> evc,
00085                 ModelManager& mgr,
00086                 const std::string& descrName = "Agent Manager",
00087                 const std::string& tagName = "Agent Manager");
00088 
00089   //! Destructor
00090   virtual ~AgentManagerA();
00091 
00092   //@}
00093 
00094   // ######################################################################
00095   //! @name Access functions
00096   //@{
00097 
00098   //! set the current image to be processed
00099   void setCurrentImage(Image<PixRGB<byte> > image, uint fNum);
00100 
00101 
00102   inline void setSubController(nub::soft_ref<SubController> subController);
00103 
00104   inline void setWindow(rutz::shared_ptr<XWinManaged> win,
00105                         Image<PixRGB<byte> > ima);
00106 
00107   void pushCommand(CommandType cmdType,
00108                    rutz::shared_ptr<Mission> mission);
00109 
00110   //! get the current image to be processed
00111   inline Image<PixRGB<byte> > getCurrentImage();
00112 
00113   //! get the current frame number
00114   inline uint getCurrentFrameNumber();
00115 
00116   inline void setWindow(rutz::shared_ptr<XWinManaged> win);
00117 
00118   inline void setVisualCortex(nub::ref<EnvVisualCortex> evc);
00119 
00120   inline void drawImage(rutz::shared_ptr< Image<PixRGB<byte> > > ima);
00121 
00122   //! initialize the vector of SensorResults
00123   void initSensorResults();
00124 
00125   //! set the current object to be processed
00126   bool updateSensorResult(rutz::shared_ptr<SensorResult> sensorResult);
00127 
00128   //! update the missions of all of agent manager's agents
00129   void updateAgentsMission(Mission theMission);
00130 
00131   rutz::shared_ptr<DownwardVisionAgent> getDownwardVisionAgent();
00132 
00133   rutz::shared_ptr<SonarListenAgent> getSonarListenAgent();
00134 
00135   rutz::shared_ptr<ForwardVisionAgent> getForwardVisionAgent();
00136 
00137   rutz::shared_ptr<CaptainAgent> getCaptainAgent();
00138 
00139   rutz::shared_ptr<MovementAgent> getMovementAgent();
00140 
00141   uint getNumCommands();
00142 
00143   rutz::shared_ptr<SensorResult> getSensorResult(SensorResult::SensorResultType type);
00144 
00145   rutz::shared_ptr<AgentManagerCommand> popCommand();
00146 
00147   void startRun();
00148 
00149   //@}
00150 
00151 private:
00152 
00153   // for display purposes
00154   rutz::shared_ptr<XWinManaged> itsWindow;
00155   Image<PixRGB<byte> > itsDisplayImage;
00156   pthread_mutex_t itsDisplayLock;
00157 
00158   // the current image and lock
00159   Image<PixRGB<byte> > itsCurrentImage;
00160   uint itsFrameNumber;
00161   rutz::shared_ptr<Timer> itsTimer;
00162   std::vector<uint64> itsFrameDuration;
00163   pthread_mutex_t itsCurrentImageLock;
00164 
00165   // forward vision agent
00166   rutz::shared_ptr<ForwardVisionAgent> itsForwardVisionAgent;
00167   pthread_t itsForwardVisionAgentThread;
00168 
00169   // prefrontal cortex agent: decision maker
00170   rutz::shared_ptr<CaptainAgent> itsCaptainAgent;
00171   pthread_t itsCaptainAgentThread;
00172 
00173   // premotor complex agent: generate motor commands
00174   rutz::shared_ptr<MovementAgent> itsMovementAgent;
00175   pthread_t itsMovementAgentThread;
00176 
00177   // collection of all the agent manager's agents
00178   std::vector<rutz::shared_ptr<SubmarineAgent> > itsSubmarineAgents;
00179 
00180   // SubController
00181   nub::soft_ref<SubController> itsSubController;
00182   pthread_mutex_t itsSubControllerLock;
00183 
00184   // store the ocean objects
00185   std::vector<rutz::shared_ptr<SensorResult> > itsSensorResults;
00186   std::vector<rutz::shared_ptr<SensorResult> >::iterator itsSensorResultsItr;
00187 
00188   pthread_mutex_t itsSensorResultsLock;
00189 
00190   // command cue to send to COM_B
00191   std::list<rutz::shared_ptr<AgentManagerCommand> > itsCommands;
00192   pthread_mutex_t itsCommandsLock;
00193 
00194   nub::soft_ref<EnvVisualCortex> itsEVC;
00195 
00196 };
00197 
00198 // ######################################################################
00199 inline void AgentManagerA::setSubController(nub::soft_ref<SubController> subController)
00200 {
00201   pthread_mutex_lock(&itsSubControllerLock);
00202   itsSubController = subController;
00203   pthread_mutex_unlock(&itsSubControllerLock);
00204 }
00205 
00206 // ######################################################################
00207 inline void AgentManagerA::setWindow(rutz::shared_ptr<XWinManaged> win)
00208 {
00209   itsWindow = win;
00210   //itsDisplayImage = ima;
00211 }
00212 
00213 // ######################################################################
00214 inline void AgentManagerA::setVisualCortex
00215 (nub::ref<EnvVisualCortex> evc)
00216 {
00217   itsEVC = evc;
00218 }
00219 
00220 // ######################################################################
00221 inline Image<PixRGB<byte> > AgentManagerA::getCurrentImage()
00222 {
00223   Image<PixRGB<byte> > image;
00224   pthread_mutex_lock(&itsCurrentImageLock);
00225   image = itsCurrentImage;
00226   pthread_mutex_unlock(&itsCurrentImageLock);
00227   return image;
00228 }
00229 
00230 // ######################################################################
00231 inline uint AgentManagerA::getCurrentFrameNumber()
00232 {
00233   uint fNum;
00234   pthread_mutex_lock(&itsCurrentImageLock);
00235   fNum = itsFrameNumber;
00236   pthread_mutex_unlock(&itsCurrentImageLock);
00237   return fNum;
00238 }
00239 
00240 // // ######################################################################
00241 inline void AgentManagerA::drawImage(rutz::shared_ptr<Image<PixRGB<byte> > > ima)
00242 {
00243   pthread_mutex_lock(&itsDisplayLock);
00244   itsWindow->drawImage(*ima, 0, 0);
00245   pthread_mutex_unlock(&itsDisplayLock);
00246 
00247 }
00248 #endif
00249 
00250 // ######################################################################
00251 /* So things look consistent in everyone's emacs... */
00252 /* Local Variables: */
00253 /* indent-tabs-mode: nil */
00254 /* End: */
Generated on Sun May 8 08:40:16 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3