Homepage Demos Overview Downloads Tutorials Reference
Credits

LostTargetTrans.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LostTargetTrans_h_
00003 #define INCLUDED_LostTargetTrans_h_
00004 
00005 #include "Behaviors/Transitions/TimeOutTrans.h"
00006 #include "Events/VisionObjectEvent.h"
00007 
00008 
00009 //! Causes a transition if the target has not been seen @e minframe times within
00010 //! @e delay milliseconds.
00011 
00012 class LostTargetTrans : public TimeOutTrans {
00013  public:
00014 
00015   //! constructor, specify delay in milliseconds
00016   LostTargetTrans(StateNode* destination, unsigned int source_id,
00017       unsigned int delay, int minframes=5) :
00018     TimeOutTrans("LostTargetTrans","LostTargetTrans",destination,delay),
00019     sid(source_id), minf(minframes), counter(0) {}
00020 
00021   //! constructor, specify delay in milliseconds
00022   LostTargetTrans(const std::string &name, StateNode* destination, unsigned int source_id,
00023       unsigned int delay, int minframes=5) :
00024     TimeOutTrans("LostTargetTrans",name,destination,delay),
00025     sid(source_id), minf(minframes), counter(0) {}
00026 
00027   //!starts timer
00028   virtual void DoStart() {
00029     TimeOutTrans::DoStart();
00030     erouter->addListener(this,EventBase::visObjEGID,sid);
00031   }
00032 
00033   virtual void processEvent(const EventBase &e) {
00034     if (e.getGeneratorID()==EventBase::visObjEGID && e.getSourceID()==sid) {
00035       ++counter;
00036       if (counter > minf) resetTimer();
00037     }
00038     else
00039       TimeOutTrans::processEvent(e);
00040   }
00041 
00042   //! resets timer; does not deactivate it
00043   virtual void resetTimer() {
00044     TimeOutTrans::resetTimer();
00045     counter = 0;
00046   }
00047 
00048   //! set minimum number of frames that target must be seen before resetting the timer
00049   virtual void set_minframes(int minframes) { minf = minframes; }
00050 
00051 protected:
00052   //! constructor, only to be called by subclasses (which need to specify their own @a classname)
00053   LostTargetTrans(const std::string &classname, const std::string &instancename, 
00054       StateNode* destination, unsigned int source_id,
00055       unsigned int delay, int minframes=5) :
00056     TimeOutTrans(classname,instancename,destination,delay),
00057     sid(source_id), minf(minframes), counter(0) {}
00058 
00059 
00060  private:
00061   unsigned int sid; //!< the source id from the detector of the object which is being monitored
00062   int minf;   //!< number of frames that target must be seen before resetting the timer
00063   int counter; //!< number of frames target has been seen so far
00064 };
00065 
00066 #endif

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