Ver Fonte

-added GlassesWindow
-fixed crash (touchEventVisualizer)

Alexander Hendrich há 10 anos atrás
pai
commit
e3988bca17

+ 21 - 3
bbiwarg/BBWIWARG.cs

@@ -6,6 +6,7 @@ using System.Linq;
 using System.Text;
 using System.Net;
 using bbiwarg.Output.DebugOutput;
+using bbiwarg.Output.GlassesOutput;
 using bbiwarg.Input.InputProviding;
 using bbiwarg.Input.InputHandling;
 using bbiwarg.TUIO;
@@ -18,8 +19,10 @@ namespace bbiwarg
         InputHandler inputHandler;
         TuioCommunicator tuioCommunicator;
         DebugWindow debugWindow;
+        GlassesWindow glassesWindow;
 
         Thread debugOutputThread;
+        Thread glassesOutputThread;
 
         static void Main(string[] args)
         {
@@ -48,11 +51,17 @@ namespace bbiwarg
             }
 
             // debug output
-            if (Parameters.DebugOutputEnabled)
+            if (Parameters.DebugWindowEnabled)
             {
                 debugOutputThread = new Thread(new ThreadStart(debugOutputThreadStart));
             }
 
+            // glasses output
+            if (Parameters.GlassesWindowEnabled)
+            {
+                glassesOutputThread = new Thread(new ThreadStart(glassesOutputThreadStart));
+            }
+
         }
 
         public void run()
@@ -71,7 +80,13 @@ namespace bbiwarg
         private void debugOutputThreadStart()
         {
             debugWindow = new DebugWindow(inputProvider, inputHandler);
-            debugWindow.Run(Parameters.DebugOutputUpdateRate, Parameters.DebugOutputRenderRate);
+            debugWindow.Run(Parameters.DebugWindowUpdateRate, Parameters.DebugWindowRenderRate);
+        }
+
+        private void glassesOutputThreadStart()
+        {
+            glassesWindow = new GlassesWindow(inputProvider, inputHandler);
+            glassesWindow.Run(Parameters.GlassesWindowUpdateRate, Parameters.GlassesWindowRenderRate);
         }
 
         private void handleDeviceStartedEvent(object sender, EventArgs e)
@@ -81,8 +96,11 @@ namespace bbiwarg
 
         private void startOutputThreads()
         {
-            if (Parameters.DebugOutputEnabled)
+            if (Parameters.DebugWindowEnabled)
                 debugOutputThread.Start();
+
+            if (Parameters.GlassesWindowEnabled)
+                glassesOutputThread.Start();
         }
 
         private static void handleArgs(String[] args)

+ 11 - 15
bbiwarg/Output/DebugOutput/DebugWindow.cs

@@ -32,8 +32,8 @@ namespace bbiwarg.Output.DebugOutput
         private DebugImages debugImages;
 
         public DebugWindow(InputProvider inputProvider, InputHandler inputHandler)
