Bläddra i källkod

-rewrote TouchEventVisualizer, just the last 2 events are displayed

Anton Rohr 11 år sedan
förälder
incheckning
6e37bf5897
1 ändrade filer med 32 tillägg och 33 borttagningar
  1. 32 33
      bbiwarg/Graphics/TouchEventVisualizer.cs

+ 32 - 33
bbiwarg/Graphics/TouchEventVisualizer.cs

@@ -13,57 +13,40 @@ namespace bbiwarg.Graphics
     {
         public OutputImage OutputImage { get; private set; }
 
-        private List<Kalman2DPositionFilter> kalmanFilters;
-        private List<List<Vector2D>> touchPositions;
         private int lastUpdated = -1;
         private int width, height;
 
+        private List<Vector2D> lastTouchPositions;
+        private List<Vector2D> currentTouchPositions;
+        private Kalman2DPositionFilter kalmanFilter;
+
         public TouchEventVisualizer(int width, int height)
         {
             this.width = width;
             this.height = height;
 
             OutputImage = new Graphics.OutputImage(width, height);
-            touchPositions = new List<List<Vector2D>>();
-            kalmanFilters = new List<Kalman2DPositionFilter>();
         }
 
         public void addPalmTouchEvent(PalmTouchEvent e, int currentFrame)
         {
-            List<Vector2D> currentList;
-            Kalman2DPositionFilter currentFilter;
-
-            bool addList = false;
-            if (lastUpdated == -1 || (currentFrame - lastUpdated) > 5)
-            {
-                currentList = new List<Vector2D>();
-                currentFilter = new Kalman2DPositionFilter(e.RelativePalmPosition);
-                addList = true;
-            }
-            else
-            {
-                currentList = touchPositions.Last<List<Vector2D>>();
-                currentFilter = kalmanFilters.Last<Kalman2DPositionFilter>();
-            }
 
             Vector2D pos;
-            if (currentFilter == null)
+            if (lastUpdated == -1 || (currentFrame - lastUpdated) > 5 || currentTouchPositions == null || kalmanFilter == null)
             {
-                currentFilter = new Kalman2DPositionFilter(e.RelativePalmPosition);
+                lastTouchPositions = currentTouchPositions;
+                currentTouchPositions = new List<Vector2D>();
+                kalmanFilter = new Kalman2DPositionFilter(e.RelativePalmPosition);
                 pos = e.RelativePalmPosition;
             }
             else
             {
-                pos = currentFilter.getCorrectedPosition(e.RelativePalmPosition);
+                pos = kalmanFilter.getCorrectedPosition(e.RelativePalmPosition);
             }
 
+
             int size = Math.Min(width, height);
-            currentList.Add(new Vector2D((int)(pos.X * size), (int)(size - pos.Y * size)));
-            if (addList)
-            {
-                touchPositions.Add(currentList);
-                kalmanFilters.Add(currentFilter);
-            }
+            currentTouchPositions.Add(new Vector2D((int)(pos.X * size), (int)(size - pos.Y * size)));
 
             lastUpdated = currentFrame;
         }
@@ -86,11 +69,26 @@ namespace bbiwarg.Graphics
             for (int i = 1; i < numColumns; i++)
             {
                 int tmp = size / numColumns * i;
-                OutputImage.drawLineSegment(new LineSegment2D(new Vector2D(tmp, 0), new Vector2D(tmp, size-2)), Constants.PalmGridColor);
+                OutputImage.drawLineSegment(new LineSegment2D(new Vector2D(tmp, 0), new Vector2D(tmp, size - 2)), Constants.PalmGridColor);
             }
 
-
-            foreach (List<Vector2D> positions in touchPositions)
+            if (currentTouchPositions != null)
+            {
+                for (int i = 1; i < currentTouchPositions.Count; ++i)
+                {
+                    OutputImage.drawLineSegment(new LineSegment2D(currentTouchPositions[i - 1], currentTouchPositions[i]), Constants.TouchEventVisualizerLineColor);
+                }
+                OutputImage.fillCircle(currentTouchPositions.Last<Vector2D>().IntX, currentTouchPositions.Last<Vector2D>().IntY, 3, Constants.TouchEventVisualizerPointColor);
+            }
+            if (lastTouchPositions != null)
+            {
+                for (int i = 1; i < lastTouchPositions.Count; ++i)
+                {
+                    OutputImage.drawLineSegment(new LineSegment2D(lastTouchPositions[i - 1], lastTouchPositions[i]), Constants.TouchEventVisualizerLineColor);
+                }
+                OutputImage.fillCircle(lastTouchPositions.Last<Vector2D>().IntX, lastTouchPositions.Last<Vector2D>().IntY, 3, Constants.TouchEventVisualizerPointColor);
+            }
+            /*foreach (List<Vector2D> positions in touchPositions)
             {
                 for (int i = 1; i < positions.Count; ++i)
                 {
@@ -99,12 +97,13 @@ namespace bbiwarg.Graphics
 
                 if (touchPositions.Count != 0)
                     OutputImage.fillCircle(positions.Last<Vector2D>().IntX, positions.Last<Vector2D>().IntY, 3, Constants.TouchEventVisualizerPointColor);
-            }
+            }*/
         }
 
         public void Reset()
         {
-            touchPositions.Clear();
+            lastTouchPositions = null;
+            currentTouchPositions = null;
             OutputImage = new OutputImage(width, height);
             lastUpdated = -1;
         }