Example #1
0
        /// <summary>
        /// We create a stroke with points close and then add the stroke to the canvas.
        /// If the points are far apart, we create a new stroke for those points.
        /// </summary>
        /// <param name="inkCanvas"></param>
        /// <param name="strokeInfo"></param>
        public static void AddStrokePreview(this InkCanvas inkCanvas, StrokeInfo strokeInfo)
        {
            StylusPoint           firstPoint = strokeInfo.PointCollection[0];
            StylusPointCollection tmpPoints  = new StylusPointCollection();

            tmpPoints.Add(firstPoint);

            for (int i = 0; i < strokeInfo.PointCollection.Count - 1; i++)
            {
                if (CalculateDistance(strokeInfo.PointCollection[i], strokeInfo.PointCollection[i + 1]) < 5)
                {
                    tmpPoints.Add(strokeInfo.PointCollection[i + 1]);
                }
                else
                {
                    inkCanvas.Strokes.Add(CreateStroke(strokeInfo, tmpPoints.Clone()));
                    tmpPoints.Clear();
                    tmpPoints.Add(strokeInfo.PointCollection[i + 1]);
                }
            }

            if (tmpPoints.Count > 0)
            {
                inkCanvas.Strokes.Add(CreateStroke(strokeInfo, tmpPoints));
            }
        }
Example #2
0
        public void Down(int stylusDeviceId, int timestamp, StylusPointCollection stylusPointCollection)
        {
            if (IsMouse(stylusDeviceId))
            {
                this.MouseDown(timestamp, stylusPointCollection);
                return;
            }
            StrokeInfo strokeInfo;

            if (!this._strokeInfoList.TryGetValue(stylusDeviceId, out strokeInfo))
            {
                strokeInfo = new StrokeInfo(stylusDeviceId, _drawingAttributes, _fillSolidColorBrush, timestamp, new InkRenderInfo(this, this.GetContainerVisual(stylusDeviceId)));
                this._strokeInfoList[stylusDeviceId] = strokeInfo;
                StylusPointCollectionInfo stylusPointCollectionInfo = new StylusPointCollectionInfo(strokeInfo, stylusPointCollection, timestamp);
                this.Run(strokeInfo, delegate
                {
                    OnDown(stylusPointCollectionInfo);
                });
                return;
            }
            if (strokeInfo.SeenUp)
            {
                return;
            }
            Console.WriteLine(string.Format("在按下的时候找到两个 stylusDeviceId {0} 当前一共有 {1} 个点按下", stylusDeviceId, this._strokeInfoList.Count), new string[0]);
        }
Example #3
0
        /// <summary>
        /// The implementation behind the public methods AddPoint/AddPoints
        /// </summary>
        /// <param name="points">a set of points representing the last increment
        /// in the moving of the erasing shape</param>
        protected override void AddPointsCore(IEnumerable <Point> points)
        {
            System.Diagnostics.Debug.Assert((points != null) && (IEnumerablePointHelper.GetCount(points) != 0));
            System.Diagnostics.Debug.Assert(_erasingStroke != null);

            // Move the shape through the new points and build the contour of the move.
            _erasingStroke.MoveTo(points);
            Rect erasingBounds = _erasingStroke.Bounds;

            if (erasingBounds.IsEmpty)
            {
                return;
            }

            List <StrokeHitEventArgs> strokeHitEventArgCollection = null;

            // Do nothing if there's nobody listening to the events
            if (StrokeHit != null)
            {
                List <StrokeIntersection> eraseAt = new List <StrokeIntersection>();

                // Test stroke by stroke and collect the results.
                for (int x = 0; x < this.StrokeInfos.Count; x++)
                {
                    StrokeInfo strokeInfo = this.StrokeInfos[x];

                    // Skip the stroke if its bounding box doesn't intersect with the one of the hitting shape.
                    if ((erasingBounds.IntersectsWith(strokeInfo.StrokeBounds) == false) ||
                        (_erasingStroke.EraseTest(StrokeNodeIterator.GetIterator(strokeInfo.Stroke, strokeInfo.Stroke.DrawingAttributes), eraseAt) == false))
                    {
                        continue;
                    }

                    // Create an event args to raise after done with hit-testing
                    // We don't fire these events right away because user is expected to
                    // modify the stroke collection in her event handler, and that would
                    // invalidate this foreach loop.
                    if (strokeHitEventArgCollection == null)
                    {
                        strokeHitEventArgCollection = new List <StrokeHitEventArgs>();
                    }
                    strokeHitEventArgCollection.Add(new StrokeHitEventArgs(strokeInfo.Stroke, eraseAt.ToArray()));
                    // We must clear eraseAt or it will contain invalid results for the next strokes
                    eraseAt.Clear();
                }
            }

            // Raise StrokeHit event if needed.
            if (strokeHitEventArgCollection != null)
            {
                System.Diagnostics.Debug.Assert(strokeHitEventArgCollection.Count != 0);
                for (int x = 0; x < strokeHitEventArgCollection.Count; x++)
                {
                    StrokeHitEventArgs eventArgs = strokeHitEventArgCollection[x];

                    System.Diagnostics.Debug.Assert(eventArgs.HitStroke != null);
                    OnStrokeHit(eventArgs);
                }
            }
        }
