gml_TrackedVector.h

00001 // gml_TrackedVector.h
00002 //
00003 //   Define the gml_TTrackedVector class.
00004 //
00005 //  Copyright (c) 2004 CLIPS-IMAG
00006 //
00007 //  See the file "gml_LicenseTerms.txt" for information on usage and redistribution
00008 //  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00009 //
00010 //  Created in March 2004 (JL).
00011 
00012 #ifndef __GML_TRACKED_OBJECT__
00013 #define __GML_TRACKED_OBJECT__
00014 
00015 // project headers
00016 #include "gml/image/gml_Geometry.h"
00017 #include "gml/base/gml_Types.h"
00018 #include "gml/base/gml_Errors.h"
00019 #include "gml/base/gml_Queue.h"
00020 
00021 
00022 ////////////////////////////////////////////////////////////////////////////////
00023 //                                                                            //
00024 //                      gml_TTrackedVector class declaration                  //
00025 //                                                                            //
00026 ////////////////////////////////////////////////////////////////////////////////
00027 
00028 ///
00029 /// gml_TTrackedVector --
00030 ///   Representation of objects tracked in 2D by the gml_TTracker class.
00031 ///
00032 class gml_TTrackedVector
00033 {
00034 public:
00035 
00036   ///
00037   /// Event --
00038   ///   Type of events that can occur during tracking
00039   ///
00040   struct Event
00041   {
00042     /// categories of tracking events
00043     enum Type { Noop, Appear, Update, Disappear };
00044 
00045     Type                  fType;        ///< type of the event
00046     UInt32                fIdentity;    ///< unique identifier of the event source object
00047     UInt64                fTimeStamp;   ///< event generation timestamp (nanoseconds)
00048     gml_TArray<Float32>   fFeatures;    ///< current object features
00049     char *Name ();                      ///< name associated with the event's type
00050   };
00051 
00052 
00053   ///
00054   /// EventQueue --
00055   ///   Queues of tracking events
00056   ///
00057   typedef gml_TQueue<Event> EventQueue;
00058 
00059 
00060   ///
00061   /// State -- 
00062   ///   Internal tracking state of a tracked object
00063   ///
00064   ///   Possible state transitions:
00065   ///   @verbatim
00066   ///             .-> Alive <--> Zombie -,
00067   ///       Born -|                      |-> Dead
00068   ///             '----------------------'          @endverbatim
00069   enum State { 
00070     Born,         ///< the object was recently detected
00071     Alive,        ///< the object was consistently detected and is tracked
00072     Zombie,       ///< the object wasn't detected, and might be either gone or missed
00073     Dead          ///< the object is not to be tracked anymore
00074   };
00075 
00076 
00077   /// 
00078   /// Init --
00079   ///   Setup tracked object data
00080   ///
00081   gml_TError Init (
00082     gml_TArray<Float32>&  features,
00083     gml_TArray<Float32>&  weights,
00084     gml_TArray<Float32>&  stability,
00085     EventQueue&           queue,                                  ///< where to push the events
00086     UInt64                startDelay     = sDefaultStartDelay(),  ///< see fStartDelay
00087     UInt64                ttlDelay       = sDefaultTTLDelay()     ///< see fTTLDelay
00088   );
00089   
00090   
00091   ///
00092   /// Dispose --
00093   ///
00094   void Dispose (UInt64 time);
00095   
00096   
00097   ///
00098   /// Update --
00099   ///   Update object's state and possibly generate events;
00100   ///   this version is used when the object has been detected
00101   ///   (i.e. a feature vector has been measured)
00102   ///
00103   gml_TError Update (
00104       UInt64 gap,                     ///< since when (in nanoseconds) ?
00105       UInt64 time,                    ///< the current timestamp (nanoseconds)
00106       gml_TArray<Float32>& features   ///< the current object features (or an empty vector)
00107     );
00108 
00109 
00110   ///
00111   /// Update --
00112   ///   Update object's state and possibly generate events;
00113   ///   this version is used when the object has not been detected
00114   ///   (i.e. a feature vector has not been measured)
00115   ///
00116   gml_TError Update (
00117       UInt64 gap,                     ///< since when (in nanoseconds) ?
00118       UInt64 time                     ///< the current timestamp (nanoseconds)
00119     );
00120 
00121 
00122   /// 
00123   /// GetState --
00124   ///   Return the current state of the tracked object
00125   ///
00126   State GetState () { return fState; }
00127   
00128   /// 
00129   /// Distance --
00130   ///
00131   ///   Return the distance to another set of features.
00132   ///   May return 0 or FLT_MAX.
00133   ///
00134   Float32 Distance (gml_TArray<Float32>& otherFeatures);
00135   
00136   /// 
00137   /// Bracket Operator --
00138   ///
00139   ///   Inspect feature values.
00140   ///
00141   Float32 operator[] (unsigned k) {
00142     return fFeatures[k];
00143   }
00144 
00145 protected:
00146 
00147   UInt32    fIdentity;                  ///< UID of the object
00148   UInt64    fLifeTime;                  ///< time since the object was born   (relevant while in Born state)
00149   UInt64    fTimeToLive;                ///< remaining lifetime of the object (relevant while in Zombie state)
00150   State     fState;                     ///< current object state
00151   
00152   UInt64    fStartDelay;                ///< time after which a consistently detected object will be tracked (nanoseconds).
00153                                         ///< i.e. delay for the Born -> Alive transition
00154   UInt64    fTTLDelay;                  ///< time after which an object will die if undetected (nanoseconds).
00155                                         ///< i.e. delay for the Zombie -> Dead transition
00156 
00157   gml_TArray<Float32>  fFeatures;       ///< tracked object's current feature vector
00158   gml_TArray<Float32>& fWeights;        ///< weight of features when comparing feature vectors
00159   gml_TArray<Float32>& fStaticStability;///< threshold under which object motion is discarded (for each feature)
00160   EventQueue&          fQueue;          ///< queue in which to push the tracking events
00161 
00162 
00163 public:
00164 
00165   // errors
00166   static gml_TError sErrorBadState;
00167 
00168   // defaults
00169   static UInt64   sDefaultStartDelay() { return (UInt64) 150e6; } ///< default for fStartDelay
00170   static UInt64   sDefaultTTLDelay()   { return (UInt64) 250e6; } ///< default for fTTLDelay
00171   static Float32  sDefaultStaticStability() { return 1.0F; }      ///< default for fStaticStability
00172 
00173 protected:
00174   // setup
00175   static void ClassInit ();     ///< class setup
00176   static bool sModuleInited;    ///< was ClassInit() called ? 
00177   
00178   // feature update
00179   void UpdateFeatures (gml_TArray<Float32>& newFeatures);
00180   
00181 };
00182 
00183 #endif /* __GML_TRACKED_OBJECT__ */
00184 
Generated on Tue Jun 12 14:03:28 2007 for gml by Doxygen 1.5.2.