예제 #1
0
    /// @brief Initialize the hand control
    ///
    /// This method provides the initialization for the hands control initializing all internal objects.
    /// It assumes the context is already valid (otherwise we fail).
    /// @note - Since we use a singleton pattern, multiple initializations will simply delete the old
    /// objects and create new ones!
    /// @note - It is the responsibility of the initializer to call @ref Dispose.
    /// @param context the context to use
    /// @param focusGesture the gesture used for focusing (i.e. this is aimed to set the hand which we will follow)
    /// @param refocusGesture the gesture used for refocus (when we lose focus temporarily)
    /// @param logger the logger object we will enter logs into
    /// @return true on success, false on failure.
    public bool Init(NIEventLogger logger, NIContext context, string focusGesture, string refocusGesture)
    {
        Dispose(); // to make sure we are not initialized
        if (InitWithContext(logger, context) == false)
        {
            return(false);
        }
        // we will create the user gestures and hands which are needed for the session manager
        // but are not needed externally (as we never access them directly).
        ProductionNode node = context.CreateNode(NodeType.Gesture);

        if (node == null)
        {
            Dispose();
            return(false);
        }
        m_internalNodes.Add(node);
        node = context.CreateNode(NodeType.Hands) as HandsGenerator;
        if (node == null)
        {
            Dispose();
            return(false);
        }
        m_internalNodes.Add(node);
        try
        {
            NINITECheckVersion.Instance.ValidatePrerequisite();
            m_sessionManager = new SessionManager(context.BasicContext, focusGesture, refocusGesture);
            if (refocusGesture.CompareTo("") == 0)
            {
                m_sessionManager.QuickRefocusTimeout = 0;
            }
            else
            {
                m_sessionManager.QuickRefocusTimeout = 15000;
            }
            m_sessionManager.SessionStart += new System.EventHandler <PositionEventArgs>(HandsControlSessionStart);
            m_sessionManager.SessionEnd   += new System.EventHandler(HandsControlSessionEnd);
            m_pointControl = new PointControl();
            m_sessionManager.AddListener(m_pointControl);
            m_pointControl.PrimaryPointDestroy += new System.EventHandler <IdEventArgs>(SessionLostFocus);
        }
        catch (System.Exception ex)
        {
            Log("failed to create session manager with error " + ex.Message, NIEventLogger.Categories.Errors, NIEventLogger.Sources.Hands);
            Dispose();
            return(false);
        }

        return(true);
    }
예제 #2
0
 /// @brief Initialize the image node.
 /// 
 /// This method initializes the image node. It assumes the context is already valid (otherwise we fail).
 /// @note - Since we use a singleton pattern, multiple initializations will simply delete the old
 /// node and create a new one!
 /// @note - It is the responsibility of the initializer to call @ref Dispose.
 /// @param context the context used
 /// @param logger the logger object we will enter logs into
 /// @return true on success, false on failure. 
 public bool Init(NIEventLogger logger, NIContext context)
 {
     Dispose(); // to make sure we are not initialized
     if (InitWithContext(logger, context) == false)
         return false; 
     m_image = context.CreateNode(NodeType.Image) as ImageGenerator;
     if(m_image==null)
     {
         Dispose();
         return false;
     }
     return true;
 }
예제 #3
0
 /// @brief Initialize the image node.
 ///
 /// This method initializes the image node. It assumes the context is already valid (otherwise we fail).
 /// @note - Since we use a singleton pattern, multiple initializations will simply delete the old
 /// node and create a new one!
 /// @note - It is the responsibility of the initializer to call @ref Dispose.
 /// @param context the context used
 /// @param logger the logger object we will enter logs into
 /// @return true on success, false on failure.
 public bool Init(NIEventLogger logger, NIContext context)
 {
     Dispose(); // to make sure we are not initialized
     if (InitWithContext(logger, context) == false)
     {
         return(false);
     }
     m_image = context.CreateNode(NodeType.Image) as ImageGenerator;
     if (m_image == null)
     {
         Dispose();
         return(false);
     }
     return(true);
 }
