private void InitializeKinect(string kinectId)
        {
            if (!Init(kinectId))
            {
                // Something went wrong
                return;
            }

            InteropImage.WindowOwner     = (new System.Windows.Interop.WindowInteropHelper(this)).Handle;
            InteropImage.OnRender        = this.DoRender;
            CompositionTarget.Rendering += this.UpdateD3D;

            // Set up camera
            SetCameraRadius((float)RadiusSlider.Value);
            SetCameraPhi((float)PhiSlider.Value * DegreesToRadians);
            SetCameraTheta((float)ThetaSlider.Value * DegreesToRadians);

            // Start rendering now!
            InteropImage.RequestRender();
        }
        private void ImageHostGridSizeChanged(object sender, SizeChangedEventArgs e)
        {
            var dpiScale = 1.0; // default value for 96 dpi

            // determine DPI
            // (as of .NET 4.6.1, this returns the DPI of the primary monitor, if you have several different DPIs)
            var hwndTarget = PresentationSource.FromVisual(this)?.CompositionTarget as HwndTarget;

            if (hwndTarget != null)
            {
                dpiScale = hwndTarget.TransformToDevice.M11;
            }

            var surfWidth  = (int)(ImageHostGrid.ActualWidth < 0 ? 0 : Math.Ceiling(ImageHostGrid.ActualWidth * dpiScale));
            var surfHeight = (int)(ImageHostGrid.ActualHeight < 0 ? 0 : Math.Ceiling(ImageHostGrid.ActualHeight * dpiScale));

            // Notify the D3D11Image of the pixel size desired for the DirectX rendering.
            // The D3DRendering component will determine the size of the new surface it is given, at that point.
            InteropImage.SetPixelSize(surfWidth, surfHeight);

            // Stop rendering if the D3DImage isn't visible - currently just if width or height is 0
            // TODO: more optimizations possible (scrolled off screen, etc...)
            var isVisible = surfWidth != 0 && surfHeight != 0;

            if (lastVisible == isVisible)
            {
                return;
            }

            lastVisible = isVisible;
            if (lastVisible)
            {
                CompositionTarget.Rendering += CompositionTarget_Rendering;
            }
            else
            {
                CompositionTarget.Rendering -= CompositionTarget_Rendering;
            }
        }
示例#3
0
        private void Host_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            double dpiScale = 1.0; // default value for 96 dpi

            // determine DPI
            // (as of .NET 4.6.1, this returns the DPI of the primary monitor, if you have several different DPIs)
            var hwndTarget = PresentationSource.FromVisual(this).CompositionTarget as HwndTarget;

            if (hwndTarget != null)
            {
                dpiScale = hwndTarget.TransformToDevice.M11;
            }

            int surfWidth  = (int)(host.ActualWidth < 0 ? 0 : Math.Ceiling(host.ActualWidth * dpiScale));
            int surfHeight = (int)(host.ActualHeight < 0 ? 0 : Math.Ceiling(host.ActualHeight * dpiScale));

            // notify the D3D11Image and the DxRendering component of the pixel size desired for the DirectX rendering.
            InteropImage.SetPixelSize(surfWidth, surfHeight);
            NativeMethods.SetRenderSize(surfWidth, surfHeight);

            // Stop rendering if the D3DImage isn't visible - currently just if width or height is 0
            // TODO: more optimizations possible (scrolled off screen, etc...)
            bool isVisible = (surfWidth != 0 && surfHeight != 0);

            if (lastVisible != isVisible)
            {
                lastVisible = isVisible;
                if (lastVisible)
                {
                    CompositionTarget.Rendering += CompositionTarget_Rendering;
                }
                else
                {
                    CompositionTarget.Rendering -= CompositionTarget_Rendering;
                }
            }
        }
示例#4
0
        private void SetInteropImagePixelSize()
        {
            double dpiScale = 1.0; // default value for 96 dpi

            // determine DPI
            // (as of .NET 4.6.1, this returns the DPI of the primary monitor, if you have several different DPIs)
            PresentationSource presentationSource = PresentationSource.FromVisual(this);
            var hwndTarget = presentationSource?.CompositionTarget as HwndTarget;

            if (hwndTarget != null)
            {
                dpiScale = hwndTarget.TransformToDevice.M11;
            }

            int surfWidth  = (int)(ImageContainer.ActualWidth < 0 ? 0 : Math.Ceiling(ImageContainer.ActualWidth * dpiScale));
            int surfHeight = (int)(ImageContainer.ActualHeight < 0 ? 0 : Math.Ceiling(ImageContainer.ActualHeight * dpiScale));

            // notify the D3D11Image and the DxRendering component of the pixel size desired for the DirectX rendering.
            InteropImage.SetPixelSize(surfWidth, surfHeight);

            //make sure the resources are created
            SyncGeometriesWithShapes();
            SyncBrushesWithShapes();
        }
示例#5
0
        private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Size size = Utils.WpfSizeToPixels(ImageGrid);

            InteropImage.SetPixelSize((int)size.Width, (int)size.Height);
        }
示例#6
0
        private void ImageContainer_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!IsSelectionEnabled)
            {
                return;
            }

            if (!_isPanning && Shapes != null)
            {
                var    mousePosition = e.GetPosition(InteropHost);
                var    testPoint     = new Vector2((float)mousePosition.X, (float)mousePosition.Y);
                IShape selectedShape = null;

                //do a hit test to see what shape is being clicked on
                foreach (var shape in Shapes)
                {
                    var pathGeometry = _createdGeometries[shape.GeometryHash];

                    var translation = Matrix3x2.Identity;
                    if (pathGeometry is GeometryPath)
                    {
                        var vectorShape = shape as VectorShape;
                        if (vectorShape != null)
                        {
                            translation = pathGeometry.GetRenderTransform(vectorShape.Scaling, vectorShape.PixelXLocation, vectorShape.PixelYLocation, vectorShape.Rotation, RenderOrigin);

                            if (pathGeometry.Geometry.FillContainsPoint(testPoint, translation, 4f))
                            {
                                var previousSelectedShape = Shapes.FirstOrDefault(s => s.IsSelected);
                                if (previousSelectedShape != null)
                                {
                                    previousSelectedShape.IsSelected = false;
                                }

                                shape.IsSelected = true;
                                selectedShape    = shape;
                            }
                            else
                            {
                                shape.IsSelected = false;
                            }
                        }
                    }
                    else if (pathGeometry is LineGeometry)
                    {
                        if (pathGeometry.Geometry.StrokeContainsPoint(testPoint, shape.StrokeWidth, _lineStrokeStyle, translation, 4f))
                        {
                            var previousSelectedShape = Shapes.FirstOrDefault(s => s.IsSelected);
                            if (previousSelectedShape != null)
                            {
                                previousSelectedShape.IsSelected = false;
                            }

                            shape.IsSelected = true;
                            selectedShape    = shape;
                        }
                        else
                        {
                            shape.IsSelected = false;
                        }
                    }
                }

                SelectedShape = selectedShape;
                InteropImage.RequestRender();
            }

            _isPanning = false;
        }
示例#7
0
 /// <summary>
 /// Request a render of the geometries defined in the Shapes DP.
 /// </summary>
 public void RequestRender()
 {
     InteropImage.RequestRender();
 }
 private void UpdateD3D(object sender, EventArgs e)
 {
     InteropImage.RequestRender();
 }