/// @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; }
/// @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); }
/// @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); }
// public methods /// @brief Initializer of the logger and context /// /// This method is responsible for initializing the context and logger (it should be used /// instead of the InitLogger method as it calls it internally! /// @note it will always return false doing nothing if the object is already valid! /// @note the context must be valid for this to work! If the context is invalid it will also invalidate this object /// @param logger the logger object we will enter logs into /// @param context the context this relates to /// @return true on success, false on failure. public bool InitWithContext(NIEventLogger logger, NIContext context) { if(Valid) return false; if (context.Valid == false) { Dispose(); return false; } if(InitLogger(logger)==false) { Dispose(); return false; } Log("initializing with context", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects,NIEventLogger.VerboseLevel.Verbose); m_context = context; return true; }
// public methods /// @brief Initializer of the logger and context /// /// This method is responsible for initializing the context and logger (it should be used /// instead of the InitLogger method as it calls it internally! /// @note it will always return false doing nothing if the object is already valid! /// @note the context must be valid for this to work! If the context is invalid it will also invalidate this object /// @param logger the logger object we will enter logs into /// @param context the context this relates to /// @return true on success, false on failure. public bool InitWithContext(NIEventLogger logger, NIContext context) { if (Valid) { return(false); } if (context.Valid == false) { Dispose(); return(false); } if (InitLogger(logger) == false) { Dispose(); return(false); } Log("initializing with context", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Verbose); m_context = context; return(true); }
/// @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); }
/// @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; }
/// @brief Initializes everything /// /// This is a mono-behavior Awake which is used to initialize everything. Note that since internal objects /// such as the context are singleton, they are constructed before BUT they are initialized here. /// This means that before the Awake function is called, all public members (such as m_Logger, m_query /// and m_XMLFileName) must have been initialized and that no one can use NIConfigurableContext before this /// is finished. public void Awake() { m_context = NIContext.Instance; if(m_context.Valid==false) { // we need to initialize... if (m_context.Init(m_Logger, m_query, m_XMLFileName, m_recordingFilename) == false) { m_Logger.Log("FAILED TO INITIALIZE CONTEXT!!!", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Errors); return; } } try { Mirror = m_initMirroring; } catch (System.Exception e) { Debug.Log("Failed to set mirroring. Are you using an XML initialization from a recording without setting the playback option in the inspector?"); throw e; } m_image = NIImage.Instance; if (m_useImageGenerator) m_image.Init(m_Logger, m_context); else m_image.Dispose(); // to make sure it is invalid m_userAndSkeletonControl = NIUserAndSkeleton.Instance; if (m_useSkeleton) { m_userAndSkeletonControl.Init(m_Logger, m_context); m_userAndSkeletonControl.SkeletonSmoothingFactor = m_smoothingFactor; } else m_userAndSkeletonControl.Dispose(); // to make sure it is invalid UpdateNodeInformation(); }