public void PositionChanged_Test()
        {
            PositionChangedCalculator target = new PositionChangedCalculator();
            int expectedY = 0;
            int expectedX = 0;

            //Setup preamble for 2 touchpoints to be used in calculate

            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(3, 6);

            ValidSetOfTouchPoints test = new ValidSetOfTouchPoints();
            test.Add(new TouchPoint2(ti1, new UIElement()));
            test.Add(new TouchPoint2(ti2, new UIElement()));

            PositionChanged actualP = target.Calculate(test) as PositionChanged;

            //Assert that both X and Y of position are correct after calculation
            Assert.AreEqual(expectedX, actualP.X);
            Assert.AreEqual(expectedY, actualP.Y);
        }
        public void DistanceChangedCalculator_Calculate_Test_For_Distance()
        {
            //Setup preamble for 2 touchpoints to be used in calculate

            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(2, 6);

            ValidSetOfTouchPoints test = new ValidSetOfTouchPoints();
            test.Add(new TouchPoint2(ti1, new UIElement()));
            test.Add(new TouchPoint2(ti2, new UIElement()));

            //Call appropriate methods
            DistanceChangedCalculator target = new DistanceChangedCalculator();

            DistanceChanged result = target.Calculate(test) as DistanceChanged;
            result.Distance = Math.Round(result.Distance, 2);
            bool actual = result.Distance.Equals(1.41);

            Assert.AreEqual(true, actual);
        }
        public void SlopeChangedCalculator_Calculate_No_History_Test()
        {
            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(3, 6);

            ValidSetOfTouchPoints vp = new ValidSetOfTouchPoints();
            vp.Add(new TouchPoint2(ti1, new UIElement()));
            vp.Add(new TouchPoint2(ti2, new UIElement()));

            SlopeChangedCalculator sc = new SlopeChangedCalculator();

            SlopeChanged actualP = sc.Calculate(vp) as SlopeChanged;

            double expectedSlope = 26.58;
            double expectedDelta = 0;
            Console.Out.WriteLine(actualP.Delta);
            Assert.IsTrue(expectedDelta == actualP.Delta);
            Assert.IsTrue(expectedSlope == Math.Round(actualP.NewSlope, 2));
        }
Example #4
0
 public TouchPoint2(TouchInfo info, UIElement source, StylusPointCollection stylusPoints)
 {
     this.Source = source;
     Stroke = new Stroke(stylusPoints);
     TouchDeviceId = info.TouchDeviceId;
     StartTime = DateTime.Now;
     UpdateTouchInfo(info);
 }
        public TouchInfo GetInfoFromContactEvent(TouchAction2 action, System.Windows.Input.TouchEventArgs e)
        {
            //Get the  point position from the ContactEventArgs (can optionally use e.Contact.getCenterPosition here for more accuracy)
            System.Windows.Point position = e.GetTouchPoint(GestureFramework.LayoutRoot).Position; // new System.Windows.Point(e.TouchPoint.CenterX, e.TouchPoint.CenterY);

            //Create a new touchinfo which will be used later to add a touchpoint
            TouchInfo info = new TouchInfo();

            //IF not Using in surface there will be not size or tag, therefore all the points are fingers.
            System.Windows.Size size = e.TouchDevice.GetTouchPoint(GestureFramework.LayoutRoot).Size;
            if (size.Height <= MinimumSize.Height && size.Width <= MinimumSize.Width)
            {
                info.IsFinger = true;
                info.Tag = null;

            }
            else
            {
                info.IsFinger = e.TouchDevice.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().IsFinger;

                if (e.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().Tag != null)
                {

                   // info.Tag = e.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().Tag;
                    /*
                    switch (e.TouchPoint.Tag.Type)
                    {
                        case Microsoft.Surface.Presentation.TagType.Byte:
                            info.Tag = e.Contact.Tag.Byte.ToString();
                            break;
                        case Microsoft.Surface.Presentation.TagType.Identity:
                            info.Tag = e.Contact.Tag.Identity.ToString();
                            break;
                        default:
                            info.Tag = null;
                            break;

                    }*/

                }
                else if (!info.IsFinger)
                {
                    //info.Bounds = new Rect((double)e.TouchPoint.CenterX, (double)e.TouchPoint.CenterY, (double)e.TouchPoint.Bounds.Width, (double)e.TouchPoint.Bounds.Height);
                    info.Bounds = e.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().Bounds;
                }
            }

            //Set the action type to the passed in action
            info.ActionType = action;

            //Set the position of the touchinfo to the previously found position from e
            info.Position = position;

            //Set the deviceid of the touchinfo to the id of the contact
            info.TouchDeviceId = e.GetTouchPoint(GestureFramework.LayoutRoot).TouchDevice.Id;

            return info;
        }
        public void SlopeChangedCalculator_Calculate_Low_Count_Test()
        {
            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            ValidSetOfTouchPoints vp = new ValidSetOfTouchPoints();
            vp.Add(new TouchPoint2(ti1, new UIElement()));

            SlopeChangedCalculator sc = new SlopeChangedCalculator();

            Assert.AreEqual(null, sc.Calculate(vp));
        }
