Пример #1
0
        private void OpenContext()
        {
            //try to open Kinect Context
            try
            {
                FContext = new Context();
                FContext.ErrorStateChanged += FContext_ErrorStateChanged;

                /*	var devices = FContext.EnumerateProductionTrees(OpenNI.NodeType.Depth, null);
                 *
                 *      foreach (var device in devices)
                 *              FDevices.Add(device.CreationInfo, device);
                 *
                 *      string[] deviceNames = new string[FDevices.Count];
                 *      FDevices.Keys.CopyTo(deviceNames, 0);
                 *      EnumManager.UpdateEnum("OpenNIDevices", deviceNames[0], deviceNames);
                 *
                 *      Query q = new Query();
                 *      q.SetCreationInfo(deviceNames[0]);
                 *      var depths = FContext.EnumerateProductionTrees(OpenNI.NodeType.Depth, q);
                 *
                 *      //here is one central depth generator that is used by downstream nodes like depth, user, hand, skeleton,..
                 *      //since this is one central generator it should not be allowed to disable it downstream
                 *      foreach (var depth in depths)*/
                FDepthGenerator = (DepthGenerator)FContext.CreateAnyProductionTree(OpenNI.NodeType.Depth, null);                 // .CreateProductionTree(depth);
                FDepthGenerator.StartGenerating();

                //creation of usergenerators requires generation of depthgenerator
                //depth node needs imagegenerator to adaptview

                //read out driver versions:
                var v = OpenNI.Version.Current;
                FOpenNI = "OpenNI: " + v.Major + "." + v.Minor + "." + v.Maintenance + "." + v.Build;

                //create a usergenerator here just for getting the NITE version
                var user = FContext.CreateAnyProductionTree(OpenNI.NodeType.User, null);
                v           = user.Info.Description.Version;
                FMiddleware = user.Info.Description.Vendor + " " + user.Info.Description.Name + ": " + v.Major + "." + v.Minor + "." + v.Maintenance + "." + v.Build;
                user.Dispose();

                v       = FDepthGenerator.Info.Description.Version;
                FSensor = FDepthGenerator.Info.Description.Vendor + " " + FDepthGenerator.Info.Description.Name + ": " + v.Major + "." + v.Minor + "." + v.Maintenance + "." + v.Build;
            }
            catch (Exception e)
            {
                FLogger.Log(e);
            }
        }
Пример #2
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FContextChanged)
            {
                if (FContextIn.PluginIO.IsConnected)
                {
                    if (FContextIn[0] != null)
                    {
                        try
                        {
                            FDepthGenerator = (DepthGenerator)FContextIn[0].GetProductionNodeByName("Depth1");
                            FFov[0]         = new Vector2D(FDepthGenerator.FieldOfView.HorizontalAngle, FDepthGenerator.FieldOfView.VerticalAngle) * (float)VMath.RadToCyc;

                            FHistogram = new int[FDepthGenerator.DeviceMaxDepth];

                            //Set the resolution of the texture
                            var mapMode = FDepthGenerator.MapOutputMode;
                            FTexWidth  = mapMode.XRes;
                            FTexHeight = mapMode.YRes;

                            //Reinitalie the vvvv texture
                            Reinitialize();

                            FContextChanged = false;
                        }
                        catch (Exception ex)
                        {
                            FLogger.Log(ex);
                        }
                    }
                }
                else
                {
                    CleanUp();
                    FContextChanged = false;
                }
            }

            if (FDepthGenerator != null)
            {
                if (FEnabledIn.IsChanged)
                {
                    if (FEnabledIn[0])
                    {
                        FDepthGenerator.StartGenerating();
                    }
                    else
                    {
                        FDepthGenerator.StopGenerating();
                    }
                }

                bool imageGeneratorChanged = false;
                try
                {
                    var imageGenerator = (ImageGenerator)FContextIn[0].GetProductionNodeByName("Image1");
                    if (FImageGenerator != imageGenerator)
                    {
                        FImageGenerator       = imageGenerator;
                        imageGeneratorChanged = true;
                    }
                }
                catch
                {}

                if (FAdaptView.IsChanged || imageGeneratorChanged)
                {
                    if (FImageGenerator == null || !FAdaptView[0])
                    {
                        FDepthGenerator.AlternativeViewpointCapability.ResetViewpoint();
                    }
                    else
                    {
                        FDepthGenerator.AlternativeViewpointCapability.SetViewpoint(FImageGenerator);
                    }
                }

                if (FDepthGenerator.IsDataNew)
                {
                    Update();
                }
            }
        }