Exemplo n.º 1
0
        public void addNToX()
        {
            n = n + 10;
            Monitor.Enter(synObj);
            try
            {
                MessageBox.Show(Thread.CurrentThread.Name + " is adding " + n + " to X values");
                Dispatcher.Invoke(() =>
                {
                    MessageBox.Show(points.ToString(), "X t2");
                    PointCollection newPoints = new PointCollection();

                    for (int i = 0; i < points.Count(); i++)
                    {
                        Point newPoint = points[i];
                        newPoint.X     = newPoint.X + n;
                        newPoints.Add(newPoint);
                    }
                    points = newPoints;
                    MessageBox.Show(points.ToString());
                });
                Monitor.Pulse(synObj);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                Monitor.Exit(synObj);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws lines amd calculates values for polygon
        /// </summary>
        private void DrawLines()
        {
            double StartCircleDiameter = 10.0;


            if (points.Count() > 0)
            {
                // make a circle to draw
                Ellipse el = new Ellipse();
                el.Width  = StartCircleDiameter;
                el.Height = StartCircleDiameter;

                // set the colour
                el.Fill            = Brushes.Green;
                el.Stroke          = Brushes.Blue;
                el.StrokeThickness = 1;

                // work out where to put it, only was is using the margin to place it
                double left = points[0].X - (StartCircleDiameter / 2);
                double top  = points[0].Y - (StartCircleDiameter / 2);
                el.Margin = new Thickness(left, top, 0, 0);

                // draw it
                myCanvas.Children.Add(el);
            }
            Polyline polyline = new Polyline();

            polyline.Stroke          = Brushes.Black;
            polyline.StrokeThickness = 2;
            polyline.Points          = points;
            myCanvas.Children.Add(polyline);

            CalculateGridValues();
        }
Exemplo n.º 3
0
        public static bool IsPointInPolygon4(PointCollection polygon, Point testPoint)
        {
            bool result = false;
            int  j      = polygon.Count() - 1;

            for (int i = 0; i < polygon.Count(); i++)
            {
                if (polygon[i].Y < testPoint.Y && polygon[j].Y >= testPoint.Y || polygon[j].Y < testPoint.Y && polygon[i].Y >= testPoint.Y)
                {
                    if (polygon[i].X + (testPoint.Y - polygon[i].Y) / (polygon[j].Y - polygon[i].Y) * (polygon[j].X - polygon[i].X) < testPoint.X)
                    {
                        result = !result;
                    }
                }
                j = i;
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculate the area of a polygon
        /// https://stackoverflow.com/questions/2034540/calculating-area-of-irregular-polygon-in-c-sharp
        /// </summary>
        private double AreaOfPolygon(PointCollection points)
        {
            if (points.Count() < 2)
            {
                return(0.0);
            }

            points.Add(points[0]);
            var area = Math.Abs(points.Take(points.Count - 1)
                                .Select((p, i) => (points[i + 1].X - p.X) * (points[i + 1].Y + p.Y))
                                .Sum() / 2);

            return(area);
        }
 public override bool AddPoint(PointWithID GraphPoint)
 {
     if (GraphPoint.NamePrefix != PointNamePrefix || PointCollection.Count(i1 => i1.ID == GraphPoint.ID) > 0)
         throw new Exception(String.Format("Point {0} not compatible from this graph or already contains in collection points.", GraphPoint));
     else
     {
         if (HashSetPoints.Add(GraphPoint))
         {
             PointIncrementalCounter = PointCollection.Count();
             return true;
         }
         else return false;
     }
 }
        private PointCollection GetDeformedKoch1Shape(PointCollection inputPoints, uint sizeModifier)
        {
            PointCollection kochPoints = new PointCollection();

            for (int i = 0; i < inputPoints.Count(); i++)
            {
                System.Windows.Point start = inputPoints[i];
                System.Windows.Point end;
                if (i + 1 == inputPoints.Count())
                {
                    end = inputPoints[0];
                }
                else
                {
                    end = inputPoints[i + 1];
                }

                var differenceX          = end.X - start.X;
                var differenceY          = end.Y - start.Y;
                var modifierXSpaceToKoch = differenceX / sizeModifier;
                var modifierYSpaceToKoch = differenceY / sizeModifier;

                var point1 = new System.Windows.Point(start.X + modifierXSpaceToKoch, start.Y + modifierYSpaceToKoch);
                var point2 = new System.Windows.Point(end.X - modifierXSpaceToKoch, end.Y - modifierYSpaceToKoch);
                var point1And2DifferenceX = point2.X - point1.X;
                var point1And2DifferenceY = point2.Y - point1.Y;
                var middlePoint           = new System.Windows.Point(point1.X + point1And2DifferenceX, point1.Y + point1And2DifferenceY);
                var degreesOfKoch         = 60;
                middlePoint = RotateAroundPointAntiClockwise(point1, middlePoint, degreesOfKoch);

                kochPoints.Add(start);
                kochPoints.Add(middlePoint);
                kochPoints.Add(point2);
            }

            return(kochPoints);
        }
Exemplo n.º 7
0
        public static VVector[] TransformPoints(this MIRSRegistration mirsReg, PointCollection sourcePoints)
        {
            VVector[] transformedPoints = new VVector[sourcePoints.Count()];
            int       index             = 0;

            if (mirsReg is MIRSRigidRegistration)
            {
                foreach (VVector p in sourcePoints)
                {
                    transformedPoints[index++] = ((MIRSRigidRegistration)mirsReg).RigidRegistration.TransformPoint(p);
                }
            }
            else if (mirsReg is MIRSNonRigidRegistration)
            {
                foreach (VVector p in sourcePoints)
                {
                    transformedPoints[index++] = ((MIRSNonRigidRegistration)mirsReg).NonRigidRegistration.TransformPoint(p);
                }
            }
            return(transformedPoints);
        }
Exemplo n.º 8
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;
            }
        }
Exemplo n.º 9
0
        public MyWindow()
        {
            Width      = 1536;
            Height     = 768;
            Title      = "My window";
            Background = BGBrush;
            int   MoveX       = 200;
            int   MoveY       = 200;
            Point bufferPoint = new Point();

            Content = myGrid;
            //Считываю строку с точками из файла
            //PointCollection readPoints = PointCollection.Parse(ReadPoints());

            //Так как строку с точками мы больше не считываем из файла, строка будет храниться в таком виде, сразу считаем количество
            PointCollection readPoints = PointCollection.Parse("20,20 846,20 868,40 42,40  912,40 934,60 956,80 868,80 846,60 64,60  86,80  980,80 1002,100 1024,120 868,120 846,100 108,100  130,120 920,120 894,140  152,140 868,160 460,160 438,140");
            int             pCount     = readPoints.Count();

            //Этот цикл тут для того, чтобы можно было двигать всю структуру.
            for (int i = 0; i < pCount;)
            {
                bufferPoint.X = readPoints[i].X + MoveX;
                bufferPoint.Y = readPoints[i].Y + MoveY;
                points.Add(bufferPoint);
                i++;
            }

            fillComboBox.HorizontalAlignment  = HorizontalAlignment.Left;
            fillComboBox.VerticalAlignment    = VerticalAlignment.Top;
            colorComboBox.HorizontalAlignment = HorizontalAlignment.Left;
            colorComboBox.VerticalAlignment   = VerticalAlignment.Top;

            //Быстрый способ заполнить комбобоксы, сразу зададим выбор по умолчанию
            for (int i = 0; i < 9; i++)
            {
                colorComboBox.Items.Add("Цвет " + (i + 1));
            }
            colorComboBox.SelectedIndex = 0;
            colorComboBox.Margin        = new Thickness(100, 0, 0, 0);

            for (int i = 0; i < 9; i++)
            {
                fillComboBox.Items.Add("Заливка " + (i + 1));
            }
            fillComboBox.SelectedIndex = 0;

            //Просто текст. Отображается текст из комбобокса с вариантом заливки.
            label1.Content    = fillComboBox.Text;
            label1.FontSize   = 20;
            label1.Foreground = System.Windows.Media.Brushes.Black;
            label1.Margin     = new Thickness(550 + MoveX, 60 + MoveY, 0, 0);

            //Рисуем всё
            myGrid.Children.Add(fillComboBox);
            myGrid.Children.Add(colorComboBox);
            myGrid.Children.Add(label1);
            DrawLines();
            DrawDots();

            //Обрабатываем события при изменении выбранного пункта комбобоксов
            fillComboBox.SelectionChanged  += new SelectionChangedEventHandler(Event_Fill);
            colorComboBox.SelectionChanged += new SelectionChangedEventHandler(Event_Select_Color);
        }
Exemplo n.º 10
0
        private void findAndDeleteStrikethrough(InkAnalyzer inkAnalyzer, InkCanvas canvas,
                                                List <Stroke> horizontalLines, ContextNodeCollection contextNodeCollection)
        {
            List <ContextNode> deletedNodes           = new List <ContextNode>();
            List <Stroke>      removedHorizontalLines = new List <Stroke>();

            //Find things to apply gestures to
            foreach (ContextNode node in contextNodeCollection)
            {
                if (node.Strokes.Count == 0)
                {
                    continue;
                }
                Rect strikethroughBounds = node.Strokes.GetBounds();
                strikethroughBounds.Height *= 0.75d;
                if (node is InkWordNode)
                {
                    PointCollection bl = (node as InkWordNode).GetBaseline();
                    if (bl != null &&
                        bl.Count() > 0)
                    {
                        double baseline = bl[0].Y;
                        strikethroughBounds.Height = baseline - strikethroughBounds.Y;
                    }
                }

                for (int j = 0; j < horizontalLines.Count; j++)
                {
                    if (node.Strokes[0] == horizontalLines[j])
                    {
                        break;
                    }
                    Stroke horizontalLine          = horizontalLines[j];
                    Rect   horizontalLineBounds    = horizontalLine.GetBounds();
                    double sideBuffer              = (1 - Constants.LINE_WORD_OVERLAPSE_RATIO) / 2;
                    double strikethroughBoundLeft  = strikethroughBounds.X + strikethroughBounds.Width * sideBuffer;
                    double strikethroughBoundRight = strikethroughBounds.X + strikethroughBounds.Width * (1 - sideBuffer);
                    if (strikethroughBounds.IntersectsWith(horizontalLineBounds) &&
                        strikethroughBoundLeft > horizontalLineBounds.X &&
                        strikethroughBoundRight < horizontalLineBounds.X + horizontalLineBounds.Width)
                    {
                        //Delete strikethrough
                        deletedNodes.Add(node);
                        removedHorizontalLines.Add(horizontalLine);
                    }
                }
            }

            foreach (Stroke stroke in removedHorizontalLines)
            {
                horizontalLines.Remove(stroke);
                canvas.Strokes.Remove(stroke);
                inkAnalyzer.RemoveStroke(stroke);
            }

            //Final step to apply the gestures, commit changes
            for (int i = deletedNodes.Count - 1; i >= 0; i--)
            {
                ContextNode node = deletedNodes[i];
                try
                {
                    Rect        bounds   = node.Strokes.GetBounds();
                    double      nodeX    = bounds.X;
                    ContextNode parent   = node.ParentNode;
                    double      closestX = double.MaxValue;
                    foreach (ContextNode sibling in parent.SubNodes)
                    {
                        double siblingX = sibling.Strokes.GetBounds().X;
                        if (siblingX > nodeX && siblingX < closestX)
                        {
                            closestX = siblingX;
                        }
                    }
                    double dx = nodeX - closestX;
                    foreach (ContextNode sibling in parent.SubNodes)
                    {
                        //Nodes right side of current
                        if (sibling.Strokes.GetBounds().X > nodeX)
                        {
                            InkUtils.transposeStrokes(inkAnalyzer, sibling.Strokes, dx, 0d);
                        }
                    }
                    canvas.Strokes.Remove(node.Strokes);
                    inkAnalyzer.RemoveStrokes(node.Strokes);
                }
                catch (Exception e)
                {
                    //Ignore already deleted error
                }
            }
        }
        public void Start()
        {
            canvas1.Children.Clear();
            points = new PointCollection(PointCount);
            GetParameters();
            Polygon poly = new Polygon()
            {
                Stroke          = Brushes.White,
                StrokeThickness = 2.0
            };
            double R;
            double X;
            double Y;
            double minX = double.MaxValue;
            double maxX = 0.0;
            double minY = double.MaxValue;
            double maxY = 0.0;

            for (double Angle = 0; Angle <= 2 * Math.PI; Angle += 2 * Math.PI / PointCount)
            {
                R = SuperShape(Angle);
                X = R * Math.Cos(Angle);
                if (X > maxX)
                {
                    maxX = X;
                }
                if (X < minX)
                {
                    minX = X;
                }
                Y = R * Math.Sin(Angle);
                if (Y > maxY)
                {
                    maxY = Y;
                }
                if (Y < minY)
                {
                    minY = Y;
                }
                points.Add(new Point(X, Y));
            }
            //Determine the Scale to fit the Polygon inside the canvas
            if (maxX - minX > maxY - minY)
            {
                Scale = (canvas1.ActualWidth - 100) / (maxX - minX);
            }
            else
            {
                Scale = (canvas1.ActualHeight - 100) / (maxY - minY);
            }
            minX = Scale * minX;
            maxX = Scale * maxX;
            minY = Scale * minY;
            maxY = Scale * maxY;
            for (int I = 0; I < points.Count(); I++)
            {
                points[I] = new Point(Scale * points[I].X + (canvas1.ActualWidth - minX - maxX) / 2, Scale * points[I].Y + (canvas1.ActualHeight - minY - maxY) / 2);
            }
            poly.Points = points;
            canvas1.Children.Add(poly);
        }
Exemplo n.º 12
0
        public void writeTo2DFile()
        {
            string DataPath = GestureTests.Config.DataPath + userDirectory.Text + "\\";// @"..\..\..\data\a001\";

            string        searchPattern = gestureSelector.Text + "???";
            DirectoryInfo di            = Directory.CreateDirectory(DataPath);

            FileInfo[] files      = di.GetFiles(searchPattern);
            int        file_index = files.Length;

            string filename = DataPath + gestureSelector.Text + file_index;

            gestureDetected.Text = gestureSelector.Text + file_index;
            StreamWriter file = File.CreateText(filename);

            file.WriteLine("GestureName: " + gestureSelector.Text);
            file.WriteLine("Duration(ms): " + pointHist.Count() * waveIn.BufferMilliseconds);
            file.WriteLine("Handedness: " + handSelector.Text);
            file.WriteLine();
            file.WriteLine("SpeakerAngles: " + selectedChannels);
            for (int i = 0; i < KF.Count; i++)
            {
                file.WriteLine(KF[i].speakerTheta);
            }

            file.WriteLine();
            file.WriteLine("InterpretedPoints: " + pointHist.Count());
            foreach (Point p in pointHist)
            {
                file.WriteLine(p.X + "," + p.Y);
            }

            file.WriteLine();
            file.WriteLine("StrokePoints: " + S.Count());
            foreach (StylusPoint p in S)
            {
                file.WriteLine(p.X + "," + p.Y);
            }

            file.WriteLine();
            file.WriteLine("Velocities: " + history[0].Count);
            for (int i = 0; i < history[0].Count; i++)
            {
                file.WriteLine(history[0][i] + "," + history[1][i]);
            }

            file.WriteLine();
            file.WriteLine("InverseVelocities: " + inverse_history[0].Count);
            for (int i = 0; i < inverse_history[0].Count; i++)
            {
                file.WriteLine(inverse_history[0][i] + "," + inverse_history[1][i]);
            }


            file.WriteLine();
            file.WriteLine("RawData: " + data_history.Count);
            for (int i = 0; i < data_history.Count; i++)
            {
                file.WriteLine(string.Join(",", data_history[i]));
            }

            file.Flush();
            file.Close();
        }