Selaa lähdekoodia

Added possibility to adjust window size scale and display multiple rows of images.

Daniel Kauth 11 vuotta sitten
vanhempi
commit
8c67a27d4c
2 muutettua tiedostoa jossa 18 lisäystä ja 9 poistoa
  1. 4 1
      bbiwarg/Constants.cs
  2. 14 8
      bbiwarg/Graphics/OutputWindow.cs

+ 4 - 1
bbiwarg/Constants.cs

@@ -9,6 +9,7 @@ namespace bbiwarg
 {
     class Constants
     {
+        // colors
         public static readonly Color ColorDetected = Color.White;
         public static readonly Color ColorTracked = Color.Yellow;
 
@@ -32,6 +33,8 @@ namespace bbiwarg
         public static readonly Color PalmConturColor = Color.Red;
         public static readonly Color PalmConvexHullColor = Color.Green;
 
-
+        // output window
+        public static readonly int NumImagesPerRow = 3;
+        public static readonly float WindwoSizeFactor = 1f; // output window size is scaled by this factor (from necessary size for images)
     }
 }

+ 14 - 8
bbiwarg/Graphics/OutputWindow.cs

@@ -25,7 +25,8 @@ namespace bbiwarg.Graphics
         private Stopwatch watch;
 
         public OutputWindow(VideoHandle videoHandle)
-            : base((int) (1.5 * videoHandle.OutputImages.Length * videoHandle.Width), (int) (1.5 * videoHandle.Height))
+            : base((int) (Constants.WindwoSizeFactor * HelperFunctions.thresholdRange<int>(1, Constants.NumImagesPerRow, videoHandle.OutputImages.Length) * videoHandle.Width), 
+                   (int) (Constants.WindwoSizeFactor * (1 + (videoHandle.OutputImages.Length - 1) / Constants.NumImagesPerRow) * videoHandle.Height))
         {
             this.videoHandle = videoHandle;
             watch = new Stopwatch();
@@ -65,12 +66,15 @@ namespace bbiwarg.Graphics
             int imageHeight = videoHandle.Height;
             float imageAspectRatio = (float)imageWidth / (float)imageHeight;
 
-            int heightForWidth = (int) ((float) screenWidth / ((float) videoHandle.OutputImages.Length * imageAspectRatio));
-
+            int numImages = videoHandle.OutputImages.Length;
+            int numRows = 1 + (numImages - 1) / Constants.NumImagesPerRow;
+            int numCols = Math.Min(videoHandle.OutputImages.Length, Constants.NumImagesPerRow);
+            int heightForWidth = (int)((float)screenWidth / ((float)numCols * imageAspectRatio) * (float)numRows);
+            
             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, videoHandle.OutputImages.Length, 1, 0, 0.001f, 10f);
+            Matrix4 projection = Matrix4.CreateOrthographicOffCenter(0, numCols, numRows, 0, 0.001f, 10f);
             GL.MatrixMode(MatrixMode.Projection);
             GL.LoadMatrix(ref projection);
         }
@@ -139,14 +143,16 @@ namespace bbiwarg.Graphics
             int imageIndex = 0;
             foreach (OutputImage image in videoHandle.OutputImages)
             {
+                int x = imageIndex % Constants.NumImagesPerRow;
+                int y = imageIndex / Constants.NumImagesPerRow;
                 GL.BindTexture(TextureTarget.Texture2D, textureId);
                 GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.Width, videoHandle.Height, 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 + imageIndex, 0, -1);
-                GL.TexCoord2(1, 0); GL.Vertex3(1 + imageIndex, 0, -1);
-                GL.TexCoord2(1, 1); GL.Vertex3(1 + imageIndex, 1, -1);
-                GL.TexCoord2(0, 1); GL.Vertex3(0 + imageIndex, 1, -1);
+                GL.TexCoord2(0, 0); GL.Vertex3(0 + x, 0 + y, -1);
+                GL.TexCoord2(1, 0); GL.Vertex3(1 + x, 0 + y, -1);
+                GL.TexCoord2(1, 1); GL.Vertex3(1 + x, 1 + y, -1);
+                GL.TexCoord2(0, 1); GL.Vertex3(0 + x, 1 + y, -1);
                 GL.End();
                 ++imageIndex;
             }