DrawVisObjBoundBehavior.hGo to the documentation of this file.00001
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
00015 class DrawVisObjBoundBehavior : public BehaviorBase {
00016 public:
00017
00018 DrawVisObjBoundBehavior() : BehaviorBase("DrawVisObjBoundBehavior"), objs(), drawn(0) {}
00019
00020 virtual void DoStart() {
00021 BehaviorBase::DoStart();
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
00026
00027 }
00028
00029 virtual void DoStop() {
00030 erouter->removeListener(this);
00031 BehaviorBase::DoStop();
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
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
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
00067
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
00081 struct Rect {
00082 float x;
00083 float y;
00084 float w;
00085 float h;
00086 };
00087
00088 std::vector<Rect> objs;
00089 unsigned int drawn;
00090
00091 private:
00092 DrawVisObjBoundBehavior(const DrawVisObjBoundBehavior&);
00093 DrawVisObjBoundBehavior& operator=(const DrawVisObjBoundBehavior&);
00094 };
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 #endif
|