/// @brief Method to reload all nodes
    ///
    /// This method is used by inspectors to load and unload the relevant nodes when those are currently
    /// not loaded.
    public static void InspectorReloadAnInstance()
    {
        NIEventLogger         loggerInstance  = FindObjectOfType(typeof(NIEventLogger)) as NIEventLogger;
        bool                  awakenLogger    = false;
        NIQuery               queryInstance   = FindObjectOfType(typeof(NIQuery)) as NIQuery;
        bool                  awakenQuery     = false;
        OpenNISettingsManager managerInstance = FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager;

        if (managerInstance == null)
        {
            Debug.LogError("Please Add an OpenNISettingsManager object to the scene");
            return;
        }
        if (managerInstance.Valid)
        {
            return; // it is already up, nothing to do...
        }
        if (loggerInstance != null && loggerInstance.Initialized == false)
        {
            loggerInstance.Awake();
            awakenLogger = true;
        }
        if (queryInstance != null && queryInstance.Initialized == false)
        {
            queryInstance.Awake();
            awakenQuery = true;
        }
        managerInstance.Awake();
        if (managerInstance.UserSkeletonValid == false)
        {
            Debug.LogError("No user generator available. Please make sure the user generator is active");
        }
        managerInstance.OnDestroy();
        if (awakenQuery)
        {
            queryInstance.OnDestroy();
        }
        if (awakenLogger)
        {
            queryInstance.OnDestroy();
        }
    }
    // public methods

    /// @brief Initialize the context object
    /// 
    /// This method initializes the context. It is assumed that this would be done once on the
    /// beginning of the game. Note that this is called on the singleton so multiple initializations
    /// will simply do nothing (which might cause problems with other objects). If for some reason a new
    /// initialization is needed, the @ref Dispose method should be called first (however ALL
    /// other initializations will be required first such as reinitializing the nodes). Also, it is assumed that
    /// every node created externally using the @ref CreateNode method will be released (using the @ref ReleaseNode
    /// method) BEFORE releasing the context.
    /// @param logger the logger object we will enter logs into
    /// @param query A query limiting the nodes found.
    /// @param xmlFileName this will hold an xml file to initialize from. A null or empty filename
    /// will simply be ignored and the object will be built without it. An illegal filename will cause
    /// an exception!
    /// @param recordingFilename This holds the filename for playing a recording.
    /// @ref OpenNIRecordAndPlayback "Recording and playing back sensor data").
    /// @return true on success, false on failure. 
    /// @note if the context was already initialized this will fail but the context would be valid!
    /// @note This implementation assumes that a depth generator is required for ALL uses including
    /// the creation of the skeleton. In theory, it is possible that some implementations will not 
    /// require a depth generator. This is currently not supported.
    public virtual bool Init(NIEventLogger logger, NIQuery query, string xmlFileName, string recordingFilename)
    {
        if (Valid)
        {
            if(logger!=null)
                logger.Log("trying to initialized a valid context!", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects,NIEventLogger.VerboseLevel.Warning);
            return false; // failed to initialize
        }
        if (InitLogger(logger) == false)
        {
            Dispose();
            return false; // we failed an initialization step.
        }
        Log("In OpenNIContext.InitContext with logger=" + logger + " query=" + query, NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Verbose);
        if(m_context!=null || m_scriptNode!=null || m_depth!=null)
            throw new System.Exception("valid is false but internal structures are not null! m_context=" + m_context + " m_scriptNode=" + m_scriptNode + " m_depth=" + m_depth);
        m_Logger = logger;
        m_query = query;
        if (xmlFileName != null && xmlFileName.CompareTo("")!=0)
        {
            try
            {
                NIOpenNICheckVersion.Instance.ValidatePrerequisite();
                m_context = Context.CreateFromXmlFile(xmlFileName, out m_scriptNode);
                m_recordingPlayer = m_context.FindExistingNode(NodeType.Player) as Player;
            }
            catch (System.Exception ex)
            {
                Debug.Log(ex.Message);
                Log("failed to create from xmlFile!", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects,NIEventLogger.VerboseLevel.Errors);
                Dispose();
                return false;
            }
            if (recordingFilename != null && recordingFilename.CompareTo("") != 0)
            {
                Log("Both xml and recording were defined. Ignoring recording information and using XML only!", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Warning);
            }
         
        }
        else
        {
            try
            {
                NIOpenNICheckVersion.Instance.ValidatePrerequisite();
                m_context = new Context();
                if (recordingFilename != null && recordingFilename.CompareTo("") != 0)
                {
                    try
                    {
                        m_recordingPlayer = m_context.OpenFileRecordingEx(recordingFilename) as Player;
                    }
                    catch (System.Exception ex)
                    {
                        Debug.Log(recordingFilename);
                        Log("Failed to create recorder with message " + ex.Message, NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Errors);
                        Dispose();
                        return false;
                    }
                    
                }
            }
            catch (System.Exception ex)
            {
                if (ex as System.DllNotFoundException != null)
                {
                    throw new System.DllNotFoundException("The dll for OpenNI is not there. Please install OpenNI (using the mega installer");
                }
                else Debug.Log(ex.Message);
            }
            
        }
		if (m_context==null)
		{
            Log("failed to create a context!", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Errors);
            Dispose();
			return false;
		}
        m_depth = CreateNode(NodeType.Depth) as DepthGenerator;
        return true;
	}
