/// <summary> /// Only checks if system has the number of history data as mentioned /// </summary> /// <param name="points"></param> /// <returns></returns> public ValidSetOfPointsCollection Validate(List<TouchPoint2> points) { ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); //Algo: For each point, we need to check if a point has n more touch points in the history. //For example, for a point p1 in points collections, we need to check if there is another point //p2 where p2.endTime is less than p1.start time. In the same way, is there any p3... and go on //upto nth level where n = _data.TouchCount ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(); // Check if enough history data is recorded if (TouchHistoryTracker.Count >= _data.TouchCount) { foreach (var point in points) { DateTime earliestValidTime = GetEarliestValidTime(point); Rect location = RuleValidationHelper.GetBoundingBox(point); if (RuleValidationHelper.HasPreviousTouchPoints(location, point, _data.TouchCount, earliestValidTime)) set.Add(point); } } if (set.Count > 0) sets.Add(set); return sets; }
public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets) { ValidSetOfPointsCollection result = new ValidSetOfPointsCollection(); foreach (var item in sets) { ValidSetOfPointsCollection list = Validate(item); foreach (var set in list) { result.Add(set); } } return result; }
public ValidSetOfPointsCollection Validate(List<TouchPoint2> points) { ValidSetOfPointsCollection list = new ValidSetOfPointsCollection(); foreach (TouchPoint2 point in points) { if (point.Tag != null) { if (point.Tag == _data.Value) list.Add(new ValidSetOfTouchPoints(points)); } } return list; }
public ValidSetOfPointsCollection Validate(System.Collections.Generic.List<TouchPoint2> points) { ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(); foreach (var point in points) { if (IsEnclosedAreaWithinRange(point.Stroke.StylusPoints)) set.Add(point); } if (set.Count > 0) sets.Add(set); return sets; }
public ValidSetOfPointsCollection Validate(System.Collections.Generic.List<TouchPoint2> points) { ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); if (points.Count > 0) { Rect parent = points[0].Stroke.GetBounds(); for (int i = 1; i < points.Count; i++) { Rect rect = points[i].Stroke.GetBounds(); parent.Union(rect); } if (parent.Height >= _data.MinHeight && parent.Height <= _data.MaxHeight && parent.Width >= _data.MinWidth && parent.Width <= _data.MaxWidth) { ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(points); sets.Add(set); } } return sets; }
public ValidSetOfPointsCollection Validate(System.Collections.Generic.List<TouchPoint2> points) { bool result = true; ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); if (points.Count > 1) { UIElement source = points[0].Source; for (int i = 1; i < points.Count; i++) { if (source != points[i].Source) { result = false; break; } } } if (result) sets.Add(new ValidSetOfTouchPoints(points)); return sets; }
public ValidSetOfPointsCollection Validate(System.Collections.Generic.List<TouchPoint2> points) { ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(); foreach (var point in points) { if (IsClosedLoop(point)) set.Add(point); } if (set.Count > 0) sets.Add(set); return sets; }
/// <summary> /// Only checks if system has the number of history data as mentioned /// </summary> /// <param name="sets"></param> /// <returns></returns> public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets) { ValidSetOfPointsCollection validSets = new ValidSetOfPointsCollection(); foreach (var set in sets) { ValidSetOfPointsCollection results = Validate(set); foreach (var result in results) { validSets.Add(result); } } return validSets; }
public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets) { ValidSetOfPointsCollection validSets = new ValidSetOfPointsCollection(); foreach (var item in sets) { // Because we know it will return only one item in the list var results = Validate(item); if (results.Count > 0) validSets.Add(results[0]); } return validSets; }
public ValidSetOfPointsCollection Validate(List<TouchPoint2> points) { ValidSetOfPointsCollection list = new ValidSetOfPointsCollection(); foreach (TouchPoint2 point in points) { if (!point.isFinger && point.Snapshot!= null && point.Tag == null) { string _type = string.Empty; string _side = string.Empty; ImageHelper.getHandType(out _type, out _side, point); if (_type == "" && _side == "") continue; if (_data.Type == string.Empty && _data.Side == string.Empty) { list.Add(new ValidSetOfTouchPoints(points)); continue; } if (_data.Side != string.Empty) { if (_type == _data.Type && _data.Side == _side) list.Add(new ValidSetOfTouchPoints(points)); } else // checks only the type { if (_type == _data.Type) list.Add(new ValidSetOfTouchPoints(points)); } } } return list; }
public ValidSetOfPointsCollection Validate(ValidSetOfTouchPoints points, string gestureName) { ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(); double length = 0; // the length can be calculated for a single touch path. So, we check each // touchPoint individually foreach (var point in points) { bool singlePoint = TrigonometricCalculationHelper.isASinglePoint(point); if (singlePoint) { continue; } // A point can't be a closed loop if (checkForVariable(point, gestureName)) { set.Add(point); } else { length = TrigonometricCalculationHelper.CalculatePathLength(point); if (length >= _data.Min && length <= _data.Max) { set.Add(point); } } } if (set.Count > 0) { sets.Add(set); } return sets; }
public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets) { ValidSetOfPointsCollection validSets = new ValidSetOfPointsCollection(); //_data.currentMin = CalculatePathLength(validSets.); foreach (var item in sets) { ValidSetOfPointsCollection list = Validate(item,sets.ExpectedGestureName); foreach (var set in list) { validSets.Add(set); } } return validSets; }
public ValidSetOfPointsCollection Validate(List<TouchPoint2> points) { ValidSetOfPointsCollection ret = new ValidSetOfPointsCollection(); foreach (var point in points) { if (!point.isFinger) { continue; } bool singlePoint = TrigonometricCalculationHelper.isASinglePoint(point); if (singlePoint) { continue; } // A point can't be a closed loop ValidSetOfTouchPoints tps = null; if (_data.Values.Equals(CIRCLE)) { tps = ValidateCircle(point); } else if (_data.Values.Equals(BOX)) { tps = ValidateBox(point); } else if (_data.Values.Equals(CHECK)) { tps = ValidateCheck(point); } else if (_data.Values.Equals(LINE)) { tps = ValidateLine(point); } if ((tps != null) && (tps.Count > 0)) { ret.Add(tps); } } return ret; }
private ValidSetOfPointsCollection IsValid(List<TouchPoint2> points) { bool result = true; ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); if (points.Count > 0) { //double minX = int.MinValue, minY = int.MinValue, maxX = int.MaxValue, maxY = int.MaxValue; Rect area = new Rect(points[0].Position, new Size(0, 0)); // Calculate the bounding box that covers all points foreach (var point in points) { if (_data.HistoryLevel > 0) { Rect location = RuleValidationHelper.GetBoundingBox(point); List<TouchPoint2> selectedPoints = new List<TouchPoint2>(); result = RuleValidationHelper.HasPreviousTouchPoints(location, point, _data.HistoryLevel, point.StartTime.AddSeconds(-_data.HistoryTimeLine), selectedPoints); if (result) // Has required number of previous touch points in selected location { foreach (var p in selectedPoints) { area.Union(p.Position); } } else { break; } } area.Union(point.Position); } // TODO: We need to implement circular area too if (result && area.Height <= _data.Height && area.Width <= _data.Width) { sets.Add(new ValidSetOfTouchPoints(points)); } } return sets; }
public ValidSetOfPointsCollection Validate(List<TouchPoint2> points) { ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); if (IsValid(points)) { sets.Add(new ValidSetOfTouchPoints(points)); } return sets; }
public static ValidSetOfPointsCollection ForEachSet(this ValidSetOfPointsCollection self, Validate validateMethod) { ValidSetOfPointsCollection validSets = new ValidSetOfPointsCollection(); foreach (var item in self) { ValidSetOfPointsCollection list = validateMethod(item); foreach (var set in list) { validSets.Add(set); } } return validSets; }
public ValidSetOfPointsCollection Validate(List<TouchPoint2> points) { ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); bool result = false; if (points == null) { return sets; } if (points.Count > 2) { // Assumption: If there are more that 2 points, then each point should // match the condition with another point in at least one condition Dictionary<TouchPoint2, bool> resultSet = new Dictionary<TouchPoint2, bool>(points.Count); Combinations combinationGen = new Combinations(points.ToArray(), 2); while (combinationGen.MoveNext()) { TouchPoint2[] arr = combinationGen.Current as TouchPoint2[]; if (IsValid(arr)) { // First item of the combinition set if (!resultSet.ContainsKey(arr[0])) resultSet.Add(arr[0], true); // Second item of the combinition set if (!resultSet.ContainsKey(arr[1])) resultSet.Add(arr[1], true); if (resultSet.Count == points.Count) { // All points have been validated at least once result = true; break; } } } } else if (points.Count == 2) { result = IsValid(points.ToArray()); } if (result) { ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(points); sets.Add(set); } return sets; }
public ValidSetOfPointsCollection Validate(List<TouchPoint2> points) { ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); ValidSetOfTouchPoints list = new ValidSetOfTouchPoints(); List<Queue<int>> PointList = new List<Queue<int>>(); Queue<int> AddQueue; foreach (var point in points) { int length = point.Stroke.StylusPoints.Count; bool continuous = true; int step = 1; AddQueue = new Queue<int>(); for (int i = 0; i < length - step; i = i + step) { var p1 = point.Stroke.StylusPoints[i]; var p2 = point.Stroke.StylusPoints[i + step]; double slope = TrigonometricCalculationHelper.GetSlopeBetweenPoints(p1, p2); String stringSlope = TouchPointExtensions.SlopeToDirection(slope); double dist = TrigonometricCalculationHelper.GetDistanceBetweenPoints(p1, p2); if (dist == 0) { continue; } if (stringSlope.Equals(_data.Values)) { if (!continuous) { continuous = true; PointList.Add(AddQueue); AddQueue = new Queue<int>(); } AddQueue.Enqueue(i); } else { continuous = false; } } if (AddQueue.Count > 0) { PointList.Add(AddQueue); } //Add seperate points for each queue made foreach (var queue in PointList) { TouchPoint2 p = point.GetEmptyCopy(); while (queue.Count > 0) { int i = queue.Dequeue(); StylusPoint newPoint = point.Stroke.StylusPoints[i]; p.Stroke.StylusPoints.Add(newPoint); } if (p.Stroke.StylusPoints.Count > 1) { list.Add(p); } } } if (list.Count > 0) { sets.Add(new ValidSetOfTouchPoints(points)); // sets.Add(list); } return sets; }
public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets) { ValidSetOfPointsCollection validSets = new ValidSetOfPointsCollection(); if (sets != null) { foreach (var set in sets) { ValidSetOfPointsCollection list = Validate(set); foreach (var item in list) { validSets.Add(item); } } } return validSets; }
public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets) { //TODO: move this code block to base class or extension methods. its common in many validators ValidSetOfPointsCollection validSets = new ValidSetOfPointsCollection(); foreach (var set in sets) { var list = Validate(set); foreach (var item in list) { validSets.Add(item); } } return validSets; }
public ValidSetOfPointsCollection Validate(List<TouchPoint2> points) { ValidSetOfPointsCollection list = new ValidSetOfPointsCollection(); if (_data.Type == TouchLimitType.FixedValue) { List<TouchPoint2> analyze = PointTranslator.removeHandRedundancy(points); if (analyze.Count == _data.Min) { list.Add(new ValidSetOfTouchPoints(analyze)); } else if (analyze.Count > _data.Min) { // Generate possible valid combinitions Combinations c = new Combinations(analyze.ToArray(), _data.Min); while (c.MoveNext()) { TouchPoint2[] arr = c.Current as TouchPoint2[]; ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(arr); list.Add(set); } } } else if (_data.Type == TouchLimitType.Range) { if (points.Count == _data.Min) { list.Add(new ValidSetOfTouchPoints(points)); } else if (points.Count > _data.Min && points.Count <= _data.Max) { // All possible combinitions of size between min & max-1 for (int size = _data.Min; size < points.Count; size++) { // Generate possible valid combinitions Combinations c = new Combinations(points.ToArray(), size); while (c.MoveNext()) { TouchPoint2[] arr = c.Current as TouchPoint2[]; ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(arr); list.Add(set); } } } } return list; }
public ValidSetOfPointsCollection Validate(List<TouchPoint2> points) { ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection(); bool result = true; foreach (var point in points) { // TODO: We need to check the unit type (i.e. sec, min,...) and compare accordingly if (_data.Unit.StartsWith("msec")) { if (point.Age.TotalMilliseconds <= _data.Value) result = false; } else if (_data.Unit.StartsWith("sec")) { if (point.Age.TotalSeconds <= _data.Value) result = false; } else { throw new LanguageSyntaxErrorException("Invalid unit for \"TouchTime\" primitive condition!"); } } if (result) sets.Add(new ValidSetOfTouchPoints(points)); return sets; }
private void ActiveHardware_MultiTouchChanged(Object sender, MultiTouchEventArgs e) { if (MultiTouchChanged != null) MultiTouchChanged(sender, e); // Validate pre-conditions ValidSetOfTouchPoints availableTouchPoints = e.TouchPoints.Copy(); ValidSetOfPointsCollection dataToEvaluate = new ValidSetOfPointsCollection(); dataToEvaluate.Add(availableTouchPoints); // Validate gestures that are in progess ValidateBlockResult[] list = PartiallyEvaluatedGestures.GetAll(); foreach (ValidateBlockResult item in list) { Gesture gesture = GestureLanguageProcessor.ActiveGestures[item.GestureName.ToLower()]; dataToEvaluate.ExpectedGestureName = gesture.Name; int stepToValidate = item.ValidateBlockNo +1; if (gesture != null) { if (gesture.ValidationBlocks.Count > stepToValidate) { var result = ValidateGesture(gesture, dataToEvaluate, stepToValidate); // If its the second last step then also run the last step if (result.Count > 0) { if (gesture.ValidationBlocks.Count == stepToValidate + 2) { stepToValidate++; result = ValidateGesture(gesture, dataToEvaluate, stepToValidate); } } // If its the final step of a gesture, then delete all related partial results from cache if (gesture.ValidationBlocks.Count == stepToValidate + 1) { PartiallyEvaluatedGestures.Remove(item); PartiallyEvaluatedGestures.cleanBuffer(); } // Remove touch points that are used in multi-step gesture from // touch points list for new gestures // dataToEvaluate.Remove(result); } } } // Validate gestures from the first validate block as if new gestures foreach (Gesture gesture in GestureLanguageProcessor.ActiveGestures.Values) { // Cleans buffer for the Primitives to use it // PartiallyEvaluatedGestures.cleanBuffer(); if (dataToEvaluate.Count > 0) ValidateGesture(gesture, dataToEvaluate, 0); } }