Example #1
0
        private static PointCollection Reverse(PointCollection pointCollection)
        {
            if (pointCollection == null) throw new ArgumentNullException("pointCollection");

            return new PointCollection(pointCollection.Reverse().ToList());
        }
Example #2
0
        public void gestureCompleted()
        {
            // Minimum number of frames of no motion to be segmented as a gesture
            int motion_threshold = 3; //originally 5

            // Minimum length of time after a gesture is completed before another gesture can be started.
            int ignore_threshold = 10;

            // If users are still reseting their hands, ignore all the movements and clear all buffers.
            if (ignoreFrames <= ignore_threshold)
            {
                motion_free         = 0;
                readyforgesture     = false;
                colorBox.Background = new SolidColorBrush(Colors.Red);
                gesture_started     = false;
                //Clear the buffers
                foreach (List <int> sublist in history)
                {
                    sublist.Clear();
                }
                foreach (List <int> sublist in inverse_history)
                {
                    sublist.Clear();
                }
                pointHist.Clear();
            }

            if (gesture_started && ignoreFrames > ignore_threshold && motion_free > motion_threshold && selectedChannels >= 2)
            {
                // Use LINQ to remove all the frames at the end that correspond to the motion free periods.
                pointHist = new PointCollection(pointHist.Reverse().Skip(motion_threshold).Reverse());
                S         = new StylusPointCollection(S.Reverse().Skip(motion_threshold).Reverse());
                for (int i = 0; i < history.Count; i++)
                {
                    history[i]         = new List <int>(history[i].Reverse <int>().Skip(motion_threshold).Reverse <int>());
                    inverse_history[i] = new List <int>(inverse_history[i].Reverse <int>().Skip(motion_threshold).Reverse <int>());
                }

                //If we are in detect mode, pass it to WEKA for classification.
                if (detectMode.IsChecked.Value && pointHist.Count > 9)
                {
                    //Call function to find features and test with weka machine
                    if (selectedChannels == 2)
                    {
                        float[] speakers = { (float)KF[0].speakerTheta, (float)KF[1].speakerTheta };
                        //temp stores the string identifier of the gesture
                        string temp = WekaHelper.Classify(false, pointHist.Count() * waveIn.BufferMilliseconds,
                                                          true, new List <float>(speakers), pointHist, S, history, inverse_history);

                        //switch statement to rename up/down gestures to forward/back when displaying in the application
                        switch (temp)
                        {
                        case "swipe_up":
                            temp = "swipe_forward";
                            break;

                        case "swipe_down":
                            temp = "swipe_back";
                            break;

                        case "tap_up":
                            temp = "tap_forward";
                            break;

                        case "tap_down":
                            temp = "tap_back";
                            break;
                        }
                        gestureDetected.Text = temp;

                        //TODO Put interaction with other applications in this switch statement
                        // Allows for changing between workspaces in windows 10.
                        if (shellIntegration.IsChecked.Value)
                        {
                            switch (temp)
                            {
                            case "swipe_forward":
                                sim.Keyboard.KeyDown(VirtualKeyCode.LWIN);
                                sim.Keyboard.KeyPress(VirtualKeyCode.TAB);
                                sim.Keyboard.KeyUp(VirtualKeyCode.LWIN);
                                break;

                            case "swipe_back":
                                break;

                            case "swipe_left":
                                if (!chrome)
                                {
                                    sim.Keyboard.KeyDown(VirtualKeyCode.LWIN);
                                    sim.Keyboard.KeyDown(VirtualKeyCode.LCONTROL);
                                    sim.Keyboard.KeyPress(VirtualKeyCode.LEFT);
                                    sim.Keyboard.KeyUp(VirtualKeyCode.LWIN);
                                    sim.Keyboard.KeyUp(VirtualKeyCode.LCONTROL);
                                }
                                else
                                {
                                    sim.Keyboard.KeyDown(VirtualKeyCode.LCONTROL);
                                    sim.Keyboard.KeyDown(VirtualKeyCode.LSHIFT);
                                    sim.Keyboard.KeyPress(VirtualKeyCode.TAB);
                                    sim.Keyboard.KeyUp(VirtualKeyCode.LSHIFT);
                                    sim.Keyboard.KeyUp(VirtualKeyCode.LCONTROL);
                                }
                                break;

                            case "swipe_right":
                                if (!chrome)
                                {
                                    sim.Keyboard.KeyDown(VirtualKeyCode.LWIN);
                                    sim.Keyboard.KeyDown(VirtualKeyCode.LCONTROL);
                                    sim.Keyboard.KeyPress(VirtualKeyCode.RIGHT);
                                    sim.Keyboard.KeyUp(VirtualKeyCode.LWIN);
                                    sim.Keyboard.KeyUp(VirtualKeyCode.LCONTROL);
                                }
                                else
                                {
                                    sim.Keyboard.KeyDown(VirtualKeyCode.LCONTROL);
                                    sim.Keyboard.KeyPress(VirtualKeyCode.TAB);
                                    sim.Keyboard.KeyUp(VirtualKeyCode.LCONTROL);
                                }
                                break;

                            case "tap_forward":
                                chrome = true;
                                break;

                            case "tap_back":
                                chrome = false;
                                break;

                            case "tap_left":
                                break;

                            case "tap_right":
                                break;
                            }
                        }
                    }


                    ignoreFrames = 0;
                }
                // Clear the buffers
                foreach (List <int> sublist in history)
                {
                    sublist.Clear();
                }
                foreach (List <int> sublist in inverse_history)
                {
                    sublist.Clear();
                }
                pointHist.Clear();

                // Prepare for next gesture (might need a button press)
                readyforgesture     = false;
                colorBox.Background = new SolidColorBrush(Colors.Red);
                gesture_started     = false;
                motion_free         = 0;
            }
        }
