Kaynağa Gözat

Fixed output image resolution and prespective.

Daniel Kauth 11 yıl önce
ebeveyn
işleme
4250ac5226
1 değiştirilmiş dosya ile 44 ekleme ve 41 silme
  1. 44 41
      bbiwarg/Graphics/OutputWindow.cs

+ 44 - 41
bbiwarg/Graphics/OutputWindow.cs

@@ -11,6 +11,9 @@ using bbiwarg.Images;
 using bbiwarg.Detectors.Touch;
 
 using Emgu.CV;
+using Emgu.CV.Structure;
+
+using bbiwarg.Utility;
 
 namespace bbiwarg.Graphics
 {
@@ -19,19 +22,19 @@ namespace bbiwarg.Graphics
         private VideoHandle videoHandle;
         private uint depthTextureID;
         private uint edgeTextureID;
-        private uint kalmanDemoTextureID;
+        private uint touchEventTextureID;
         private bool paused = false;
         private long timeSpacePressed, timeLeftPressed, timeRightPressed;
         private Stopwatch watch;
-        private KalmanDemo kalmanDemo;
+        private TouchEventVisualizer touchEventVisualizer;
 
         public OutputWindow(VideoHandle videoHandle)
-            : base(4 * videoHandle.Width, 2 * videoHandle.Height)
+            : base(3 * videoHandle.Width, videoHandle.Height)
         {
             this.videoHandle = videoHandle;
             watch = new Stopwatch();
             watch.Start();
-            kalmanDemo = new KalmanDemo();
+            touchEventVisualizer = new TouchEventVisualizer();
         }
 
         protected override void OnLoad(EventArgs e)
@@ -62,9 +65,9 @@ namespace bbiwarg.Graphics
             GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
             GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
 
-            //kalman demo texture
-            GL.GenTextures(1, out kalmanDemoTextureID);
-            GL.BindTexture(TextureTarget.Texture2D, kalmanDemoTextureID);
+            //touch event texture
+            GL.GenTextures(1, out touchEventTextureID);
+            GL.BindTexture(TextureTarget.Texture2D, touchEventTextureID);
             GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
             GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
 
@@ -73,15 +76,28 @@ namespace bbiwarg.Graphics
         protected override void OnResize(EventArgs e)
         {
             base.OnResize(e);
-            GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
-            Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 3, Width / (float)Height, 0.01f, 3.0f);
+            
+            const int numImages = 3;
+
+            int screenWidth = ClientRectangle.Width;
+            int screenHeight = ClientRectangle.Height;
+
+            int imageWidth = videoHandle.Width;
+            int imageHeight = videoHandle.Height;
+            float imageAspectRatio = (float)imageWidth / (float)imageHeight;
+
+            int heightForWidth = (int) ((float) screenWidth / ((float) numImages * imageAspectRatio));
+
+            GL.Viewport(0, (screenHeight - heightForWidth) / 2, screenWidth, heightForWidth);
+
+            // top left at (0,0) every image from (i, j) to (i + 1, j + 1)
+            Matrix4 projection = Matrix4.CreateOrthographicOffCenter(0, 3, 1, 0, 0.001f, 10f);
             GL.MatrixMode(MatrixMode.Projection);
             GL.LoadMatrix(ref projection);
         }
 
         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);
@@ -140,21 +156,15 @@ namespace bbiwarg.Graphics
 
             if (changedFrame || !videoHandle.sourceIsMovie())
             {
-                foreach (PalmTouchEvent ev in videoHandle.getTouchEvents())
+                foreach (PalmTouchEvent ev in videoHandle.getPalmTouchEvents())
                 {
-                    Console.WriteLine("touch at " + ev.Position + " -> " + ev.RelativePalmPosition);
+                    //Console.WriteLine("touch at " + ev.Position + " -> " + ev.RelativePalmPosition);
                     //touchVisualizer.addTouchEvent(ev);
                 }
             }
 
-            // kalman demo
-            int mouseX = Mouse.X - (2 * Width) / 3 - 30;
-            int mouseY = Mouse.Y - 85;
-            if (mouseX >= 0 && mouseX <= videoHandle.Width && mouseY >= 0 && mouseY <= Height)
-                kalmanDemo.addPoint(new Point(mouseX, mouseY));
-            // reset with right click
-            if (OpenTK.Input.Mouse.GetState().IsButtonDown(OpenTK.Input.MouseButton.Right))
-                kalmanDemo.reset();
+            if (videoHandle.sourceIsMovie())
+                Title = "BBIWARG - Output (Frame " + videoHandle.getCurrentMovieFrame() + ")";
 
             //draw textures
             Int16[] depthTextureData = new Int16[3 * videoHandle.Width * videoHandle.Height];