Example #7
0
        public TouchPoint2 AddNewTouchPoint(TouchInfo info, UIElement source)
        {
            TouchPoint2 newTouchPoint = null;
            if (!ActiveTouchPoints.ContainsKey(info.TouchDeviceId))
            {
                newTouchPoint = new TouchPoint2(info, source);
                ActiveTouchPoints.Add(info.TouchDeviceId, newTouchPoint);
            }
            else
            {
                newTouchPoint = ActiveTouchPoints[info.TouchDeviceId];
                newTouchPoint.Source = source;
            }

            return newTouchPoint;
        }
        public void TouchPointsCalculator_Calculate_With_A_Count()
        {
            TouchPointsCalculator tpCalc = new TouchPointsCalculator();

            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            ValidSetOfTouchPoints vp = new ValidSetOfTouchPoints();
            vp.Add(new TouchPoint2(ti1, new UIElement()));

            TouchPoints returned = tpCalc.Calculate(vp) as TouchPoints;

            Assert.IsTrue(returned.Count == 1);
            Assert.AreEqual(returned[0].ToString(), "1,5");
        }
Example #9
0
        public TouchPoint2(TouchInfo info, UIElement source)
        {
            this.Source = source;

            #if SILVERLIGHT
            Stroke = new Stroke();
            #else
            var stylusPoints = new StylusPointCollection(1);
            stylusPoints.Add(new StylusPoint(info.Position.X, info.Position.Y));
            Stroke = new Stroke(stylusPoints);
            #endif

            TouchDeviceId = info.TouchDeviceId;
            StartTime = DateTime.Now;

            #if SILVERLIGHT
            UpdateTouchStroke(info);
            #endif
            UpdateTouchInfo(info);
        }
        public void UpdateActiveTouchPoints(TouchAction2 action, Point position, int iPointerID)
        {
            TouchInfo info = new TouchInfo();
            info.ActionType = action;
            info.Position = position;
            info.TouchDeviceId = iPointerID;

            TouchPoint2 touchPoint = null;

            //If it is contact down, we want to add the point, otherwise we want to update that particular point
            if (action == TouchAction2.Down)
            {
                //VisualTreeHelper.HitTest(mainWindow, null, new HitTestResultCallback(HitTestCallBack), new GeometryHitTestParameters(m_egHitArea));

                //add the new touch point to the base
                touchPoint = base.AddNewTouchPoint(info, null);
                touchPoint.UpdateSource();
            }
            else
            {
                touchPoint = base.UpdateActiveTouchPoint(info);
            }

            // Update local cache
            if (_activeTouchPoints.ContainsKey(info.TouchDeviceId))
            {
                _activeTouchPoints[info.TouchDeviceId] = touchPoint;
                _activeTouchInfos[info.TouchDeviceId] = info;
            }
            else
            {
                _activeTouchPoints.Add(info.TouchDeviceId, touchPoint);
                _activeTouchInfos.Add(info.TouchDeviceId, info);
            }

            _lastTouchInfo = info;

            RaiseEvents();
        }
        public void UpdateActiveTouchPoints(TouchAction2 action, TouchContactEventArgs e)
        {
            Point position = e.TouchContact.GetPosition(GestureFramework.LayoutRoot);

            TouchInfo info = new TouchInfo();

            info.ActionType = action;

            info.Position = position;

            info.TouchDeviceId = e.TouchContact.ID;

            TouchPoint2 touchPoint = null;

            //If it is contact down, we want to add the point, otherwise we want to update that particular point
            if (action == TouchAction2.Down)
            {
                //add the new touch point to the base
                touchPoint = base.AddNewTouchPoint(info, e.OriginalSource as UIElement);
            }
            else
            {
                touchPoint = base.UpdateActiveTouchPoint(info);
            }

            // Update local cache
            if (_activeTouchPoints.ContainsKey(info.TouchDeviceId))
            {
                _activeTouchPoints[info.TouchDeviceId] = touchPoint;
                _activeTouchInfos[info.TouchDeviceId] = info;
            }
            else
            {
                _activeTouchPoints.Add(info.TouchDeviceId, touchPoint);
                _activeTouchInfos.Add(info.TouchDeviceId, info);
            }
        }
