コード例 #1
0
        protected override void OnDragOver(DragEventArgs e)
        {
            base.OnDragOver(e);

            Point mouseLocation = e.GetPosition(sharedCanvas);
            Point canvasBounds  = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas));

            // If the Cursor is within the Canvas
            if (mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y)
            {
                // Ensure the Ghost and Text are Visible while dragging
                MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Visible;
                ghostTextBlock.Visibility         = System.Windows.Visibility.Visible;

                // Relocate Ghost
                Canvas.SetLeft(MainWindow.GhostBorder, mouseLocation.X - (MainWindow.GhostBorder.Width / 2));
                Canvas.SetTop(MainWindow.GhostBorder, mouseLocation.Y - (MainWindow.GhostBorder.Height / 2));

                // Update Location Text
                Point p = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas);
                ghostTextBlock.Text = "(" + Math.Round(p.X, 1) + ", " + Math.Round(p.Y, 1) + ")";

                // Relocate Ghost Text
                Canvas.SetLeft(ghostTextBlock, mouseLocation.X - (MainWindow.GhostBorder.Width / 2));
                Canvas.SetTop(ghostTextBlock, mouseLocation.Y - (MainWindow.GhostBorder.Height / 2));
            }

            // If the Cursor is not within the Canvas
            else
            {
                // Hide the Ghost and Text because it would be drawn off the Canvas
                MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden;
                ghostTextBlock.Visibility         = System.Windows.Visibility.Hidden;
            }
        }
コード例 #2
0
        /// <summary>
        /// This updates the Range drawing for a given tracker
        /// </summary>
        /// <param name="tracker"></param>
        public void updateRange(Tracker tracker)
        {
            double FOVAngle = tracker.FieldOfView.Value / 2;

            // We want to adjust the MinRange triangle, so we're using sin law
            if (tracker.MinRange.HasValue)
            {
                double leftX       = (tracker.MinRange.Value * Math.Sin(Util.DEGREES_TO_RADIANS * FOVAngle)) / (Util.DEGREES_TO_RADIANS * (180.0 - FOVAngle - 90));
                double leftXPixels = DrawingResources.ConvertFromMetersToPixelsX(leftX, MainWindow.SharedCanvas);
                double YPixels     = DrawingResources.ConvertFromMetersToPixelsY(tracker.MinRange.Value, MainWindow.SharedCanvas);

                NearTriangle.Points.Clear();

                NearTriangle.Points.Add(new Point(50, 15));
                NearTriangle.Points.Add(new Point(50 + leftXPixels, 15 + YPixels));
                NearTriangle.Points.Add(new Point(50 - leftXPixels, 15 + YPixels));
            }

            // Adjusting the FarLine
            if (tracker.MaxRange.HasValue)
            {
                double leftX       = (tracker.MaxRange.Value * Math.Sin(Util.DEGREES_TO_RADIANS * FOVAngle)) / (Util.DEGREES_TO_RADIANS * (180.0 - FOVAngle - 90));
                double leftXPixels = DrawingResources.ConvertFromMetersToPixelsX(leftX, MainWindow.SharedCanvas);
                double YPixels     = DrawingResources.ConvertFromMetersToPixelsY(tracker.MaxRange.Value, MainWindow.SharedCanvas);

                FarLine.X1 = 50 + leftXPixels;
                FarLine.Y1 = YPixels;
                FarLine.X2 = 50 - leftXPixels;
                FarLine.Y2 = YPixels;
            }
        }
コード例 #3
0
        // Adds Gridlines based on the width and height of the canvas onto the Grid gridLines
        public static void GenerateGridLines(Canvas canvas, Grid gridLines, double scale)
        {
            gridLines.ColumnDefinitions.Clear();
            gridLines.RowDefinitions.Clear();

            // Finds out how many pixels 1 meter is
            double gridWidth = DrawingResources.ConvertFromMetersToDisplayCoordinates(new Point(scale, scale), canvas).X;

            // Calculates the number of rows and columns to add
            double numberOfLinesWide = canvas.ActualWidth / gridWidth;
            double numberOfLinesHigh = canvas.ActualHeight / gridWidth;

            // Generate Columns
            for (int i = 0; i < numberOfLinesWide; i++)
            {
                ColumnDefinition columnDefinition = new ColumnDefinition();
                columnDefinition.Width = new GridLength(gridWidth);
                gridLines.ColumnDefinitions.Add(columnDefinition);
            }

            // Generate Rows
            for (int i = 0; i < numberOfLinesHigh; i++)
            {
                RowDefinition rowDefinition = new RowDefinition();
                rowDefinition.Height = new GridLength(gridWidth);
                gridLines.RowDefinitions.Add(rowDefinition);
            }
        }
