Browse Source

-implemented testOutput with points and rectangles
-removed vertex and vertexbufferobject
-added transparency

Alexander Hendrich 11 years ago
parent
commit
2e4ff63bdd

+ 5 - 0
bbiwarg/DataSource/Palm.cs

@@ -39,5 +39,10 @@ namespace bbiwarg.DataSource
         {
             return lowerLeft;
         }
+
+        public Vector[] getCorners()
+        {
+            return new Vector[4] { upperLeft, upperRight, lowerRight, lowerLeft };
+        }
     }
 }

+ 0 - 3
bbiwarg/Graphics/IGraphicElement.cs

@@ -11,8 +11,5 @@ namespace bbiwarg.Graphics
     interface IGraphicElement
     {
         void draw();
-        List<Vector> getVertices();
-        uint[] getTriangleIndices();
-        Color getColor();
     }
 }

+ 42 - 126
bbiwarg/Graphics/Output.cs

@@ -17,7 +17,7 @@ namespace bbiwarg.Graphics
     {
         private IVideoHandle videoHandle;
 
-        private uint imageBufferId, pointBufferId, quadBufferId;
+        private uint imageBufferId;
 
         public Output(IVideoHandle videoHandle)
         {
@@ -30,6 +30,10 @@ namespace bbiwarg.Graphics
             Title = "OutputTest";
             GL.ClearColor(Color.Black);
 
+            // transparency
+            GL.Enable(EnableCap.Blend);
+            GL.BlendEquation(BlendEquationMode.Max);
+
             initBuffers();
         }
 
@@ -46,142 +50,39 @@ namespace bbiwarg.Graphics
             Stopwatch sw = new Stopwatch();
             sw.Start();
 
-            GL.EnableClientState(ArrayCap.VertexArray);
-            GL.EnableClientState(ArrayCap.ColorArray);
-
-            GL.BindBuffer(BufferTarget.ArrayBuffer, imageBufferId);
-            videoHandle.createVertexArray(GL.MapBuffer(BufferTarget.ArrayBuffer, BufferAccess.WriteOnly));
-            GL.UnmapBuffer(BufferTarget.ArrayBuffer);
-
-            GL.VertexPointer(3, VertexPointerType.Float, 3 * sizeof(float) + 4 * sizeof(byte), IntPtr.Zero);
-            GL.ColorPointer(4, ColorPointerType.UnsignedByte, 3 * sizeof(float) + 4 * sizeof(byte), 3 * sizeof(float));
-
-            GL.PointSize(2.0f);
-            GL.DrawArrays(PrimitiveType.Points, 0, videoHandle.getWidth() * videoHandle.getHeight());
+            drawDepthImage();
 
-            // draw points
-            float[] pointData;
-            
-            DetectionStatus[] fingerStatus = videoHandle.getFingerStatus(1);
-            int numFingersDetected = 0;
-            for (int i = 0; i < fingerStatus.Length; ++i)
-            {
-                if (fingerStatus[i] == DetectionStatus.Detected || fingerStatus[i] == DetectionStatus.Tracked)
-                    ++numFingersDetected;
-            }
-
-            pointData = new float[(4 + 3) * (3 + numFingersDetected)];
-            Color y = Color.Yellow;
+            // palm (iisu)
             Vector palmPosition = videoHandle.getPalmPosition3D(1);
-            Vector foreFingerPosition = videoHandle.getForeFingerPosition3D(1);
-            Vector foreArmPosition = videoHandle.getForearmPosition3D(1);
-
-            pointData[0] = palmPosition[0];
-            pointData[1] = palmPosition[1];
-            pointData[2] = -palmPosition[2];
+            Point palmPoint = new Point(palmPosition, Color.Yellow, 0.005f);
+            palmPoint.draw();
 
-            pointData[3] = y.R / 255.0f;
-            pointData[4] = y.G / 255.0f;
-            pointData[5] = y.B / 255.0f;
-            pointData[6] = y.A / 255.0f;
-
-            pointData[7] = foreArmPosition[0];
-            pointData[8] = foreArmPosition[1];
-            pointData[9] = -foreArmPosition[2];
-
-            pointData[10] = y.R / 255.0f;
-            pointData[11] = y.G / 255.0f;
-            pointData[12] = y.B / 255.0f;
-            pointData[13] = y.A / 255.0f;
+            // foreFinger
+            Vector foreFingerPosition = videoHandle.getForeFingerPosition3D(1);
+            Point foreFingerPoint = new Point(foreFingerPosition, Color.Red, 0.005f);
+            foreFingerPoint.draw();
 
+            // foreArm (iisu)
+            Vector foreArmPosition = videoHandle.getForearmPosition3D(1);
+            Point foreArmPoint = new Point(foreArmPosition, Color.Yellow, 0.005f);
+            foreArmPoint.draw();
 
-            int index = 14;
+            // finger (iisu)
             Vector[] fingerPositions = videoHandle.getFingerTipPositions3D(1);
+            DetectionStatus[] fingerStatus = videoHandle.getFingerStatus(1);
             for (int i = 0; i < fingerStatus.Length; ++i)
             {
                 if (fingerStatus[i] == DetectionStatus.Detected || fingerStatus[i] == DetectionStatus.Tracked)
                 {
-                    pointData[index + 0] = fingerPositions[i][0];
-                    pointData[index + 1] = fingerPositions[i][1];
-                    pointData[index + 2] = -fingerPositions[i][2];
-
-                    pointData[index + 3] = y.R / 255.0f;
-                    pointData[index + 4] = y.G / 255.0f;
-                    pointData[index + 5] = y.B / 255.0f;
-                    pointData[index + 6] = y.A / 255.0f;
-                    index += 7;
+                    Point fingerPoint = new Point(fingerPositions[i], Color.Yellow, 0.005f);
+                    fingerPoint.draw();
                 }
             }
-            pointData[index + 0] = foreFingerPosition[0];
-            pointData[index + 1] = foreFingerPosition[1];
-            pointData[index + 2] = foreFingerPosition[2];
-            pointData[index + 3] = Color.Red.R / 255.0f;
-            pointData[index + 4] = Color.Red.G / 255.0f;
-            pointData[index + 5] = Color.Red.B / 255.0f;
-            pointData[index + 6] = Color.Red.A / 255.0f;
-            index += 7;
-
-            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
-            GL.BindBuffer(BufferTarget.ArrayBuffer, pointBufferId);
-            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(pointData.Length * sizeof(float)), pointData, BufferUsageHint.DynamicDraw);
-            GL.VertexPointer(3, VertexPointerType.Float, (4 + 3) * sizeof(float), IntPtr.Zero);
-            GL.ColorPointer(4, ColorPointerType.Float, (4 + 3) * sizeof(float), 3 * sizeof(float));
-
-            GL.PointSize(10f);
-            GL.DrawArrays(PrimitiveType.Points, 0, pointData.Length / (4 + 3));
-
-            // draw quads
-            float[] quadData = new float[4 * (4 + 3) * 1];
 