-            : base((int)(Parameters.DebugOutputScaleFactor * Math.Max(1, Math.Min(Parameters.DebugOutputNumImagesPerRow, Parameters.DebugOutputNumImages)) * Parameters.ImageWidth),
-                   (int)(Parameters.DebugOutputScaleFactor * (1 + (Parameters.DebugOutputNumImages - 1) / Parameters.DebugOutputNumImagesPerRow) * Parameters.ImageHeight))
+            : base((int)(Parameters.DebugWindowScaleFactor * Math.Max(1, Math.Min(Parameters.DebugWindowNumImagesPerRow, Parameters.DebugWindowNumImages)) * Parameters.ImageWidth),
+                   (int)(Parameters.DebugWindowScaleFactor * (1 + (Parameters.DebugWindowNumImages - 1) / Parameters.DebugWindowNumImagesPerRow) * Parameters.ImageHeight))
         {
             this.inputProvider = inputProvider;
             this.inputHandler = inputHandler;
@@ -46,16 +46,9 @@ namespace bbiwarg.Output.DebugOutput
         protected override void OnLoad(EventArgs e)
         {
             base.OnLoad(e);
-            Title = Parameters.DebugOutputTitle;
+            Title = Parameters.DebugWindowTitle;
             GL.ClearColor(Color.Black);
 
-            // transparency
-            GL.Enable(EnableCap.Blend);
-            GL.BlendEquation(BlendEquationMode.Max);
-
-            // Depth Test 
-            GL.Enable(EnableCap.DepthTest);
-
             // Texture
             GL.Enable(EnableCap.Texture2D);
             GL.GenTextures(1, out textureID);
@@ -83,8 +76,8 @@ namespace bbiwarg.Output.DebugOutput
             int screenWidth = ClientRectangle.Width;
             int screenHeight = ClientRectangle.Height;
 
-            int numRows = 1 + (Parameters.DebugOutputNumImages - 1) / Parameters.DebugOutputNumImagesPerRow;
-            int numCols = Math.Min(Parameters.DebugOutputNumImages, Parameters.DebugOutputNumImagesPerRow);
+            int numRows = 1 + (Parameters.DebugWindowNumImages - 1) / Parameters.DebugWindowNumImagesPerRow;
+            int numCols = Math.Min(Parameters.DebugWindowNumImages, Parameters.DebugWindowNumImagesPerRow);
             int heightForWidth = (int)((float)screenWidth / ((float)numCols * Parameters.ImageAspectRatio) * (float)numRows);
 
             GL.Viewport(0, (screenHeight - heightForWidth) / 2, screenWidth, heightForWidth);
@@ -100,6 +93,9 @@ namespace bbiwarg.Output.DebugOutput
             Timer.start("DebugWindow.OnUpdateFrame");
             base.OnUpdateFrame(e);
 
+            if (!inputProvider.IsActive)
+                Exit();
+
             FrameData frameData = inputHandler.FrameData;
             if (frameData != null)
             {
@@ -128,7 +124,7 @@ namespace bbiwarg.Output.DebugOutput
             GL.MatrixMode(MatrixMode.Modelview);
             GL.LoadMatrix(ref modelview);
 
-            Title = Parameters.DebugOutputTitle + " (Frame: " + currentFrameID + ")";
+            Title = Parameters.DebugWindowTitle + " (Frame: " + currentFrameID + ")";
 
             GL.Enable(EnableCap.Texture2D);
 
@@ -136,8 +132,8 @@ namespace bbiwarg.Output.DebugOutput
             int imageIndex = 0;
             foreach (OutputImage image in debugImages.Images)
             {
-                int column = imageIndex % Parameters.DebugOutputNumImagesPerRow;
-                int row = imageIndex / Parameters.DebugOutputNumImagesPerRow;
+                int column = imageIndex % Parameters.DebugWindowNumImagesPerRow;
+                int row = imageIndex / Parameters.DebugWindowNumImagesPerRow;
                 GL.BindTexture(TextureTarget.Texture2D, textureID);
                 GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, Parameters.ImageWidth, Parameters.ImageHeight, 0, PixelFormat.Rgb, PixelType.UnsignedByte, image.Image.MIplImage.imageData);
                 GL.Begin(PrimitiveType.Quads);

+ 2 - 2
bbiwarg/Output/DebugOutput/TouchEventVisualizer.cs

@@ -97,8 +97,8 @@ namespace bbiwarg.Output.DebugOutput
                 foreach (List<Vector2D> positions in activeTouches.Values)
                 {
                     Vector2D lastPosition = positions.Last();
-                    int activeRow = (int)Math.Floor(lastPosition.Y * Parameters.PalmGridNumRows);
-                    int activeCol = (int)Math.Floor(lastPosition.X * Parameters.PalmGridNumColumns);
+                    int activeRow = (int)Math.Min(lastPosition.Y * Parameters.PalmGridNumRows, numRows-1);
+                    int activeCol = (int)Math.Min(lastPosition.X * Parameters.PalmGridNumColumns, numColumns-1);
                     activeBlocks[activeRow, activeCol] = true;
                 }
             }

+ 151 - 0
bbiwarg/Output/GlassesOutput/GlassesWindow.cs

@@ -0,0 +1,151 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Drawing;
+using System.Text;
+using System.Threading.Tasks;
+using OpenTK;
+using OpenTK.Input;
+using OpenTK.Graphics.OpenGL;
+using OpenTK.Graphics;
+using bbiwarg.Input.InputHandling;
+using bbiwarg.Input.InputProviding;
+using bbiwarg.Utility;
+
+namespace bbiwarg.Output.GlassesOutput
+{
+    class GlassesWindow : GameWindow
+    {
+        private InputHandler inputHandler;
+        private InputProvider inputProvider;
+        private uint textureID;
+        private int currentFrameID;
+        private OutputImage image;
+
+        public GlassesWindow(InputProvider inputProvider, InputHandler inputHandler)
+            : base(Parameters.GlassesWindowWidth, Parameters.GlassesWindowHeight)
+        {
+            this.inputProvider = inputProvider;
+            this.inputHandler = inputHandler;
+        }
+
+        protected override void OnLoad(EventArgs e)
+        {
+            base.OnLoad(e);
+            Title = Parameters.GlassesWindowTitle;
+            GL.ClearColor(Color.Black);
+            /*
+            // transparency
+            GL.Enable(EnableCap.Blend);
+            GL.BlendEquation(BlendEquationMode.Max);
+
+            // Depth Test 
+            GL.Enable(EnableCap.DepthTest);
+            */
+            // Texture
+            GL.Enable(EnableCap.Texture2D);
+            GL.GenTextures(1, out textureID);
+            GL.BindTexture(TextureTarget.Texture2D, textureID);
+            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
+            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
+
+            Keyboard.KeyDown += handleKeyDown;
+        }
+
+        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
+        {
+            base.OnClosing(e);
+
+            inputProvider.stop();
+        }
+
+        protected override void OnResize(EventArgs e)
+        {
+            base.OnResize(e);
+
+            int screenWidth = ClientRectangle.Width;
+            int screenHeight = ClientRectangle.Height;
+            /*
+            int numRows = 1 + (Parameters.DebugWindowNumImages - 1) / Parameters.DebugWindowNumImagesPerRow;
+            int numCols = Math.Min(Parameters.DebugWindowNumImages, Parameters.DebugWindowNumImagesPerRow);
+            int heightForWidth = (int)((float)screenWidth / ((float)numCols * Parameters.ImageAspectRatio) * (float)numRows);
+            */
+            GL.Viewport(0, 0, screenWidth, screenHeight);
+            //GL.Viewport(0, (screenHeight - heightForWidth) / 2, screenWidth, heightForWidth);
+
+            //Matrix4 projection = Matrix4.CreateOrthographicOffCenter(0, numCols, numRows, 0, 0.001f, 10f);
+            Matrix4 projection = Matrix4.CreateOrthographicOffCenter(0, 1, 1, 0, 0.001f, 10f);
+            GL.MatrixMode(MatrixMode.Projection);
+            GL.LoadMatrix(ref projection);
+        }
+
+        protected override void OnUpdateFrame(FrameEventArgs e)
+        {
+            Timer.start("GlassesWindow.OnUpdateFrame");
+            base.OnUpdateFrame(e);
+
+            if (!inputProvider.IsActive)
+                Exit();
+
+            FrameData frameData = inputHandler.FrameData;
+            if (frameData != null)
+            {
+                lock (frameData)
+                {
+                    if (currentFrameID != frameData.FrameID)
+                    {
+                        currentFrameID = frameData.FrameID;
+
+                        Timer.start("GlassesWindow.OnUpdateFrame::updateImage");
+                        //TODO update image
+                        image = new OutputImage(Parameters.GlassesWindowWidth, Parameters.GlassesWindowHeight);
+                        Timer.stop("GlassesWindow.OnUpdateFrame::updateImage");
+                    }
+                }
+            }
+
+            Timer.stop("GlassesWindow.OnUpdateFrame");
+        }
+
+
+        protected override void OnRenderFrame(FrameEventArgs e)
+        {
+            Timer.start("GlassesWindow.OnRenderFrame");
+            base.OnRenderFrame(e);
+            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
+            Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
+            GL.MatrixMode(MatrixMode.Modelview);
+            GL.LoadMatrix(ref modelview);
+
+            Title = Parameters.DebugWindowTitle + " (Frame: " + currentFrameID + ")";
+
+            GL.Enable(EnableCap.Texture2D);
+
+            Timer.start("GlassesWindow.OnRenderFrame::drawImage");
+            
+            GL.BindTexture(TextureTarget.Texture2D, textureID);
+            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, Parameters.ImageWidth, Parameters.ImageHeight, 0, PixelFormat.Rgb, PixelType.UnsignedByte, image.Image.MIplImage.imageData);
+            GL.Begin(PrimitiveType.Quads);
+            GL.Color3(1.0, 1.0, 1.0);
+            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();
+
+            Timer.stop("GlassesWindow.OnRenderFrame::drawImage");
+
+            Timer.start("GlassesWindow.OnRenderFrame::SwapBuffers");
+            SwapBuffers();
+            Timer.stop("GlassesWindow.OnRenderFrame::SwapBuffers");
+
+            Timer.stop("GlassesWindow.OnRenderFrame");
+        }
+
+        private void handleKeyDown(object sender, KeyboardKeyEventArgs e)
+        {
+            Console.WriteLine("jens ist plööhöhöhöhööt");
+        }
+
+    }
+}

+ 17 - 9
bbiwarg/Parameters.cs

@@ -19,7 +19,7 @@ namespace bbiwarg
     class Parameters
     {
         // input
-        public static readonly InputType InputSource = InputType.Movie;
+        public static readonly InputType InputSource = InputType.Camera;
         public static readonly String InputMoviePath = "..\\..\\videos\\touch\\4.skv";
 
         // Logger
@@ -27,14 +27,22 @@ namespace bbiwarg
         public static readonly int ConsoleWidth = 90;
         public static readonly int ConsoleHeight = 30;
 
-        // Debug-Output
-        public static readonly bool DebugOutputEnabled = true;
-        public static readonly int DebugOutputUpdateRate = 30;
-        public static readonly int DebugOutputRenderRate = 30;
-        public static readonly int DebugOutputNumImages = 5;
-        public static readonly int DebugOutputNumImagesPerRow = 3;
-        public static readonly float DebugOutputScaleFactor = 1f; // output window size is scaled by this factor (from necessary size for images)
-        public static readonly String DebugOutputTitle = "BBIWARG - DebugOutput";
+        // Debug window
+        public static readonly bool DebugWindowEnabled = true;
+        public static readonly int DebugWindowUpdateRate = 30;
+        public static readonly int DebugWindowRenderRate = 30;
+        public static readonly int DebugWindowNumImages = 5;
+        public static readonly int DebugWindowNumImagesPerRow = 3;
+        public static readonly float DebugWindowScaleFactor = 1f; // output window size is scaled by this factor (from necessary size for images)
+        public static readonly String DebugWindowTitle = "BBIWARG - DebugOutput";
+
+        // glasses window
+        public static readonly bool GlassesWindowEnabled = true;
+        public static readonly int GlassesWindowUpdateRate = 30;
+        public static readonly int GlassesWindowRenderRate = 30;
+        public static readonly int GlassesWindowWidth = 1280;
+        public static readonly int GlassesWindowHeight = 720;
+        public static readonly String GlassesWindowTitle = "BBIWARG - GlassesOutput";
 
         // TUIO
         public static bool TuioEnabled { get; private set; }

+ 1 - 1
bbiwarg/Utility/Timer.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.Linq;
 using System.Text;
-using System.Threading.Tasks;
+using System.Threading;
 
 namespace bbiwarg.Utility
 {

+ 1 - 0
bbiwarg/bbiwarg.csproj

@@ -83,6 +83,7 @@
   <ItemGroup>
     <Compile Include="Input\InputHandling\FrameData.cs" />
     <Compile Include="Output\DebugOutput\DebugImages.cs" />
+    <Compile Include="Output\GlassesOutput\GlassesWindow.cs" />
     <Compile Include="Parameters.cs" />
     <Compile Include="Output\DebugOutput\DebugWindow.cs" />
     <Compile Include="Input\InputHandling\InputHandler.cs" />