Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

DrawVisObjBoundBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_DrawVisObjBoundBehavior_h_
00003 #define INCLUDED_DrawVisObjBoundBehavior_h_
00004 
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Events/EventRouter.h"
00007 #include "Shared/ProjectInterface.h"
00008 #include "Events/VisionObjectEvent.h"
00009 #include "Events/FilterBankEvent.h"
00010 #include "Vision/Graphics.h"
00011 #include "Shared/Config.h"
00012 #include "Vision/RawCameraGenerator.h"
00013 
00014 //! Draws a boundary box in camera frame around all detected vision object events
00015 class DrawVisObjBoundBehavior : public BehaviorBase {
00016 public:
00017   //! constructor
00018   DrawVisObjBoundBehavior() : BehaviorBase("DrawVisObjBoundBehavior"), objs(), drawn(0) {}
00019 
00020   virtual void DoStart() {
00021     BehaviorBase::DoStart(); // do this first (required)
00022     erouter->addListener(this, EventBase::visObjEGID);
00023     erouter->addListener(this, EventBase::visRawCameraEGID,ProjectInterface::visRawCameraSID,EventBase::statusETID);
00024     erouter->addListener(this, EventBase::visSegmentEGID,ProjectInterface::visSegmentSID,EventBase::statusETID);
00025     //This part isn't done -- we can't draw into RLE images until RLEGraphics is written
00026     //  erouter->addListener(this, EventBase::visRLEEGID,ProjectInterface::visRLESID,EventBase::statusETID);
00027   }
00028 
00029   virtual void DoStop() {
00030     erouter->removeListener(this); //generally a good idea, unsubscribe all
00031     BehaviorBase::DoStop(); // do this last (required)
00032   }
00033 
00034   virtual void processEvent(const EventBase& e) {
00035     if(e.getGeneratorID()==EventBase::visObjEGID) {
00036       if(drawn>=2) {
00037         objs.clear();
00038         drawn=0;
00039       }
00040       if(e.getTypeID()!=EventBase::deactivateETID) {
00041         const VisionObjectEvent& vis=dynamic_cast<const VisionObjectEvent&>(e);
00042         Rect r={vis.getLeft(),vis.getTop(),vis.getWidth(),vis.getHeight()};
00043         objs.push_back(r);
00044       }
00045     } else {
00046       //cache current layer, channel, and pen color (depends on whether we're handling the seg cam or the raw cam
00047       unsigned int layer, chan;
00048       unsigned char color;
00049       const FilterBankEvent& fbe=dynamic_cast<const FilterBankEvent&>(e);
00050       if(e.getGeneratorID()==EventBase::visRawCameraEGID) {
00051         layer=fbe.getNumLayers()-1-config->vision.rawcam_y_skip;
00052         chan=RawCameraGenerator::CHAN_Y;
00053         color=255;
00054       } else if(e.getGeneratorID()==EventBase::visSegmentEGID) {
00055         layer=fbe.getNumLayers()-1-config->vision.rlecam_skip;
00056         chan=config->vision.rlecam_channel;
00057         color=7;
00058       }
00059 
00060       //do the drawing
00061       Graphics g(*fbe.getSource(),layer,chan);
00062       g.setColor(color);
00063       for(std::vector<Rect>::const_iterator it=objs.begin(); it!=objs.end(); ++it)
00064         g.drawRect(it->x,it->y,it->w,it->h);
00065       
00066       //this is only needed until RLEGraphics is in place
00067       //  in the mean time, we trigger the RLE generator to recompress the modified seg cam image
00068       if(config->vision.rlecam_compression==Config::vision_config::COMPRESS_RLE)
00069         ProjectInterface::defRLEGenerator->invalidateCaches();
00070       
00071       drawn++;
00072     }
00073   }
00074 
00075   static std::string getClassDescription() { return "Draws a boundary box in camera frame around all detected vision object events"; }
00076   virtual std::string getDescription() const { return getClassDescription(); }
00077   
00078 
00079 protected:
00080   //! a simple structure for storing bounding box info for each detected object
00081   struct Rect {
00082     float x; //!< left edge, in resolution-independent coordinates
00083     float y; //!< top edge, in resolution-independent coordinates
00084     float w; //!< width, in resolution-independent coordinates
00085     float h; //!< height, in resolution-independent coordinates
00086   };
00087 
00088   std::vector<Rect> objs; //!< vector of boundary boxes from the current frame
00089   unsigned int drawn; //!< a counter of the number of frames that have been updated, when this hits 2, the next vision object will clear the list
00090   
00091 private:
00092   DrawVisObjBoundBehavior(const DrawVisObjBoundBehavior&); //!< don't call (copy constructor)
00093   DrawVisObjBoundBehavior& operator=(const DrawVisObjBoundBehavior&); //!< don't call (assignment operator)
00094 };
00095 
00096 /*! @file
00097  * @brief Defines DrawVisObjBoundBehavior, which draws a boundary box in camera frame around all detected vision object events
00098  * @author ejt (Creator)
00099  *
00100  * $Author: ejt $
00101  * $Name: tekkotsu-2_4_1 $
00102  * $Revision: 1.4 $
00103  * $State: Exp $
00104  * $Date: 2005/08/04 21:09:26 $
00105  */
00106 
00107 #endif

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:46 2005 by Doxygen 1.4.4