Exemplo n.º 1
0
        /// <summary>
        /// Callback that handles results from the Wizard Labeler.  The SocketClient
        /// forwards each full sketch received to the recognizer.  This method
        /// unmarshalls the received sketch and stores it internally; a
        /// recognition event is fired only when the user has antecedently
        /// triggered recognition.
        /// </summary>
        /// <param name="xmlStr">The XML string that the Wizard Labeler sent.</param>
        private void socketClient_SketchRecievedEvent(string xmlStr)
        {
            // Read the XML string and fetch the sketch
            XmlTextReader xmlReader = new XmlTextReader(new StringReader(xmlStr));

            xmlReader.WhitespaceHandling = WhitespaceHandling.None;
            ReadXML readXml = new ReadXML(xmlReader);

            this.currentSketch      = readXml.Sketch;
            this.lastSketchReceived = DateTime.Now;

            // Apply error to current sketch before constructing
            // a recognition result
            this.applyErrorToCurrentRecognitionResult();

            // Construct a recognition result
            this.currentRecognitionResult                       = new RecognizerEventArgs();
            this.currentRecognitionResult.eventTime             = DateTime.Now;
            this.currentRecognitionResult.recognitionResults[0] = this.currentSketch;
            this.currentRecognitionResult.userTriggered         = waitingOnWizard;

            // If we were waiting for the Wizard to finish labeling a sketch,
            // then fire a recognition event.  In the future, we might
            // 'fade in' recognition results as they are received.
            if (waitingOnWizard)
            {
                waitingOnWizard = false;
                RecognitionEvent(this, this.currentRecognitionResult);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public DummyRecognizer()
        {
            // Read in the sketch
            Sketch.Sketch dummySketch = (new ReadXML(UIConstants.DummyRecognitionFilepath)).Sketch;

            // Construct the recognition results to return
            dummyRecognitionResults = new RecognizerEventArgs();
            dummyRecognitionResults.recognitionResults[0] = dummySketch;
            dummyRecognitionResults.eventTime             = DateTime.Now;
            dummyRecognitionResults.userTriggered         = true;
        }
        /// <summary>
        /// When the user manually triggers recognition, label everything
        /// in the sketch as a wire.
        /// </summary>
        void Recognizer.recognize(Sketch.Sketch sketch, bool userTriggered)
        {
            // Only operate on user triggered recognition events
            if (!userTriggered)
            {
                return;
            }

            foreach (Sketch.Substroke substroke in sketch.Substrokes)
            {
                sketch.AddLabel(substroke, UIConstants.WireLabel, 1.0);
            }

            lastLabeledSketchArgs = new RecognizerEventArgs();
            lastLabeledSketchArgs.recognitionResults[0] = sketch;
            lastLabeledSketchArgs.eventTime             = DateTime.Now;
            lastLabeledSketchArgs.userTriggered         = true;

            RecognitionEvent(this, lastLabeledSketchArgs);
        }