Example #4
0
        public ActionResult Post([FromForm] StrokeInfo info)
        {
            string rootDirectory = @"C:\MRI\mriresult";
            string path          = HttpUtility.UrlDecode(info.Path);
            string directory     = path.Substring(0, path.LastIndexOf("/")).Replace("/", "");
            string jsonPath      = Path.Combine(rootDirectory, directory, "stroke.json");

            Directory.CreateDirectory(Path.GetDirectoryName(jsonPath));

            // Delete the file if it exists.
            if (System.IO.File.Exists(jsonPath))
            {
                System.IO.File.Delete(jsonPath);
            }

            System.IO.File.WriteAllBytes(
                jsonPath,
                JsonSerializer.SerializeToUtf8Bytes <StrokeInfo>(
                    info,
                    new JsonSerializerOptions
            {
                Encoder       = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
                WriteIndented = true
            }));
            return(new NoContentResult());
        }
Example #5
0
 private static void AddPointsToStroke(Stroke stroke, StrokeInfo strokeInfo)
 {
     //Console.WriteLine("Added points to an existing stroke");
     foreach (StylusPoint sp in strokeInfo.PointCollection)
     {
         stroke.StylusPoints.Add(sp);
     }
 }
Example #6
0
        private void MouseMove(int timestamp, StylusPointCollection stylusPointCollection)
        {
            StrokeInfo mouseStrokeInfo = MouseStrokeInfo;

            if (mouseStrokeInfo != null)
            {
                stylusPointCollection = this.SetStylusPointDescription(stylusPointCollection);
                StylusPointCollectionInfo stylusPointCollectionInfo = new StylusPointCollectionInfo(mouseStrokeInfo, stylusPointCollection, timestamp);
                this.OnMove(stylusPointCollectionInfo);
            }
        }
Example #7
0
            public void InitStrokeTipBuilder(StylusPointCollectionInfo stylusPointCollectionInfo)
            {
                StrokeInfo          strokeInfo          = stylusPointCollectionInfo.StrokeInfo;
                InkRenderInfo       inkRenderInfo       = strokeInfo.InkRenderInfo;
                InkStrokeTipBuilder inkStrokeTipBuilder = inkRenderInfo.InkStrokeTipBuilderBuilder.GetInkStrokeTipBuilder();

                inkStrokeTipBuilder.Brush             = strokeInfo.FillSolidColorBrush;
                inkStrokeTipBuilder.DrawingAttributes = strokeInfo.DrawingAttributes;
                inkRenderInfo.StrokeTipBuilder        = inkStrokeTipBuilder;
                inkRenderInfo.ContainerVisual.Children.Add(inkRenderInfo.StrokeTipBuilder.CreateStroke());
                this.RenderPackets(stylusPointCollectionInfo);
            }
