VisionBrainComponentI.C

00001  #include "Robots/SeaBeeIII/VisionBrainComponentI.H"
00002 #include "Component/ModelParam.H"
00003 #include "Component/ModelOptionDef.H"
00004 
00005 #ifndef VISIONBRAINCOMPONENTI_C
00006 #define VISIONBRAINCOMPONENTI_C
00007 
00008 const ModelOptionCateg MOC_VisionBrainComponent = {
00009     MOC_SORTPRI_3, "VisionBrainComponent Related Options" };
00010 
00011 const ModelOptionDef OPT_CameraSource =
00012 { MODOPT_ARG(std::string), "CameraSource", &MOC_VisionBrainComponent, OPTEXP_CORE,
00013     "The string description to be matched against incoming Retina messages\n"
00014   "when using Ice as an input source",
00015     "camera-source", '\0', "<string>", "Camera0" };
00016 
00017 // ######################################################################
00018 VisionBrainComponentI::VisionBrainComponentI(OptionManager& mgr,
00019     const std::string& descrName, const std::string& tagName) :
00020   RobotBrainComponent(mgr, descrName, tagName),
00021         itsOfs(new OutputFrameSeries(mgr)),
00022   itsFrameCount(0),
00023   itsCameraSource(&OPT_CameraSource, this, 0),
00024   itsCurrentImgFwdCam(false),
00025   lastFrameCount(-1)
00026 {
00027   //addSubComponent(itsIfs);
00028   addSubComponent(itsOfs);
00029 }
00030 
00031 // ######################################################################
00032 VisionBrainComponentI::~VisionBrainComponentI()
00033 {
00034 }
00035 
00036 void VisionBrainComponentI::registerVisionTopics()
00037 {
00038   LINFO("Registering VisionBrainComponent Message");
00039   this->registerSubscription("RetinaMessageTopic");
00040 }
00041 
00042 void VisionBrainComponentI::registerVisionPublisher(const std::string& MessageTopic)
00043 {
00044   this->registerPublisher(MessageTopic);
00045   registerVisionTopics();
00046 }
00047 
00048 bool VisionBrainComponentI::publishVisionMsg(const::std::string& MessageTopic, RobotSimEvents::EventMessagePtr msg)
00049 {
00050   return this->publish(MessageTopic,msg);
00051 }
00052 
00053 void VisionBrainComponentI::evolve()
00054 {
00055 
00056 //        Image<PixRGB<byte> > img;
00057 //        FrameState fs = itsIfs->updateNext();
00058 //
00059 //        // If using IFS, we do not currently check if img from forward or downward cam
00060 //        if(fs == FRAME_NEXT)
00061 //        {
00062 //                img = itsIfs->readRGB();
00063 //
00064 //                if(img.initialized() && img.size() > 1)
00065 //                {
00066 //                        itsImgMutex.lock();
00067 //                        itsCurrentImg = img;
00068 //                        itsFrameCount++;
00069 //                        itsImgMutex.unlock();
00070 //                }
00071 //        }
00072 //
00073 
00074         itsImgMutex.lock();
00075         {
00076                 if(itsCurrentImg.initialized() && itsFrameCount != lastFrameCount)
00077                 {
00078                         lastFrameCount = itsFrameCount;
00079                         updateFrame(itsCurrentImg, itsCurrentCameraID);
00080                 }
00081         }
00082         itsImgMutex.unlock();
00083                 //
00084 }
00085 
00086 // ######################################################################
00087 void VisionBrainComponentI::updateMessage(const RobotSimEvents::EventMessagePtr& eMsg,
00088                 const Ice::Current&)
00089 {
00090         //Get a retina message
00091         if(eMsg->ice_isA("::RobotSimEvents::RetinaMessage"))
00092         {
00093                 RobotSimEvents::RetinaMessagePtr retinaMessage = RobotSimEvents::RetinaMessagePtr::dynamicCast(eMsg);
00094                 itsImgMutex.lock();
00095                 if(retinaMessage->cameraID == itsCameraSource.getVal() || itsCameraSource.getVal() == "all")
00096                 {
00097                         Image<PixRGB<byte> > retinaImage = Ice2Image<PixRGB<byte> >(retinaMessage->img);
00098                         itsCurrentImg = retinaImage;
00099                         itsCurrentCameraID = retinaMessage->cameraID;
00100 
00101                         if(retinaMessage->cameraID == "FwdCamera")
00102                                 itsCurrentImgFwdCam = true;
00103                         else
00104                                 itsCurrentImgFwdCam = false;
00105 
00106                         itsFrameCount++;
00107 
00108                         //updateFrame(itsCurrentImg, itsCurrentCameraID);
00109                 }
00110                 //      else
00111                 //LINFO("id name does match src %s,%s",retinaMessage->cameraID.c_str(), itsCameraSource.c_str());
00112                 itsImgMutex.unlock();
00113         }
00114 }
00115 
00116 #endif
Generated on Sun May 8 08:05:39 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3