Ejemplo n.º 1
0
        private void MyCheckButton_Click(object sender, RoutedEventArgs e)
        {
            // show the image if the image is not enabled
            if (!MyImageButton.IsChecked.Value)
            {
                InteractionTools.SetImage(MyImage, myImageFiles[MyCurrentIndex]);
                MySymbolsComboBox.SelectedIndex = MyCurrentIndex;
            }

            // hide the bottom command bar and shwo the top bar
            ShowAppBarButtons(true);
            MyInkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.None;
            MyRightSide.Visibility = Visibility.Visible;

            // shift the ink canvas to the right
            MyGrid.ColumnDefinitions[0].Width = new GridLength(0);
            MyGrid.ColumnDefinitions[1].Width = new GridLength(5, GridUnitType.Star);
            MyGrid.ColumnDefinitions[2].Width = new GridLength(5, GridUnitType.Star);

            // get the model and input sketches
            Sketch model = myTemplates[MyCurrentIndex];
            Sketch input = Sketch.CreateStroke("", new List <InkStroke>(MyInkStrokes.GetStrokes()), myTimeCollection, 0, 0, BorderLength, BorderLength);

            // train and run the recognizers
            myStructureRecognizer.Train(model, myTemplates, input);
            myTechniqueRecognizer.Train(model, input);
            myStructureRecognizer.Run();
            myTechniqueRecognizer.Run();

            // check the visual structure
            CheckStructure(myStructureRecognizer);

            // check the written technique
            CheckTechnique(myTechniqueRecognizer);
        }
Ejemplo n.º 2
0
        private async void MySymbolCorrectnessPlayButton_Click(object sender, RoutedEventArgs e)
        {
            //
            //EnableStructureButtons(false);
            MyImage.Visibility = Visibility.Collapsed;

            // get the model and input strokes
            Sketch model = SketchTools.Clone(myTemplates[MyCurrentIndex]);
            Sketch input = Sketch.CreateStroke("", new List <InkStroke>(MyInkStrokes.GetStrokes()), myTimeCollection, 0, 0, BorderLength, BorderLength);

            // store and remove the original strokes from the ink canvas
            List <InkStroke> originalStrokes = SketchTools.Clone(new List <InkStroke>(MyInkStrokes.GetStrokes()));

            foreach (InkStroke stroke in MyInkStrokes.GetStrokes())
            {
                stroke.Selected = true;
            }
            MyInkStrokes.DeleteSelected();

            // set the animation colors
            SolidColorBrush modelBrush = new SolidColorBrush(Colors.Green)
            {
                Opacity = 1.0
            };
            SolidColorBrush inputBrush = new SolidColorBrush(Colors.Red)
            {
                Opacity = 1.0
            };

            // get the animations
            List <Storyboard> modelStoryboards = Helper.DisplaySymbol(MyCanvas, model.Strokes, modelBrush, SMALL_DOT_SIZE, STROKE_DURATION);
            List <Storyboard> inputStoryboards = Helper.DisplaySymbol(MyCanvas, input.Strokes, inputBrush, StrokeVisuals.Size.Width, STROKE_DURATION);

            // animate the feedback
            foreach (Storyboard storyboard in modelStoryboards)
            {
                storyboard.Begin();
            }
            foreach (Storyboard storyboard in inputStoryboards)
            {
                storyboard.Begin();
            }

            // re-add the original strokes to the ink canvas and re-enable return button
            int delay = STROKE_DURATION;
            await InteractionTools.Delay(delay);

            MyInkStrokes.AddStrokes(originalStrokes);

            //
            //EnableStructureButtons(true);
            MyImage.Visibility = Visibility.Visible;
        }
Ejemplo n.º 3
0
        private void MyImageButton_Click(object sender, RoutedEventArgs e)
        {
            if (!MyImageButton.IsChecked.Value)
            {
                MyImage.Source = null;
            }

            else
            {
                InteractionTools.SetImage(MyImage, myImageFiles[MyCurrentIndex]);
                MySymbolsComboBox.SelectedIndex = MyCurrentIndex;
            }
        }
