Bladeren bron

implemented graphics

Alexander Hendrich 11 jaren geleden
bovenliggende
commit
b0e85e734c

+ 13 - 0
bbiwarg/Graphics/IGraphicElement.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace bbiwarg.Graphics
+{
+    interface IGraphicElement
+    {
+        void draw();
+    }
+}

+ 85 - 0
bbiwarg/Graphics/Output.cs

@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using OpenTK;
+using OpenTK.Graphics.OpenGL;
+using MathNet.Numerics.LinearAlgebra.Single;
+using bbiwarg.DataSource;
+
+
+namespace bbiwarg.Graphics
+{
+    class Output : GameWindow
+    {
+        private IVideoDataSource source;
+
+        public Output(IVideoDataSource source)
+        {
+            this.source = source;
+        }
+
+        protected override void OnLoad(EventArgs e)
+        {
+            base.OnLoad(e);
+            Title = "OutputTest";
+            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);
+
+            source.updateFrame();
+
+            ImageData image = source.getImageData();
+            int width = image.getWidth();
+            int height = image.getHeight();
+
+            for (int x = 0; x < width; x++) {
+                for (int y = 0; y < height; y++) {
+                    if (image.getConfidence(x, y) > 100) {
+                        int depth = image.getDepth(x, y);
+                        Vertex vertex = new Vertex(x-width/2, height/2-y, depth);
+                        Color color = image.getColor(x, y);
+                        float size = 0.5f;
+
+                        Point pixel = new Point(vertex, color, size);
+                        pixel.draw();
+                    }
+                }
+            }
+
+            Vector palmPosition2D = source.getPalmPosition2D(1);
+            int palmX = (int) palmPosition2D[0];
+            int palmY = (int) palmPosition2D[1];
+            int palmDepth = image.getDepth(palmX, palmY);
+            Vertex palmVertex = new Vertex(palmX - width / 2, height / 2 - palmY, palmDepth);
+            Color palmColor = Color.Yellow;
+            float palmSize = 5.0f;
+
+            Point palmPixel = new Point(palmVertex, palmColor, palmSize);
+            palmPixel.draw();
+
+
+            SwapBuffers();
+            source.releaseFrame();
+        }
+
+        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);
+        }
+    }
+}

+ 34 - 0
bbiwarg/Graphics/Point.cs

@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using OpenTK.Graphics.OpenGL;
+
+namespace bbiwarg.Graphics
+{
+    class Point : IGraphicElement
+    {
+        private Vertex position;
+        private Color color;
+        private float size;
+
+        public Point(Vertex position, Color color, float size) {
+            this.position = position;
+            this.color = color;
+            this.size = size;
+        }
+
+        public void draw() {
+            GL.Color4(color);
+
+            GL.Begin(BeginMode.Polygon);
+            GL.Vertex3(position.getX() - size, position.getY() + size, -position.getZ());
+            GL.Vertex3(position.getX() + size, position.getY() + size, -position.getZ());
+            GL.Vertex3(position.getX() + size, position.getY() - size, -position.getZ());
+            GL.Vertex3(position.getX() - size, position.getY() - size, -position.getZ());
+            GL.End();
+        }
+    }
+}

+ 36 - 0
bbiwarg/Graphics/Vertex.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace bbiwarg.Graphics
+{
+    class Vertex
+    {
+        private float x;
+        private float y;
+        private float z;
+
+        public Vertex(float x, float y, float z) {
+            this.x = x;
+            this.y = y;
+            this.z = z;// 300;
+        }
+
+        public float getX()
+        {
+            return x;
+        }
+
+        public float getY()
+        {
+            return y;
+        }
+
+        public float getZ()
+        {
+            return z;
+        }
+    }
+}

+ 23 - 0
bbiwarg/Main/OutputTest.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using bbiwarg.DataSource;
+using bbiwarg.Graphics;
+
+namespace bbiwarg.Main
+{
+    class OutputTest
+    {
+        static void Main(string[] args)
+        {
+            IVideoDataSource source = new IIsuDataSource();//"..\\..\\videos\\10.skv");
+            source.init();
+            source.start();
+
+            Output output = new Output(source);
+            output.Run(30);
+        }
+    }
+}

+ 0 - 0
bbiwarg/Test/TestDataSource.cs → bbiwarg/Main/TestDataSource.cs


+ 7 - 2
bbiwarg/bbiwarg.csproj

@@ -32,7 +32,7 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <PropertyGroup>
-    <StartupObject>bbiwarg.Test.OutputTest</StartupObject>
+    <StartupObject>bbiwarg.Main.OutputTest</StartupObject>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="iisuNet, Version=3.0.0.0, Culture=neutral, processorArchitecture=x86">
@@ -63,10 +63,15 @@
     <Compile Include="DataSource\DepthImage.cs" />
     <Compile Include="DataSource\IisuDataSource.cs" />
     <Compile Include="DataSource\IVideoDataSource.cs" />
+    <Compile Include="Graphics\IGraphicElement.cs" />
+    <Compile Include="Graphics\Point.cs" />
+    <Compile Include="Graphics\Vertex.cs" />
+    <Compile Include="Main\OutputTest.cs" />
+    <Compile Include="Graphics\Output.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Test\OutputTest.cs" />
     <Compile Include="Test\Pixel3D.cs" />
-    <Compile Include="Test\TestDataSource.cs" />
+    <Compile Include="Main\TestDataSource.cs" />
     <Compile Include="Test\Triangle.cs" />
   </ItemGroup>
   <ItemGroup>