コード例 #4
0
        /// <summary>
        /// This updates the FOV draw lines for a given tracker
        /// </summary>
        /// <param name="tracker"></param>
        public void updateFOV(Tracker tracker)
        {
            double FOVAngle    = tracker.FieldOfView.Value / 2;
            double leftX       = (tracker.MaxRange.Value * Math.Sin(Util.DEGREES_TO_RADIANS * FOVAngle)) / (Util.DEGREES_TO_RADIANS * (180.0 - FOVAngle - 90));
            double leftXPixels = DrawingResources.ConvertFromMetersToPixelsX(leftX, MainWindow.SharedCanvas);
            double YPixels     = DrawingResources.ConvertFromMetersToPixelsY(tracker.MaxRange.Value, MainWindow.SharedCanvas);

            RightLine.X2 = 50 + leftXPixels;
            RightLine.Y2 = YPixels;
            LeftLine.X2  = 50 - leftXPixels;
            LeftLine.Y2  = YPixels;

            //double topAngle = Util.NormalizeAngle(270 + FOVAngle);
            //double topX = Math.Cos(topAngle * Math.PI / 180);
            //double topY = Math.Sin(topAngle * Math.PI / 180);
            //Point newLeft = DrawingResources.ConvertPointToProperLength(new Point(topX, topY), DrawingResources.TRACKER_FOV_LENGTH);
            //LeftLine.X2 = newLeft.X;
            //LeftLine.Y2 = -newLeft.Y;

            //double bottomAngle = Util.NormalizeAngle(270 - FOVAngle);
            //double bottomX = Math.Cos(bottomAngle * Math.PI / 180);
            //double bottomY = Math.Sin(bottomAngle * Math.PI / 180);
            //Point newRight = DrawingResources.ConvertPointToProperLength(new Point(bottomX, bottomY), DrawingResources.TRACKER_FOV_LENGTH);
            //RightLine.X2 = newRight.X;
            //RightLine.Y2 = -newRight.Y;
        }
コード例 #5
0
        public void onLocationChanged(Device device)
        {
            PairableDevice pairableDevice = (PairableDevice)device;

            //Dispatch UI Changes to Main Thread
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                if (pairableDevice.Location.HasValue)
                {
                    if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
                    {
                        MyDisplayState = DisplayState.LocatedAndOnStackPanel;
                    }

                    Point newPoint = DrawingResources.ConvertFromMetersToDisplayCoordinates(pairableDevice.Location.Value, MainWindow.SharedCanvas);

                    // InnerBorder.Width / 2 is to make it so that the point that the DeviceControl is drawn at is actually the center of the Border
                    Canvas.SetLeft(this, newPoint.X - (InnerBorder.Width / 2));
                    Canvas.SetTop(this, newPoint.Y - (InnerBorder.Height / 2));
                }
                else if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
                {
                    MyDisplayState = DisplayState.UnlocatedAndOnStackPanel;
                }
            }));
        }
コード例 #6
0
        public void onOrientationChanged(Device device)
        {
            PairableDevice pairableDevice = (PairableDevice)device;
            // Draw two lines to serve as field of view indicators
            double topAngle = Util.NormalizeAngle(pairableDevice.Orientation.Value + pairableDevice.FieldOfView.Value);
            double topX     = Math.Cos(topAngle * Math.PI / 180);
            double topY     = Math.Sin(topAngle * Math.PI / 180);


            double bottomAngle = Util.NormalizeAngle(pairableDevice.Orientation.Value - pairableDevice.FieldOfView.Value);
            double bottomX     = Math.Cos(bottomAngle * Math.PI / 180);
            double bottomY     = Math.Sin(bottomAngle * Math.PI / 180);

            Point newLeft  = DrawingResources.ConvertPointToProperLength(new Point(topX, topY), DrawingResources.DEVICE_FOV_LENGTH);
            Point newRight = DrawingResources.ConvertPointToProperLength(new Point(bottomX, bottomY), DrawingResources.DEVICE_FOV_LENGTH);

            //Dispatch UI Changes to Main Thread
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                LeftLine.X2 = newLeft.X;
                LeftLine.Y2 = -newLeft.Y;

                RightLine.X2 = newRight.X;
                RightLine.Y2 = -newRight.Y;

                if (pairableDevice.PairingState == PairingState.Paired)
                {
                    LeftLine.Visibility  = System.Windows.Visibility.Visible;
                    RightLine.Visibility = System.Windows.Visibility.Visible;
                }
            }));
        }
コード例 #7
0
 public void OnPairingStateChanged(PairablePerson pairablePerson)
 {
     //Dispatch Brush Change to Main Thread
     Application.Current.Dispatcher.BeginInvoke(new Action(() => {
         //Set Color of Ellipse to Appropriate Color
         PersonEllipse.Stroke = DrawingResources.GetBrushFromPairingState(pairablePerson.PairingState);
     }));
 }