예제 #4
0
    /// @brief Initialize the user and skeleton information
    ///
    /// This method initializes the user and skeleton information. It assumes the
    /// context is already valid (otherwise we fail).
    /// @note - Since we use a singleton pattern, multiple initializations will simply delete
    /// the old information and create new one!
    /// @note - It is the responsibility of the initializer to call @ref Dispose.
    /// @param context the context used
    /// @param logger the logger object we will enter logs into
    /// @return true on success, false on failure.
    public bool Init(NIEventLogger logger, NIContext context)
    {
        NIOpenNICheckVersion.Instance.ValidatePrerequisite();
        Dispose(); // to make sure we are not initialized
        if (InitWithContext(logger, context) == false)
        {
            return(false);
        }

        m_userGenerator = context.CreateNode(NodeType.User) as UserGenerator;
        if (m_userGenerator == null || m_userGenerator.SkeletonCapability == null)
        {
            Log("Failed to create proper user generator.", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.Skeleton, NIEventLogger.VerboseLevel.Errors);
            // we either don't have a user generator or the user generator we received does not have a skeleton
            Dispose();
            return(false);
        }
        // skeleton heuristics tries to handle the skeleton when the confidence is low. It can
        // have two values: 0 (no heuristics) or 255 (use heuristics).
        m_userGenerator.SetIntProperty("SkeletonHeuristics", 255);
        // makes sure we use all joints
        m_userGenerator.SkeletonCapability.SetSkeletonProfile(SkeletonProfile.All);
        PoseDetectionCapability cap = UserNode.PoseDetectionCapability;

        if (cap != null)
        {
            m_legalPoses = cap.GetAllAvailablePoses();
        }
        else
        {
            m_legalPoses = null;
        }
        m_poseDetectionCounter    = new List <poseDetectionReferenceCounter>();
        m_userGenerator.LostUser += new EventHandler <UserLostEventArgs>(LostUserCallback);

        return(true);
    }
예제 #5
0
    /// @brief Initialize the user and skeleton information
    /// 
    /// This method initializes the user and skeleton information. It assumes the 
    /// context is already valid (otherwise we fail).
    /// @note - Since we use a singleton pattern, multiple initializations will simply delete 
    /// the old information and create new one!
    /// @note - It is the responsibility of the initializer to call @ref Dispose.
    /// @param context the context used
    /// @param logger the logger object we will enter logs into
    /// @return true on success, false on failure. 
    public bool Init(NIEventLogger logger, NIContext context)
    {
        NIOpenNICheckVersion.Instance.ValidatePrerequisite();
        Dispose(); // to make sure we are not initialized
        if (InitWithContext(logger, context) == false)
            return false;

        m_userGenerator = context.CreateNode(NodeType.User) as UserGenerator;
        if (m_userGenerator == null || m_userGenerator.SkeletonCapability==null)
        {
            Log("Failed to create proper user generator.", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.Skeleton, NIEventLogger.VerboseLevel.Errors);
            // we either don't have a user generator or the user generator we received does not have a skeleton
            Dispose();
            return false;
        }
        // skeleton heuristics tries to handle the skeleton when the confidence is low. It can
        // have two values: 0 (no heuristics) or 255 (use heuristics).
        m_userGenerator.SetIntProperty("SkeletonHeuristics", 255);
        // makes sure we use all joints
        m_userGenerator.SkeletonCapability.SetSkeletonProfile(SkeletonProfile.All);
        PoseDetectionCapability cap = UserNode.PoseDetectionCapability;
        if (cap != null)
            m_legalPoses = cap.GetAllAvailablePoses();
        else
            m_legalPoses = null;
        m_poseDetectionCounter = new List<poseDetectionReferenceCounter>();
        m_userGenerator.LostUser += new EventHandler<UserLostEventArgs>(LostUserCallback);

        return true;
    }