Example #12
0
        public void InfoCalculator_Valid_Input_Test()
        {
            //Setup preamble for 2 touchpoints to be used in calculate

            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 6);

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(2, 5);

            ValidSetOfTouchPoints test = new ValidSetOfTouchPoints();
            test.Add(new TouchPoint2(ti1, new UIElement()));
            test.Add(new TouchPoint2(ti2, new UIElement()));

            //Call appropriate methods to test the calculate
            InfoCalculator target = new InfoCalculator();
            Info result = target.Calculate(test) as Info;

            Assert.IsTrue(result.Message == string.Empty);
        }
Example #13
0
        /// <summary>
        /// Return an empty version of this point
        /// </summary>
        public TouchPoint2 GetEmptyCopy()
        {
            TouchInfo info = new TouchInfo();
            info.ActionType = Action.ToTouchAction();
            info.Position = Position;
            info.TouchDeviceId = TouchDeviceId;
            info.Bounds = Bounds;
            info.IsFinger = isFinger;
            info.Tag = Tag;
              //  info.Snapshot = new List<System.Drawing.Bitmap>();

            TouchPoint2 output = new TouchPoint2(info, Source);
            return output;
        }
Example #14
0
 private void CreateProxyObject(TouchInfo touchInfo)
 {
     ProxyObject po = new ProxyObject(touchInfo);
     _rootPanel.Children.Add(po);
     _proxyObjects.Add(po);
 }
Example #15
0
            public ProxyObject(TouchInfo _touchInfo)
            {
                Age = 0;
                Shape shape = null;

                if (_touchInfo.IsFinger)
                {
                    shape = new Ellipse();
                    this.SetValue(Canvas.TopProperty, _touchInfo.Position.Y);
                    this.SetValue(Canvas.LeftProperty, _touchInfo.Position.X);
                    this.Height = 20;
                    this.Width = 20;
                }
                else {
                    shape = new Rectangle();
                    // Set postion
                    this.SetValue(Canvas.TopProperty, _touchInfo.Bounds.Top);
                    this.SetValue(Canvas.LeftProperty, _touchInfo.Bounds.Left);
                    // Set default size & opacity
                    this.Height = _touchInfo.Bounds.Height;
                    this.Width = _touchInfo.Bounds.Width;
                }

                shape.Fill = new SolidColorBrush(Colors.Blue);
                shape.Opacity = 0.9;
                this.Children.Add(shape);
            }
Example #16
0
        private TouchInfo MakeInfo(TuioCursor c, TouchAction2 action)
        {
            Tuple<double, double> screenDim = GetDimensions();
            double screen_width = screenDim.Item1;
            double screen_height = screenDim.Item2;

            double x = c.getX() * screen_width;
            double y = c.getY() * screen_height;
            TouchInfo info = new TouchInfo();
            info.ActionType = action;
            info.Position = new Point(x, y);
            info.TouchDeviceId = (int)c.getSessionID();

            return info;
        }
Example #17
0
 private void CreateProxyObject(TouchInfo touchInfo)
 {
     ProxyObject po = new ProxyObject(touchInfo.Position.X, touchInfo.Position.Y, touchInfo.GroupId);
     _rootPanel.Children.Add(po);
     _proxyObjects.Add(po);
 }
Example #18
0
 private void UpdateTouchStroke(TouchInfo info)
 {
     // Adds a new point in the stroke collection
     Stroke.StylusPoints.Add(new StylusPoint(info.Position.X, info.Position.Y));
 }