コード例 #8
0
 public void onLocationChanged(Device device)
 {
     if (device.Location.HasValue)
     {
         this.Dispatcher.Invoke(new Action(delegate()
         {
             Point newPoint = DrawingResources.ConvertFromMetersToDisplayCoordinates(device.Location.Value, MainWindow.SharedCanvas);
             Canvas.SetLeft(this, newPoint.X);
             Canvas.SetTop(this, newPoint.Y);
         }));
     }
 }
コード例 #9
0
        // Updates the scale of the Gridlines
        private void UpdateGridlines(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (GridLinesScaleSlider.Value == 1)
            {
                MetersTextBlock.Text = " meter";
            }
            else
            {
                MetersTextBlock.Text = " meters";
            }

            DrawingResources.GenerateGridLines(canvas, GridLines, GridLinesScaleSlider.Value);
        }
コード例 #10
0
        public void OnLocationChanged(Person person)
        {
            this.Dispatcher.Invoke(new Action(delegate()
            {
                if (person.Location.HasValue)
                {
                    Point newPoint = DrawingResources.ConvertFromMetersToDisplayCoordinates(person.Location.Value, MainWindow.SharedCanvas);

                    // PersonEllipse.Width / 2 is to make it so that the point that the PersonControl is drawn at is actually the center of the Ellipse
                    Canvas.SetLeft(this, newPoint.X - (PersonEllipse.Width / 2));
                    Canvas.SetTop(this, newPoint.Y - (PersonEllipse.Height / 2));

                    CoordinatesLabel.Content = string.Format("Location: ({0:0.0},{1:0.0})", person.Location.Value.X, person.Location.Value.Y);
                }
            }));
        }
コード例 #11
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.Dispatcher.Invoke(new Action(delegate()
            {
                DrawingResources.GenerateGridLines(canvas, GridLines, GridLinesScaleSlider.Value);
                GridLines.ShowGridLines = true;

                // When we do the event handling through XAML, an event fires before the Window is loaded, and it freezes the program, so we do event binding after Window is loaded
                GridLinesScaleSlider.ValueChanged += UpdateGridlines;
                GridLinesCheckBox.Checked         += ChangeGridlineVisibility;
                GridLinesCheckBox.Unchecked       += ChangeGridlineVisibility;
                RangeCheckBox.Checked             += ChangeRangeVisibility;
                RangeCheckBox.Unchecked           += ChangeRangeVisibility;

                //Create Dictionaries for DeviceControl, PersonControl
                DeviceControlDictionary  = new Dictionary <string, DeviceControl>();
                PersonControlDictionary  = new Dictionary <PairablePerson, PersonControl>();
                TrackerControlDictionary = new Dictionary <string, TrackerControl>();


                //Initialize and Start MSEKinectManager
                kinectManager = new MSEKinectManager();
                kinectManager.Start();

                // The tracker is created in the PersonManager constructor, so there's actually no way for us to listen for its creation the first time
                //trackerChanged(kinectManager.PersonManager, kinectManager.PersonManager.Tracker);

                //Setup Events for Device Addition and Removal, Person Addition and Removal
                kinectManager.DeviceManager.DeviceAdded         += deviceAdded;
                kinectManager.DeviceManager.DeviceRemoved       += deviceRemoved;
                kinectManager.PersonManager.PersonAdded         += personAdded;
                kinectManager.PersonManager.PersonRemoved       += personRemoved;
                kinectManager.PersonManager.newKinectDiscovered += KinectDiscovered;
                kinectManager.PersonManager.kinectRemoved       += KinectRemoved;

                //Seperate components for displaying the visible skeletons
                skeletonRenderer = new SkeletonRenderer(SkeletonBasicsImage);

                //// Values retrieved from:
                //// http://blogs.msdn.com/b/kinectforwindows/archive/2012/01/20/near-mode-what-it-is-and-isn-t.aspx
                //// http://msdn.microsoft.com/en-us/library/jj131033.aspx
                //tracker.MinRange = 0.8;
                //tracker.MaxRange = 4;
                //tracker.FieldOfView = 57;
            }));
        }
コード例 #12
0
        public void onPairingStateChanged(PairableDevice pairableDevice)
        {
            //Dispatch UI Changes to Main Thread
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                //Set device border to appropriate colour
                InnerBorder.BorderBrush = DrawingResources.GetBrushFromPairingState(pairableDevice.PairingState);

                //Set the control's owner
                if (pairableDevice.PairingState == PairingState.Paired)
                {
                    // When paired, we move the device to the canvas.
                    this.MyDisplayState = DisplayState.PairedAndOnCanvas;
                }
                else
                {
                    // If we are not paired or in pairing attempt, we go to stackpanel
                    this.MyDisplayState = DisplayState.UnpairedAndOnStackPanel;
                }
            }));
        }