Example #8
0
        /// <summary>
        /// Check whether a certain percentage of the stroke is within the lasso
        /// </summary>
        /// <param name="lassoPoints"></param>
        /// <param name="percentageWithinLasso"></param>
        /// <returns></returns>
        public bool HitTest(IEnumerable <Point> lassoPoints, int percentageWithinLasso)
        {
            if (lassoPoints == null)
            {
                throw new System.ArgumentNullException("lassoPoints");
            }

            if ((percentageWithinLasso < 0) || (percentageWithinLasso > 100))
            {
                throw new System.ArgumentOutOfRangeException("percentageWithinLasso");
            }

            if (percentageWithinLasso == 0)
            {
                return(true);
            }


            StrokeInfo strokeInfo = null;

            try
            {
                strokeInfo = new StrokeInfo(this);

                StylusPointCollection stylusPoints = strokeInfo.StylusPoints;
                double target = strokeInfo.TotalWeight * percentageWithinLasso / 100.0f - PercentageTolerance;

                Lasso lasso = new SingleLoopLasso();
                lasso.AddPoints(lassoPoints);

                for (int i = 0; i < stylusPoints.Count; i++)
                {
                    if (true == lasso.Contains((Point)stylusPoints[i]))
                    {
                        target -= strokeInfo.GetPointWeight(i);
                        if (DoubleUtil.LessThan(target, 0f))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            finally
            {
                if (strokeInfo != null)
                {
                    //detach from event handlers, or else we leak.
                    strokeInfo.Detach();
                }
            }
        }
Example #9
0
        private static Stroke CreateStroke(StrokeInfo strokeInfo)
        {
            Stroke newStroke = new Stroke(strokeInfo.PointCollection);

            newStroke.DrawingAttributes.Color     = strokeInfo.StrokeColor;
            newStroke.DrawingAttributes.StylusTip = strokeInfo.BrushTip;
            newStroke.DrawingAttributes.Height    = strokeInfo.BrushSize;
            newStroke.DrawingAttributes.Width     = strokeInfo.BrushSize;
            newStroke.AddPropertyData(GUIDs.ID, strokeInfo.StrokeID.ToString());

            return(newStroke);
        }
Example #10
0
 private void Run(StrokeInfo strokeInfo, Action action)
 {
     strokeInfo.InkRenderInfo.Dispatcher.InvokeAsync(delegate()
     {
         try
         {
             action();
         }
         catch (Exception)
         {
         }
     }, DispatcherPriority.Send);
 }
Example #11
0
 public StylusPointCollectionInfo(StrokeInfo strokeInfo, StylusPointCollection stylusPoints, int timestamp)
 {
     if (strokeInfo == null)
     {
         throw new ArgumentNullException("strokeInfo");
     }
     if (stylusPoints == null)
     {
         throw new ArgumentNullException("stylusPoints");
     }
     StrokeInfo             = strokeInfo;
     StylusPlugInCollection = stylusPoints;
     Timestamp = timestamp;
 }
        public bool RecognizeUseCase(Strokes inkStrokes)
        {
            if (inkStrokes.Count == 1)
            {
                StrokeInfo strokeInfo1 = new StrokeInfo(inkStrokes[0]);

                if (strokeInfo1.StrokeStatistics.StartEndProximity < CLOSED_PROXIMITY &&
                    strokeInfo1.StrokeStatistics.Square < 0.85 && strokeInfo1.StrokeStatistics.Diagonal > 0.13)
                    return true;
                else
                    return false;
            }
            else
                return false;
        }
Example #13
0
        /// <summary>
        /// IHT's can get into a state where their StrokeInfo cache is too
        /// out of sync with the StrokeCollection to incrementally update it.
        /// When we detect this has happened, we just rebuild the entire cache.
        /// </summary>
        private void RebuildStrokeInfoCache()
        {
            List <StrokeInfo> newStrokeInfos = new List <StrokeInfo>(_strokes.Count);

            foreach (Stroke stroke in _strokes)
            {
                bool found = false;
                for (int x = 0; x < _strokeInfos.Count; x++)
                {
                    StrokeInfo strokeInfo = _strokeInfos[x];
                    if (strokeInfo != null && stroke == strokeInfo.Stroke)
                    {
                        newStrokeInfos.Add(strokeInfo);
                        //just set to null instead of removing and shifting
                        //we're about to GC _strokeInfos
                        _strokeInfos[x] = null;
                        found           = true;
                        break;
                    }
                }
                if (!found)
                {
                    //we didn't find an existing strokeInfo
                    newStrokeInfos.Add(new StrokeInfo(stroke));
                }
            }

            //detach the remaining strokeInfo's from their strokes
            for (int x = 0; x < _strokeInfos.Count; x++)
            {
                StrokeInfo strokeInfo = _strokeInfos[x];

                if (strokeInfo != null)
                {
                    strokeInfo.Detach();
                }
            }

            _strokeInfos = newStrokeInfos;

#if DEBUG
            Debug.Assert(_strokeInfos.Count == _strokes.Count);
            for (int x = 0; x < _strokeInfos.Count; x++)
            {
                Debug.Assert(_strokeInfos[x].Stroke == _strokes[x]);
            }
#endif
        }
Example #14
0
        private void MouseDown(int timestamp, StylusPointCollection stylusPointCollection)
        {
            if (this.MouseStrokeInfo != null)
            {
                this.OnUp(new StylusPointCollectionInfo(this.MouseStrokeInfo, new StylusPointCollection(this.StylusPointDescription), timestamp));
            }
            this.StylusPointDescription = stylusPointCollection.Description;
            stylusPointCollection       = this.SetStylusPointDescription(stylusPointCollection);
            StrokeInfo strokeInfo;

            strokeInfo = new StrokeInfo(-1, this._drawingAttributes, this._fillSolidColorBrush, timestamp, new InkRenderInfo(this, this.GetContainerVisual(0)));
            StylusPointCollectionInfo stylusPointCollectionInfo = new StylusPointCollectionInfo(strokeInfo, stylusPointCollection, timestamp);

            this.OnDown(stylusPointCollectionInfo);
            this.MouseStrokeInfo = strokeInfo;
        }
Example #15
0
            public void RenderPackets(StylusPointCollectionInfo stylusPointCollectionInfo)
            {
                StrokeInfo    strokeInfo    = stylusPointCollectionInfo.StrokeInfo;
                InkRenderInfo inkRenderInfo = strokeInfo.InkRenderInfo;

                foreach (var stylusPoint in stylusPointCollectionInfo.StylusPlugInCollection)
                {
                    StylusPointCollection stylusPointCollection = inkRenderInfo.StrokeTipBuilder.AddPoint(stylusPoint);
                    if (stylusPointCollection != null)
                    {
                        StrokeVisual strokeVisual = new StrokeVisual(strokeInfo.FillSolidColorBrush, strokeInfo.DrawingAttributes, stylusPointCollection);
                        inkRenderInfo.ContainerVisual.Children.Add(strokeVisual);
                        inkRenderInfo.StrokeVisualList.AddLast(strokeVisual);
                        strokeVisual.Redraw();
                    }
                }
                // inkRenderInfo.StrokeTipBuilder.Redraw();
            }
Example #16
0
        /// <summary>
        /// Check whether a certain percentage of the stroke is within the Rect passed in.
        /// </summary>
        /// <param name="bounds"></param>
        /// <param name="percentageWithinBounds"></param>
        /// <returns></returns>
        public bool HitTest(Rect bounds, int percentageWithinBounds)
        {
            if ((percentageWithinBounds < 0) || (percentageWithinBounds > 100))
            {
                throw new System.ArgumentOutOfRangeException("percentageWithinBounds");
            }

            if (percentageWithinBounds == 0)
            {
                return(true);
            }

            StrokeInfo strokeInfo = null;

            try
            {
                strokeInfo = new StrokeInfo(this);

                StylusPointCollection stylusPoints = strokeInfo.StylusPoints;
                double target = strokeInfo.TotalWeight * percentageWithinBounds / 100.0f - PercentageTolerance;

                for (int i = 0; i < stylusPoints.Count; i++)
                {
                    if (true == bounds.Contains((Point)stylusPoints[i]))
                    {
                        target -= strokeInfo.GetPointWeight(i);
                        if (DoubleUtil.LessThanOrClose(target, 0d))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            finally
            {
                if (strokeInfo != null)
                {
                    //detach from event handlers, or else we leak.
                    strokeInfo.Detach();
                }
            }
        }
Example #17
0
        public static Stroke AddStroke(this InkCanvas inkCanvas, StrokeInfo strokeInfo, Stroke lastStroke = null)
        {
            try
            {
                if (lastStroke != null && lastStroke.StylusPoints.Count <= 500)
                {
                    if ((string)lastStroke.GetPropertyData(GUIDs.ID) == strokeInfo.StrokeID.ToString())
                    {
                        AddPointsToStroke(lastStroke, strokeInfo);
                        return(lastStroke);
                    }
                }

                Stroke stroke = CreateStroke(strokeInfo);
                inkCanvas.Strokes.Add(stroke);
                return(stroke);
            }
            catch
            {
                return(null);
            }
        }
        public bool RecognizeActor(Strokes inkStrokes)
        {
            if (inkStrokes.Count >= 4)
            {
                StrokeInfo strokeInfo1 = new StrokeInfo(inkStrokes[0]);
                StrokeInfo strokeInfo2 = new StrokeInfo(inkStrokes[1]);

                if (strokeInfo1.StrokeStatistics.StartEndProximity < CLOSED_PROXIMITY &&
                   strokeInfo1.StrokeStatistics.Square < 0.85 && strokeInfo1.StrokeStatistics.Diagonal > 0.15)
                {
                    if (strokeInfo2.StrokeStatistics.StartEndProximity > CLOSED_PROXIMITY &&
                        strokeInfo2.StrokeStatistics.Square > 0.9 && strokeInfo2.StrokeStatistics.Diagonal < 0.2)
                        return true;
                    else
                        return false;
                }
                else
                    return false;
            }
            else
                return false;
        }
        public bool recognizePackage(Strokes inkStrokes)
        {
            if (inkStrokes.Count == 2)
            {
                StrokeInfo strokeInfo1 = new StrokeInfo(inkStrokes[0]);
                StrokeInfo strokeInfo2 = new StrokeInfo(inkStrokes[1]);
                if (strokeInfo1.StrokeStatistics.Square > 0.9 && strokeInfo1.StrokeStatistics.Diagonal < 0.09 &&
                    strokeInfo1.StrokeStatistics.StartEndProximity < CLOSED_PROXIMITY)
                {
                    if (strokeInfo2.StrokeStatistics.Square > 0.9 && strokeInfo2.StrokeStatistics.Diagonal < 0.09)
                        return true;
                    else
                        return false;
                }
                else
                {
                    return false;
                }

            }
            else
                return false;
        }
Example #20
0
 internal void AddStrokeInfoRef(StrokeInfo si)
 {
     _strokeInfoList.Add(si);
 }
 public StrokeSentEventArgs(dynamic data)
 {
     _strokeInfo = new StrokeInfo(data);
 }
Example #22
0
 /*----------------------------------------------------------------------------------------------*/
 /*------------------------Recognize the Gesture for Given Ink Stroke-------------------*/
 private void RecognizeStroke(InkPicture myDrawingArea)
 {
     Stroke stroke = myDrawingArea.Ink.Strokes[0];
     StrokeInfo sInfo = new StrokeInfo(stroke);
     CustomGesture[] gesture = customReco.Recognize(stroke);
     MessageBox.Show(myDrawingArea.Ink.Strokes.Count.ToString());
     try
     {
         MessageBox.Show(gesture[0].Name.ToString());
     }
     catch
     {
         MessageBox.Show("No Gesture");
     }
 }
Example #23
0
 internal void RemoveStrokeInfoRef(StrokeInfo si)
 {
     _strokeInfoList.Remove(si);
 }
 public void Enqueue(StrokeInfo strokeInfo)
 {
     _strokeInfoQueue.Enqueue(strokeInfo);
 }
Example #25
0
        /// <summary>
        /// Hit-testing with lasso
        /// </summary>
        /// <param name="lassoPoints">points making the lasso</param>
        /// <param name="percentageWithinLasso">the margin value to tell whether a stroke
        /// is in or outside of the rect</param>
        /// <returns>collection of strokes found inside the rectangle</returns>
        public StrokeCollection HitTest(IEnumerable <Point> lassoPoints, int percentageWithinLasso)
        {
            // Check the input parameters
            if (lassoPoints == null)
            {
                throw new System.ArgumentNullException("lassoPoints");
            }
            if ((percentageWithinLasso < 0) || (percentageWithinLasso > 100))
            {
                throw new System.ArgumentOutOfRangeException("percentageWithinLasso");
            }

            if (IEnumerablePointHelper.GetCount(lassoPoints) < 3)
            {
                return(new StrokeCollection());
            }

            Lasso lasso = new SingleLoopLasso();

            lasso.AddPoints(lassoPoints);

            // Enumerate through the strokes and collect those captured by the lasso.
            StrokeCollection lassoedStrokes = new StrokeCollection();

            foreach (Stroke stroke in this)
            {
                if (percentageWithinLasso == 0)
                {
                    lassoedStrokes.Add(stroke);
                }
                else
                {
                    StrokeInfo strokeInfo = null;
                    try
                    {
                        strokeInfo = new StrokeInfo(stroke);

                        StylusPointCollection stylusPoints = strokeInfo.StylusPoints;
                        double target = strokeInfo.TotalWeight * percentageWithinLasso / 100.0f - Stroke.PercentageTolerance;

                        for (int i = 0; i < stylusPoints.Count; i++)
                        {
                            if (true == lasso.Contains((Point)stylusPoints[i]))
                            {
                                target -= strokeInfo.GetPointWeight(i);
                                if (DoubleUtil.LessThanOrClose(target, 0f))
                                {
                                    lassoedStrokes.Add(stroke);
                                    break;
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (strokeInfo != null)
                        {
                            //detach from event handlers, or else we leak.
                            strokeInfo.Detach();
                        }
                    }
                }
            }

            // Return the resulting collection
            return(lassoedStrokes);
        }