Browse Source

-added visibility of touch Events (Detected + Tracked)

Anton Rohr 10 years ago
parent
commit
7b1962ee35
2 changed files with 53 additions and 21 deletions
  1. 23 16
      bbiwarg/Graphics/OutputWindow.cs
  2. 30 5
      bbiwarg/Images/TouchImage.cs

+ 23 - 16
bbiwarg/Graphics/OutputWindow.cs

@@ -21,7 +21,8 @@ namespace bbiwarg.Graphics
         private long timeSpacePressed, timeLeftPressed, timeRightPressed;
         private Stopwatch watch;
 
-        public OutputWindow(VideoHandle videoHandle): base(3 * videoHandle.getWidth(), 2 * videoHandle.getHeight())
+        public OutputWindow(VideoHandle videoHandle)
+            : base(3 * videoHandle.getWidth(), 2 * videoHandle.getHeight())
         {
             this.videoHandle = videoHandle;
             watch = new Stopwatch();
@@ -68,7 +69,7 @@ namespace bbiwarg.Graphics
 
         protected override void OnRenderFrame(FrameEventArgs e)
         {
-            
+
             base.OnRenderFrame(e);
             GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
             Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
@@ -139,9 +140,9 @@ namespace bbiwarg.Graphics
                     Int16 blue = 0;
 
                     //depthTexture
-                    float relDepth = videoHandle.getRelativeDepth(x,y);
+                    float relDepth = videoHandle.getRelativeDepth(x, y);
                     red = green = blue = (Int16)((1.0f - videoHandle.getRelativeDepth(x, y)) * Int16.MaxValue);
-                    
+
                     // palm
                     switch (videoHandle.getPalmImageStateAt(x, y))
                     {
@@ -159,9 +160,11 @@ namespace bbiwarg.Graphics
                             blue = red = 0;
                             break;
                         case PalmImageState.palmGrid:
-                            green = blue = red = Int16.MaxValue;
+                            green = (Int16)(green / 2 + Int16.MaxValue / 2);
+                            blue = (Int16)(blue / 2 + Int16.MaxValue / 2);
+                            red = (Int16)(red / 2 + Int16.MaxValue / 2);
                             break;
-                            
+
 
                     }
 
@@ -184,13 +187,17 @@ namespace bbiwarg.Graphics
                             blue = (Int16)(blue / 2);
                             break;
                         case TouchImageState.touchDetected:
-                            red = blue = 0;
-                            green = Int16.MaxValue;
+                            red = (Int16)(red / 2);
+                            blue = (Int16)(blue / 2);
+                            green = (Int16)(green / 2 + Int16.MaxValue / 2);
                             break;
                         case TouchImageState.touchTracked:
-                            red = Int16.MaxValue;
-                            green = blue = 0;
+                            red = (Int16)(red / 2 + Int16.MaxValue / 2);
+                            green = (Int16)(green / 2);
+                            blue = (Int16)(blue / 2);
                             break;
+                        
+                        
                     }
 
                     depthTextureData[index] = red;
@@ -198,7 +205,7 @@ namespace bbiwarg.Graphics
                     depthTextureData[index + 2] = blue;
 
                     //edgeTexture
-                    FingerImageState fis = videoHandle.getFingerImageStateAt(x,y);
+                    FingerImageState fis = videoHandle.getFingerImageStateAt(x, y);
                     red = green = blue = 0;
                     if (videoHandle.isEdgeAt(x, y)) blue = Int16.MaxValue;
                     else if (fis == FingerImageState.fingerTracked) green = Int16.MaxValue;
@@ -218,7 +225,7 @@ namespace bbiwarg.Graphics
             GL.BindTexture(TextureTarget.Texture2D, depthTextureID);
             GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.getWidth(), videoHandle.getHeight(), 0, PixelFormat.Rgb, PixelType.Short, depthTextureData);
             float size = 0.5f;
-            float size_2 = (float) (size / 2.0f);
+            float size_2 = (float)(size / 2.0f);
             GL.Begin(PrimitiveType.Quads);
             GL.Color3(1.0, 1.0, 1.0);
             GL.TexCoord2(0.0, 0.0); GL.Vertex3(0, size_2, -0.5);
@@ -232,10 +239,10 @@ namespace bbiwarg.Graphics
             GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.getWidth(), videoHandle.getHeight(), 0, PixelFormat.Rgb, PixelType.Short, edgeTextureData);
             GL.Begin(PrimitiveType.Quads);
             GL.Color3(1.0, 1.0, 1.0);
-            GL.TexCoord2(0.0, 0.0); GL.Vertex3(0, -size/2.0, -0.5);
-            GL.TexCoord2(-1.0, 0.0); GL.Vertex3(-size, -size/2.0, -0.5);
-            GL.TexCoord2(-1.0, -1.0); GL.Vertex3(-size, size/2.0, -0.5);
-            GL.TexCoord2(0.0, -1.0); GL.Vertex3(0, size/2.0, -0.5);
+            GL.TexCoord2(0.0, 0.0); GL.Vertex3(0, -size / 2.0, -0.5);
+            GL.TexCoord2(-1.0, 0.0); GL.Vertex3(-size, -size / 2.0, -0.5);
+            GL.TexCoord2(-1.0, -1.0); GL.Vertex3(-size, size / 2.0, -0.5);
+            GL.TexCoord2(0.0, -1.0); GL.Vertex3(0, size / 2.0, -0.5);
             GL.End();
 
 

+ 30 - 5
bbiwarg/Images/TouchImage.cs

@@ -5,9 +5,13 @@ using System.Text;
 using System.Threading.Tasks;
 using Emgu.CV;
 using Emgu.CV.Structure;
+
+using bbiwarg.Utility;
+
 namespace bbiwarg.Images
 {
-    public enum TouchImageState {
+    public enum TouchImageState
+    {
         none = 0,
         touchArea = 1,
         touchAreaMatched = 2,
@@ -19,16 +23,37 @@ namespace bbiwarg.Images
     class TouchImage
     {
         private Image<Gray, byte> image;
+        private List<Vector2D> oldTouches;
 
-        public TouchImage(int width, int height) {
+        public TouchImage(int width, int height)
+        {
             image = new Image<Gray, byte>(width, height);
+            oldTouches = new List<Vector2D>();
         }
 
-        public void setTouchAt(int x, int y, TouchImageState tis) {
-            image.Data[y, x, 0] = (byte) tis;
+        public void setTouchAt(int x, int y, TouchImageState tis)
+        {
+            image.Data[y, x, 0] = (byte)tis;
+
+            int size = 5;
+            if (tis == TouchImageState.touchTracked || tis == TouchImageState.touchDetected)
+            {
+                for (int i = x - size; i < x + size; i++)
+                {
+                    for (int j = y - size; j < y + size; j++)
+                    {
+                        if (i >= 0 && j >= 0 && i <= image.Width && j <= image.Height && Math.Sqrt(((x - i) * (x - i)) + ((y - j) * (y - j))) <= size)
+                        {
+                            image.Data[j, i, 0] = (byte)tis;
+                        }
+                    }
+                }
+            }
         }
 
-        public TouchImageState getStateAt(int x, int y) {
+
+        public TouchImageState getStateAt(int x, int y)
+        {
             return (TouchImageState)image.Data[y, x, 0];
         }
     }