瀏覽代碼

Histogram is drawn.

Daniel Kauth 11 年之前
父節點
當前提交
0bb0785e55
共有 2 個文件被更改,包括 24 次插入11 次删除
  1. 20 7
      bbiwarg/Graphics/Output2D.cs
  2. 4 4
      bbiwarg/Images/DepthImage.cs

+ 20 - 7
bbiwarg/Graphics/Output2D.cs

@@ -80,22 +80,35 @@ namespace bbiwarg.Graphics
                 }
             }
 
-            int[] histogram = videoHandle.getHistogram();
-            for (int i = 0; i < histogram.Length; ++i)
-            {
-                //...
-            }
-
-            GL.BindTexture(TextureTarget.Texture2D, textureId);
+            /*GL.BindTexture(TextureTarget.Texture2D, textureId);
             GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.getWidth(), videoHandle.getHeight(), 0,
                           PixelFormat.Rgb, PixelType.Short, textureData);
 
             float size_2 = 0.5f / 2.0f;
             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.End();*/
+
+
+            int[] histogram = videoHandle.getHistogram();
+            int maxValue = 0;
+            for (int i = 0; i < histogram.Length; ++i)
+            {
+                if (histogram[i] > maxValue)
+                    maxValue = histogram[i];
+            }
+
+            GL.Begin(PrimitiveType.LineStrip);
+            GL.Color3(0, 0, 1.0);
+            GL.LineWidth(5.0f);
+            for (int i = 0; i < histogram.Length; ++i)
+            {
+                GL.Vertex3(-0.25 + i * (0.5 / histogram.Length), -0.25 + histogram[i] * (0.5 / (maxValue - 5)), -0.5);
+            }
             GL.End();
 
             sw.Stop();

+ 4 - 4
bbiwarg/Images/DepthImage.cs

@@ -76,17 +76,17 @@ namespace bbiwarg.Images
             Int16 minDepth = getMinDepth();
             Int16 maxDepth = getMaxDepth();
 
-            histogram = new int[maxDepth - minDepth + 1];
+            histogram = new int[maxDepth - minDepth];
             for (int x = 0; x < width; ++x)
             {
                 for (int y = 0; y < height; ++y)
                 {
                     int depth = getDepth(x, y);
-                    histogram[depth - minDepth]++;
+                    if (depth != maxDepth)
+                        histogram[depth - minDepth]++;
                 }
             }
-            histogram[maxDepth - minDepth] = 0;
-
+            
             return histogram;
         }