Example #3
0
        //****************************************************
        // Split a panel into two sub-panels
        public bool Split(double start, double radius, double depth, out Panel panel_1, out Panel panel_2)
        {
            bool            addTo_1        = true;
            PointCollection points_1       = new PointCollection();
            PointCollection points_2       = new PointCollection();
            Point           points_2_start = new Point(0, 0);
            Point           top            = new Point();
            Point           bottom         = new Point();


            for (int ii = 0; ii < Points.Count - 1; ii++)
            {
                Point  first      = Points[ii];
                Point  second     = Points[ii + 1];
                Point  startPoint = new Point();
                double min        = Math.Min(first.X, second.X);
                double max        = Math.Max(first.X, second.X);
                if (min <= start && max >= start)
                {
                    if (first.X == start)
                    {
                        startPoint = first;
                    }
                    else if (second.X == start)
                    {
                        startPoint = second;
                    }
                    else
                    {
                        // need to find point on line between first and second
                        // NOTE: because of the above conditions, we can't have a vertical line. They are ruled out.
                        double slope = (second.Y - first.Y) / (second.X - first.X);
                        startPoint = new Point(start, first.Y + slope * (start - first.X));
                    }

                    if (addTo_1)
                    {
                        top = startPoint;
                        if (first != startPoint)
                        {
                            points_1.Add(first);
                        }
                        points_2.Add(top);
                    }
                    else
                    {
                        bottom = startPoint;

                        if (first != startPoint)
                        {
                            points_2.Add(first);
                        }
                        PointCollection     splitter_1 = PanelSplitter.Tongues(top, bottom, (int)radius, depth);
                        IEnumerable <Point> splitter_2 = splitter_1.Reverse();

                        foreach (Point p in splitter_1)
                        {
                            points_1.Add(p);
                        }

                        foreach (Point p in splitter_2)
                        {
                            points_2.Add(p);
                        }
                    }

                    addTo_1 = !addTo_1;
                }
                else
                {
                    if (addTo_1)
                    {
                        points_1.Add(Points[ii]);
                    }
                    else
                    {
                        points_2.Add(Points[ii]);
                    }
                }
            }

            // close the panels
            points_1.Add(points_1[0]);
            //points_2.Add(top);

            panel_1 = new Panel(points_1);
            panel_2 = new Panel(points_2);

            panel_1.name = name + "A";
            panel_2.name = name + "B";

            return(true);
        }