NITE 1.5.1 - API Reference

XnVSessionManager.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *                                                                              *
00003 *   PrimeSense NITE 1.3                                                        *
00004 *   Copyright (C) 2010 PrimeSense Ltd.                                         *
00005 *                                                                              *
00006 *******************************************************************************/
00007 
00008 
00009 #ifndef _XNV_SESSION_MANAGER_H_
00010 #define _XNV_SESSION_MANAGER_H_
00011 
00012 #include "XnVDeviceControl.h"
00013 #include "XnVMessageGenerator.h"
00014 #include "XnVMultipleHands.h"
00015 #include "XnVGesture.h"
00016 #include "XnVPointTracker.h"
00017 #include "XnVPointMessage.h"
00018 #include "XnVSessionGenerator.h"
00019 #include "XnV3DVector.h"
00020 #include "XnVSteadyDetector.h"
00021 
00022 class XnVGestureHash;
00032 class XNV_NITE_API XnVSessionManager :
00033     public XnVContextControl,
00034     public XnVSessionGenerator
00035 {
00036 public:
00042     XnVSessionManager(const XnChar* strName = "XnVSessionManager");
00043     ~XnVSessionManager();
00044 
00057     XnStatus Initialize(xn::Context* pContext,
00058                         const XnChar* strUseAsFocus, const XnChar* strUseAsQuickRefocus,
00059                         xn::HandsGenerator* pTracker = NULL, xn::GestureGenerator* pFocusGenerator = NULL,
00060                         xn::GestureGenerator* pQuickRefocusGenerator = NULL);
00061 
00069     void Update(XnVMessage* pMessage);
00075     void Update(const xn::Context* pContext);
00081     void ProcessPoints(XnVMultipleHands* pHands);
00082 
00088     void SetTracker(XnVPointTracker* pTracker);
00089     void SetTracker(xn::HandsGenerator generator);
00090 
00096     void SetQuickRefocusTimeout(XnUInt32 nMilliseconds);
00097     XnUInt32 GetQuickRefocusTimeout() const;
00098 
00104     XnStatus LosePoint(XnUInt32 nID);
00108     XnStatus LosePoints();
00109 
00113     XnStatus EndSession();
00119     XnStatus ForceSession(const XnPoint3D& ptFocus);
00125     XnStatus TrackPoint(const XnPoint3D& pt);
00126 
00130     void ClearQueue();
00131 
00137     XnStatus SetQuickRefocusArea(const XnBoundingBox3D& bbQuickRefocusArea);
00145     XnStatus SetQuickRefocusArea(XnFloat fLengthX, XnFloat fLengthY, XnFloat fLengthZ);
00146 
00147     void GetQuickRefocusArea(XnFloat& fLengthX, XnFloat& fLengthY, XnFloat& fLengthZ);
00154     void ForceQuickRefocus(XnBoundingBox3D* pbbForcedArea, XnUInt32 nForcedTimeout);
00155 
00163     XnUInt32 AddGesture(XnVGesture* pGesture);
00172     XnUInt32 AddGesture(xn::GestureGenerator& generator, const XnChar* strName);
00181     XnUInt32 AddGesture(xn::Context& context, const XnChar* strName);
00187     void RemoveGesture(XnUInt32 nId);
00188 
00196     XnUInt32 AddQuickRefocus(XnVGesture* pGesture);
00205     XnUInt32 AddQuickRefocus(xn::GestureGenerator& generator, const XnChar* strName);
00214     XnUInt32 AddQuickRefocus(xn::Context& context, const XnChar* strName);
00220     void RemoveQuickRefocus(XnUInt32 nId);
00221 
00225     void StartPrimaryStatic();
00229     void StopPrimaryStatic();
00235     void SetPrimaryStaticTimeout(XnFloat fTimeout);
00241     XnFloat GetPrimarySteadyTimeout() const;
00242 
00251     void SetPrimaryStaticBoundingBox(XnFloat fX, XnFloat fY, XnFloat fZ);
00259     void GetPrimaryStaticBoundingBox(XnFloat& fX, XnFloat& fY, XnFloat& fZ);
00260 
00261     XnStatus XN_API_DEPRECATED("Please use Initialize() instead.")
00262         Initialize(XnVGesture* pFocusGesture, XnVGesture* pQuickRefocusGesture, XnVPointTracker* pTracker);
00263 
00264     void XN_API_DEPRECATED("Please use AddGesture() instead.")
00265         SetGesture(XnVGesture* pGesture);
00266     void XN_API_DEPRECATED("Please use AddGesture() instead.")
00267         SetGesture(xn::GestureGenerator gestureGenerator, const XnChar* strGestures);
00268 
00269     void XN_API_DEPRECATED("Please use AddQuickRefocus() instead.")
00270         SetQRGesture(XnVGesture* pGesture);
00271     void XN_API_DEPRECATED("Please use AddQuickRefocus() instead.")
00272         SetQRGesture(xn::GestureGenerator gestureGenerator, const XnChar* strGestures);
00273 
00274 protected:
00275 
00276     void SessionStop();
00277     void StartQuickRefocus(XnBoundingBox3D* pbbROI, XnUInt32 nTimeout);
00278 
00279     XnStatus FindTracker(xn::Context* pContext, xn::HandsGenerator* pTracker, xn::HandsGenerator& tracker);
00280 
00281     static void XN_CALLBACK_TYPE Gesture_Recognized(const XnChar* strGesture, const XnPoint3D& ptIDPosition, const XnPoint3D& ptEndPosition, void* cxt);
00282     static void XN_CALLBACK_TYPE Gesture_StartRecognized(const XnChar* strGesture, const XnPoint3D& pos, XnFloat fProgress, void* cxt);
00283     void GestureRecognized(const XnChar* strGesture, const XnPoint3D& ptIDPosition, const XnPoint3D& ptEndPosition);
00284     void GestureStartRecognized(const XnChar* strGesture, const XnPoint3D& pos, XnFloat fProgress);
00285 
00286     XnUInt64 GetTime();
00287 
00288     void EnableGestures(XnBoundingBox3D* pROI = NULL);
00289     void EnableQuickRefocusGestures(XnBoundingBox3D* pROI = NULL);
00290     void DisableGestures();
00291     void DisableQuickRefocusGestures();
00292     void UpdateGestures(const xn::Context* pContext);
00293     void UpdateQuickRefocusGestures(const xn::Context* pContext);
00294 
00295     XnBool m_bGesturesEnabled;
00296     XnBool m_bQuickRefocusEnabled;
00297 
00298     void ClearGestureHash(XnVGestureHash& hash);
00299     XnVGestureHash* m_pMainGestures;
00300     XnVGestureHash* m_pQuickRefocusGestures;
00301     XnUInt32 m_nNextGestureID;
00302 
00303     XnUInt32 AddGesture(XnVGesture* pGesture, XnBool bAuto, XnUInt32 nHintID, XnBool bFocus);
00304 
00305     XnUInt32 AddGesture(xn::Context& context, const XnChar* strName, const XnStringsHash& hash, XnBool bFocus);
00306     XnUInt32 AddGesture(xn::GestureGenerator& generator, const XnChar* strName, const XnStringsHash& hash, XnBool bFocus);
00307 
00308     void RemoveGesture(XnUInt32 nId, XnVGestureHash& hash);
00309 
00310     XnVPointTracker* m_pTracker;
00311     XnBool m_bAutoTracker;
00312 
00313     enum
00314     {
00315         SMGR_ILLEGAL        = 0x0000,
00316         SMGR_NOT_IN_SESSION = 0x0001,
00317         SMGR_IN_SESSION     = 0x0002,
00318         SMGR_QUICK_REFOCUS  = SMGR_IN_SESSION | SMGR_NOT_IN_SESSION,
00319         SMGR_START_SESSION  = 0x0004,
00320     } m_eSessionState;
00321 
00322     inline XnBool IsInSession() const {return (m_eSessionState & SMGR_IN_SESSION) != 0;}
00323     inline XnBool IsNotInSession() const {return (m_eSessionState & SMGR_NOT_IN_SESSION) != 0;}
00324     inline XnBool IsQuickRefocus() const {return m_eSessionState == SMGR_QUICK_REFOCUS;}
00325 
00326     XnBool m_bQuickRefocusAllowed;
00327 
00328     XnCallbackHandle m_hGesture;
00329     XnCallbackHandle m_hGestureMid;
00330     XnCallbackHandle m_hQRGesture;
00331 
00332     XnUInt32 m_nQuickRefocusTimeout;
00333     XnUInt64 m_nQuickRefocusExpire;
00334 
00335     static const XnUInt32 ms_nQuickRefocusDefaultTimeout;
00336 
00337     XnV3DVector m_ptLastPrimaryPosition;
00338 
00339     XnBoundingBox3D m_bbQuickRefocusArea;
00340     const xn::Context* m_pContext;
00341 
00342     XnBool m_bCheckPrimaryForStatic;
00343     XnBool m_bPrimaryIsStatic;
00344     XnVSteadyDetector* m_pSteadyDetector;
00345 
00346     static void XN_CALLBACK_TYPE PrimaryIsSteady(XnUInt32 id, XnFloat dummy, void* cxt);
00347     static void XN_CALLBACK_TYPE PrimaryIsNotSteady(XnUInt32 id, XnFloat dummy, void* cxt);
00348 
00349     XnFloat m_fLastSteadyTime;
00350     XnFloat m_fLastPrimaryTime;
00351     XnFloat m_fSteadyTimeout;
00352 
00353     XnUInt32 m_nLastPrimaryID;
00354     XnPoint3D m_GestureWhileTrackingThreshold;
00355 
00356     void InitializeStatic();
00357     void FinalizeStatic();
00358 };
00359 
00360 #endif