Homepage Demos Overview Downloads Tutorials Reference
Credits

VisualTargetTrans.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_VisualTargetTrans_h_
00003 #define INCLUDED_VisualTargetTrans_h_
00004 
00005 #include "Events/EventRouter.h"
00006 #include "Events/VisionObjectEvent.h"
00007 #include "Shared/debuget.h"
00008 #include "Shared/WorldState.h"
00009 
00010 //! causes a transition when a visual object is "close"
00011 class VisualTargetTrans : public Transition {
00012 public:
00013   //!constructor
00014   VisualTargetTrans(StateNode* destination, unsigned int source_id)
00015     : Transition("VisualTargetTrans",destination), sid(source_id), count(0) {}
00016 
00017   //!constructor
00018   VisualTargetTrans(const std::string& name, StateNode* destination, unsigned int source_id)
00019     : Transition("VisualTargetTrans",name,destination), sid(source_id), count(0) {}
00020 
00021   //!starts listening for the object specified by the source id in the constructor
00022   virtual void DoStart() {
00023     //serr->printf("VisualTargetTrans::DoStart() - enter\n");
00024     Transition::DoStart();
00025     count=0;
00026     erouter->addListener(this,EventBase::visObjEGID,sid);
00027     //serr->printf("VisualTargetTrans::DoStart() - leave\n");
00028   }
00029 
00030   //!called by StateNode when it becomes inactive - undo whatever you did in Enable()
00031   virtual void DoStop() {
00032     //serr->printf("VisualTargetTrans::DoStop() - enter\n");
00033     erouter->removeListener(this);
00034     count=0;
00035     Transition::DoStop();
00036     //serr->printf("VisualTargetTrans::DoStop() - leave\n");
00037   }
00038 
00039   //!if the object is "close", calls fire()
00040   virtual void processEvent(const EventBase& e) {
00041     //serr->printf("VisualTargetTrans::processEvent() - enter %d\n",get_time());
00042 
00043     if(e.getTypeID()==EventBase::deactivateETID)
00044       count=0;
00045     else
00046       count++;
00047     if(count>5)
00048       fire();
00049 
00050     //serr->printf("VisualTargetTrans::processEvent() - leave %d\n",get_time());
00051   }
00052 
00053 protected:
00054   //!Source ID of object to track
00055   unsigned int sid;
00056   //! number of frames for which we've seen the object
00057   unsigned int count;
00058 };
00059 
00060 /*! @file
00061  * @brief Defines VisualTargetTrans, which causes a transition when a visual object is seen for a few frames
00062  * @author ejt (Creator)
00063  *
00064  * $Author: ejt $
00065  * $Name: tekkotsu-2_2_2 $
00066  * $Revision: 1.13 $
00067  * $State: Exp $
00068  * $Date: 2004/11/15 22:46:19 $
00069  */
00070 
00071 #endif

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:15 2005 by Doxygen 1.4.0