Exemplo n.º 1
0
        private void CreateStrokes()
        {
            if (theInk.Strokes.Count > 0)
            {
                return;
            }
            points  = new Point[] { new Point(0, 0), new Point(100, 100) };
            points2 = new Point[] { new Point(0, 0), new Point(150, 150) };

            stroke1 = theInk.CreateStroke(points);
            stroke2 = theInk.CreateStroke(points);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="ink"></param>
        private Stroke handleStroke(XmlReader reader, Ink ink)
        {
            // new empty list to store the points
            List <Point> stroke = new List <Point>();

            while (reader.Read())
            {
                String nodeNameLowerCase = reader.Name.ToLower();
                switch (nodeNameLowerCase)
                {
                case "p":
                    // C# Seems to use Bankers' Rounding
                    // Can we handle numbers like: x="2.80733975875E8" y="538.625" ??? YES, I think so...
                    // Will we lose precision by casting to INT?
                    int x = (int)Math.Round(Double.Parse(reader.GetAttribute("x")));
                    int y = (int)Math.Round(Double.Parse(reader.GetAttribute("y")));
                    //Console.WriteLine("Sample: {0} {1} {2} {3}", x, y, reader.GetAttribute("f"), reader.GetAttribute("t"));
                    stroke.Add(new Point(x, y));
                    break;

                case "stroke":
                    //Console.WriteLine("</Stroke>");
                    Point[] strokesArray = stroke.ToArray();
                    Stroke  inkStroke    = ink.CreateStroke(strokesArray);
                    return(inkStroke);

                default:
                    break;
                }
            }
            return(null);
        }
Exemplo n.º 3
0
            public object Clone()
            {
                Cache c = new Cache(_owner); // _owner will be fixed up in AfterClone

                c._dirty = _dirty;
                if (_cached != null)
                {
                    Ink ink = new Ink();
                    c._cached = ink.CreateStroke(_cached.GetPoints());
                }
                return(c);
            }
Exemplo n.º 4
0
        public String Recognizer(String strokesStr, int count)
        {
            List <List <int[]> > strokes = new List <List <int[]> >();
            var array = Regex.Split(strokesStr, ",eb,");

            foreach (var item in array)
            {
                var stroke = new List <int[]>();
                var array2 = item.Split(',');
                for (var i = 0; i < array2.Length; i = i + 2)
                {
                    int[] point = new int[2];
                    point[0] = int.Parse(array2[i]);
                    point[1] = int.Parse(array2[i + 1]);
                    stroke.Add(point);
                }
                strokes.Add(stroke);
            }

            RecognizerContext recognizerContext = new Recognizers().GetDefaultRecognizer().CreateRecognizerContext();
            Ink ink = new Ink();

            recognizerContext.Strokes = ink.CreateStrokes();
            foreach (List <int[]> stroke in strokes)
            {
                Point[] points = new Point[stroke.Count];
                for (int i = 0; i < stroke.Count; i++)
                {
                    points[i] = new Point(stroke[i][0], stroke[i][1]);
                }
                recognizerContext.Strokes.Add(ink.CreateStroke(points));
            }
            RecognitionStatus recognitionStatus = RecognitionStatus.NoError;
            RecognitionResult recognitionResult = recognizerContext.Recognize(out recognitionStatus);
            var text = "";

            if (recognitionStatus == RecognitionStatus.NoError)
            {
                RecognitionAlternates alts = recognitionResult.GetAlternatesFromSelection();
                for (int i = 0; i < alts.Count && i < count; i++)
                {
                    RecognitionAlternate alt = alts[i];
                    text += alt.ToString() + " ";
                }
            }
            return(text.Trim());
        }
Exemplo n.º 5
0
    public static Ink ToInk(this TraceGroup traceGroup)
    {
      var ink = new Ink();

      foreach (var trace in traceGroup.Traces)
      {
        //var points = new Point[trace.Points.Count];
        //foreach (var point in trace.Points)
        //{
          
        //}
        var points = trace.Points.ToList().ConvertAll(c => c.ToPoint());
        var stroke = ink.CreateStroke(points.ToArray());
        ink.Strokes.Add(stroke);
      }
      return ink;
    }
Exemplo n.º 6
0
        public static Ink ToInk(this TraceGroup traceGroup)
        {
            var ink = new Ink();

            foreach (var trace in traceGroup.Traces)
            {
                //var points = new Point[trace.Points.Count];
                //foreach (var point in trace.Points)
                //{

                //}
                var points = trace.Points.ToList().ConvertAll(c => c.ToPoint());
                var stroke = ink.CreateStroke(points.ToArray());
                ink.Strokes.Add(stroke);
            }
            return(ink);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="sketch"></param>
        public MakeJnt(Sketch.Sketch sketch)
        {
            ink = new Ink();

            Sketch.Substroke[] substrokes = sketch.Substrokes;
            int slength = substrokes.Length;
            int plength;
            int i;
            int k;

            for (i = 0; i < slength; ++i)
            {
                Sketch.Point[]         sketchPts = substrokes[i].Points;
                System.Drawing.Point[] simplePts = new System.Drawing.Point[sketchPts.Length];

                plength = simplePts.Length;
                for (k = 0; k < plength; k++)
                {
                    simplePts[k] = new System.Drawing.Point((int)sketchPts[k].X, (int)sketchPts[k].Y);
                }

                ink.CreateStroke(simplePts);
            }
        }
        /// <summary>
        /// Occurs when the stylus leaves the digitizer surface.
        /// Retrieve the packet array for this stylus and use it to create
        /// a new stoke.
        /// </summary>
        /// <param name="sender">The real time stylus associated with the notification</param>
        /// <param name="data">The notification data</param>
        public void StylusUp(RealTimeStylus sender, StylusUpData data)
        {
            // Retrieve the packet array from the hashtable using the cursor id
            // as a key.  Then, clean this entry from the hash since it is no
            // longer needed.
            ArrayList collectedPackets = (ArrayList)myPackets[data.Stylus.Id];

            myPackets.Remove(data.Stylus.Id);

            // Add the packet data from StylusUp to the array
            collectedPackets.AddRange(data.GetData());

            // Create the stroke using the specified drawing attributes.
            int[] packets = (int[])(collectedPackets.ToArray(typeof(int)));
            TabletPropertyDescriptionCollection tabletProperties = myRealTimeStylus.GetTabletPropertyDescriptionCollection(data.Stylus.TabletContextId);

            Stroke stroke = myInk.CreateStroke(packets, tabletProperties);

            if (stroke != null)
            {
                stroke.DrawingAttributes.Color = myDynamicRenderer.DrawingAttributes.Color;
                stroke.DrawingAttributes.Width = myDynamicRenderer.DrawingAttributes.Width;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Translate real-time ink packets to a stroke and return RTStrokeAdded.
        /// </summary>
        /// <param name="rtispm"></param>
        /// <returns></returns>
        internal object AddRealTimeInkSheetPackets(UW.ClassroomPresenter.Network.Messages.Presentation.RealTimeInkSheetPacketsMessage rtispm)
        {
            //Resolve the sheetId to a slideId, and use it to look up a TOC entry.
            if (!sheetToSlideLookup.ContainsKey(rtispm.TargetId))
            {
                if (this.currentSlideId.Equals(Guid.Empty))
                {
                    warning += "Warning: found real-time ink on an unknown sheet.  Ignoring the ink.  ";
                    return(null);
                }
                //Can we assume current slide??  Probably..
                sheetToSlideLookup.Add(rtispm.TargetId, currentSlideId);
            }

            TableOfContents.TocEntry tocEntry = toc.LookupBySlideId((Guid)sheetToSlideLookup[rtispm.TargetId]);
            if (tocEntry == null)
            {
                warning += "Warning: Failed to find a TOC entry for a slide when applying real-time ink.  Ignoring the ink.  ";
                return(null);
            }

            //Tablet Properties should have been received in a StylusDown message.
            if (previousTabletProperties == null)
            {
                warning += "Warning: Received real-time ink without tablet properties.  Ignoring the ink.  ";
                return(null);
            }

            //Debug.WriteLine("***** Realtime Ink packets StrokeID=" + rtispm.StrokeId.ToString() + "; stylusId=" + rtispm.StylusId.ToString());

            // Verify that the stroke we're about to render matches the StrokeId
            // from the most recent StylusDown event.  (If not, then something
            // probably got lost over the network.)
            if (this.previousRealTimeStroke != rtispm.StrokeId)
            {
                previousRealTimeStroke  = rtispm.StrokeId;
                previousRealTimePackets = new int[] { };
            }

            // Get the DrawingAttributes which were in effect on StylusDown.  We should have received this in a
            // RealTimeInkSheetInformationMessage previously.
            if (!this.sheetToDrawingAttributesLookup.ContainsKey(rtispm.TargetId))
            {
                //Note: this seems to happen all the time, but I don't notice any ill effects.  Ignore the ink but leave out the warning.
                //this.warning += "Warning: Real-time ink was found that lacks DrawingAttributes.  The ink will be ignored.  ";
                return(null);
            }
            DrawingAttributes atts = (DrawingAttributes)this.sheetToDrawingAttributesLookup[rtispm.TargetId];

            // Ink packets for this stroke so far.  Initial packets should have been received in the Stylus Down message.
            if (this.previousRealTimePackets == null)
            {
                this.warning += "Warning: Failed to find previous real-time ink packets. The ink will be ignored.  ";
                return(null);
            }

            // Assemble the completed information we'll need to create the mini-stroke.
            int[] combinedPackets = new int[this.previousRealTimePackets.Length + rtispm.Packets.Length];
            this.previousRealTimePackets.CopyTo(combinedPackets, 0);
            rtispm.Packets.CopyTo(combinedPackets, this.previousRealTimePackets.Length);

            // Store the new data.
            this.previousRealTimePackets = combinedPackets;

            // Now that we have the data, we're ready to create the temporary stroke.
            Ink    ink    = new Ink();
            Stroke stroke = ink.CreateStroke(combinedPackets, previousTabletProperties);

            stroke.DrawingAttributes = atts;

            //Look up the data for this stroke, or assign a new Guid if needed.
            RTStrokeData rtsData;

            if (!realTimeStrokesPending.TryGetValue(rtispm.StrokeId, out rtsData))
            {
                rtsData = new RTStrokeData(Guid.NewGuid(), tocEntry.DeckId, tocEntry.SlideIndex);
                realTimeStrokesPending.Add(rtispm.StrokeId, rtsData);
            }
            Guid strokeId = rtsData.StrokeId;

            //WebViewer requires the CP2 extended property to allow deletion of the stroke
            ink.Strokes[0].ExtendedProperties.Add(CP2StrokeIdExtendedProperty, (object)strokeId.ToString());
            //WebViewer wants ink to be scaled to 500x500
            ink.Strokes.Scale(500f / getCurrentSlideWidth(), 500f / getCurrentSlideHeight());


            Debug.WriteLine("***** Adding Real-time Stroke ID=" + strokeId.ToString());
            RTDrawStroke rtds = new RTDrawStroke(ink, strokeId, false, tocEntry.DeckId, tocEntry.SlideIndex);

            return(rtds);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="ink"></param>
        private Stroke handleStroke(XmlReader reader, Ink ink)
        {
            // new empty list to store the points
            List<Point> stroke = new List<Point>();

            while (reader.Read()) {
                String nodeNameLowerCase = reader.Name.ToLower();
                switch (nodeNameLowerCase) {
                    case "p":
                        // C# Seems to use Bankers' Rounding
                        // Can we handle numbers like: x="2.80733975875E8" y="538.625" ??? YES, I think so...
                        // Will we lose precision by casting to INT?
                        int x = (int)Math.Round(Double.Parse(reader.GetAttribute("x")));
                        int y = (int)Math.Round(Double.Parse(reader.GetAttribute("y")));
                        //Console.WriteLine("Sample: {0} {1} {2} {3}", x, y, reader.GetAttribute("f"), reader.GetAttribute("t"));
                        stroke.Add(new Point(x, y));
                        break;
                    case "stroke":
                        //Console.WriteLine("</Stroke>");
                        Point[] strokesArray = stroke.ToArray();
                        Stroke inkStroke = ink.CreateStroke(strokesArray);
                        return inkStroke;
                    default:
                        break;
                }
            }
            return null;
        }
Exemplo n.º 11
0
 /// <summary>
 /// Adds a new stroke to be recognized. Call <see cref="Recognize"/>
 /// to convert the strokes to text.
 /// </summary>
 /// <param name="stroke">The stroke to add.</param>
 public void AddStroke(TouchStroke stroke)
 {
     EnsureNotDisposed();
     _strokes.Add(_ink.CreateStroke(stroke.GetPoints()));
 }