Ejemplo n.º 1
0
        /// <summary>
        /// When the user manually triggers recognition, label everything
        /// in the sketch as a wire.
        /// </summary>
        void Recognizer.recognize(Sketch.Sketch sketch, Sketch.Stroke[] selectedStrokes, bool userTriggered)
        {
            // Only operate on user triggered recognition events
            if (!userTriggered)
            {
                return;
            }

            lastLabeledSketchArgs = new RecognizerEventArgs();

            foreach (Sketch.Stroke selectedStroke in selectedStrokes)
            {
                if (selectedStroke == null)
                {
                    // The recognition triggerer left empty elements in
                    // the selected strokes array.  Here we just ignore
                    // the lack of a stroke.
                    continue;
                }


                // Get the corresponding stroke in the sketch to make sure we label
                // the right substrokes
                Sketch.Stroke sketchStroke = sketch.GetStroke((System.Guid)selectedStroke.XmlAttrs.Id);

                if (sketchStroke == null)
                {
                    // The selected stroke is not in the sketch.
                    // In some scenarios, we might want to throw an exception,
                    // but in this case we just skip the stroke
                    continue;
                }

                // Now label the substrokes
                Sketch.Substroke[] selectedSubstrokes = sketchStroke.Substrokes;
                foreach (Sketch.Substroke selectedSubstroke in selectedSubstrokes)
                {
                    if (selectedSubstroke.GetLabels().Length > 0)
                    {
                        continue;
                    }

                    // Apply wire label or error label using simulated error rate
                    if (randobj.NextDouble() < UIConstants.ErrorLabelErrorRate)
                    {
                        sketch.AddLabel(selectedSubstroke, UIConstants.ErrorLabel, 1.0);
                    }
                    else
                    {
                        sketch.AddLabel(selectedSubstroke, UIConstants.WireLabel, 1.0);
                    }
                }
            }

            lastLabeledSketchArgs.recognitionResults[0] = sketch;
            lastLabeledSketchArgs.eventTime             = DateTime.Now;
            lastLabeledSketchArgs.userTriggered         = true;

            RecognitionEvent(this, lastLabeledSketchArgs);
        }