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/AgentManager.H $ 00035 // $Id: AgentManager.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 #include "Component/ModelManager.H" 00044 00045 #include "Raster/Raster.H" 00046 #include "Image/Image.H" 00047 #include "Image/Pixels.H" 00048 #include "Image/CutPaste.H" 00049 00050 #include "Neuro/EnvVisualCortex.H" 00051 00052 #include "GUI/XWinManaged.H" 00053 00054 #include "Globals.H" 00055 #include "AgentManagerCommand.H" 00056 00057 #include "ForwardVision.H" 00058 // #include "Captain.H" 00059 // #include "Movement.H" 00060 #include "SubController.H" 00061 #include "SensorResult.H" 00062 // #include "DownwardVision.H" 00063 // #include "SonarListen.H" 00064 00065 #include "GUI/DebugWin.H" 00066 00067 #include "Util/Timer.H" 00068 #include <pthread.h> 00069 00070 //class CaptainAgent; 00071 //class MovementAgent; 00072 class ForwardVisionAgent; 00073 //class DownwardVisionAgent; 00074 //class SonarListenAgent; 00075 00076 class AgentManager : public ModelComponent 00077 { 00078 public: 00079 00080 // ###################################################################### 00081 /*! @name Constructors and Destructors */ 00082 //@{ 00083 00084 //! Constructor 00085 AgentManager(nub::soft_ref<SubController> subController, 00086 nub::soft_ref<EnvVisualCortex> evc, 00087 ModelManager& mgr, 00088 const std::string& descrName = "Agent Manager", 00089 const std::string& tagName = "Agent Manager"); 00090 00091 //! Destructor 00092 virtual ~AgentManager(); 00093 00094 //@} 00095 00096 // ###################################################################### 00097 //! @name Access functions 00098 //@{ 00099 00100 //! set the current image to be processed 00101 void setCurrentForwardImage(Image<PixRGB<byte> > image, uint fNum); 00102 00103 void setCurrentDownwardImage(Image<PixRGB<byte> > image, uint fNum); 00104 00105 00106 inline void setSubController(nub::soft_ref<SubController> subController); 00107 00108 inline void setForwardWindow(rutz::shared_ptr<XWinManaged> win); 00109 00110 inline void setDownwardWindow(rutz::shared_ptr<XWinManaged> win); 00111 00112 00113 void pushCommand(CommandType cmdType, 00114 rutz::shared_ptr<Mission> mission); 00115 00116 //! get the current image to be processed 00117 inline Image<PixRGB<byte> > getCurrentForwardImage(); 00118 inline Image<PixRGB<byte> > getCurrentDownwardImage(); 00119 00120 //! get the current frame number 00121 inline uint getCurrentFrameNumber(); 00122 00123 inline void setWindow(rutz::shared_ptr<XWinManaged> win); 00124 00125 inline void setVisualCortex(nub::ref<EnvVisualCortex> evc); 00126 00127 inline void drawForwardImage(rutz::shared_ptr< Image<PixRGB<byte> > > ima); 00128 inline void drawDownwardImage(rutz::shared_ptr< Image<PixRGB<byte> > > ima); 00129 00130 //! initialize the vector of SensorResults 00131 void initSensorResults(); 00132 00133 //! set the current object to be processed 00134 bool updateSensorResult(rutz::shared_ptr<SensorResult> sensorResult); 00135 00136 //! update the missions of all of agent manager's agents 00137 void updateAgentsMission(Mission theMission); 00138 00139 // rutz::shared_ptr<DownwardVisionAgent> getDownwardVisionAgent(); 00140 00141 // rutz::shared_ptr<SonarListenAgent> getSonarListenAgent(); 00142 00143 rutz::shared_ptr<ForwardVisionAgent> getForwardVisionAgent(); 00144 00145 // rutz::shared_ptr<CaptainAgent> getCaptainAgent(); 00146 00147 // rutz::shared_ptr<MovementAgent> getMovementAgent(); 00148 00149 uint getNumCommands(); 00150 00151 rutz::shared_ptr<SensorResult> getSensorResult(SensorResult::SensorResultType type); 00152 00153 rutz::shared_ptr<AgentManagerCommand> popCommand(); 00154 00155 void startRun(); 00156 00157 int itsMissionGateForwardTime; 00158 int itsMissionGateDepth; 00159 00160 const Image<PixRGB<byte> >* getForwardDebugImagePtr(); 00161 00162 //@} 00163 00164 private: 00165 00166 Image<PixRGB<byte> > itsForwardDebugImage; 00167 00168 // for display purposes 00169 rutz::shared_ptr<XWinManaged> itsForwardWindow; 00170 rutz::shared_ptr<XWinManaged> itsDownwardWindow; 00171 Image<PixRGB<byte> > itsDisplayImage; 00172 pthread_mutex_t itsForwardDisplayLock; 00173 pthread_mutex_t itsDownwardDisplayLock; 00174 00175 // the current image and lock 00176 Image<PixRGB<byte> > itsCurrentForwardImage; 00177 Image<PixRGB<byte> > itsCurrentDownwardImage; 00178 uint itsFrameNumber; 00179 rutz::shared_ptr<Timer> itsTimer; 00180 std::vector<uint64> itsFrameDuration; 00181 pthread_mutex_t itsCurrentForwardImageLock; 00182 pthread_mutex_t itsCurrentDownwardImageLock; 00183 00184 // // downward vision agent 00185 // rutz::shared_ptr<DownwardVisionAgent> itsDownwardVisionAgent; 00186 // pthread_t itsDownwardVisionAgentThread; 00187 00188 // // sonar agent 00189 // rutz::shared_ptr<SonarListenAgent> itsSonarListenAgent; 00190 // pthread_t itsSonarListenAgentThread; 00191 00192 // forward vision agent 00193 rutz::shared_ptr<ForwardVisionAgent> itsForwardVisionAgent; 00194 // pthread_t itsForwardVisionAgentThread; 00195 00196 // // prefrontal cortex agent: decision maker 00197 // rutz::shared_ptr<CaptainAgent> itsCaptainAgent; 00198 // pthread_t itsCaptainAgentThread; 00199 00200 // // premotor complex agent: generate motor commands 00201 // rutz::shared_ptr<MovementAgent> itsMovementAgent; 00202 // pthread_t itsMovementAgentThread; 00203 00204 // collection of all the agent manager's agents 00205 // std::vector<rutz::shared_ptr<SubmarineAgent> > itsSubmarineAgents; 00206 00207 // SubController 00208 nub::soft_ref<SubController> itsSubController; 00209 pthread_mutex_t itsSubControllerLock; 00210 00211 // store the ocean objects 00212 std::vector<rutz::shared_ptr<SensorResult> > itsSensorResults; 00213 std::vector<rutz::shared_ptr<SensorResult> >::iterator itsSensorResultsItr; 00214 00215 pthread_mutex_t itsSensorResultsLock; 00216 00217 // command cue to send to COM_B 00218 std::list<rutz::shared_ptr<AgentManagerCommand> > itsCommands; 00219 pthread_mutex_t itsCommandsLock; 00220 00221 nub::soft_ref<EnvVisualCortex> itsEVC; 00222 00223 }; 00224 00225 // ###################################################################### 00226 inline void AgentManager::setSubController(nub::soft_ref<SubController> subController) 00227 { 00228 pthread_mutex_lock(&itsSubControllerLock); 00229 itsSubController = subController; 00230 pthread_mutex_unlock(&itsSubControllerLock); 00231 } 00232 00233 // ###################################################################### 00234 inline void AgentManager::setForwardWindow(rutz::shared_ptr<XWinManaged> win) 00235 { 00236 itsForwardWindow = win; 00237 //itsDisplayImage = ima; 00238 } 00239 00240 // ###################################################################### 00241 inline void AgentManager::setDownwardWindow(rutz::shared_ptr<XWinManaged> win) 00242 { 00243 itsDownwardWindow = win; 00244 //itsDisplayImage = ima; 00245 } 00246 00247 // ###################################################################### 00248 inline void AgentManager::setVisualCortex 00249 (nub::ref<EnvVisualCortex> evc) 00250 { 00251 itsEVC = evc; 00252 } 00253 00254 // ###################################################################### 00255 inline Image<PixRGB<byte> > AgentManager::getCurrentForwardImage() 00256 { 00257 Image<PixRGB<byte> > image; 00258 pthread_mutex_lock(&itsCurrentForwardImageLock); 00259 image = itsCurrentForwardImage; 00260 pthread_mutex_unlock(&itsCurrentForwardImageLock); 00261 return image; 00262 } 00263 00264 // ###################################################################### 00265 inline Image<PixRGB<byte> > AgentManager::getCurrentDownwardImage() 00266 { 00267 Image<PixRGB<byte> > image; 00268 pthread_mutex_lock(&itsCurrentDownwardImageLock); 00269 image = itsCurrentDownwardImage; 00270 pthread_mutex_unlock(&itsCurrentDownwardImageLock); 00271 return image; 00272 } 00273 00274 // ###################################################################### 00275 inline uint AgentManager::getCurrentFrameNumber() 00276 { 00277 uint fNum; 00278 pthread_mutex_lock(&itsCurrentForwardImageLock); 00279 fNum = itsFrameNumber; 00280 pthread_mutex_unlock(&itsCurrentForwardImageLock); 00281 return fNum; 00282 } 00283 00284 // // ###################################################################### 00285 inline void AgentManager::drawForwardImage(rutz::shared_ptr<Image<PixRGB<byte> > > ima) 00286 { 00287 pthread_mutex_lock(&itsForwardDisplayLock); 00288 itsForwardWindow->drawImage(*ima, 0, 0); 00289 pthread_mutex_unlock(&itsForwardDisplayLock); 00290 00291 } 00292 00293 // // ###################################################################### 00294 inline void AgentManager::drawDownwardImage(rutz::shared_ptr<Image<PixRGB<byte> > > ima) 00295 { 00296 pthread_mutex_lock(&itsDownwardDisplayLock); 00297 itsDownwardWindow->drawImage(*ima, 0, 0); 00298 pthread_mutex_unlock(&itsDownwardDisplayLock); 00299 00300 } 00301 #endif 00302 00303 // ###################################################################### 00304 /* So things look consistent in everyone's emacs... */ 00305 /* Local Variables: */ 00306 /* indent-tabs-mode: nil */ 00307 /* End: */