Example #19
0
        public TouchPoint2 UpdateActiveTouchPoint(TouchInfo info, UIElement source = null)
        {
            TouchPoint2 tPoint = null;

            // Update touch details (i.e. touch path)
            if (ActiveTouchPoints.ContainsKey(info.TouchDeviceId))
            {
                tPoint = ActiveTouchPoints[info.TouchDeviceId];
                tPoint.Update(info);
            }
            else
            {
                tPoint = AddNewTouchPoint(info, source);
            }

            // Touches that are going to be inactive in next frame
            if (info.ActionType == TouchAction.Up.ToTouchActions())
            {
                inactiveTouchPoints.Add(info.TouchDeviceId);
                ActiveTouchPoints.Remove(info.TouchDeviceId);
            }

            return tPoint;
        }
        public void DistanceChangedCalculator_Calculate_Test_With_Low_Counts()
        {
            //Setup preamble for 2 touchpoints to be used in calculate

            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(2, 6);

            ValidSetOfTouchPoints test = new ValidSetOfTouchPoints();
            test.Add(new TouchPoint2(ti1, new UIElement()));
            test.Add(new TouchPoint2(ti2, new UIElement()));

            //Call appropriate methods
            DistanceChangedCalculator target = new DistanceChangedCalculator();

            DistanceChanged result = target.Calculate(test) as DistanceChanged;

            Assert.IsTrue(result.Delta == 0);
        }
Example #21
0
        private void anotoServer_OnStroke(object sender, AnotoPenEvent args)
        {
            // Initialize some variables onto the conoto converter will write to.
            string function; // function string of the area hit by the pen (as configured in configuration)
            long functionid; // function id of the area hit by the pen (as configured in configuration)
            double x, y; // converted x/y coordinates
            TouchInfo info = new TouchInfo();
            TouchAction2 actionType = TouchAction2.Move;

            // handle the type of event we got and call other handler functions
            switch (args.Type)
            {
                case AnotoPenEventType.StrokeStart: // = pen down
                    actionType = TouchAction2.Down;
                    break;
                case AnotoPenEventType.StrokeDrag: // = pen move/drag (there is no hover due the AnotoPen does not support it)
                    actionType = TouchAction2.Move;
                    break;
                case AnotoPenEventType.StrokeEnd: // = pen up
                    actionType = TouchAction2.Up;
                    break;
            }

            // convert AnotoPen coordiantes to the configured ones (in this case, screen coordinates)
            conoto.Convert((ulong)args.PageId, args.X, args.Y,
                           out function, out functionid, out x, out y);

            info.ActionType = actionType;
            info.Position = new Point(x, y);
            info.TouchDeviceId = (int)args.PenId;

            RemoveInactiveTouchPoints();
            UpdateActiveTouchPoint(info);
            foreach (var point in ActiveTouchPoints.Values)
            {
                if (actionType == TouchAction2.Down)
                {
                    point.UpdateSource();
                }
            }

            //Call the delegates
            if (SingleTouchChanged != null)
            {
                foreach (var point in ActiveTouchPoints.Values)
                {
                    SingleTouchChanged(this, new SingleTouchEventArgs(point));
                }
            }

            if (MultiTouchChanged != null)
            {
                MultiTouchChanged(this, new MultiTouchEventArgs(ActiveTouchPoints.Values.ToList<TouchPoint2>()));
            }

            if (FrameChanged != null)
            {
                FrameInfo finfo = new FrameInfo();
                List<TouchPoint2> points = ActiveTouchPoints.Values.ToList<TouchPoint2>();
                List<TouchInfo> infos = new List<TouchInfo>();
                foreach (var point in points)
                {
                    TouchInfo inf = new TouchInfo();
                    inf.ActionType = point.Action.ToTouchActions();
                    inf.Position = point.Position;
                    inf.TouchDeviceId = point.TouchDeviceId;
                    infos.Add(inf);
                }

                finfo.Touches = infos;
                finfo.TimeStamp = args.Timestamp;
                finfo.WaitTime = (int)args.Timestamp - (int)lastTimeStamp;
                FrameChanged(this, finfo);
            }
            lastTimeStamp = (int)args.Timestamp;
        }
Example #22
0
 public void Update(TouchInfo info)
 {
     ActionType = info.ActionType;
     Position = info.Position;
     if (info.Snapshot != null)
         Snapshot = info.Snapshot;
     //Snapshot
        // Snapshot.AddRange(info.Snapshot);
 }
Example #23
0
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            TouchInfo info = new TouchInfo() { ActionType = TouchAction2.Down, GroupId = 0, Position = new Point(1, 1), TouchDeviceId = 14 };
            info.Tags.Add("size", "20");

            FrameInfo fi = new FrameInfo() { TimeStamp = 123121, WaitTime = 10 };
            fi.Touches.Add(info);

            List<FrameInfo> frames = new List<FrameInfo>();
            frames.Add(fi);

            string content = TouchToolkit.Framework.Utility.SerializationHelper.Serialize(frames);

            // Initialize Gesture Framework
            TouchInputProvider inputProvider = new SilverlightTouchInputProvider();
            GestureFramework.Initialize(inputProvider, LayoutRoot, Assembly.GetExecutingAssembly());
            //GestureFramework.ShowDebugPanel(GestureFramework.DebugPanels.GestureRecorder);

            // Add touch feedbacks
            GestureFramework.AddTouchFeedback(typeof(BubblesPath));

            // Add gesture feedbacks
            GestureFramework.AddGesturFeedback("lasso", typeof(HighlightSelectedArea));

            // Load UI
            LoadImages(false);
        }
Example #24
0
        private void CallDelegates(TuioTime ftime)
        {
            if (SingleTouchChanged != null)
            {
                foreach (var point in ActiveTouchPoints.Values)
                {
                    SingleTouchChanged(this, new SingleTouchEventArgs(point));
                }
            }

            if (MultiTouchChanged != null)
            {
                List<TouchPoint2> list = ActiveTouchPoints.Values.ToList<TouchPoint2>();
                MultiTouchChanged(this, new MultiTouchEventArgs(list));
            }

            if (FrameChanged != null)
            {
                List<TouchPoint2> points = ActiveTouchPoints.Values.ToList<TouchPoint2>();
                List<TouchInfo> infos = new List<TouchInfo>();
                foreach (var point in points)
                {
                    TouchInfo info = new TouchInfo();
                    info.ActionType = point.Action.ToTouchActions();
                    info.Position = point.Position;
                    info.TouchDeviceId = point.TouchDeviceId;
                    infos.Add(info);
                }
                FrameInfo finfo = new FrameInfo();

                finfo.Touches = infos;
                finfo.TimeStamp = ftime.getMicroseconds();
                finfo.WaitTime = (int)ftime.getMicroseconds() - (int)lastTimeStamp;
                FrameChanged(this, finfo);
            }
            lastTimeStamp = (int)ftime.getMicroseconds();
        }
        public static List<TouchInfo> ToTouchInfo(this TouchPointCollection self)
        {
            List<TouchInfo> list = new List<TouchInfo>(self.Count);
            foreach (var item in self)
            {
                var info = new TouchInfo()
                {
                    ActionType = item.Action.ToTouchActions(),
                    Position = item.Position,
                    TouchDeviceId = item.TouchDevice.Id
                };

                info.Tags.Add("Size", item.Size.ToString());

                list.Add(info);
            }

            return list;
        }
Example #26
0
        public TouchPoint2 GetRange(int index1, int index2)
        {
            if (index1 == index2)
                return this;

            TouchInfo info = new TouchInfo();
            info.ActionType = Action.ToTouchAction();
            info.Position = Position;
            info.TouchDeviceId = TouchDeviceId;
            info.Bounds = Bounds;
            info.IsFinger = isFinger;
            info.Tag = Tag;
            info.Snapshot = Snapshot;

            TouchPoint2 output = new TouchPoint2(info, Source);
            StylusPointCollection spc = new StylusPointCollection();
            for(int i = index1; i < index2; i++)
            {
                spc.Add(Stroke.StylusPoints[i]);
            }
            output.Stroke.StylusPoints = spc;
            return output;
        }
        public void SlopeChangedCalculator_Calculate_With_History_Test()
        {
            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);
            TouchPoint2 tp1 = new TouchPoint2(ti1, new UIElement());
            tp1.Stroke.StylusPoints.Add(new System.Windows.Input.StylusPoint());
            tp1.Stroke.StylusPoints.Add(new System.Windows.Input.StylusPoint());

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(3, 6);
            TouchPoint2 tp2 = new TouchPoint2(ti1, new UIElement());
            tp2.Stroke.StylusPoints.Add(new System.Windows.Input.StylusPoint());
            tp2.Stroke.StylusPoints.Add(new System.Windows.Input.StylusPoint());

            ValidSetOfTouchPoints vp = new ValidSetOfTouchPoints();
            vp.Add(tp1);
            vp.Add(tp2);

            SlopeChangedCalculator sc = new SlopeChangedCalculator();

            SlopeChanged actualP = sc.Calculate(vp) as SlopeChanged;

            double expectedSlope = 0;
            double expectedDelta = 0;

            Assert.IsTrue(expectedDelta == actualP.Delta);
            Assert.AreEqual(expectedSlope, Math.Round(actualP.NewSlope, 2));
        }
Example #28
0
 public void Update(TouchInfo info)
 {
     UpdateTouchStroke(info);
     UpdateTouchInfo(info);
 }
Example #29
0
        private void UpdateTouchInfo(TouchInfo info)
        {
            Action = info.ActionType.ToTouchAction();
            Position = info.Position;
            EndTime = DateTime.Now;
            isFinger = info.IsFinger;
            Bounds = info.Bounds;
            Tag = info.Tag;
              //  if (Snapshot == null)
            //        Snapshot = new List<System.Drawing.Bitmap>();

            //Snapshot.AddRange(info.Snapshot);
            if (info.Snapshot != null)
                Snapshot = info.Snapshot;
        }
Example #30
0
        public static List<TouchPoint2> FindLines(TouchPoint2 points)
        {
            double length = TrigonometricCalculationHelper.CalculatePathLength(points);
            List<TouchPoint2> newPoints = new List<TouchPoint2>();

            if (length < 10)
            {
                newPoints.Add(points);
                return newPoints;
            }

            TouchPoint2 temp;
            StylusPointCollection simplerPoints = new StylusPointCollection();
            simplerPoints = TrigonometricCalculationHelper.removeRedundancy(points.Stroke.StylusPoints);

            TouchInfo info = new TouchInfo();
            info.ActionType = points.Action.ToTouchAction();
            info.TouchDeviceId = points.TouchDeviceId;
            info.Bounds = points.Bounds;
            info.IsFinger = points.isFinger;
            TouchPoint2 output = new TouchPoint2(info, points.Source, simplerPoints);
            string lastDirection = "";
            int idxIni = 0;
            int i;

            int diffCount = 0;
            int increment=1;
                                                                        //default = 0.1
            int minimumLength = (int)(simplerPoints.Count * .05);
            switch (NoiseReduction)
            {
                case NoiseReductionType.Low: increment = 3;
                    break;
                case NoiseReductionType.Medium: increment = 5;
                    break;
                case NoiseReductionType.High: increment = 10;
                    break;

            }
            string sPreviousDirection = "";
            for (i = increment; i < simplerPoints.Count; i = i + increment)
            {
                StylusPoint p1 = simplerPoints[i - 1];
                StylusPoint p2 = simplerPoints[i];
                double slope = TrigonometricCalculationHelper.GetSlopeBetweenPoints(p1, p2);
                string sDirection = TouchPointExtensions.SlopeToDirection(slope);

                if (sPreviousDirection == "")
                    sPreviousDirection = sDirection;

                if (sPreviousDirection != sDirection)
                     diffCount++;
                else  // This makes that it has to be different diffCount times in a row
                    diffCount = 0;

                if ((diffCount >= minimumLength))
                {
                     p1 = simplerPoints[idxIni];
                     p2 = simplerPoints[i];
                     slope = TrigonometricCalculationHelper.GetSlopeBetweenPoints(p1, p2);
                     string sCurrentDirection = TouchPointExtensions.SlopeToDirection(slope);

                    temp = output.GetRange(idxIni, i);
                    if (lastDirection == sCurrentDirection)
                    {
                        newPoints[newPoints.Count - 1].Stroke.StylusPoints.Add(temp.Stroke.StylusPoints);
                    }
                    else {
                      if (lastDirection == "")
                          lastDirection = sCurrentDirection;
                      temp.Action = TouchAction.Move;
                      newPoints.Add(temp);
                    }
                    diffCount = 0;
                    lastDirection = sCurrentDirection;
                    sPreviousDirection = sDirection;
                    idxIni = i;

                }
            }
            // If nothing was added then, there is only one step which is the whole gesture
            if (newPoints.Count == 0)
                newPoints.Add(output);
            // If there are several points after the last recognized step add the last remaining points as a new step
            else if (i - idxIni > minimumLength)
            {
                temp = output.GetRange(idxIni, i - increment);
                if (lastDirection == sPreviousDirection)
                {
                    newPoints[newPoints.Count - 1].Stroke.StylusPoints.Add(temp.Stroke.StylusPoints);
                }
                else
                {
                    temp.Action = TouchAction.Move;
                    newPoints.Add(temp);
                }
            }
            newPoints[newPoints.Count - 1].Action = output.Action;
            return newPoints;
        }