/// @brief Releases a request to a pose detection /// /// This method releases a request to detect a pose for a user which lowers the reference count. /// if no one uses the pose, the pose detection will be stopped. /// @param pose The pose we want to detect /// @param user The openNI user id of the user we want to detect on. /// @return true on success, false on failure. public bool ReleasePoseDetection(string pose, int user) { if (UserNode.PoseDetectionCapability == null || pose == null) { return(false); } for (int i = 0; i < m_poseDetectionCounter.Count; i++) { poseDetectionReferenceCounter refCounter = m_poseDetectionCounter[i]; if (refCounter.m_usedID == user && pose.CompareTo(refCounter.m_pose) == 0) { // we found the reference, lets dereference refCounter.m_referenceCount--; if (refCounter.m_referenceCount > 0) { return(true); // nothing to do, others still need it. } try { UserNode.PoseDetectionCapability.StopSinglePoseDetection(user, pose); } catch (System.Exception ex) { Log("Failed to stop pose detection with message " + ex.Message, NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Errors); refCounter.m_referenceCount++; // we failed to stop so we return it... return(false); } Log("Stopped following pose " + pose + " for user " + user, NIEventLogger.Categories.Misc, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Verbose); m_poseDetectionCounter[i] = m_poseDetectionCounter[m_poseDetectionCounter.Count - 1]; m_poseDetectionCounter.RemoveAt(m_poseDetectionCounter.Count - 1); return(true); } } return(false); // no such user }
/// @brief Request a pose detection to start /// /// This method requests a pose detection to start. It supports reference counting so as to /// make sure pose detection will continue as long as at least one /// @param pose The pose we want to detect /// @param user The openNI user id of the user we want to detect on. /// @return true on success, false on failure. public bool RequestPoseDetection(string pose, int user) { if (UserNode.PoseDetectionCapability == null || pose == null) { return(false); } foreach (poseDetectionReferenceCounter refCounter in m_poseDetectionCounter) { if (refCounter.m_usedID == user && pose.CompareTo(refCounter.m_pose) == 0) { // we already have this pose for this user so we are already detecting, just increase // the reference count refCounter.m_referenceCount++; return(true); } } // if we are here then we are not yet following this user so we need to create a new reference // counter try { UserNode.PoseDetectionCapability.StartPoseDetection(pose, user); } catch (System.Exception ex) { Log("Failed to start pose detection with message " + ex.Message, NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Errors); return(false); } Log("Started following pose " + pose + " for user " + user, NIEventLogger.Categories.Misc, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Verbose); poseDetectionReferenceCounter newCounter = new poseDetectionReferenceCounter(); newCounter.m_pose = pose; newCounter.m_referenceCount = 1; newCounter.m_usedID = user; m_poseDetectionCounter.Add(newCounter); return(true); }
/// @brief Request a pose detection to start /// /// This method requests a pose detection to start. It supports reference counting so as to /// make sure pose detection will continue as long as at least one /// @param pose The pose we want to detect /// @param user The openNI user id of the user we want to detect on. /// @return true on success, false on failure. public bool RequestPoseDetection(string pose, int user) { if (UserNode.PoseDetectionCapability == null || pose==null) return false; foreach (poseDetectionReferenceCounter refCounter in m_poseDetectionCounter) { if (refCounter.m_usedID == user && pose.CompareTo(refCounter.m_pose) == 0) { // we already have this pose for this user so we are already detecting, just increase // the reference count refCounter.m_referenceCount++; return true; } } // if we are here then we are not yet following this user so we need to create a new reference // counter try { UserNode.PoseDetectionCapability.StartPoseDetection(pose, user); } catch (System.Exception ex) { Log("Failed to start pose detection with message " + ex.Message, NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Errors); return false; } Log("Started following pose " + pose + " for user " + user, NIEventLogger.Categories.Misc, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Verbose); poseDetectionReferenceCounter newCounter = new poseDetectionReferenceCounter(); newCounter.m_pose = pose; newCounter.m_referenceCount = 1; newCounter.m_usedID = user; m_poseDetectionCounter.Add(newCounter); return true; }