00001 /*!@file SeaBee/AgentManagerB.H management class for agents on COM-B*/ 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/AgentManagerB.H $ 00035 // $Id: AgentManagerB.H 10794 2009-02-08 06:21:09Z itti $ 00036 // 00037 00038 #ifndef BEOSUB_BEEBRAIN_AGENT_MANAGER_B_H_DEFINED 00039 #define BEOSUB_BEEBRAIN_AGENT_MANAGER_B_H_DEFINED 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 "GUI/XWinManaged.H" 00050 00051 #include "Globals.H" 00052 #include "DownwardVision.H" 00053 #include "SonarListen.H" 00054 00055 #include "AgentManagerCommand.H" 00056 #include "SubmarineAgent.H" 00057 00058 #include "Util/Timer.H" 00059 00060 #include <pthread.h> 00061 00062 class DownwardVisionAgent; 00063 class SonarListenAgent; 00064 00065 class AgentManagerB : public ModelComponent 00066 { 00067 public: 00068 00069 // ###################################################################### 00070 /*! @name Constructors and Destructors */ 00071 //@{ 00072 00073 //! Constructor 00074 AgentManagerB(OptionManager& mgr, 00075 const std::string& descrName = "Agent Manager B", 00076 const std::string& tagName = "Agent Manager B"); 00077 00078 //! Destructor 00079 virtual ~AgentManagerB(); 00080 00081 //@} 00082 00083 // ###################################################################### 00084 //! @name Access functions 00085 //@{ 00086 00087 //! set the current image to be processed 00088 void setCurrentImageF(Image<PixRGB<byte> > image, uint fNum); 00089 void setCurrentImageB(Image<PixRGB<byte> > image, uint fNum); 00090 00091 inline void setWindow(rutz::shared_ptr<XWinManaged> win); 00092 // Image<PixRGB<byte> > ima); 00093 inline void setWindowB(rutz::shared_ptr<XWinManaged> win, 00094 Image<PixRGB<byte> > ima); 00095 00096 void pushResult(SensorResult sensorResult); 00097 00098 //! get the current image to be processed 00099 inline Image<PixRGB<byte> > getCurrentImage(); 00100 00101 //! get the current frame number 00102 inline uint getCurrentFrameNumber(); 00103 00104 //! update the missions of all of agent manager's agents 00105 void updateAgentsMission(Mission theMission); 00106 00107 rutz::shared_ptr<DownwardVisionAgent> getDownwardVisionAgent(); 00108 00109 rutz::shared_ptr<SonarListenAgent> getSonarListenAgent(); 00110 00111 uint getNumResults(); 00112 00113 SensorResult popResult(); 00114 00115 inline void drawImage(Image<PixRGB<byte> > ima);//, Point2D<int> point); 00116 // void drawImageB(Image<PixRGB<byte> > ima, Point2D<int> point); 00117 00118 //@} 00119 00120 // ###################################################################### 00121 //! @name member functions 00122 //@{ 00123 00124 //@} 00125 00126 private: 00127 00128 // collection of all the agent manager's agents 00129 std::vector<rutz::shared_ptr<SubmarineAgent> > itsSubmarineAgents; 00130 00131 // for display purposes 00132 rutz::shared_ptr<XWinManaged> itsWindow; 00133 Image<PixRGB<byte> > itsDisplayImage; 00134 pthread_mutex_t itsDisplayLock; 00135 00136 // the current image and lock 00137 Image<PixRGB<byte> > itsCurrentImage; 00138 uint itsFrameNumber; 00139 rutz::shared_ptr<Timer> itsInputImageTimer; 00140 std::vector<uint64> itsFrameDuration; 00141 pthread_mutex_t itsCurrentImageLock; 00142 00143 // for display purposes B 00144 rutz::shared_ptr<XWinManaged> itsWindowB; 00145 Image<PixRGB<byte> > itsDisplayImageB; 00146 pthread_mutex_t itsDisplayLockB; 00147 00148 // the current image and lock B 00149 Image<PixRGB<byte> > itsCurrentImageB; 00150 uint itsFrameNumberB; 00151 rutz::shared_ptr<Timer> itsInputImageTimerB; 00152 std::vector<uint64> itsFrameDurationB; 00153 pthread_mutex_t itsCurrentImageLockB; 00154 00155 // forward vision agent 00156 rutz::shared_ptr<DownwardVisionAgent> itsDownwardVisionAgent; 00157 pthread_t itsDownwardVisionAgentThread; 00158 00159 // prefrontal cortex agent: decision maker 00160 rutz::shared_ptr<SonarListenAgent> itsSonarListenAgent; 00161 pthread_t itsSonarListenAgentThread; 00162 00163 // the results of the commands processed 00164 std::vector<SensorResult> itsResults; 00165 pthread_mutex_t itsResultsLock; 00166 00167 }; 00168 00169 // // ###################################################################### 00170 inline void AgentManagerB::drawImage(Image<PixRGB<byte> > ima) 00171 { 00172 pthread_mutex_lock(&itsDisplayLock); 00173 itsWindow->drawImage(ima, 0, 0); 00174 pthread_mutex_unlock(&itsDisplayLock); 00175 00176 } 00177 00178 // ###################################################################### 00179 inline void AgentManagerB::setWindow(rutz::shared_ptr<XWinManaged> win) 00180 //Image<PixRGB<byte> > ima) 00181 { 00182 itsWindow = win; 00183 // itsDisplayImage = ima; 00184 } 00185 00186 00187 // ###################################################################### 00188 inline void AgentManagerB::setWindowB(rutz::shared_ptr<XWinManaged> win, 00189 Image<PixRGB<byte> > ima) 00190 { 00191 itsWindowB = win; 00192 itsDisplayImageB = ima; 00193 } 00194 00195 // ###################################################################### 00196 inline Image<PixRGB<byte> > AgentManagerB::getCurrentImage() 00197 { 00198 Image<PixRGB<byte> > image; 00199 pthread_mutex_lock(&itsCurrentImageLock); 00200 image = itsCurrentImage; 00201 pthread_mutex_unlock(&itsCurrentImageLock); 00202 return image; 00203 } 00204 00205 // ###################################################################### 00206 inline uint AgentManagerB::getCurrentFrameNumber() 00207 { 00208 uint fNum; 00209 pthread_mutex_lock(&itsCurrentImageLock); 00210 fNum = itsFrameNumber; 00211 pthread_mutex_unlock(&itsCurrentImageLock); 00212 return fNum; 00213 } 00214 00215 #endif 00216 00217 // ###################################################################### 00218 /* So things look consistent in everyone's emacs... */ 00219 /* Local Variables: */ 00220 /* indent-tabs-mode: nil */ 00221 /* End: */