Beispiel #1
0
        // object owning data should be locked
        private static void Render3D(IPluginViewSettings pluginViewSettings, viz.Texture texture, EventTypePluginData data, nui.Registration registration)
        {
            Debug.Assert(data != null);

            DepthPlugin3DViewSettings depthPlugin3DViewSettings = pluginViewSettings as DepthPlugin3DViewSettings;

            if ((registration != null) && (depthPlugin3DViewSettings != null))
            {
                DepthPlugin.UpdateData(depthPlugin3DViewSettings, texture, data);

                bool doColor     = false;
                bool doBodyIndex = false;

                if (texture != null)
                {
                    uint textureWidth  = texture.GetWidth();
                    uint textureHeight = texture.GetHeight();

                    doColor = (textureWidth == nui.Constants.STREAM_COLOR_WIDTH) &&
                              (textureHeight == nui.Constants.STREAM_COLOR_HEIGHT);

                    doBodyIndex = (texture.GetTextureFormat() == viz.TextureFormat.B8G8R8A8_UNORM) &&
                                  (textureWidth == nui.Constants.STREAM_DEPTH_WIDTH) &&
                                  (textureHeight == nui.Constants.STREAM_DEPTH_HEIGHT);
                }

                if ((depthPlugin3DViewSettings.IsSupplyingSurface && doBodyIndex) ||
                    (!depthPlugin3DViewSettings.IsSupplyingSurface && depthPlugin3DViewSettings.ViewType == DepthPlugin3DViewSettings.Depth3DViewType.SurfaceNormal))
                {
                    if (data.depthMap != null)
                    {
                        // special case for body index
                        viz.Effect effect = new viz.Effect()
                        {
                            Direction      = new viz.Vector(0.5f, 0.3f, 1.5f, 0),
                            Ambient        = new viz.Vector(0.0f, 0.0f, 0.0f, 1.0f),
                            Diffuse        = new viz.Vector(0.5f, 0.5f, 0.5f, 1.0f),
                            Specular       = new viz.Vector(1.0f, 1.0f, 1.0f, 1.0f),
                            Power          = 25.0f,
                            EnableLighting = true,
                            EnableTexture  = false,
                        };

                        if ((depthPlugin3DViewSettings.IsSupplyingSurface && doBodyIndex))
                        {
                            if (data.depthMap != null)
                            {
                                data.depthMap.SetMode(viz.DepthVertexMode.SurfaceWithNormal, viz.DepthRampMode.None);
                                effect.EnableTexture = true;
                            }
                        }

                        if (!depthPlugin3DViewSettings.IsSupplyingSurface)
                        {
                            texture = null;
                        }

                        data.depthMap.Render(effect, texture);
                    }
                }
                else
                {
                    if (depthPlugin3DViewSettings.IsSupplyingSurface && doColor)
                    {
                        // special case for color
                        if ((registration != null) && (data.depthMap != null) && (data.uvTable != null) && (data.sharedDepthFrame != null))
                        {
                            data.depthMap.SetMode(viz.DepthVertexMode.SurfaceWithUV, viz.DepthRampMode.None);

                            IntPtr ptr = data.sharedDepthFrame.Buffer;

                            if (ptr != IntPtr.Zero)
                            {
                                registration.Process(ptr, data.uvTable.Buffer);
                            }

                            data.depthMap.UpdateUVTable(data.uvTable.Buffer, data.uvTable.Size);
                        }
                    }

                    if (data.depthMap != null)
                    {
                        viz.Effect effect = new viz.Effect()
                        {
                            EnableTexture = texture != null,
                        };

                        data.depthMap.Render(effect, texture);
                    }
                }
            }
        }
        // object owning data should be locked
        private static void Render2D(IPluginViewSettings pluginViewSettings, viz.Texture texture, float left, float top, float width, float height, EventTypePluginData data, nui.Registration registration)
        {
            Debug.Assert(data != null);

            BodyPlugin2DViewSettings bodyPluginViewSettings = pluginViewSettings as BodyPlugin2DViewSettings;

            if ((bodyPluginViewSettings != null) && (registration != null) && (data.body != null) && data.bodiesValid)
            {
                if (bodyPluginViewSettings.RenderBodies || bodyPluginViewSettings.RenderHands)
                {
                    viz.Body2DMode bodyMode = viz.Body2DMode.DepthIR;
                    if ((texture != null) && (texture.GetWidth() == nui.Constants.STREAM_COLOR_WIDTH) && (texture.GetHeight() == nui.Constants.STREAM_COLOR_HEIGHT))
                    {
                        bodyMode = viz.Body2DMode.Color;
                    }

                    data.body.Begin2D(left, top, width, height, bodyMode, registration.GetCalibrationData());

                    for (uint i = 0; i < BodyPlugin.bodyOptions.Length; ++i)
                    {
                        if (bodyPluginViewSettings.RenderBodies)
                        {
                            viz.Vector color = BodyPlugin.bodyOptions[i].ColorVector;
                            color.A = 0.7f;
                            data.body.RenderBones2D(i, color);
                        }

                        if (bodyPluginViewSettings.RenderHands)
                        {
                            data.body.RenderHandStates2D(i);
                        }
                    }

                    data.body.End2D();
                }
            }
        }
        protected override void OnGetLayout(viz.Context context, viz.Texture texture, ref float layoutWidth, ref float layoutHeight)
        {
            DebugHelper.AssertUIThread();

            bool fixZoom = (this.imageWidth == 0) || (this.imageHeight == 0);

            if (texture == null)
            {
                this.imageWidth  = Image2DVisualizationControl.defaultWidth;
                this.imageHeight = Image2DVisualizationControl.defaultHeight;
            }
            else
            {
                this.imageWidth  = texture.GetWidth();
                this.imageHeight = texture.GetHeight();
            }

            double scale = 1.0;

            if (this.IsZoomToFit)
            {
                if (this.scrollViewer != null)
                {
                    this.scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden;
                    this.scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;

                    scale = CalcScaleOnZoomToFit(this.scrollViewer.ActualWidth, this.scrollViewer.ActualHeight);
                }

                int zoom = (int)(100.0 * scale);

                if (this.Zoom != zoom)
                {
                    if (this.scaleTransform != null)
                    {
                        this.scaleTransform.ScaleX = scale;
                        this.scaleTransform.ScaleY = scale;
                    }

                    fixZoom = true;

                    this.ignoreZoom++;
                    this.SetValue(Image2DVisualizationControl.ZoomProperty, zoom);
                    this.ignoreZoom--;
                }
            }
            else
            {
                scale = this.Zoom / 100.0;

                if (this.scrollViewer != null)
                {
                    this.scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
                    this.scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                }
            }

            if (fixZoom)
            {
                this.OnZoomChanged();
            }

            layoutWidth  = (float)(this.imageWidth * scale);
            layoutHeight = (float)(this.imageHeight * scale);
        }