+            // palm
             Palm palm = videoHandle.getPalm(1);
-            Vector ul = palm.getUpperLeft();
-            Vector ur = palm.getUpperRight();
-            Vector lr = palm.getLowerRight();
-            Vector ll = palm.getLowerLeft();
-
-            quadData[0] = ul.x();
-            quadData[1] = ul.y();
-            quadData[2] = -ul.z();
-
-            quadData[3] = y.R / 255.0f;
-            quadData[4] = y.G / 255.0f;
-            quadData[5] = y.B / 255.0f;
-            quadData[6] = 0.5f;
-
-            quadData[7] = ur.x();
-            quadData[8] = ur.y();
-            quadData[9] = -ur.z();
-
-            quadData[10] = y.R / 255.0f;
-            quadData[11] = y.G / 255.0f;
-            quadData[12] = y.B / 255.0f;
-            quadData[13] = 0.5f;
-
-            quadData[14] = lr.x();
-            quadData[15] = lr.y();
-            quadData[16] = -lr.z();
-
-            quadData[17] = y.R / 255.0f;
-            quadData[18] = y.G / 255.0f;
-            quadData[19] = y.B / 255.0f;
-            quadData[20] = 0.5f;
-
-            quadData[21] = ll.x();
-            quadData[22] = ll.y();
-            quadData[23] = -ll.z();
-
-            quadData[24] = y.R / 255.0f;
-            quadData[25] = y.G / 255.0f;
-            quadData[26] = y.B / 255.0f;
-            quadData[27] = 0.5f;
-
-            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
-            GL.BindBuffer(BufferTarget.ArrayBuffer, quadBufferId);
-            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(quadData.Length * sizeof(float)), quadData, BufferUsageHint.DynamicDraw);
-            GL.VertexPointer(3, VertexPointerType.Float, (4 + 3) * sizeof(float), IntPtr.Zero);
-            GL.ColorPointer(4, ColorPointerType.Float, (4 + 3) * sizeof(float), 3 * sizeof(float));
-
-            GL.DrawArrays(PrimitiveType.Quads, 0, quadData.Length / (4 + 3));
+            Rectangle palmRect = new Rectangle(palm.getCorners(), Color.FromArgb(128, Color.Blue));
+            palmRect.draw();
 
             sw.Stop();
             Console.WriteLine(sw.ElapsedMilliseconds);