Ejemplo n.º 4
0
        private async void MyStrokeCountPlayButton_Click(object sender, RoutedEventArgs e)
        {
            // do not show feedback if canvas has no strokes
            if (MyInkStrokes.GetStrokes().Count <= 0)
            {
                return;
            }

            //
            EnableTechniqueButtons(false);

            // get the model and input strokes
            Sketch model = myTemplates[MyCurrentIndex];

            model = SketchTools.Clone(model);
            Sketch input = Sketch.CreateStroke("", new List <InkStroke>(MyInkStrokes.GetStrokes()), myTimeCollection, 0, 0, BorderLength, BorderLength);

            input = SketchTools.Clone(input);
            input = SketchTransformation.Resample(input, 128);

            // set the animation colors
            SolidColorBrush modelBrush = new SolidColorBrush(Colors.Green)
            {
                Opacity = 1.0
            };
            SolidColorBrush inputBrush = new SolidColorBrush(Colors.Red)
            {
                Opacity = 1.0
            };

            // get the animations
            List <Storyboard> modelStoryboards = InteractionTools.DisplayEndpoints(MyCanvas, model.Strokes, modelBrush, LARGE_DOT_SIZE, STROKE_DURATION);
            List <Storyboard> inputStoryboards = InteractionTools.DisplayEndpoints(MyCanvas, input.Strokes, inputBrush, SMALL_DOT_SIZE, STROKE_DURATION, model);

            // animate the feedback
            foreach (Storyboard storyboard in modelStoryboards)
            {
                storyboard.Begin();
            }
            foreach (Storyboard storyboard in inputStoryboards)
            {
                storyboard.Begin();
            }

            // re-add the original strokes to the ink canvas and re-enable return button
            int delay = STROKE_DURATION * model.Strokes.Count;
            await InteractionTools.Delay(delay);

            //
            EnableTechniqueButtons(true);
        }
Ejemplo n.º 5
0
        private async void MyPlayButton_Click(object sender, RoutedEventArgs e)
        {
            //
            if (!MyImageButton.IsChecked.Value)
            {
                return;
            }

            //
            EnableAppBarButtons(false);
            MyInkCanvas.InkPresenter.IsInputEnabled = false;

            //
            Sketch model = myTemplates[MyCurrentIndex];

            model = SketchTools.Clone(model);
            double          opacity = 0.8;
            Color           color   = Colors.Green;
            SolidColorBrush brush   = new SolidColorBrush(color)
            {
                Opacity = opacity
            };

            // animate the expert's model strokes
            List <Storyboard> modelStoryboards = InteractionTools.Trace(MyCanvas, model.Strokes, model.Times, LARGE_DOT_SIZE, brush, POINT_DURATION);

            foreach (Storyboard storyboard in modelStoryboards)
            {
                storyboard.Begin();
            }

            //
            int numModelPoints = 0;

            foreach (InkStroke stroke in model.Strokes)
            {
                numModelPoints += stroke.GetInkPoints().Count;
            }
            int delay = numModelPoints * POINT_DURATION;
            await InteractionTools.Delay(delay);

            //
            EnableAppBarButtons(true);
            MyInkCanvas.InkPresenter.IsInputEnabled = true;
        }
Ejemplo n.º 6
0
        private void MyCheckButton_Click(object sender, RoutedEventArgs e)
        {
            // show the image if the image is not enabled
            if (!MyImageButton.IsChecked.Value)
            {
                InteractionTools.SetImage(MyImage, myImageFiles[MyCurrentIndex]);
                MySymbolsComboBox.SelectedIndex = MyCurrentIndex;
            }

            // hide the bottom command bar and shwo the top bar
            ShowAppBarButtons(true);
            MyInkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.None;
            MyRightSide.Visibility = Visibility.Visible;

            // shift the ink canvas to the right
            MyGrid.ColumnDefinitions[0].Width = new GridLength(0);
            MyGrid.ColumnDefinitions[1].Width = new GridLength(5, GridUnitType.Star);
            MyGrid.ColumnDefinitions[2].Width = new GridLength(5, GridUnitType.Star);

            // get the model and input sketches
            Sketch model = myTemplates[MyCurrentIndex];
            Sketch input = Sketch.CreateStroke("", new List <InkStroke>(MyInkStrokes.GetStrokes()), myTimeCollection, 0, 0, BorderLength, BorderLength);

            //
            myTechniqueRecognizer.Train(model, input);
            myTechniqueRecognizer.Run();
            bool strokeCountResult     = myTechniqueRecognizer.StrokeCountResult;
            bool strokeOrderResult     = myTechniqueRecognizer.StrokeOrderResult;
            bool strokeDirectionResult = myTechniqueRecognizer.StrokeDirectionResult;
            bool strokeSpeedResult     = myTechniqueRecognizer.StrokeSpeedResult;

            //
            MyStrokeCountResultText.Text       = strokeCountResult ? "CORRECT" : "INCORRECT";
            MyStrokeCountResultText.Foreground = strokeCountResult ? CORRECT_BRUSH : INCORRECT_BRUSH;

            MyStrokeOrderResultText.Text       = strokeOrderResult ? "CORRECT" : "INCORRECT";
            MyStrokeOrderResultText.Foreground = strokeOrderResult ? CORRECT_BRUSH : INCORRECT_BRUSH;

            MyStrokeDirectionResultText.Text       = strokeDirectionResult ? "CORRECT" : "INCORRECT";
            MyStrokeDirectionResultText.Foreground = strokeDirectionResult ? CORRECT_BRUSH : INCORRECT_BRUSH;

            MyStrokeSpeedResultText.Text       = strokeSpeedResult ? "SUFFICIENT" : "INSUFFICIENT";
            MyStrokeSpeedResultText.Foreground = strokeSpeedResult ? CORRECT_BRUSH : INCORRECT_BRUSH;
        }
Ejemplo n.º 7
0
        private async void LoadImages()
        {
            //
            StorageFolder imagesFolder = await Package.Current.InstalledLocation.GetFolderAsync(@"Assets\Images");

            //
            myImageFiles = new List <StorageFile>();
            foreach (StorageFile file in await imagesFolder.GetFilesAsync())
            {
                string name = file.Name;
                if (name.EndsWith(".png") || name.EndsWith(".jpg") || name.EndsWith(".gif"))
                {
                    myImageFiles.Add(file);

                    MySymbolsComboBox.Items.Add(Path.GetFileNameWithoutExtension(file.Path));
                }
            }

            //
            InteractionTools.SetImage(MyImage, myImageFiles[0]);
            MySymbolsComboBox.SelectedIndex = 0;
        }
Ejemplo n.º 8
0
        private void MySymbolsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //
            if (!MyIsReady)
            {
                return;
            }

            //
            MyImage.Source = null;
            MyImageIndex   = MySymbolsComboBox.SelectedIndex;
            if (MyImageButton.IsChecked.Value)
            {
                InteractionTools.SetImage(MyImage, myImageFiles[MyImageIndex]);
            }

            //
            string promptedSymbol = MySymbolsComboBox.SelectedValue.ToString().ToUpper();

            MyPrompText.Text = PROMPT_TEXT + promptedSymbol;

            //
            Clear();
        }
Ejemplo n.º 9
0
 private void MySymbolsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     ImageIndex = MySymbolsComboBox.SelectedIndex;
     InteractionTools.SetImage(MyImage, myImageFiles[ImageIndex]);
 }
Ejemplo n.º 10
0
        private async void MyStrokeSpeedTestPlayButton_Click(object sender, RoutedEventArgs e)
        {
            // do not show feedback if canvas has no strokes or incorrect stroke count
            if (MyInkStrokes.GetStrokes().Count <= 0)
            {
                return;
            }
            if (!myTechniqueRecognizer.StrokeCountResult)
            {
                return;
            }

            //
            EnableTechniqueButtons(false);

            //
            bool   hasInput = false;
            Sketch model    = SketchTools.Clone(myTemplates[MyCurrentIndex]);
            Sketch input    = null;

            if (MyInkStrokes.GetStrokes().Count > 0)
            {
                input    = new Sketch("", new List <InkStroke>(MyInkStrokes.GetStrokes()), myTimeCollection, 0, 0, BorderLength, BorderLength);
                hasInput = true;
            }

            // get the converted model times
            long modelOffset = model.Times[0][0];
            long modelShift  = 0;
            List <List <long> > modelTimesCollection = new List <List <long> >();
            long modelFactor = 2;

            for (int i = 0; i < model.Times.Count; ++i)
            {
                //
                List <long> newModelTimes = new List <long>();
                foreach (long modelTime in model.Times[i])
                {
                    long newModelTime = (modelTime - modelOffset - modelShift) / modelFactor;
                    newModelTimes.Add(newModelTime);
                }

                //
                if (i < model.Times.Count - 1)
                {
                    long nextStart = model.Times[i + 1][0];
                    long prevLast  = model.Times[i][model.Times[i].Count - 1];
                    modelShift += nextStart - prevLast;
                }

                modelTimesCollection.Add(newModelTimes);
            }

            //
            model = new Sketch(model.Label, model.Strokes, modelTimesCollection, model.FrameMinX, model.FrameMinY, model.FrameMaxX, model.FrameMaxY);
            SolidColorBrush modelBrush = new SolidColorBrush(Colors.Black)
            {
                Opacity = 0.8
            };
            List <Storyboard> modelStoryboards = InteractionTools.Playback(MyCanvas, model.Strokes, model.Times, LARGE_DOT_SIZE, modelBrush);

            foreach (Storyboard storyboard in modelStoryboards)
            {
                storyboard.Begin();
            }

            //
            if (!hasInput)
            {
                return;
            }
            input = SketchTools.Clone(input);
            SolidColorBrush inputBrush = new SolidColorBrush(Colors.Red)
            {
                Opacity = 1.0
            };
            List <Storyboard> inputStoryboards = InteractionTools.Playback(MyCanvas, input.Strokes, input.Times, SMALL_DOT_SIZE, inputBrush);

            foreach (Storyboard storyboard in inputStoryboards)
            {
                storyboard.Begin();
            }

            //
            int inputDelay = (int)((input.Times[input.Times.Count - 1])[input.Times[input.Times.Count - 1].Count - 1] - (input.Times[0])[0]);
            int modelDelay = (int)((model.Times[model.Times.Count - 1])[model.Times[model.Times.Count - 1].Count - 1] - (model.Times[0])[0]);
            int delay      = inputDelay > modelDelay ? inputDelay : modelDelay;
            await InteractionTools.Delay(delay);


            //
            EnableTechniqueButtons(true);
        }
Ejemplo n.º 11
0
        private async void MyStrokeDirectionPlayButton_Click(object sender, RoutedEventArgs e)
        {
            // do not show feedback if canvas has no strokes or incorrect stroke count
            if (MyInkStrokes.GetStrokes().Count <= 0)
            {
                return;
            }
            if (!myTechniqueRecognizer.StrokeCountResult)
            {
                return;
            }

            //
            EnableTechniqueButtons(false);

            // get the input sketch and stroke directions
            Sketch input = Sketch.CreateStroke("", new List <InkStroke>(MyInkStrokes.GetStrokes()), myTimeCollection, 0, 0, BorderLength, BorderLength);

            input = SketchTools.Clone(input);
            input = SketchTransformation.Resample(input, 128);
            List <bool> strokeDirections = new List <bool>(myTechniqueRecognizer.StrokeDirections);

            // create solution
            InkStrokeBuilder builder         = new InkStrokeBuilder();
            List <InkStroke> solutionStrokes = new List <InkStroke>();

            for (int i = 0; i < input.Strokes.Count; ++i)
            {
                // get the current input stroke and times
                InkStroke   inputStroke = input.Strokes[i];
                List <long> inputTimes  = input.Times[i];

                // get current input points and stroke direction status
                List <InkPoint> inputPoints     = new List <InkPoint>(inputStroke.GetInkPoints());
                bool            strokeDirection = strokeDirections[i];

                // create the solution stroke
                List <Point> solutionPoints = new List <Point>();
                foreach (InkPoint inputPoint in inputPoints)
                {
                    solutionPoints.Add(new Point(inputPoint.Position.X, inputPoint.Position.Y));
                }
                if (!strokeDirection)
                {
                    solutionPoints.Reverse();
                }
                InkStroke solutionStroke = builder.CreateStroke(solutionPoints);

                // add the solution stroke to the list
                solutionStrokes.Add(solutionStroke);
            }

            // display solution
            SolidColorBrush newInputBrush = new SolidColorBrush(Colors.Black)
            {
                Opacity = 1.0
            };
            List <Storyboard> newInputStoryboards = InteractionTools.Trace(MyCanvas, solutionStrokes, input.Times, LARGE_DOT_SIZE, newInputBrush, POINT_DURATION);

            foreach (Storyboard storyboard in newInputStoryboards)
            {
                storyboard.Begin();
            }

            // display original
            SolidColorBrush inputBrush = new SolidColorBrush(Colors.Red)
            {
                Opacity = 1.0
            };
            List <Storyboard> inputStoryboards = InteractionTools.Trace(MyCanvas, input.Strokes, input.Times, LARGE_DOT_SIZE, inputBrush, POINT_DURATION);

            foreach (Storyboard storyboard in inputStoryboards)
            {
                storyboard.Begin();
            }

            // re-enable return button
            int delay = 0;

            foreach (InkStroke inputStroke in input.Strokes)
            {
                delay += POINT_DURATION * inputStroke.GetInkPoints().Count;
            }
            await InteractionTools.Delay(delay);

            //
            EnableTechniqueButtons(true);
        }
Ejemplo n.º 12
0
        private async void MyPlayButton_Click(object sender, RoutedEventArgs e)
        {
            // get the input and model sketch, and set the duration
            List <InkStroke> strokes = new List <InkStroke>();

            foreach (InkStroke stroke in MyInkStrokes.GetStrokes())
            {
                strokes.Add(stroke);
            }
            Sketch input    = new Sketch("", strokes, myTimeCollection, 0, 0, MyBorderLength, MyBorderLength);
            Sketch model    = myTemplates[MyImageIndex];
            int    duration = 30000;

            // animate the expert's model strokes
            if (MyImageButton.IsChecked.Value)
            {
                Sketch          sketch  = SketchTools.Clone(model);
                double          opacity = strokes.Count > 0 ? 0.8 : 1.0;
                Color           color   = strokes.Count > 0 ? Colors.Black : Colors.Green;
                SolidColorBrush brush   = new SolidColorBrush(color)
                {
                    Opacity = opacity
                };

                List <Storyboard> modelStoryboards = InteractionTools.Trace(MyCanvas, sketch.Strokes, sketch.Times, brush, duration);
                foreach (Storyboard storyboard in modelStoryboards)
                {
                    storyboard.Begin();
                }
            }

            // animate the user's input strokes
            if (strokes.Count > 0)
            {
                Sketch sketch = SketchTools.Clone(input);
                sketch = SketchTransformation.Resample(sketch, 128);
                double          opacity = 1.0;
                Color           color   = Colors.Red;
                SolidColorBrush brush   = new SolidColorBrush(color)
                {
                    Opacity = opacity
                };

                List <Storyboard> inputStoryboards = InteractionTools.Trace(MyCanvas, sketch.Strokes, sketch.Times, brush, duration, model);
                foreach (Storyboard storyboard in inputStoryboards)
                {
                    storyboard.Begin();
                }
            }

            //
            if (strokes.Count == 0 && !MyImageButton.IsChecked.Value)
            {
                return;
            }

            //
            int numModelPoints = 0;

            foreach (InkStroke stroke in model.Strokes)
            {
                numModelPoints += stroke.GetInkPoints().Count;
            }
            int delay = (numModelPoints * duration) / 10000;

            MyPlayButton.IsEnabled = false;
            MyInkCanvas.InkPresenter.IsInputEnabled = false;
            await Task.Delay(delay);

            MyPlayButton.IsEnabled = true;
            MyInkCanvas.InkPresenter.IsInputEnabled = true;
        }