Esempio n. 1
0
 /// <summary>
 /// Signals that the kinect sensor has streamed its first frame.
 /// </summary>
 /// <param name="obj"></param>
 private void KinectProcessor_OnKinectStreamingStarted(KinectProcessing obj)
 {
     Dispatcher.BeginInvoke((Action)delegate()
     {
         _pzCalibration.FitContent();
         _pzManage.FitContent();
     });
 }
Esempio n. 2
0
        /// <summary>
        /// This is called to signal that the kinect has recieved a new frame.
        /// </summary>
        /// <remarks>It is called from the Kinect processing thread, so we need to dispatch this function to the GUI thread.</remarks>
        /// <param name="pKinect">The calling kinect processor.</param>
        private void KinectProcessor_OnFrameReady(KinectProcessing pKinect)
        {
            // If we have a valid image.
            if (pKinectVideoTarget == null)
                return;

            // Dispatch the following code to the UI thread.
            Dispatcher.BeginInvoke(new Action(() =>
            {
                // If we are showing the projector selection.
                if (tabProjector.IsSelected)
                    return;

                // If we are showing the calibration video.
                if (tabSettings.IsSelected || tabDisplayControl.IsSelected)
                {
                    // Copy all the pixels from the current buffer into the video stream target.
                    pKinect.ImageToWriteableBitmap(pKinectVideoTarget);
                }

                // Update the FPS.
                _FPSLabel.Content = KinectProcessor.FPS + " fps";
            }));


            // Signal the point cloud processor thread.
            Parallel.Invoke(() =>
            {
                // For each spatial query, begin a new frame.
                var tQueries = UbiDisplays.Model.Surface.SpatialQueries.ToArray();
                foreach (var pQuery in tQueries)
                    pQuery.BeginFrame();

                // Wipe all the debug pixels back to transparent.
                Array.Clear(tKinectVideoDebugBackBuffer, 0, tKinectVideoDebugBackBuffer.Length);

                // Perform the actual processing.
                KinectProcessor.QueryPointCloud(tQueries, tKinectVideoDebugBackBuffer);

                // End the frame.
                foreach (var pQuery in tQueries)
                    pQuery.EndFrame();

                // Then tell the dispatcher to blit the new pixels.
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    // Check we have data to write to.
                    if (pKinectVideoDebugTarget == null)
                        return;

                    // Now fill in the debug information.
                    pKinectVideoDebugTarget.WritePixels(
                        new Int32Rect(0, 0, pKinectVideoDebugTarget.PixelWidth, pKinectVideoDebugTarget.PixelHeight),
                        tKinectVideoDebugBackBuffer,
                        pKinectVideoDebugTarget.PixelWidth * 4,
                        0);
                }));
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Handle the window load event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Create a new kinect processor.
            this.KinectProcessor = new KinectProcessing();

            // Let us know when we get new frames.
            KinectProcessor.OnFrameReady += KinectProcessor_OnFrameReady;
            KinectProcessor.OnKinectStreamingStarted += KinectProcessor_OnKinectStreamingStarted;

            // Bind log messages.
            Log.OnNewLogMessage += new Action<Log.LogMessage>(Log_OnNewLogMessage);

            // Listen for surface changes.
            Authority.OnSurfaceListChanged += new Action(Authority_OnSurfaceListChanged);

            // Make the top bar show wpf glass.
            Glass.Extend(this, 32, 32);  // (int)topBar.ActualHeight

            // Create an output monitor window.
            OutputWindow = new Projector();
            OutputWindow.Hide();
            OutputWindow.ShowCalibrationPoint = false;

            // Push globals to the surface (so it can interface with the app).
            UbiDisplays.Model.Surface.KinectProcessor = this.KinectProcessor;
            UbiDisplays.Model.Surface.ProjectionRenderer = OutputWindow.Renderer;

            // Detect monitors and kinects.
            DetectMonitors();
            DetectKinects();

            #region Polygon Creation
            // Create region selection UI polygon.  Used on the calibration stage.
            pAllowedSurfacePoly = new Polygon();
            pAllowedSurfacePoly.Stroke = Brushes.LightBlue;
            pAllowedSurfacePoly.Fill = new SolidColorBrush(Color.FromArgb(56, 56, 56, 160));
            pAllowedSurfacePoly.StrokeThickness = 1.5;
            pAllowedSurfacePoly.Visibility = System.Windows.Visibility.Hidden;
            _pzCalibration.Children.Add(pAllowedSurfacePoly);

            // Create the region drawing UI polygon.  Used when drawing displays out.
            pDrawSurfacePoly = new Polygon();
            pDrawSurfacePoly.Visibility = System.Windows.Visibility.Hidden;
            pDrawSurfacePoly.Stroke = Brushes.Purple;
            pDrawSurfacePoly.Fill = new SolidColorBrush(Color.FromArgb(160, 56, 56, 56));
            pDrawSurfacePoly.StrokeThickness = 0.5;
            _pzManage.Children.Add(pDrawSurfacePoly);

            // The surface calibration adjust poly.
            pSurfaceCalibrationAdjustPoly = new Polygon();
            pSurfaceCalibrationAdjustPoly.Visibility = System.Windows.Visibility.Hidden;
            pSurfaceCalibrationAdjustPoly.Stroke = Brushes.LightBlue;
            pSurfaceCalibrationAdjustPoly.Fill = new SolidColorBrush(Color.FromArgb(150, 40, 40, 40));
            pSurfaceCalibrationAdjustPoly.StrokeThickness = 0.5;
            _pzManage.Children.Add(pSurfaceCalibrationAdjustPoly);
            #endregion

            // Bind Kinect Window clicks to dragging.
            _vidManage.MouseLeftButtonDown += CornerDrag_InnerMouseLeftButtonDown;

            // Flip the video feeds.
            _pzCalibration.RenderTransform = new ScaleTransform(-1, 1);
            _pzCalibration.RenderTransformOrigin = new Point(0.5, 0.5);
            _pzManage.RenderTransform = new ScaleTransform(-1, 1, 0.5, 0.5);
            _pzManage.RenderTransformOrigin = new Point(0.5, 0.5);

            // Now the window is loaded, see if we need to load any files from the command line.
            if (App.CommandLineArgs != null)
            {
                // For each argument.
                foreach (var sArg in App.CommandLineArgs)
                {
                    // If it is a command to hide the window after load.
                    if (sArg == "--hidden" || sArg == "-h")
                    {
                        this.Hide();
                    }

                    // It is none of our know types, try and load as a file.
                    else
                    {
                        #region Attempted Load
                        try
                        {
                            this.Load(true, true, true, sArg);
                            Log.Write("Loaded from " + sArg, "Application", Log.Type.AppInfo);
                        }
                        catch (ArgumentNullException excp)
                        {
                            Log.Write("Unable to load. Is all the required XML present?", "Application", Log.Type.AppWarning);
                            sConfigurationFile = "";
                            bSettingsChosen = false;
                        }
                        catch (Exception excp)
                        {
                            Log.Write("Unable to load. " + excp.Message, "Application", Log.Type.AppWarning);
                            MessageBox.Show("Unable to load. " + excp.Message, "Ubi Displays", MessageBoxButton.OK, MessageBoxImage.Warning);
                            sConfigurationFile = "";
                            bSettingsChosen = false;
                        }
                        #endregion
                    }
                }
            }

            // Say we are ready.
            Log.Write("Ready", "Application", Log.Type.AppInfo);
        }