public static Sketch CreateStroke(string label, List <InkStroke> strokeCollection, List <List <long> > timeCollection, double minX, double minY, double maxX, double maxY) { // InkStrokeBuilder builder = new InkStrokeBuilder(); List <InkStroke> newStrokeCollection = new List <InkStroke>(); List <List <long> > newTimeCollection = new List <List <long> >(); for (int i = 0; i < strokeCollection.Count; ++i) { IReadOnlyList <InkPoint> points = strokeCollection[i].GetInkPoints(); List <long> times = timeCollection[i]; int count = times.Count < points.Count ? times.Count : points.Count; List <Point> newPoints = new List <Point>(); List <long> newTimes = new List <long>(); for (int j = 0; j < count; ++j) { InkPoint point = points[j]; long time = times[j]; newPoints.Add(new Point(point.Position.X, point.Position.Y)); newTimes.Add(time); } newStrokeCollection.Add(builder.CreateStroke(newPoints)); newTimeCollection.Add(newTimes); } // Sketch sketch = new Sketch(label, newStrokeCollection, newTimeCollection, minX, minY, maxX, maxY); return(sketch); }
public static double PairwiseDistance(InkStroke stroke, InkStroke other) { // List <InkPoint> strokePoints = new List <InkPoint>(stroke.GetInkPoints()); List <InkPoint> otherPoints = new List <InkPoint>(other.GetInkPoints()); // int strokeCount = strokePoints.Count; int otherCount = otherPoints.Count; int count = strokeCount < otherCount ? strokeCount : otherCount; // double distances = 0.0; for (int i = 0; i < count; ++i) { InkPoint strokePoint = strokePoints[i]; InkPoint otherPoint = otherPoints[i]; double distance = Distance(strokePoint, otherPoint); distances += distance; } return(distances); }
private void coreWetStrokeUpdateSource_StrokeStopping(CoreWetStrokeUpdateSource sender, CoreWetStrokeUpdateEventArgs args) { if (args.NewInkPoints.Count > 0) { InkPoint firstPoint = args.NewInkPoints.First(); Point p = new Point() { X = firstPoint.Position.X, Y = firstPoint.Position.Y }; if (GeometryHelper.PointIsInPolygon(P1, P2, P3, p) == true) { IsInkSpace = false; Snap = false; args.Disposition = CoreWetStrokeDisposition.Completed; } } if (Snap == true) { this.SnapPoints(args.NewInkPoints); } else if (IsInkSpace == false) { args.NewInkPoints.Clear(); } SaveNecessity = true; }
private void PointerPressed(InkPoint point, PointerPoint pointer) { TmpRectGra = (GraphicsRectSizeBase)GraphicsInstCreateManager.CreateGraphics(Drawer.PenType, Drawer.LocPenModel, Drawer, InkCanvasSharp); Drawer.GraphicsRects.Add(TmpRectGra); TmpRectGra.BeginDraw(point, pointer); //TmpRectGra.PenAttribute.SetLinerPoints(TmpRectGra.Bounds); TmpRectGra.IsFill = Drawer.IsFill; Drawer.HistoriesManager.PushHistory(new CreateGraphicsHistory(Drawer, TmpRectGra)); Drawer.LocPenModel = Drawer.LocPenModel.Copy(); /* * if (TmpRectGra is GraphicsTextModel) * { * var tm = (TmpRectGra as GraphicsTextModel); * tm.Text = Drawer.Text; * tm.TextFormat = Drawer.TextFormat; * * var ctf = new CanvasTextFormat(); * var propdic = new Dictionary<string, PropertyInfo>(); * foreach (var item in ctf.GetType().GetProperties()) * { * propdic.Add(item.Name, item); * } * Drawer.TextFormat.GetType().GetProperties().ToList().ForEach(prop =>propdic[prop.Name].SetValue(ctf, prop.GetValue(Drawer.TextFormat))); * * //?????? * Drawer.TextFormat = new CanvasTextFormat() { FontSize=Drawer.TextFormat.FontSize}; * } */ }
private void coreWetStrokeUpdateSource_StrokeStarting(CoreWetStrokeUpdateSource sender, CoreWetStrokeUpdateEventArgs args) { InkPoint firstPoint = args.NewInkPoints.First(); Point p = new Point() { X = firstPoint.Position.X, Y = firstPoint.Position.Y }; if (GeometryHelper.MinimalDistanceToGeodreieck(P1, P2, P3, p) <= 72) { Snap = true; IsInkSpace = true; this.SnapPoints(args.NewInkPoints); } else if (GeometryHelper.PointIsInPolygon(P1, P2, P3, p) == true) { IsInkSpace = false; Snap = false; args.NewInkPoints.Clear(); } else { IsInkSpace = true; Snap = false; } SaveNecessity = true; }
private List <InkStroke> Dotify(List <InkStroke> strokes) { List <InkPoint> points = new List <InkPoint>(); foreach (InkStroke stroke in strokes) { foreach (InkPoint point in stroke.GetInkPoints()) { points.Add(point); } } List <InkStroke> dotStrokes = new List <InkStroke>(); InkStrokeBuilder builder = new InkStrokeBuilder(); for (int i = 0; i < points.Count; ++i) { if (i % 20 != 0) { continue; } InkPoint point = points[i]; List <Point> dotPoint = new List <Point> { new Point(point.Position.X, point.Position.Y) }; InkStroke dotStroke = builder.CreateStroke(dotPoint); dotStroke.DrawingAttributes = DOT_VISUALS; dotStrokes.Add(dotStroke); } return(dotStrokes); }
private void PointerMove(InkPoint point, PointerPoint pointer) { if (TmpRectGra != null) { TmpRectGra?.Drawing(point); //TmpRectGra.PenAttribute.SetLinerPoints(TmpRectGra.Bounds); } }
public SerializablePoint(InkPoint point) { Position = point.Position; Pressure = point.Pressure; TiltX = point.TiltX; TiltY = point.TiltY; Timestamp = point.Timestamp; }
private void PointerPressed(InkPoint point, PointerPoint p) { Drawer.LocPenModel.SetSolidColorBrush(Colors.White);//可以为背景颜色 TmpRectGra = (GraphicsRectSizeBase)GraphicsInstCreateManager.CreateGraphics(GraphicsTypes.CurveLine, Drawer.LocPenModel, Drawer, InkCanvasSharp); TmpRectGra.IsLock = true; Drawer.GraphicsRects.Add(TmpRectGra); TmpRectGra.BeginDraw(point, p); Drawer.HistoriesManager.PushHistory(new CreateGraphicsHistory(Drawer, TmpRectGra)); Drawer.LocPenModel = Drawer.LocPenModel.Copy(); }
private void PointerMoved(InkPoint point, PointerPoint p) { Drawer.GraphicsRects.Where(g => g.PeekIsPointOn(p.Position)).ToList(). ForEach(g => { g.Revocate(Drawer); //Drawer.GraphicsRects.Remove(g); //Drawer.HistoriesManager.PushHistory(new DeleteGraphicsHistory(Drawer, g)); }); }
private void PointerReleased(InkPoint point, PointerPoint p) { Drawer.GraphicsRects.ForEach(gr => { if (gr.IsPointOn(point, p)) { Drawer.HistoriesManager.PushHistory(new MoveGraphicsHistory(Drawer, gr)); } }); }
private static float InterpolatePressure(InkPoint start, InkPoint end, Point p) { var distanceStartEnd = PointDistance(start.Position, end.Position); var distanceStartP = PointDistance(start.Position, p); var percentageAlongLine = distanceStartP / distanceStartEnd; var pressure = (end.Pressure * percentageAlongLine) + (start.Pressure * (1 - percentageAlongLine)); return((float)pressure); }
public static double Distance(Sketch alphaSketch, Sketch betaSketch) { // double distances = 0.0; // get the alpha and beta points from their respective strokes List <InkPoint> alphaPoints = new List <InkPoint>(); List <InkPoint> betaPoints = new List <InkPoint>(); foreach (InkStroke stroke in alphaSketch.Strokes) { alphaPoints.AddRange(stroke.GetInkPoints().ToList()); } foreach (var stroke in betaSketch.Strokes) { betaPoints.AddRange(stroke.GetInkPoints().ToList()); } // iterate through each alpha point var pairs = new List <Tuple <InkPoint, InkPoint> >(); double minDistance, weight, distance; int index; InkPoint minPoint = betaPoints[0]; foreach (var alphaPoint in alphaPoints) { minDistance = Double.MaxValue; // iterate through each beta point to find the min beta point to the alpha point index = 1; foreach (var betaPoint in betaPoints) { distance = Distance(alphaPoint, betaPoint); // update the min distance and min point if (minDistance > distance) { minDistance = distance; minPoint = betaPoint; } } // update distance between alpha and beta point lists weight = 1 - ((index - 1) / alphaPoints.Count); distances += minDistance * weight; // pair the alpha point to the min beta point and remove min beta point from list of beta points pairs.Add(new Tuple <InkPoint, InkPoint>(alphaPoint, minPoint)); betaPoints.Remove(minPoint); } // return(distances); }
public void CreatePreviewInkStroke() { var strokePreviewInkPoints = new List <InkPoint>(); for (var i = 0; i < Commons.Constants.PreviewStrokeCoordinates.Length; i += 2) { var newPoint = new Point(Commons.Constants.PreviewStrokeCoordinates[i], Commons.Constants.PreviewStrokeCoordinates[i + 1] + 10); var inkPoint = new InkPoint(newPoint, 1f); strokePreviewInkPoints.Add(inkPoint); } var inkStrokeBuilder = new InkStrokeBuilder(); var newStroke = inkStrokeBuilder.CreateStrokeFromInkPoints(strokePreviewInkPoints, Matrix3x2.Identity); PreviewInkStroke = newStroke; }
public static List <InkPoint> ConvertPixelsToMillimeters(IReadOnlyList <InkPoint> pointsInPixels, float DpiX, float DpiY) { var transformedInkPoints = new List <InkPoint>(); const float inchToMillimeterFactor = 25.4f; foreach (var point in pointsInPixels) { var transformedX = (point.Position.X / DpiX) * inchToMillimeterFactor; var transformedY = (point.Position.Y / DpiY) * inchToMillimeterFactor; var transformedPoint = new Point(transformedX, transformedY); var transformedInkPoint = new InkPoint(transformedPoint, point.Pressure); transformedInkPoints.Add(transformedInkPoint); } return(transformedInkPoints); }
/// <summary> /// /// </summary> /// <param name="pointsInPixels"></param> /// <param name="DpiX"></param> /// <param name="DpiY"></param> /// <returns></returns> private List <InkPoint> ConvertPixelsToMillimeters( IEnumerable <System.Windows.Input.StylusPoint> pointsInPixels, float DpiX, float DpiY) { var transformedInkPoints = new List <InkPoint>(); const float inchToMillimeterFactor = 25.4f; foreach (var point in pointsInPixels) { var transformedX = (point.X / DpiX) * inchToMillimeterFactor; var transformedY = (point.Y / DpiY) * inchToMillimeterFactor; var transformedInkPoint = new InkPoint((float)transformedX, (float)transformedY); transformedInkPoints.Add(transformedInkPoint); } return(transformedInkPoints); }
private void CreatePencilPreviewStroke() { var strokePreviewInkPoints = new List <InkPoint>(); for (var i = 0; i < PreviewStrokeCoordinates.Length; i += 2) { var newPoint = new Point(PreviewStrokeCoordinates[i], PreviewStrokeCoordinates[i + 1] + 10); var inkPoint = new InkPoint(newPoint, 1f); strokePreviewInkPoints.Add(inkPoint); } var inkStrokeBuilder = new InkStrokeBuilder(); var newStroke = inkStrokeBuilder.CreateStrokeFromInkPoints( strokePreviewInkPoints, Matrix3x2.Identity); PencilPreviewInkStroke = newStroke; }
private double GetResampledPairwiseDistance(Sketch input, Sketch model, int i, int j) { // get the corresponding model stroke, points, and point count InkStroke modelStroke = model.Strokes[j]; List <InkPoint> modelPoints = new List <InkPoint>(modelStroke.GetInkPoints()); int numModelPoints = modelPoints.Count; // wrap the current input stroke into a sketch, then resample to match model stroke InkStroke inputStroke = input.Strokes[i]; List <long> inputTimes = input.Times[i]; Sketch inputSketch = new Sketch("", new List <InkStroke>() { inputStroke }, new List <List <long> > { inputTimes }, 0, 0, 0, 0); // resample the input stroke's points to match the current model stroke's points inputSketch = SketchTools.Clone(inputSketch); inputSketch = SketchTransformation.Resample(inputSketch, modelPoints.Count); inputStroke = inputSketch.Strokes[0]; // get the number of points to iterate between the corresponding model and input stroke int numInputPoints = inputStroke.GetInkPoints().Count; int count = numModelPoints < numInputPoints ? numModelPoints : numInputPoints; // calculate the distances both forward and backwards between the model and input strokes double distance1 = 0.0; double distance2 = 0.0; for (int a = 0, b = count - 1; a < count; ++a, --b) { InkPoint modelPoint = modelStroke.GetInkPoints()[a]; InkPoint inputPoint1 = inputStroke.GetInkPoints()[a]; InkPoint inputPoint2 = inputStroke.GetInkPoints()[b]; distance1 += SketchTransformation.Distance(modelPoint, inputPoint1); distance2 += SketchTransformation.Distance(modelPoint, inputPoint2); } double distance = distance1 < distance2 ? distance1 : distance2; return(distance); }
void OnStrokeStarting(CoreWetStrokeUpdateSource sender, CoreWetStrokeUpdateEventArgs args) { // as the stroke is starting, reset our member variables which store // which X or Y point we want to snap to. this.snapX = this.snapY = null; // I am assuming that we do get a first ink point. InkPoint firstPoint = args.NewInkPoints.First(); // now decide whether we need to set up a snap point for the X value or // one for the Y value. if (this.currentMode == Mode.SnapX) { this.snapX = this.NearestGridSizeMultiple(firstPoint.Position.X); } else if (this.currentMode == Mode.SnapY) { this.snapY = this.NearestGridSizeMultiple(firstPoint.Position.Y); } this.SnapPoints(args.NewInkPoints); }
private void SnapPoints(IList <InkPoint> newInkPoints) { try { Point p = new Point(); for (int i = 0; i < newInkPoints.Count; i++) { p.X = newInkPoints[i].Position.X; p.Y = newInkPoints[i].Position.Y; if (GeometryHelper.PointIsInPolygon(P1, P2, P3, p) == false) { Point pt = GeometryHelper.NearestPointOnGeodreieck(P1, P2, P3, p); Point np = GeometryHelper.NewInkPoint(pt, p, ViewModel.CurrentStrokeWidth); newInkPoints[i] = new InkPoint(np, newInkPoints[i].Pressure); } else { newInkPoints.RemoveAt(i); } } } catch { } }
void SnapPoints(IList <InkPoint> newInkPoints) { // do we need to do any snapping? if (this.currentMode != Mode.Freeform) { for (int i = 0; i < newInkPoints.Count; i++) { if (this.snapX.HasValue) { // replace this point with the same point but with the X value snapped. newInkPoints[i] = new InkPoint( new Point(this.snapX.Value, newInkPoints[i].Position.Y), newInkPoints[i].Pressure); } else if (this.snapY.HasValue) { // replace this point with the same point but with the Y value snapped. newInkPoints[i] = new InkPoint( new Point(newInkPoints[i].Position.X, this.snapY.Value), newInkPoints[i].Pressure); } } } }
public static double Distance(InkPoint a, InkPoint b) { double distance = Math.Sqrt((b.Position.X - a.Position.X) * (b.Position.X - a.Position.X) + (b.Position.Y - a.Position.Y) * (b.Position.Y - a.Position.Y)); return(distance); }
/// <summary> /// Initializes a new instance of the <see cref="Ink"/>. /// </summary> public Ink(DeviceContext2 context2, InkPoint startPoint) :this(IntPtr.Zero) { context2.CreateInk(startPoint, this); }
public abstract void BeginDraw(InkPoint point, PointerPoint pointer);
public abstract void Drawing(InkPoint point);
public abstract void BeginMove(InkPoint ipoint, PointerPoint point);
public virtual bool IsPointOn(InkPoint ipoint, PointerPoint point) { return(false); }
private InkStroke ParseFromJSON(JObject stroke) { List <InkPoint> inkPoints = new List <InkPoint>(); foreach (var point in stroke.Value <JArray>("points")) { JObject o = (JObject)point; Point p = new Point(o.Value <float>("x"), o.Value <float>("y")); InkPoint ip = new InkPoint(p, o.Value <float>("p")); inkPoints.Add(ip); _ = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher. RunAsync(CoreDispatcherPriority.Low, () => { if (o.Value <float>("y") >= inkCanvas.Height - EXPAND_MARGIN) { expandBoard(o.Value <float>("y")); } else if (o.Value <float>("x") >= inkCanvas.Width - EXPAND_MARGIN) { expandBoard(o.Value <float>("x")); } }); } InkStrokeBuilder b = new InkStrokeBuilder(); InkDrawingAttributes da = new InkDrawingAttributes(); // Pressure JObject toolInfo = stroke.Value <JObject>("tool"); if (toolInfo != null) { if (toolInfo.Value <Boolean>("pencil")) { da = InkDrawingAttributes.CreateForPencil(); } else { da.DrawAsHighlighter = toolInfo.Value <Boolean>("marker"); } da.Size = new Size((double)toolInfo.Value <JObject>("size").GetValue("w"), (double)toolInfo.Value <JObject>("size").GetValue("h")); } // Color da.Color = Windows.UI.ColorHelper.FromArgb( (byte)stroke.Value <JObject>("color").GetValue("A"), (byte)stroke.Value <JObject>("color").GetValue("R"), (byte)stroke.Value <JObject>("color").GetValue("G"), (byte)stroke.Value <JObject>("color").GetValue("B") ); da.IgnorePressure = false; da.FitToCurve = true; b.SetDefaultDrawingAttributes(da); InkStroke c = b.CreateStrokeFromInkPoints(inkPoints, Matrix3x2.Identity); return(c); }
public virtual bool Move(InkPoint iPoint, PointerPoint point) { return(false); }
private void PointerReleased(InkPoint point, PointerPoint pointer) { //FIXME:关联大小???? //Drawer.TextFormat = new CanvasTextFormat() { FontSize = Drawer.TextFormat.FontSize }; }
public override void BeginDraw(InkPoint point, PointerPoint pointer) { base.BeginDraw(point, pointer); Text = Drawer.Text; TextFormat = Drawer.TextFormat; }