@@ -201,13 +102,28 @@ namespace bbiwarg.Graphics
         private void initBuffers()
         {
             GL.GenBuffers(1, out imageBufferId);
-            GL.GenBuffers(1, out pointBufferId);
-            GL.GenBuffers(1, out quadBufferId);
 
             GL.BindBuffer(BufferTarget.ArrayBuffer, imageBufferId);
             GL.BufferData(BufferTarget.ArrayBuffer, 
                           (IntPtr)((3 * sizeof(float) + 4  * sizeof(byte)) * videoHandle.getWidth() * videoHandle.getHeight()), 
                           IntPtr.Zero, BufferUsageHint.StreamDraw);
-        } 
+        }
+
+        private void drawDepthImage()
+        {
+            GL.EnableClientState(ArrayCap.VertexArray);
+            GL.EnableClientState(ArrayCap.ColorArray);
+
+            GL.BindBuffer(BufferTarget.ArrayBuffer, imageBufferId);
+            videoHandle.createVertexArray(GL.MapBuffer(BufferTarget.ArrayBuffer, BufferAccess.WriteOnly));
+            GL.UnmapBuffer(BufferTarget.ArrayBuffer);
+
+            GL.VertexPointer(3, VertexPointerType.Float, 3 * sizeof(float) + 4 * sizeof(byte), IntPtr.Zero);
+            GL.ColorPointer(4, ColorPointerType.UnsignedByte, 3 * sizeof(float) + 4 * sizeof(byte), 3 * sizeof(float));
+
+            GL.PointSize(2.0f);
+            GL.DrawArrays(PrimitiveType.Points, 0, videoHandle.getWidth() * videoHandle.getHeight());
+           
+        }
     }
 }

+ 8 - 32
bbiwarg/Graphics/Point.cs