コード例 #13
0
        protected override void OnDrop(DragEventArgs e)
        {
            string DataType = e.Data.GetFormats(true)[0];

            //if the object dropped is a tracker
            if (DataType == "trackerControl")
            {
                base.OnDrop(e);
                Point mouseLocation = e.GetPosition(sharedCanvas);

                // Grab the data we packed into the DataObject
                TrackerControl trackerControl = (TrackerControl)e.Data.GetData("trackerControl");

                // Hide the Ghost and Text since a Drop has been made
                MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden;
                ghostTextBlock.Visibility         = System.Windows.Visibility.Hidden;

                // Return the Opacity of the TrackerControl
                trackerControl.Opacity = 1;

                trackerControl.Tracker.Location = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas);


                // Check if the TrackerControl is already a child of Shared Canvas
                Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas));

                if (!trackerControl.IsDescendantOf(SharedCanvas))
                {
                    trackerControl.formatForCanvas();
                    kinectWrapPanel.Children.Remove(trackerControl);
                    SharedCanvas.Children.Add(trackerControl);

                    if (trackerControl.Tracker.Orientation == null)
                    {
                        trackerControl.Tracker.Orientation = 270;
                    }
                }

                // if the cursor is outside the canvas, put the tracker back in stackpanel.
                else if (!(mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y))
                {
                    trackerControl.Tracker.StopStreaming();
                    cleanUpKinectPersons(trackerControl.Tracker.Identifier);
                    trackerControl.formatForStackPanel();
                    SharedCanvas.Children.Remove(trackerControl);
                    kinectWrapPanel.Children.Add(trackerControl);
                }
            }

            //if the objet dropped is a device.
            else if (DataType == "deviceControl")
            {
                base.OnDrop(e);
                Point mouseLocation = e.GetPosition(sharedCanvas);

                // Grab the data we packed into the DataObject
                DeviceControl deviceControl = (DeviceControl)e.Data.GetData("deviceControl");

                // Hide the Ghost and Text since a Drop has been made
                MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden;
                ghostTextBlock.Visibility         = System.Windows.Visibility.Hidden;

                // Return the Opacity of the DeviceControl
                deviceControl.Opacity = 1;

                PairableDevice device   = deviceControl.PairableDevice;
                IADevice       iaDevice = deviceControl.IADevice;

                IARequest request = new IARequest(Routes.SetLocationRoute);
                request.Parameters["identifier"] = iaDevice.Name;

                Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas));

                //if the dragged device is a pairable device (i.e iPad)
                if (!iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
                {
                    Point mouseLocationOnCanvas = mouseLocation = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas);
                    bool  pairedToNewDevice     = false;

                    foreach (KeyValuePair <PairablePerson, PersonControl> keyPair in PersonControlDictionary)
                    {
                        Point  personLocation = keyPair.Key.Location.Value;
                        double distance       = Math.Sqrt(Math.Pow(mouseLocationOnCanvas.X - personLocation.X, 2) + Math.Pow(mouseLocationOnCanvas.Y - personLocation.Y, 2));

                        //if the mouse drop is close to a person, pair the device with that person.
                        if (distance < 0.3 && (device.HeldByPersonIdentifier == keyPair.Key.Identifier || keyPair.Key.PairingState != PairingState.Paired))
                        {
                            if (device.PairingState == PairingState.Paired || device.PairingState == PairingState.PairedButOccluded)
                            {
                                kinectManager.PairingRecognizer.UnpairDevice(device);
                            }

                            kinectManager.PairingRecognizer.Pair(device, keyPair.Key);
                            pairedToNewDevice = true;
                            break;
                        }
                    }

                    //if the mouse drop is not close to a person then unpair the device.
                    if (!pairedToNewDevice)
                    {
                        kinectManager.PairingRecognizer.UnpairDevice(device);
                    }
                }

                //if the dragged device is not a pairable device (i.e table-top)
                else if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
                {
                    if (mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y)
                    {
                        // Dropped within Canvas, so we want to place it on the canvas
                        device.Location = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas);
                        request.SetBodyWith(new IntermediatePoint(device.Location.Value));
                    }
                    else
                    {
                        // Not dropped within Canvas, so we want to put it back on the stack panel
                        device.Location = null;
                        request.SetBodyWith(null);
                    }

                    // Send a request to the Device that their location has changed
                    kinectManager.IntAirAct.SendRequest(request, iaDevice);
                }
            }
        }