private void AddPoint(List <InputPoint> point) { bool getNewPoint = false; foreach (var p in point) { // Don't accept point if it's within specified distance of last point unless it's the first point if (_pointsCaptured.ContainsKey(p.ContactIdentifier)) { var stroke = _pointsCaptured[p.ContactIdentifier]; if (stroke.Count != 0) { if (PointPatternMath.GetDistance(stroke.Last(), p.Point) < AppConfig.MinimumPointDistance) { continue; } if (State == CaptureState.CapturingInvalid) { State = CaptureState.Capturing; } } getNewPoint = true; // Add point to captured points list stroke.Add(p.Point); } } if (getNewPoint) { // Notify subscribers that point has been captured OnPointCaptured(new PointsCapturedEventArgs(new List <List <Point> >(_pointsCaptured.Values), point.Select(p => p.Point).ToList())); } }
public static string GetPatternFeatures(List <List <Point> > pattern) { string output = ""; for (int i = 0; i < pattern.Count; i++) { var currentStroke = pattern[i]; if (currentStroke.Count == 1) { output += 0; continue; } var strokeFeature = PointPatternMath.GetPointArrayAngularMargins(PointPatternMath.GetInterpolatedPointArray(currentStroke.ToArray(), 9)); uint feature = 0; for (int j = 0; j < strokeFeature.Length; j++) { var feat = strokeFeature[j] / Math.PI + 1 - 3.0 / 8.0; if (feat < 0) { feat = 2 + feat; } feature = feature << 4; feature |= (uint)(feat / 2 * 8) << 1; feature++; } output += feature.ToString("x8"); } return(output); }
private void CheckCancel() { int reversalCount = 0; double previousAngle = 0; double nextAngle = 0; PointF previousPoint = default(PointF); PointF currentPoint = default(PointF); PointF nextPoint = default(PointF); // Loop through all points captured so far except for the first and last point. // We skip the first and last point because we need that one point margin to allow us to // compare the next and previous points (relative to current point index) so that we can check // for hard reversals (quick back and forth) for (int currentIndex = 1; currentIndex < _PointsCaptured.Count() - 1; currentIndex++) { // Get points based on current index previousPoint = _PointsCaptured[currentIndex - 1]; currentPoint = _PointsCaptured[currentIndex]; nextPoint = _PointsCaptured[currentIndex + 1]; // Get angular change between previous and next point previousAngle = PointPatternMath.GetAngularGradient(previousPoint, currentPoint); nextAngle = PointPatternMath.GetAngularGradient(currentPoint, nextPoint); // Check if we have a reversal, do this by getting the angular change (delta) between the previous angle and the // next angle (in radians), then convert the delta from radians to degrees so that we have an easy way to see if our // delta is within the threshold (between ReversalAngleThreshold and 180) to be considered a reversal double angularDelta = PointPatternMath.GetDegreeFromRadian(PointPatternMath.GetAngularDelta(previousAngle, nextAngle)); if (angularDelta > Properties.Settings.Default.ReversalAngleThreshold) { reversalCount++; } // If we have enough reversals to cancel then cancel the capture process if (reversalCount > Properties.Settings.Default.ReversalCountCancel) { CancelCapture(); return; } } }