Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds the items from the specified collection into existing collection
 /// </summary>
 /// <param name="self"></param>
 /// <param name="itemsToAdd"></param>
 public static void Add(this ValidSetOfPointsCollection self, ValidSetOfPointsCollection itemsToAdd)
 {
     foreach (ValidSetOfTouchPoints item in itemsToAdd)
     {
         self.Add(item);
     }
 }
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 4
0
        public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets)
        {
            ValidSetOfPointsCollection list = new ValidSetOfPointsCollection();
            foreach (ValidSetOfTouchPoints set in sets)
            {
                ValidSetOfPointsCollection tmpList = Validate(set);
                list.AddRange(tmpList);
            }

            return list;
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
        public static void Add(string gestureName, int blockNo, ValidSetOfPointsCollection data, string blockName)
        {
            List<ValidateBlockResult> previous = Get(gestureName, blockNo);

            if (previous.Count >= 1)
            {
                Remove(previous[0]);
            }

            var item = new ValidateBlockResult()
            {
                Data = data,
                GestureName = gestureName,
                ValidateBlockNo = blockNo,
                ValidateBlockName = blockName
            };
            _cache.Add(item);
        }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
0
        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;
        }
Exemplo n.º 12
0
        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;
        }
Exemplo n.º 13
0
        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;
        }
Exemplo n.º 14
0
 public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets)
 {
     return sets.ForEachSet(Validate);
 }
Exemplo n.º 15
0
        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(ValidSetOfPointsCollection sets)
        {
            List<ValidateBlockResult> firstBlockResults = PartiallyEvaluatedGestures.Get(sets.ExpectedGestureName, _data.Gesture1);
            List<ValidateBlockResult> secBlockResults = PartiallyEvaluatedGestures.Get(sets.ExpectedGestureName, _data.Gesture2);

            if (firstBlockResults.Count == 0 || secBlockResults.Count == 0)
                return new ValidSetOfPointsCollection();

            TouchPoint2 point1 = firstBlockResults[0].Data[0][0];
            TouchPoint2 point2 = secBlockResults[0].Data[0][0];

            if (_data.Position == TouchRelativePosition.LEFT)
                if (point1.Position.X < point2.Position.X)
                    return sets;

            if (_data.Position == TouchRelativePosition.RIGHT)
                if (point1.Position.X > point2.Position.X)
                    return sets;

            return new ValidSetOfPointsCollection();
        }
Exemplo n.º 17
0
        public ValidSetOfPointsCollection Validate(List<TouchPoint2> points)
        {
            ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection();
            if (IsValid(points))
            {
                sets.Add(new ValidSetOfTouchPoints(points));
            }

            return sets;
        }
Exemplo n.º 18
0
        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;
        }
Exemplo n.º 19
0
        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;
        }
Exemplo n.º 20
0
        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;
        }
Exemplo n.º 21
0
        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;
        }
Exemplo n.º 22
0
        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;
        }
Exemplo n.º 23
0
        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(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(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;
        }
Exemplo n.º 26
0
        public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets)
        {
            Console.WriteLine("AngleName:" + sets.ExpectedGestureName);

            List<ValidateBlockResult> firstBlockResults = PartiallyEvaluatedGestures.Get(sets.ExpectedGestureName, _data.Gesture1);
            List<ValidateBlockResult> secBlockResults = PartiallyEvaluatedGestures.Get(sets.ExpectedGestureName, _data.Gesture2);

            if (firstBlockResults.Count == 0 || secBlockResults.Count == 0)
                return new ValidSetOfPointsCollection();

            ValidSetOfPointsCollection step1 = firstBlockResults[0].Data;

            ValidSetOfTouchPoints line1 = ValidateLine(step1[0][0]);

            if (line1.Count > 0)
            {
                ValidSetOfPointsCollection step2 = secBlockResults[0].Data;
                ValidSetOfTouchPoints line2 = ValidateLine(step2[0][0]);

                if (line2.Count == 0)
                {
                    return new ValidSetOfPointsCollection();
                }
                var stylusPoints1 = TrigonometricCalculationHelper.removeRedundancy(line1[0].Stroke.StylusPoints);
                var stylusPoints2 = TrigonometricCalculationHelper.removeRedundancy(line2[0].Stroke.StylusPoints);
                if (stylusPoints2.Count == 0)
                {
                    return new ValidSetOfPointsCollection();
                }

                // Considering that they are two lines, the angle will only be checked if their edges are  nearby
                if (!linesTouch(stylusPoints1, stylusPoints2))
                {
                    return new ValidSetOfPointsCollection();
                }

                // Calculate slope of each line represented by the two sets of touch points
                // as the final of a line is usually fuzzy, get the middle points(1/4,3/4), that have a more fixed pattern
                int avg1 = stylusPoints1.Count;
                int avg2 = stylusPoints2.Count;

                double set1Angle = TrigonometricCalculationHelper.GetSlopeBetweenPoints(stylusPoints1[avg1 / 4], stylusPoints1[avg1 * 3 / 4]);
                double set2Angle = TrigonometricCalculationHelper.GetSlopeBetweenPoints(stylusPoints2[avg2 / 4], stylusPoints2[avg2 * 3 / 4]);

                double angularDiff = (set1Angle - set2Angle) * 180 / 3.14;

                if (angularDiff < 0)
                    angularDiff = 180 + angularDiff;

                if (angularDiff > 180)
                    angularDiff = angularDiff - 180;

                double angleValueMin = _data.Min;
                double angleValueMax = _data.Max;

                if (Math.Abs(angularDiff) > angleValueMin && Math.Abs(angularDiff) < angleValueMax)
                {
                    return sets;
                }
                else
                {
                    angularDiff = Math.Abs(angularDiff) - 180;
                    if (Math.Abs(angularDiff) > angleValueMin && Math.Abs(angularDiff) < angleValueMax)
                    {
                        return sets;
                    }
                }
            }
            return new ValidSetOfPointsCollection();
        }
Exemplo n.º 27
0
        public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets)
        {
            var result = false;
            var firstBlockResults = PartiallyEvaluatedGestures.Get(sets.ExpectedGestureName, _data.Gesture1);
            var secBlockResults = PartiallyEvaluatedGestures.Get(sets.ExpectedGestureName, _data.Gesture2);

            foreach (var firstBlockResult in firstBlockResults)
            {
                foreach (var secBlockResult in secBlockResults)
                {
                    if (Validate(firstBlockResult, secBlockResult))
                    {
                        result = true;
                        // TODO:???
                        firstBlockResult.AssociatedResults.Add(secBlockResult.Id);
                        secBlockResult.AssociatedResults.Add(firstBlockResult.Id);
                        break;
                    }
                }
            }

            if (result)
                return sets;
            else
                return new ValidSetOfPointsCollection();
        }
Exemplo n.º 28
0
        /// <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;
        }
Exemplo n.º 29
0
        public ValidSetOfPointsCollection Validate(ValidSetOfPointsCollection sets)
        {
            ValidSetOfPointsCollection list = new ValidSetOfPointsCollection();
            foreach (var item in sets)
            {
                var tlist = Validate(item);
                list.AddRange(tlist);
            }

            return list;
        }
Exemplo n.º 30
0
        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;
        }