@@ -11,11 +11,11 @@ namespace bbiwarg.Graphics
 {
     class Point : IGraphicElement
     {
-        public Vertex position;
-        public Color color;
-        public float size;
+        private Vector position;
+        private Color color;
+        private float size;
 
-        public Point(Vertex position, Color color, float size)
+        public Point(Vector position, Color color, float size)
         {
             this.position = position;
             this.color = color;
@@ -27,35 +27,11 @@ namespace bbiwarg.Graphics
             GL.Color4(color);
 
             GL.Begin(BeginMode.Polygon);
-            GL.Vertex3(position.x - size/2, position.y + size/2, -position.z);
-            GL.Vertex3(position.x + size/2, position.y + size/2, -position.z);
-            GL.Vertex3(position.x + size/2, position.y - size/2, -position.z);
-            GL.Vertex3(position.x - size/2, position.y - size/2, -position.z);
+            GL.Vertex3(position[0] - size/2, position[1] + size/2, -position[2]);
+            GL.Vertex3(position[0] + size/2, position[1] + size/2, -position[2]);
+            GL.Vertex3(position[0] + size/2, position[1] - size/2, -position[2]);
+            GL.Vertex3(position[0] - size/2, position[1] - size/2, -position[2]);
             GL.End();
         }
-
-        public List<Vector> getVertices()
-        {
-
-            List<Vector> result = new List<Vector>();
-
-            result.Add(new DenseVector(new float[] { position.x - size/2, position.y + size/2, -position.z }));
-            result.Add(new DenseVector(new float[] { position.x + size/2, position.y + size/2, -position.z }));
-            result.Add(new DenseVector(new float[] { position.x + size/2, position.y - size/2, -position.z }));
-            result.Add(new DenseVector(new float[] { position.x - size/2, position.y - size/2, -position.z }));
-
-            return result;
-
-        }
-
-        public uint[] getTriangleIndices()
-        {
-            return new uint[] { 0, 1, 2, 0, 2, 3 };
-        }
-
-        public Color getColor()
-        {
-            return color;
-        }
     }
 }

+ 8 - 32
bbiwarg/Graphics/Rectangle.cs

@@ -11,10 +11,10 @@ namespace bbiwarg.Graphics
 {
     class Rectangle : IGraphicElement
     {
-        public Vertex[] corners;
-        public Color color;
+        private Vector[] corners;
+        private Color color;
 
-        public Rectangle(Vertex[] corners, Color color)
+        public Rectangle(Vector[] corners, Color color)
         {
             this.corners = corners;
             this.color = color;
@@ -24,36 +24,12 @@ namespace bbiwarg.Graphics
         {
             GL.Color4(color);
 
-            GL.Begin(BeginMode.Polygon);
-            GL.Vertex3(corners[0].x, corners[0].y, -corners[0].z);
-            GL.Vertex3(corners[1].x, corners[0].y, -corners[0].z);
-            GL.Vertex3(corners[1].x, corners[1].y, -corners[1].z);
-            GL.Vertex3(corners[0].x, corners[1].y, -corners[1].z);
+            GL.Begin(BeginMode.Quads);
+            GL.Vertex3(corners[0][0], corners[0][1], -corners[0][2]);
+            GL.Vertex3(corners[1][0], corners[1][1], -corners[1][2]);
+            GL.Vertex3(corners[2][0], corners[2][1], -corners[2][2]);
+            GL.Vertex3(corners[3][0], corners[3][1], -corners[3][2]);
             GL.End();
         }
-
-        public List<Vector> getVertices()
-        {
-
-            List<Vector> result = new List<Vector>();
-
-            result.Add(new DenseVector(new float[] { corners[0].x, corners[0].y, -corners[0].z }));
-            result.Add(new DenseVector(new float[] { corners[1].x, corners[0].y, -corners[0].z }));
-            result.Add(new DenseVector(new float[] { corners[1].x, corners[1].y, -corners[1].z }));
-            result.Add(new DenseVector(new float[] { corners[0].x, corners[1].y, -corners[1].z }));
-
-            return result;
-
-        }
-
-        public uint[] getTriangleIndices()
-        {
-            return new uint[] { 0, 1, 2, 0, 2, 3 };
-        }
-
-        public Color getColor()
-        {
-            return color;
-        }
     }
 }

+ 0 - 21
bbiwarg/Graphics/Vertex.cs

@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace bbiwarg.Graphics
-{
-    class Vertex
-    {
-        public float x;
-        public float y;
-        public float z;
-
-        public Vertex(float x, float y, float z) {
-            this.x = x;
-            this.y = y;
-            this.z = z;
-        }
-    }
-}

+ 0 - 101
bbiwarg/Graphics/VertexBufferObject.cs

@@ -1,101 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Drawing;
-using OpenTK;
-using OpenTK.Graphics.OpenGL;
-using MathNet.Numerics.LinearAlgebra.Single;
-
-
-namespace bbiwarg.Graphics
-{
-    class VertexBufferObject : GameWindow
-    {
-        int VBOid = new int();
-        int IBOid = new int();
-        float[] vertices;
-        uint[] triangles;
-
-        static void Main(string[] args)
-        {
-            VertexBufferObject demo = new VertexBufferObject();
-            demo.initSource();
-            demo.Run(30);
-        }
-
-        public void initSource()
-        {
-
-            GL.EnableClientState(ArrayCap.VertexArray);
-
-            vertices = new float[] {
-                1.0f, 0.0f, 0.0f, 
-                0.0f, 0.0f, -5.0f,
-                
-                0.0f, 1.0f, 0.0f,
-                0.0f, 1.0f, -5.0f, 
-                
-                0.0f, 0.0f, 1.0f,
-                1.0f, 0.0f, -5.0f};
-            triangles = new uint[] { 0, 1, 2 };
-
-
-
-            GL.GenBuffers(1, out VBOid);
-            GL.GenBuffers(1, out IBOid);
-
-            GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
-            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StreamDraw);
-            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
-
-
-            GL.BindBuffer(BufferTarget.ElementArrayBuffer, IBOid);
-            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(triangles.Length * sizeof(int)), triangles, BufferUsageHint.StaticDraw);
-            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
-
-
-            //GL.DeleteBuffers(1, ref VBOid); GL.DeleteBuffers(1, ref IBOid);
-
-        }
-
-        protected override void OnLoad(EventArgs e)
-        {
-            base.OnLoad(e);
-            Title = "vbo test";
-            GL.ClearColor(Color.Black);
-        }
-
-        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);
-            GL.MatrixMode(MatrixMode.Modelview);
-            GL.LoadMatrix(ref modelview);
-
-            GL.Color3(Color.Red);
-
-            GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
-            GL.BindBuffer(BufferTarget.ElementArrayBuffer, IBOid);
-
-            GL.InterleavedArrays(InterleavedArrayFormat.C3fV3f, 0, IntPtr.Zero);
-            GL.DrawElements(BeginMode.Triangles, triangles.Length, DrawElementsType.UnsignedInt, 0);
-
-            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
-            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
-
-            SwapBuffers();
-        }
-
-        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 / 4, Width / (float)Height, 1.0f, 3000.0f);
-            GL.MatrixMode(MatrixMode.Projection);
-            GL.LoadMatrix(ref projection);
-        }
-    }
-}

+ 1 - 1
bbiwarg/Main/OutputTest.cs

@@ -12,7 +12,7 @@ namespace bbiwarg.Main
     {
         static void Main(string[] args)
         {
-            IInputProvider inputProvider = new IisuInputProvider("..\\..\\videos\\1.skv");
+            IInputProvider inputProvider = new IisuInputProvider("..\\..\\videos\\3.skv");
             IVideoHandle videoHandle = new VideoHandle(inputProvider);
 
             Output output = new Output(videoHandle);

+ 0 - 2
bbiwarg/bbiwarg.csproj

@@ -73,8 +73,6 @@
     <Compile Include="Graphics\Rectangle.cs" />
     <Compile Include="Graphics\IGraphicElement.cs" />
     <Compile Include="Graphics\Point.cs" />
-    <Compile Include="Graphics\Vertex.cs" />
-    <Compile Include="Graphics\VertexBufferObject.cs" />
     <Compile Include="Main\OutputTest.cs" />
     <Compile Include="Graphics\Output.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />