src/FingersDance.GestureControl/GestureVector.cs
changeset 176 0896f36b9d57
parent 174 45c9e55fcf23
child 177 89cbcb52b674
--- a/src/FingersDance.GestureControl/GestureVector.cs	Mon Oct 26 16:03:34 2009 +0100
+++ b/src/FingersDance.GestureControl/GestureVector.cs	Tue Oct 27 01:59:56 2009 +0100
@@ -1,8 +1,4 @@
 using System;
-using System.IO;
-using System.Xml;
-using System.Reflection;
-using System.Xml.Linq;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -22,11 +18,8 @@
         /// Allow some variation without log a direction
         /// </summary>
         public int Precision { get; set; }
-        /// <summary>
-        /// List of pattern readed in the patterns.xml
-        /// </summary>
-        public List<SurfaceGesturePattern> Pattern = new List<SurfaceGesturePattern>();
         #endregion
+
         #region Constructor
         /// <summary>
         /// load know patterns and generate the vector list from a list of points with a default 20 precision factor
@@ -35,7 +28,6 @@
         public SurfaceGesture(List<SurfaceGesturePoint> list)
         {
             this.Precision = 20;
-            CommonPattern();
             this.Generate(list);
         }
         /// <summary>
@@ -46,20 +38,10 @@
         public SurfaceGesture(List<SurfaceGesturePoint> list, int precision)
         {
             this.Precision = precision;
-            CommonPattern();
             this.Generate(list);
         }
-        //public SurfaceGesture(System.Windows.Ink.Stroke stroke, int precision)
-        //{
-        //    StylusPointCollection tmp = stroke.GetBezierStylusPoints();
-        //    List<SurfaceGesturePoint> pointList = new List<SurfaceGesturePoint>();
-        //    foreach (StylusPoint p in tmp)
-        //        pointList.Add(new SurfaceGesturePoint { X = p.X, Y = p.Y });
-        //    this.Precision = precision;
-        //    this.Generate(pointList);
-        //    CommonPattern();
-        //}
         #endregion
+
         #region GenerateVector
         /// <summary>
         /// Generate list of vector from courbe mouvements, filter with the pas value
@@ -69,7 +51,7 @@
         /// <returns></returns>
         private bool GenerateCourb(List<SurfaceGesturePoint> list, int pas)
         {
-            List<SurfaceGesturePattern> tmp = new List<SurfaceGesturePattern>();
+            //List<SurfaceGesturePattern> tmp = new List<SurfaceGesturePattern>();
             int sep = list.Count / pas;
             double count = 0; ;
             SurfaceGesturePoint past = new SurfaceGesturePoint() { X = 0, Y = 0 };
@@ -109,9 +91,9 @@
                 }
             }
             Console.Write(this);
-            if (this.GetPattern() != "None")
+            /*if (this.GetPattern() != "None")
                 return true;
-            else
+            else*/
                 return false;
         }
         /// <summary>
@@ -132,8 +114,8 @@
         {
             if (this.Count == 0)
             {
-                this.Add(new SurfaceGestureVector{Direction = type, Lenght=42});
-                return ;
+                this.Add(new SurfaceGestureVector { Direction = type, Lenght = 42 });
+                return;
             }
             if (this[this.Count - 1].Direction != type)
                 this.Add(new SurfaceGestureVector { Direction = type, Lenght = 42 });
@@ -145,7 +127,7 @@
         private void Generate(List<SurfaceGesturePoint> list)
         {
             if (list.Count < 2)
-                return ;
+                return;
             SurfaceGestureVectorDirection lastDirection = SurfaceGestureVectorDirection.NONE;
             int lastPoint = 0;
             SurfaceGesturePoint LastChange = list[0];
@@ -218,6 +200,7 @@
             return SurfaceGestureVectorDirection.NONE;
         }
         #endregion
+
         #region Override
         public override String ToString()
         {
@@ -231,150 +214,5 @@
             return ret;
         }
         #endregion
-        #region Pattern
-        /// <summary>
-        /// return a String with the recognized pattern, "None" if no pattern
-        /// </summary>
-        /// <returns></returns>
-        public String GetPattern()
-        {
-            foreach (SurfaceGesturePattern p in this.Pattern)
-            {
-                if (p.Count == this.Count)
-                {
-                    int i;
-                    for (i = 0; i < p.Count; i++)
-                    {
-                        if (this[i].Direction != p[i].Direction)
-                            break ;
-                    }
-                    if (i == p.Count)
-                        return p.Name;
-                }
-            }
-            return "None";
-        }
-        /// <summary>
-        /// Load know patterns from the Resources/Patterns.xml file
-        /// </summary>
-        private void CommonPattern()
-        {
-            try
-            {
-                #region Load Patterns
-                System.IO.Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream("GestureControl.Resources.Patterns.xml");
-                XmlDocument xml = new XmlDocument();
-                xml.Load(file);
-                XmlElement root = xml.DocumentElement;
-                XmlNodeList nodes = root.SelectNodes("//Pattern");
-                SurfaceGesturePattern p;
-                int i = 0;
-                foreach (XmlNode node in nodes)
-                {
-                    string name = node["Name"].InnerText;
-                    XmlNodeList subNodes = node.SelectNodes("//Directions");
-                    if (subNodes == null)
-                        continue;
-                    p = new SurfaceGesturePattern() { Name = name };
-                    foreach (XmlNode subNode in subNodes[i++])
-                    {
-                        XmlNodeList dl = subNode.ChildNodes;
-                        foreach (XmlNode d in dl)
-                        {
-                            switch (d.InnerText)
-                            {
-                                case "Up":
-                                    p.Add(new SurfaceGestureVector() { Direction = SurfaceGestureVectorDirection.UP });
-                                    break;
-                                case "Down":
-                                    p.Add(new SurfaceGestureVector() { Direction = SurfaceGestureVectorDirection.DOWN });
-                                    break;
-                                case "Left":
-                                    p.Add(new SurfaceGestureVector() { Direction = SurfaceGestureVectorDirection.LEFT });
-                                    break;
-                                case "Right":
-                                    p.Add(new SurfaceGestureVector() { Direction = SurfaceGestureVectorDirection.RIGHT });
-                                    break;
-                                case "DownRight":
-                                    p.Add(new SurfaceGestureVector() { Direction = SurfaceGestureVectorDirection.DOWNRIGHT });
-                                    break;
-                                case "DownLeft":
-                                    p.Add(new SurfaceGestureVector() { Direction = SurfaceGestureVectorDirection.DOWNLEFT });
-                                    break;
-                                case "UpRight":
-                                    p.Add(new SurfaceGestureVector() { Direction = SurfaceGestureVectorDirection.UPRIGHT });
-                                    break;
-                                case "UpLeft":
-                                    p.Add(new SurfaceGestureVector() { Direction = SurfaceGestureVectorDirection.UPLEFT });
-                                    break;
-                                default:
-                                    break;
-                            }
-                        }
-                    }
-                    this.Pattern.Add(p);
-                }
-                #endregion
-            }
-            catch
-            {
-                throw new Exception("Error loading Patterns.xml");
-            }
-        }
-        #endregion
     }
-    #region Tools
-    /// <summary>
-    /// Gesture event who return a object with a Gesture String value
-    /// </summary>
-    public class GestureRoutedEventArgs : RoutedEventArgs
-    {
-        public String Gesture { get; private set; }
-            
-        public GestureRoutedEventArgs() : base() { }
-        public GestureRoutedEventArgs(String gesture) : base() { this.Gesture = gesture; }
-        public GestureRoutedEventArgs(RoutedEvent routedEvent) : base(routedEvent) { }
-        public GestureRoutedEventArgs(RoutedEvent routedEvent, String gesture) : base(routedEvent) { this.Gesture = gesture; }
-        public GestureRoutedEventArgs(RoutedEvent routedEvent, Object source) : base(routedEvent, source) { }
-        public GestureRoutedEventArgs(RoutedEvent routedEvent, Object source, String gesture) : base(routedEvent, source) { this.Gesture = gesture; }
-    }
-
-    public class SurfaceGesturePattern : List<SurfaceGestureVector>
-    {
-        public String Name { get; set; }
-
-    }
-    /// <summary>
-    /// Possible Gesture Vector
-    /// </summary>
-    public enum SurfaceGestureVectorDirection
-    {
-        UP,
-        DOWN,
-        LEFT,
-        RIGHT,
-        UPLEFT,
-        UPRIGHT,
-        DOWNLEFT,
-        DOWNRIGHT,
-        NONE,
-    }
-    /// <summary>
-    /// Describe a point in the grid
-    /// </summary>
-    public class SurfaceGesturePoint
-    {
-        public double X { get; set; }
-        public double Y { get; set; }
-    }
-
-    /// <summary>
-    /// Describe a vector to help the recognize pass
-    /// </summary>
-    public class SurfaceGestureVector
-    {
-        public SurfaceGestureVectorDirection Direction { get; set; }
-        public Double Lenght { get; set; }
-    }
-    #endregion
 }