private void DrawEllipse(InkAnalysisInkDrawing shape)
        {
            var     points  = shape.Points;
            Ellipse ellipse = new Ellipse();

            ellipse.Width = Math.Sqrt((points[0].X - points[2].X) * (points[0].X - points[2].X) +
                                      (points[0].Y - points[2].Y) * (points[0].Y - points[2].Y));
            ellipse.Height = Math.Sqrt((points[1].X - points[3].X) * (points[1].X - points[3].X) +
                                       (points[1].Y - points[3].Y) * (points[1].Y - points[3].Y));

            var             rotAngle        = Math.Atan2(points[2].Y - points[0].Y, points[2].X - points[0].X);
            RotateTransform rotateTransform = new RotateTransform();

            rotateTransform.Angle   = rotAngle * 180 / Math.PI;
            rotateTransform.CenterX = ellipse.Width / 2.0;
            rotateTransform.CenterY = ellipse.Height / 2.0;

            TranslateTransform translateTransform = new TranslateTransform();

            translateTransform.X = shape.Center.X - ellipse.Width / 2.0;
            translateTransform.Y = shape.Center.Y - ellipse.Height / 2.0;

            TransformGroup transformGroup = new TransformGroup();

            transformGroup.Children.Add(rotateTransform);
            transformGroup.Children.Add(translateTransform);
            ellipse.RenderTransform = transformGroup;

            var brush = new SolidColorBrush(Windows.UI.ColorHelper.FromArgb(255, 0, 0, 255));

            ellipse.Stroke          = brush;
            ellipse.StrokeThickness = 2;
            canvas.Children.Add(ellipse);
        }
        private static void AddPolygonToCanvas(InkAnalysisInkDrawing shape, Canvas drawingSurface)
        {
            Polygon polygon = new Polygon();

            polygon.IsHitTestVisible = false;

            foreach (var point in shape.Points)
            {
                polygon.Points.Add(point);
            }

            var attributes = canvas.InkPresenter.CopyDefaultDrawingAttributes();

            polygon.Stroke          = new SolidColorBrush(attributes.Color);
            polygon.StrokeThickness = attributes.Size.Width;

            drawingSurface.Children.Add(polygon);

            if (RecognitionOccured != null)
            {
                RecognitionOccured(null, new RecognitionEventArgs(polygon)
                {
                    Description = $"Polygon with {shape.Points.Count} sides"
                });
            }
        }
Beispiel #3
0
 private void RemoveStrokes(InkAnalysisInkDrawing shape)
 {
     // Find stroke that has id: strokeID and delete it
     foreach (var strokeId in shape.GetStrokeIds())
     {
         RemoveStroke(strokeId);
     }
 }
Beispiel #4
0
 private void Draw(InkAnalysisInkDrawing node)
 {
     if (node.DrawingKind == InkAnalysisDrawingKind.Circle || node.DrawingKind == InkAnalysisDrawingKind.Ellipse)
     {
         DrawEllipse(node);
     }
     else
     {
         DrawPolygon(node);
     }
 }
Beispiel #5
0
        private void AddPolygonToCanvas(InkAnalysisInkDrawing shape)
        {
            Polygon polygon = new Polygon();

            // The points of the polygon are reported clockwise.
            foreach (var point in shape.Points)
            {
                polygon.Points.Add(point);
            }

            canvas.Children.Add(polygon);
        }
Beispiel #6
0
        private void RemoveInkStrokes(InkAnalysisInkDrawing drawing)
        {
            foreach (var strokeId in drawing.GetStrokeIds())
            {
                InkStroke stroke = _inkPresenter.StrokeContainer.GetStrokeById(strokeId);
                if (stroke != null)
                {
                    stroke.Selected = true;
                }
            }

            _inkAnalyzer.RemoveDataForStrokes(drawing.GetStrokeIds());
        }
Beispiel #7
0
        private void DrawEllipse(InkAnalysisInkDrawing shape)
        {
            // Part of loading back the shapes, not working at the moment
            CanvasComponent ellipse = shapeHelper.BuildEllipse(shape);

            RemoveStrokes(shape);
            ellipse.shape.Stroke          = new SolidColorBrush(currentBrush.Color);
            ellipse.stroke                = new SolidColorBrush(currentBrush.Color).Color;
            ellipse.shape.StrokeThickness = currentBrush.Size.Width;
            ellipse.strokeThickness       = currentBrush.Size.Width;

            components.Add(ellipse);
            AddShapeToCanvas?.Invoke(ellipse.shape);
        }
Beispiel #8
0
        private void DrawPolygon(InkAnalysisInkDrawing shape)
        {
            // Part of loading back the shapes, not working at the moment
            CanvasComponent polygon = shapeHelper.BuildPolygon(shape);

            RemoveStrokes(shape);
            polygon.shape.Stroke          = new SolidColorBrush(currentBrush.Color);
            polygon.stroke                = new SolidColorBrush(currentBrush.Color).Color;
            polygon.shape.StrokeThickness = currentBrush.Size.Width;
            polygon.strokeThickness       = currentBrush.Size.Width;

            components.Add(polygon);
            AddShapeToCanvas?.Invoke(polygon.shape);
        }
Beispiel #9
0
        private void DrawPolygon(InkAnalysisInkDrawing shape)
        {
            var x = shape.Points.First().X;
            var y = shape.Points.First().Y;

            var newPoint = new Point(x, y);

            var newPoints = new List <Point>();

            newPoints.AddRange(shape.Points);
            newPoints.Add(newPoint);

            ApplyInkFromPoints(newPoints);
        }
Beispiel #10
0
        private void AddEllipseToCanvas(InkAnalysisInkDrawing shape)
        {
            Ellipse ellipse = new Ellipse();

            // Ellipses and circles are reported as four points
            // in clockwise orientation.
            // Points 0 and 2 are the extrema of one axis,
            // and points 1 and 3 are the extrema of the other axis.
            // See Ellipse.svg for a diagram.
            IReadOnlyList <Point> points = shape.Points;

            // Calculate the geometric center of the ellipse.
            var center = new Point((points[0].X + points[2].X) / 2.0, (points[0].Y + points[2].Y) / 2.0);

            // Calculate the length of one axis.
            ellipse.Width = Distance(points[0], points[2]);

            var compositeTransform = new CompositeTransform();

            if (shape.DrawingKind == InkAnalysisDrawingKind.Circle)
            {
                ellipse.Height = ellipse.Width;
            }
            else
            {
                // Calculate the length of the other axis.
                ellipse.Height = Distance(points[1], points[3]);

                // Calculate the amount by which the ellipse has been rotated
                // by looking at the angle our "width" axis has been rotated.
                // Since the Y coordinate is inverted, this calculates the amount
                // by which the ellipse has been rotated clockwise.
                double rotationAngle = Math.Atan2(points[2].Y - points[0].Y, points[2].X - points[0].X);

                RotateTransform rotateTransform = new RotateTransform();
                // Convert radians to degrees.
                compositeTransform.Rotation = rotationAngle * 180.0 / Math.PI;
                compositeTransform.CenterX  = ellipse.Width / 2.0;
                compositeTransform.CenterY  = ellipse.Height / 2.0;
            }

            compositeTransform.TranslateX = center.X - ellipse.Width / 2.0;
            compositeTransform.TranslateY = center.Y - ellipse.Height / 2.0;

            ellipse.RenderTransform = compositeTransform;

            canvas.Children.Add(ellipse);
        }
        private void DrawPolygon(InkAnalysisInkDrawing shape)
        {
            var     points  = shape.Points;
            Polygon polygon = new Polygon();

            foreach (var point in points)
            {
                polygon.Points.Add(point);
            }

            var brush = new SolidColorBrush(Windows.UI.ColorHelper.FromArgb(255, 0, 0, 255));

            polygon.Stroke          = brush;
            polygon.StrokeThickness = 2;
            canvas.Children.Add(polygon);
        }
Beispiel #12
0
        // Draw a polygon on the recognitionCanvas.
        private void DrawPolygon(InkAnalysisInkDrawing shape)
        {
            var points  = new List <Point>(shape.Points);
            var polygon = new Polygon();

            foreach (var point in points)
            {
                polygon.Points.Add(point);
            }

            var stroke = inkCanvas.InkPresenter.StrokeContainer.GetStrokeById(shape.GetStrokeIds().First());

            polygon.Stroke          = new SolidColorBrush(stroke.DrawingAttributes.Color);
            polygon.StrokeThickness = 2;
            recognitionCanvas.Children.Add(polygon);
        }
Beispiel #13
0
        private void AddEmoji(InkAnalysisInkDrawing drawing, string glyph)
        {
            Viewbox   vb = new Viewbox();
            TextBlock tb = new TextBlock();

            vb.SetValue(Canvas.TopProperty, drawing.BoundingRect.Top);
            vb.SetValue(Canvas.LeftProperty, drawing.BoundingRect.Left);

            tb.Text = glyph;

            tb.FontSize = 68;
            vb.Width    = drawing.BoundingRect.Width;
            vb.Height   = drawing.BoundingRect.Height;
            vb.Child    = tb;
            vb.Stretch  = Stretch.Fill;
            xamloverlay.Children.Add(vb);
        }
Beispiel #14
0
        // Draw an ellipse on the recognitionCanvas.
        private void DrawEllipse(InkAnalysisInkDrawing shape)
        {
            var     points  = shape.Points;
            Ellipse ellipse = new Ellipse();

            ellipse.Width  = shape.BoundingRect.Width;
            ellipse.Height = shape.BoundingRect.Height;

            Canvas.SetTop(ellipse, shape.BoundingRect.Top);
            Canvas.SetLeft(ellipse, shape.BoundingRect.Left);

            var brush = new SolidColorBrush(Windows.UI.ColorHelper.FromArgb(255, 0, 0, 255));

            ellipse.Stroke          = brush;
            ellipse.StrokeThickness = 2;
            RecognitionCanvas.Children.Add(ellipse);
        }
Beispiel #15
0
        // Draw an ellipse on the recognitionCanvas.
        private void DrawEllipse(InkAnalysisInkDrawing shape)
        {
            var points  = shape.Points;
            var ellipse = new Ellipse();

            ellipse.Width  = shape.BoundingRect.Width;
            ellipse.Height = shape.BoundingRect.Height;

            Canvas.SetTop(ellipse, shape.BoundingRect.Top);
            Canvas.SetLeft(ellipse, shape.BoundingRect.Left);

            var stroke = inkCanvas.InkPresenter.StrokeContainer.GetStrokeById(shape.GetStrokeIds().First());

            ellipse.Stroke          = new SolidColorBrush(stroke.DrawingAttributes.Color);
            ellipse.StrokeThickness = 2;
            recognitionCanvas.Children.Add(ellipse);
        }
Beispiel #16
0
        internal CanvasComponent BuildPolygon(InkAnalysisInkDrawing shape)
        {
            // From ink analysis result, constuct polygon
            CanvasComponent component = new CanvasComponent(CanvasComponent.ComponentType.Polygon);

            var     points  = shape.Points;
            Polygon polygon = new Polygon();

            foreach (var point in points)
            {
                polygon.Points.Add(point);
                // Save polygin information in component for use when erasing and saving
                component.points.Add(point);
            }
            component.shape = polygon;

            return(component);
        }
Beispiel #17
0
        internal CanvasComponent BuildEllipse(InkAnalysisInkDrawing shape)
        {
            // From the ink analysis result, construct ellipse
            CanvasComponent component = new CanvasComponent(CanvasComponent.ComponentType.Ellipse);

            var     points  = shape.Points;
            Ellipse ellipse = new Ellipse();

            ellipse.Width = Math.Sqrt((points[0].X - points[2].X) * (points[0].X - points[2].X) +
                                      (points[0].Y - points[2].Y) * (points[0].Y - points[2].Y));
            ellipse.Height = Math.Sqrt((points[1].X - points[3].X) * (points[1].X - points[3].X) +
                                       (points[1].Y - points[3].Y) * (points[1].Y - points[3].Y));

            var             rotAngle        = Math.Atan2(points[2].Y - points[0].Y, points[2].X - points[0].X);
            RotateTransform rotateTransform = new RotateTransform();

            rotateTransform.Angle   = rotAngle * 180 / Math.PI;
            rotateTransform.CenterX = ellipse.Width / 2.0;
            rotateTransform.CenterY = ellipse.Height / 2.0;

            TranslateTransform translateTransform = new TranslateTransform();

            translateTransform.X = shape.Center.X - ellipse.Width / 2.0;
            translateTransform.Y = shape.Center.Y - ellipse.Height / 2.0;

            TransformGroup transformGroup = new TransformGroup();

            transformGroup.Children.Add(rotateTransform);
            transformGroup.Children.Add(translateTransform);
            ellipse.RenderTransform = transformGroup;

            // Save ellipse information in component for use when erasing and saving
            component.a        = ellipse.Width / 2.0;
            component.b        = ellipse.Height / 2.0;
            component.rotAngle = rotAngle;

            var point = new Point(shape.Center.X, shape.Center.Y);

            component.center = point;

            component.shape = ellipse;

            return(component);
        }
Beispiel #18
0
        private void AddHeart(InkAnalysisInkDrawing drawing)
        {
            Viewbox   vb = new Viewbox();
            TextBlock tb = new TextBlock();

            vb.SetValue(Canvas.TopProperty, drawing.BoundingRect.Top);
            vb.SetValue(Canvas.LeftProperty, drawing.BoundingRect.Left);

            tb.Foreground = new SolidColorBrush(Colors.Red);
            tb.FontFamily = new FontFamily("Segoe MDL2 Assets");
            tb.Text       = "\uE00B";

            tb.FontSize = 68;
            vb.Width    = drawing.BoundingRect.Width;
            vb.Height   = drawing.BoundingRect.Height;
            vb.Child    = tb;
            vb.Stretch  = Stretch.Fill;
            xamloverlay.Children.Add(vb);
        }
        private static void AddEllipseToCanvas(InkAnalysisInkDrawing shape, Canvas drawingSurface)
        {
            Ellipse ellipse = new Ellipse();

            ellipse.IsHitTestVisible = false;

            // Ellipses and circles are reported as four points
            // in clockwise orientation.
            // Points 0 and 2 are the extrema of one axis,
            // and points 1 and 3 are the extrema of the other axis.
            // See Ellipse.svg for a diagram.
            IReadOnlyList <Point> points = shape.Points;

            // Calculate the geometric center of the ellipse.
            var center = new Point((points[0].X + points[2].X) / 2.0, (points[0].Y + points[2].Y) / 2.0);

            // Calculate the length of one axis.
            ellipse.Width = Distance(points[0], points[2]);

            var compositeTransform = new CompositeTransform();

            if (shape.DrawingKind == InkAnalysisDrawingKind.Circle)
            {
                ellipse.Height = ellipse.Width;
            }
            else
            {
                // Calculate the length of the other axis.
                ellipse.Height = Distance(points[1], points[3]);

                // Calculate the amount by which the ellipse has been rotated
                // by looking at the angle our "width" axis has been rotated.
                // Since the Y coordinate is inverted, this calculates the amount
                // by which the ellipse has been rotated clockwise.
                double rotationAngle = Math.Atan2(points[2].Y - points[0].Y, points[2].X - points[0].X);

                // Convert radians to degrees.
                compositeTransform.Rotation = rotationAngle * 180.0 / Math.PI;
                compositeTransform.CenterX  = ellipse.Width / 2.0;
                compositeTransform.CenterY  = ellipse.Height / 2.0;
            }

            compositeTransform.TranslateX = center.X - ellipse.Width / 2.0;
            compositeTransform.TranslateY = center.Y - ellipse.Height / 2.0;

            ellipse.RenderTransform = compositeTransform;

            var attributes = canvas.InkPresenter.CopyDefaultDrawingAttributes();

            ellipse.Stroke          = new SolidColorBrush(attributes.Color);
            ellipse.StrokeThickness = attributes.Size.Width;

            drawingSurface.Children.Add(ellipse);

            if (RecognitionOccured != null)
            {
                RecognitionOccured(null, new RecognitionEventArgs(ellipse)
                {
                    Description = $"Ellipse centered at {center}"
                });
            }
        }
Beispiel #20
0
        private async void Analyze()
        {
            InkAnalysisResult result = await inkAnalyzer.AnalyzeAsync();

            Shape drawnShape = null;

            if (result.Status == InkAnalysisStatus.Updated && inkAnalyzer.AnalysisRoot.Children.Count > 0)
            {
                if (inkAnalyzer.AnalysisRoot.Children.Last().Kind == InkAnalysisNodeKind.InkDrawing)
                {
                    // the things we can recognise:  https://docs.microsoft.com/en-us/uwp/api/windows.ui.input.inking.analysis.inkanalysisdrawingkind

                    LinearGradientBrush newRandomBrush = GetRandomGradientBrush();

                    InkAnalysisInkDrawing drawing = inkAnalyzer.AnalysisRoot.Children.Last() as InkAnalysisInkDrawing;
                    if (drawing.DrawingKind == InkAnalysisDrawingKind.Circle ||
                        drawing.DrawingKind == InkAnalysisDrawingKind.Ellipse)
                    {
                        // we have detected a circle or ellipse
                        CompositeTransform transform = new CompositeTransform();
                        Ellipse            ellipse   = new Ellipse();
                        AttachDragHandlers(ellipse);
                        ellipse.Fill   = newRandomBrush;
                        ellipse.Stroke = new SolidColorBrush(Colors.Black);
                        ellipse.Width  = Distance(drawing.Points[0], drawing.Points[2]);
                        var center = new Point((drawing.Points[0].X + drawing.Points[2].X) / 2.0,
                                               (drawing.Points[0].Y + drawing.Points[2].Y) / 2.0);

                        if (drawing.DrawingKind == InkAnalysisDrawingKind.Circle)
                        {
                            ellipse.Height = ellipse.Width;
                        }
                        else
                        {
                            ellipse.Height = Distance(drawing.Points[1], drawing.Points[3]);

                            double rotationAngle = Math.Atan2(drawing.Points[2].Y - drawing.Points[0].Y,
                                                              drawing.Points[2].X - drawing.Points[0].X);
                            transform.Rotation = rotationAngle * 180.0 / Math.PI;
                        }
                        transform.TranslateX          = center.X - ellipse.Width / 2.0d;
                        transform.TranslateY          = center.Y - ellipse.Height / 2.0d;
                        ellipse.RenderTransform       = transform;
                        ellipse.RenderTransformOrigin = new Point(0.5, 0.5);
                        root.Children.Add(ellipse);
                        drawnShape = ellipse;
                        if (animationToggle.IsChecked == true)
                        {
                            AddAnimation(ellipse);
                        }
                    }
                    else
                    {
                        // we have detected a polygon
                        Polygon polygon = new Polygon();
                        AttachDragHandlers(polygon);
                        polygon.Fill   = newRandomBrush;
                        polygon.Stroke = new SolidColorBrush(Colors.Black);
                        foreach (Point pt in drawing.Points)
                        {
                            polygon.Points.Add(pt);
                        }
                        CompositeTransform transform = new CompositeTransform();
                        transform.CenterX       = drawing.Center.X;
                        transform.CenterY       = drawing.Center.Y;
                        polygon.RenderTransform = transform;
                        root.Children.Add(polygon);
                        drawnShape = polygon;
                        if (animationToggle.IsChecked == true)
                        {
                            AddAnimation(polygon);
                        }
                    }
                }
                else
                {
                    // neither ellipse or polygon
                    System.Diagnostics.Debug.WriteLine(inkAnalyzer.AnalysisRoot.Children.Last().Kind.ToString());
                }

                // see if we have a match
                if (drawnShape != null)
                {
                    ViewModel.SeekTarget(drawnShape);
                }
            }
            inkCanvas.InkPresenter.StrokeContainer.Clear();
            inkAnalyzer.ClearDataForAllStrokes();
        }