Homepage
Demos
Overview
Downloads
Dev. Resources
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 @e delay milliseconds.
00010 class LostTargetTrans : public TimeOutTrans {
00011  public:
00012 
00013   //! constructor, specify delay in milliseconds
00014   LostTargetTrans(StateNode* destination, unsigned int source_id,
00015       unsigned int delay, int minframes=5) :
00016     TimeOutTrans("LostTargetTrans","LostTargetTrans",destination,delay),
00017     sid(source_id), minf(minframes), counter(0) {}
00018 
00019   //! constructor, specify delay in milliseconds
00020   LostTargetTrans(const std::string &name, StateNode* destination, unsigned int source_id,
00021       unsigned int delay, int minframes=5) :
00022     TimeOutTrans("LostTargetTrans",name,destination,delay),
00023     sid(source_id), minf(minframes), counter(0) {}
00024 
00025   //!starts timer
00026   virtual void DoStart() {
00027     TimeOutTrans::DoStart();
00028     erouter->addListener(this,EventBase::visObjEGID,sid);
00029   }
00030 
00031   virtual void processEvent(const EventBase &e) {
00032     if (e.getGeneratorID()==EventBase::visObjEGID && e.getSourceID()==sid) {
00033       ++counter;
00034       if (counter > minf) resetTimer();
00035     }
00036     else
00037       TimeOutTrans::processEvent(e);
00038   }
00039 
00040   //! resets timer; does not deactivate it
00041   virtual void resetTimer() {
00042     TimeOutTrans::resetTimer();
00043     counter = 0;
00044   }
00045 
00046   //! set minimum number of frames that target must be seen before resetting the timer
00047   virtual void set_minframes(int minframes) { minf = minframes; }
00048 
00049 protected:
00050   //! constructor, only to be called by subclasses (which need to specify their own @a classname)
00051   LostTargetTrans(const std::string &classname, const std::string &instancename, 
00052       StateNode* destination, unsigned int source_id,
00053       unsigned int delay, int minframes=5) :
00054     TimeOutTrans(classname,instancename,destination,delay),
00055     sid(source_id), minf(minframes), counter(0) {}
00056 
00057 
00058  private:
00059   unsigned int sid; //!< the source id from the detector of the object which is being monitored
00060   int minf;   //!< number of frames that target must be seen before resetting the timer
00061   int counter; //!< number of frames target has been seen so far
00062 };
00063 
00064 #endif
00065 
00066 /*! @file
00067  * @brief Defines LostTargetTrans, which causes a transition if the target has not been seen @e minframe times within @e delay milliseconds.
00068  * @author ejt (Creator)
00069  *
00070  * $Author: ejt $
00071  * $Name: tekkotsu-2_4_1 $
00072  * $Revision: 1.4 $
00073  * $State: Exp $
00074  * $Date: 2005/01/04 19:51:41 $
00075  */

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