@@ -194,8 +204,6 @@ namespace bbiwarg.Graphics
                             blue = (Int16)(blue / 2 + Int16.MaxValue / 2);
                             red = (Int16)(red / 2 + Int16.MaxValue / 2);
                             break;
-
-
                     }
 
                     // touch
@@ -249,20 +257,15 @@ namespace bbiwarg.Graphics
                 }
             }
 
-            float size = 0.5f;
-            float size_2 = size / 2.0f;
-            float size_1_5 = 1.5f * size;
-            float gap = 0.0f;
-
             GL.Enable(EnableCap.Texture2D);
             GL.BindTexture(TextureTarget.Texture2D, edgeTextureID);
             GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.Width, videoHandle.Height, 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(-size_1_5 - gap,  size_2, -0.5);
-            GL.TexCoord2(1.0, 0.0); GL.Vertex3(-size_2   - gap,  size_2, -0.5);
-            GL.TexCoord2(1.0, 1.0); GL.Vertex3(-size_2   - gap, -size_2, -0.5);
-            GL.TexCoord2(0.0, 1.0); GL.Vertex3(-size_1_5 - gap, -size_2, -0.5);
+            GL.TexCoord2(0, 0); GL.Vertex3(0, 0, -1);
+            GL.TexCoord2(1, 0); GL.Vertex3(1, 0, -1);
+            GL.TexCoord2(1, 1); GL.Vertex3(1, 1, -1);
+            GL.TexCoord2(0, 1); GL.Vertex3(0, 1, -1);
             GL.End();
 
             GL.Enable(EnableCap.Texture2D);
@@ -270,22 +273,22 @@ namespace bbiwarg.Graphics
             GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.Width, videoHandle.Height, 0, PixelFormat.Rgb, PixelType.Short, depthTextureData);
             GL.Begin(PrimitiveType.Quads);
             GL.Color3(1.0, 1.0, 1.0);
-            GL.TexCoord2(0.0, 0.0); GL.Vertex3(-size_2,  size_2, -0.5);
-            GL.TexCoord2(1.0, 0.0); GL.Vertex3( size_2,  size_2, -0.5);
-            GL.TexCoord2(1.0, 1.0); GL.Vertex3( size_2, -size_2, -0.5);
-            GL.TexCoord2(0.0, 1.0); GL.Vertex3(-size_2, -size_2, -0.5);
+            GL.TexCoord2(0, 0); GL.Vertex3(1, 0, -1);
+            GL.TexCoord2(1, 0); GL.Vertex3(2, 0, -1);
+            GL.TexCoord2(1, 1); GL.Vertex3(2, 1, -1);
+            GL.TexCoord2(0, 1); GL.Vertex3(1, 1, -1);
             GL.End();
 
             GL.Enable(EnableCap.Texture2D);
-            GL.BindTexture(TextureTarget.Texture2D, kalmanDemoTextureID);
+            GL.BindTexture(TextureTarget.Texture2D, touchEventTextureID);
             GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.Width, videoHandle.Height, 0, PixelFormat.Rgb, PixelType.Short, 
-                kalmanDemo.getTextureData(videoHandle.Width, videoHandle.Height));
+                touchEventVisualizer.getTextureData(videoHandle.Width, videoHandle.Height));
             GL.Begin(PrimitiveType.Quads);
             GL.Color3(1.0, 1.0, 1.0);
-            GL.TexCoord2(0.0, 0.0); GL.Vertex3(size_2   + gap,  size_2, -0.5);
-            GL.TexCoord2(1.0, 0.0); GL.Vertex3(size_1_5 + gap,  size_2, -0.5);
-            GL.TexCoord2(1.0, 1.0); GL.Vertex3(size_1_5 + gap, -size_2, -0.5);
-            GL.TexCoord2(0.0, 1.0); GL.Vertex3(size_2   + gap, -size_2, -0.5);
+            GL.TexCoord2(0, 0); GL.Vertex3(2, 0, -1);
+            GL.TexCoord2(1, 0); GL.Vertex3(3, 0, -1);
+            GL.TexCoord2(1, 1); GL.Vertex3(3, 1, -1);
+            GL.TexCoord2(0, 1); GL.Vertex3(2, 1, -1);
             GL.End();
 
             SwapBuffers();