Exemple #3
0
    // public methods

    /// @brief Initialize the context object
    ///
    /// This method initializes the context. It is assumed that this would be done once on the
    /// beginning of the game. Note that this is called on the singleton so multiple initializations
    /// will simply do nothing (which might cause problems with other objects). If for some reason a new
    /// initialization is needed, the @ref Dispose method should be called first (however ALL
    /// other initializations will be required first such as reinitializing the nodes). Also, it is assumed that
    /// every node created externally using the @ref CreateNode method will be released (using the @ref ReleaseNode
    /// method) BEFORE releasing the context.
    /// @param logger the logger object we will enter logs into
    /// @param query A query limiting the nodes found.
    /// @param xmlFileName this will hold an xml file to initialize from. A null or empty filename
    /// will simply be ignored and the object will be built without it. An illegal filename will cause
    /// an exception!
    /// @param recordingFilename This holds the filename for playing a recording.
    /// @ref OpenNIRecordAndPlayback "Recording and playing back sensor data").
    /// @return true on success, false on failure.
    /// @note if the context was already initialized this will fail but the context would be valid!
    /// @note This implementation assumes that a depth generator is required for ALL uses including
    /// the creation of the skeleton. In theory, it is possible that some implementations will not
    /// require a depth generator. This is currently not supported.
    public virtual bool Init(NIEventLogger logger, NIQuery query, string xmlFileName, string recordingFilename)
    {
        if (Valid)
        {
            if (logger != null)
            {
                logger.Log("trying to initialized a valid context!", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Warning);
            }
            return(false); // failed to initialize
        }
        if (InitLogger(logger) == false)
        {
            Dispose();
            return(false); // we failed an initialization step.
        }
        Log("In OpenNIContext.InitContext with logger=" + logger + " query=" + query, NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Verbose);
        if (m_context != null || m_scriptNode != null || m_depth != null)
        {
            throw new System.Exception("valid is false but internal structures are not null! m_context=" + m_context + " m_scriptNode=" + m_scriptNode + " m_depth=" + m_depth);
        }
        m_Logger = logger;
        m_query  = query;
        if (xmlFileName != null && xmlFileName.CompareTo("") != 0)
        {
            try
            {
                NIOpenNICheckVersion.Instance.ValidatePrerequisite();
                m_context         = Context.CreateFromXmlFile(xmlFileName, out m_scriptNode);
                m_recordingPlayer = m_context.FindExistingNode(NodeType.Player) as Player;
            }
            catch (System.Exception ex)
            {
                Debug.Log(ex.Message);
                Log("failed to create from xmlFile!", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Errors);
                Dispose();
                return(false);
            }
            if (recordingFilename != null && recordingFilename.CompareTo("") != 0)
            {
                Log("Both xml and recording were defined. Ignoring recording information and using XML only!", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Warning);
            }
        }
        else
        {
            try
            {
                NIOpenNICheckVersion.Instance.ValidatePrerequisite();
                m_context = new Context();
                if (recordingFilename != null && recordingFilename.CompareTo("") != 0)
                {
                    try
                    {
                        m_recordingPlayer = m_context.OpenFileRecordingEx(recordingFilename) as Player;
                    }
                    catch (System.Exception ex)
                    {
                        Debug.Log(recordingFilename);
                        Log("Failed to create recorder with message " + ex.Message, NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Errors);
                        Dispose();
                        return(false);
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (ex as System.DllNotFoundException != null)
                {
                    throw new System.DllNotFoundException("The dll for OpenNI is not there. Please install OpenNI (using the mega installer");
                }
                else
                {
                    Debug.Log(ex.Message);
                }
            }
        }
        if (m_context == null)
        {
            Log("failed to create a context!", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Errors);
            Dispose();
            return(false);
        }
        m_depth = CreateNode(NodeType.Depth) as DepthGenerator;
        return(true);
    }
Exemple #4
0
    // public methods

    /// @brief Initialize the context object
    ///
    /// This method initializes the context. It is assumed that this would be done once on the
    /// beginning of the game. Note that this is called on the singleton so multiple initializations
    /// will simply do nothing (which might cause problems with other objects). If for some reason a new
    /// initialization is needed, the @ref Dispose method should be called first (however ALL
    /// other initializations will be required first such as reinitializing the nodes). Also, it is assumed that
    /// every node created externally using the @ref CreateNode method will be released (using the @ref ReleaseNode
    /// method) BEFORE releasing the context.
    /// @param logger the logger object we will enter logs into
    /// @param query A query limiting the nodes found.
    /// @param xmlFileName this will hold an xml file to initialize from. A null or empty filename
    /// will simply be ignored and the object will be built without it. An illegal filename will cause
    /// an exception!
    /// @param playerbackMode If this is true then the context is in playback mode (see
    /// @ref OpenNIRecordAndPlayback "Recording and playing back sensor data").
    /// @return true on success, false on failure.
    /// @note if the context was already initialized this will fail but the context would be valid!
    /// @note This implementation assumes that a depth generator is required for ALL uses including
    /// the creation of the skeleton. In theory, it is possible that some implementations will not
    /// require a depth generator. This is currently not supported.
    public virtual bool Init(NIEventLogger logger, NIQuery query, string xmlFileName, bool playerbackMode)
    {
        if (Valid)
        {
            if (logger != null)
            {
                logger.Log("trying to initialized a valid context!", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects);
            }
            return(false); // failed to initialize
        }
        if (InitLogger(logger) == false)
        {
            Dispose();
            return(false); // we failed an initialization step.
        }
        Log("In OpenNIContext.InitContext with logger=" + logger + " query=" + query, NIEventLogger.Categories.Initialization, NIEventLogger.Sources.BaseObjects);
        if (m_context != null || m_scriptNode != null || m_depth != null)
        {
            throw new System.Exception("valid is false but internal structures are not null! m_context=" + m_context + " m_scriptNode=" + m_scriptNode + " m_depth=" + m_depth);
        }
        m_Logger = logger;
        m_query  = query;
        if (xmlFileName != null && xmlFileName.CompareTo("") != 0)
        {
            try
            {
                NIOpenNICheckVersion.Instance.ValidatePrerequisite();
                m_context = Context.CreateFromXmlFile(xmlFileName, out m_scriptNode);
            }
            catch
            {
                Log("failed to create from xmlFile!", NIEventLogger.Categories.Errors, NIEventLogger.Sources.BaseObjects);
                Dispose();
                return(false);
            }
        }
        else
        {
            try
            {
                NIOpenNICheckVersion.Instance.ValidatePrerequisite();
                m_context = new Context();
            }
            catch (System.Exception ex)
            {
                if (ex as System.DllNotFoundException != null)
                {
                    throw new System.DllNotFoundException("The dll for OpenNI is not there. Please install OpenNI (using the mega installer");
                }
                else
                {
                    Debug.Log(ex.Message);
                }
            }
        }
        if (m_context == null)
        {
            Log("failed to create a context!", NIEventLogger.Categories.Errors, NIEventLogger.Sources.BaseObjects);
            Dispose();
            return(false);
        }
        m_playerbackMode = playerbackMode;
        m_depth          = CreateNode(NodeType.Depth) as DepthGenerator;
        return(true);
    }
Exemple #5
0
    /// editor OnInspectorGUI to control the NIEventLogger properties
    override public void OnInspectorGUI()
    {
        EditorGUI.indentLevel = 0;
        EditorGUIUtility.LookLikeInspector();
        NIQuery query = target as NIQuery;

        if (query.Valid == false)
        {
            query.ForceInit();
        }
        if (query.m_queryDescriptions != null)
        {
            if (m_queryFoldout == null || m_queryFoldout.Length != query.m_queryDescriptions.Length)
            {
                m_queryFoldout = new bool[query.m_queryDescriptions.Length];
                for (int i = 0; i < m_queryFoldout.Length; i++)
                {
                    m_queryFoldout[i] = false;
                }
            }

            GUILayout.Label("Queries supported for " + query.m_queryDescriptions.Length + " nodes ");
            for (int i = 0; i < query.m_queryDescriptions.Length; i++)
            {
                m_queryFoldout[i] = EditorGUILayout.Foldout(m_queryFoldout[i], "" + query.m_queryDescriptions[i].m_nodeType + " nodes query");
                if (m_queryFoldout[i])
                {
                    EditorGUI.indentLevel += 2;
                    QueryDescription desc = query.m_queryDescriptions[i];
                    if (EditorApplication.isPlaying == false)
                    {
                        desc.m_nodeName   = EditorGUILayout.TextField("Node name", desc.m_nodeName);
                        desc.m_vendorName = EditorGUILayout.TextField("Vendor name", desc.m_vendorName);
                        EditorGUILayout.LabelField("Min version: ", desc.RequiresMinVersion() ? "Limited" : "no limitation");
                        desc.GetMinVersionArr(ref m_Version);
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();
                        for (int j = 0; j < m_Version.Length; j++)
                        {
                            if (j != 0)
                            {
                                GUILayout.Label(".", GUILayout.MaxWidth(5));
                            }
                            m_Version[j] = EditorGUILayout.IntField(m_Version[j], GUILayout.MaxWidth(25));
                        }
                        EditorGUILayout.EndHorizontal();
                        desc.SetMinVersion(m_Version);

                        EditorGUILayout.LabelField("Max version: ", desc.RequiresMaxVersion() ? "Limited" : "no limitation");
                        desc.GetMaxVersionArr(ref m_Version);
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();
                        for (int j = 0; j < m_Version.Length; j++)
                        {
                            if (j != 0)
                            {
                                GUILayout.Label(".", GUILayout.MaxWidth(5));
                            }
                            m_Version[j] = EditorGUILayout.IntField(m_Version[j], GUILayout.MaxWidth(25));
                        }
                        EditorGUILayout.EndHorizontal();
                        desc.SetMaxVersion(m_Version);
                    }
                    ProductionNodeDescription curNodeDesc;
                    if (OpenNISettingsManager.GetProductionNodeInformation(desc.m_nodeType, out curNodeDesc))
                    {
                        EditorGUILayout.LabelField("Last node loaded was:", "");
                        EditorGUI.indentLevel += 2;
                        EditorGUILayout.LabelField("Node name", curNodeDesc.Name);
                        EditorGUILayout.LabelField("Vendor name", curNodeDesc.Vendor);
                        EditorGUILayout.LabelField("Version:", "" + curNodeDesc.Version.Major + "." + curNodeDesc.Version.Minor + "." + curNodeDesc.Version.Maintenance + "." + curNodeDesc.Version.Build);
                        EditorGUI.indentLevel -= 2;
                    }
                    else
                    {
                        GUILayout.Label("    Load node to see its info");
                    }

                    EditorGUI.indentLevel       -= 2;
                    query.m_queryDescriptions[i] = desc;
                }
            }
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }