public static List <int> GetCorners(InkStroke stroq, InkStroke oInkStroke) { List <int> corners = new List <int>(); // List of index of corners. List <double> straws = new List <double>(); // List of length of straws at each inkStroke points. List <double> temp = new List <double>(); double t, localMin; int W = 3, i, localMinIndex; corners.Add(0); for (i = 0; i < W; i++) { straws.Add(0.0); } for (i = W; i < stroq.Points.Count - W; i++) { straws.Add(Distance(stroq.Points[i - W], stroq.Points[i + W])); temp.Add(straws[i]); } for (i = stroq.Points.Count - W; i < stroq.Points.Count; i++) { straws.Add(0.0); } // Find the median and threshold. if (temp.Count == 0) { Debug.WriteLine("Too few points. Try to draw more points."); return(corners); } temp.Sort(); t = temp[temp.Count / 2] * 0.95; // Find local minimum of potential corners. for (i = W; i < stroq.Points.Count - W; i++) { if (straws[i] < t) { localMin = 100000.0; localMinIndex = i; while (i < stroq.Points.Count - W && straws[i] < t) { if (straws[i] < localMin) { localMin = straws[i]; localMinIndex = i; } i++; } corners.Add(localMinIndex); } } corners.Add(stroq.Points.Count - 1); // Do post process to the potential corners. corners = PostProcessCorners(stroq, corners, straws); // Remove corners on curve. corners = CurveCheck(stroq, corners); // Find original corners. corners = ResampleToOriginal(stroq, oInkStroke, corners); if (corners.Count != 0) { InkStroke cinkStroke = new InkStroke(); cinkStroke.Points.Add(stroq.Points[corners[0]]); for (i = 1; i < corners.Count; i++) { cinkStroke.Points.Add(oInkStroke.Points[corners[i]]); } } else { Debug.WriteLine("No corners found."); } return(corners); }
// Determines the interspacing pixel distance between resampled points. public static double DetermineResampleSpacing(InkStroke stroq) { Rect bound = stroq.BoundingRect; return(Distance(new Point(bound.Left, bound.Top), new Point(bound.Right, bound.Bottom)) / 80.0); }