private static bool IsLine(SketchStroke stroke, int i1, int i2) { SketchPoint p1 = stroke.Points[i1]; SketchPoint p2 = stroke.Points[i2]; return(MathHelpers.EuclideanDistance(p1, p2) / SketchStrokeFeatureExtraction.PathLength(stroke, i1, i2) > LineValidationThreshold); }
public static SketchStroke ResampleStroke(SketchStroke stroke, int n) { SketchStroke resampledStroke = new SketchStroke(); List <SketchPoint> points = new List <SketchPoint>(); List <long> timeStamp = new List <long>(); // Copies the points and timeStamps list of the initial stroke foreach (SketchPoint p in stroke.Points) { points.Add(p); } foreach (long t in stroke.TimeStamp) { timeStamp.Add(t); } double totalLength = SketchStrokeFeatureExtraction.PathLength(stroke); double increment = totalLength / (n - 1); double dist = 0; resampledStroke.AppendPoint(points[0]); for (int i = 1; i < points.Count; i++) { SketchPoint cur = points[i]; SketchPoint pre = points[i - 1]; double d = MathHelpers.EuclideanDistance(cur, pre); if (dist + d >= increment) { double qx = pre.X + ((increment - dist) / d) * (cur.X - pre.X); double qy = pre.Y + ((increment - dist) / d) * (cur.Y - pre.Y); SketchPoint q = new SketchPoint(qx, qy); resampledStroke.AppendPoint(q); points.Insert(i, q); dist = 0.0; } else { dist = dist + d; } } int oldTimeCount = timeStamp.Count; int newTimeCount = resampledStroke.Points.Count; for (int j = 0; j < newTimeCount; ++j) { int index = (int)((double)j / newTimeCount * oldTimeCount); resampledStroke.AppendTime(timeStamp[index]); } return(resampledStroke); }
private static SketchStroke ResampleForCornerFinding(SketchStroke stroke) { BoundingBox bb = new BoundingBox(stroke); double resamplingDistance = bb.Diagonal / DiagonalDividedFactor; double strokeLength = SketchStrokeFeatureExtraction.PathLength(stroke); int numOfSampledPoints = (int)(strokeLength / resamplingDistance + 1); SketchStroke resampledStroke = SketchStrokePreprocessing.ResampleStroke(stroke, numOfSampledPoints); return(resampledStroke); }
private void StrokeIntersectionPlayButton_Click(object sender, RoutedEventArgs e) { if (!this.techAssessor.IsCorrectStrokeCount) { return; } this.AnimationCanvas.Children.Clear(); int[] correspondance = this.techAssessor.StrokeToStrokeCorrespondenceSameCount; string[,] sampleIntersections = this.techAssessor.SampleIntersectionMatrix; string[,] templateIntersections = this.techAssessor.TemplateIntersectionMatrix; for (int i = 0; i < sampleIntersections.GetLength(0); i++) { for (int j = 0; j < sampleIntersections.GetLength(0); j++) { if (i == j) { continue; } if (sampleIntersections[i, j] != templateIntersections[i, j]) { int realI = 0; int realJ = 0; for (int index = 0; index < correspondance.GetLength(0); index++) { if (correspondance[index] == i) { realI = index; } if (correspondance[index] == j) { realJ = index; } } SketchPoint intersection = SketchStrokeFeatureExtraction.Intersection(this.sketchStrokes[realI], this.sketchStrokes[realJ]); if (intersection != null) { InteractionTools.HighlightWrongIntersection(this.AnimationCanvas, intersection); } else { InteractionTools.HighlightStrokes(this.AnimationCanvas, this.WritingInkCanvas, realI, realJ); } } } } }
public static string[,] IntersectionMatrix(List <SketchStroke> strokes) { string[,] intersectionMatrix = new string[strokes.Count, strokes.Count]; for (int i = 0; i < strokes.Count; i++) { for (int j = 0; j < strokes.Count; j++) { if (i == j) { intersectionMatrix[i, j] = "none"; } else { intersectionMatrix[i, j] = SketchStrokeFeatureExtraction.IntersectionRelationship(strokes[i], strokes[j]); } } } return(intersectionMatrix); }
public static List <SketchStroke> Resample(List <SketchStroke> strokes, int n) { double totalLength = 0; foreach (SketchStroke stroke in strokes) { totalLength += SketchStrokeFeatureExtraction.PathLength(stroke); } double I = totalLength / (n - 1); double D = 0.0; List <SketchStroke> newStrokes = new List <SketchStroke>(); // Iterates through each stroke points in a list of strokes int pointCount = 0; foreach (SketchStroke stroke in strokes) { //Resamples point locations List <SketchPoint> points = stroke.Points; List <SketchPoint> newPoints = new List <SketchPoint>(); newPoints.Add(new SketchPoint(points[0].X, points[0].Y)); ++pointCount; bool isDone = false; for (int i = 1; i < points.Count; ++i) { double d = MathHelpers.EuclideanDistance(points[i - 1], points[i]); if (D + d >= I) { double qx = points[i - 1].X + ((I - D) / d) * (points[i].X - points[i - 1].X); double qy = points[i - 1].Y + ((I - D) / d) * (points[i].Y - points[i - 1].Y); if (pointCount < n - 1) { newPoints.Add(new SketchPoint(qx, qy)); ++pointCount; points.Insert(i, new SketchPoint(qx, qy)); D = 0.0; } else { isDone = true; } } else { D += d; } if (isDone) { break; } } D = 0.0; // Resamples time stamps List <long> timeStamp = stroke.TimeStamp; List <long> newTimeStamp = new List <long>(); int oldCount = timeStamp.Count; int newCount = newPoints.Count; for (int j = 0; j < newCount; ++j) { int index = (int)((double)j / newCount * oldCount); newTimeStamp.Add(timeStamp[index]); } SketchStroke newStroke = new SketchStroke(newPoints, newTimeStamp); newStrokes.Add(newStroke); } return(newStrokes); }