Parcourir la source

cleanup graphic-namespace

Alexander Hendrich il y a 10 ans
Parent
commit
4de3f5bac0

+ 15 - 0
bbiwarg/Graphics/GraphicElements2D/IGraphicElement2D.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MathNet.Numerics.LinearAlgebra.Single;
+
+namespace bbiwarg.Graphics.GraphicElements2D
+{
+    interface IGraphicElement2D
+    {
+        void draw(short[] textureData, int width);
+    }
+}

+ 32 - 0
bbiwarg/Graphics/GraphicElements2D/Point2D.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using OpenTK.Graphics.OpenGL;
+using bbiwarg.DataSource;
+using MathNet.Numerics.LinearAlgebra.Single;
+
+namespace bbiwarg.Graphics.GraphicElements2D
+{
+    class Point2D : IGraphicElement2D
+    {
+        private Vector position;
+        private Color color;
+
+        public Point2D(Vector position, Color color)
+        {
+            this.position = position;
+            this.color = color;
+        }
+
+        public void draw(short[] textureData, int width)
+        {
+            int index = (3 * ((int)position.y() * width + (int)position.x()));
+            textureData[index + 0] = (short) ((Int16.MaxValue / byte.MaxValue) * color.R);
+            textureData[index + 1] = (short) ((Int16.MaxValue / byte.MaxValue) * color.G);
+            textureData[index + 2] = (short) ((Int16.MaxValue / byte.MaxValue) * color.B);
+        }
+    }
+}

+ 14 - 14
bbiwarg/Graphics/IGraphicElement.cs → bbiwarg/Graphics/GraphicElements3D/IGraphicElement3D.cs

@@ -1,15 +1,15 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using MathNet.Numerics.LinearAlgebra.Single;
-
-namespace bbiwarg.Graphics
-{
-    interface IGraphicElement
-    {
-        void draw();
-    }
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MathNet.Numerics.LinearAlgebra.Single;
+
+namespace bbiwarg.Graphics.GraphicElements3D
+{
+    interface IGraphicElement3D
+    {
+        void draw();
+    }
 }

+ 37 - 37
bbiwarg/Graphics/Point.cs → bbiwarg/Graphics/GraphicElements3D/Point3D.cs

@@ -1,37 +1,37 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using OpenTK.Graphics.OpenGL;
-using MathNet.Numerics.LinearAlgebra.Single;
-
-namespace bbiwarg.Graphics
-{
-    class Point : IGraphicElement
-    {
-        private Vector position;
-        private Color color;
-        private float size;
-
-        public Point(Vector 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[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();
-        }
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using OpenTK.Graphics.OpenGL;
+using MathNet.Numerics.LinearAlgebra.Single;
+
+namespace bbiwarg.Graphics.GraphicElements3D
+{
+    class Point3D : IGraphicElement3D
+    {
+        private Vector position;
+        private Color color;
+        private float size;
+
+        public Point3D(Vector 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[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();
+        }
+    }
+}

+ 3 - 3
bbiwarg/Graphics/Rectangle.cs → bbiwarg/Graphics/GraphicElements3D/Rectangle3D.cs

@@ -7,14 +7,14 @@ using System.Threading.Tasks;
 using OpenTK.Graphics.OpenGL;
 using MathNet.Numerics.LinearAlgebra.Single;
 
-namespace bbiwarg.Graphics
+namespace bbiwarg.Graphics.GraphicElements3D
 {
-    class Rectangle : IGraphicElement
+    class Rectangle3D : IGraphicElement3D
     {
         private Vector[] corners;
         private Color color;
 
-        public Rectangle(Vector[] corners, Color color)
+        public Rectangle3D(Vector[] corners, Color color)
         {
             this.corners = corners;
             this.color = color;

+ 7 - 6
bbiwarg/Graphics/Output.cs

@@ -9,6 +9,7 @@ using OpenTK;
 using OpenTK.Graphics.OpenGL;
 using MathNet.Numerics.LinearAlgebra.Single;
 using bbiwarg.DataSource;
+using bbiwarg.Graphics.GraphicElements3D;
 
 
 namespace bbiwarg.Graphics
@@ -61,24 +62,24 @@ namespace bbiwarg.Graphics
 
             // palm (iisu)
             Vector palmPosition = videoHandle.getPalmPosition3D(1);
-            Point palmPoint = new Point(palmPosition, Color.Yellow, 0.005f);
+            Point3D palmPoint = new Point3D(palmPosition, Color.Yellow, 0.005f);
             palmPoint.draw();
 
             // foreFinger
             Vector foreFingerPosition = videoHandle.getForeFingerPosition3D(1);
-            Point foreFingerPoint = new Point(foreFingerPosition, Color.Red, 0.05f);
+            Point3D foreFingerPoint = new Point3D(foreFingerPosition, Color.Red, 0.05f);
             foreFingerPoint.draw();
 
             //handPoints
             List<Vector> handPoints = videoHandle.getHandPoints();
             for (int i = 0; i < handPoints.Count(); i++)
             {
-                new Point(videoHandle.pixel2VertexPosition(handPoints[i]), Color.Yellow, 0.001f).draw();
+                new Point3D(videoHandle.pixel2VertexPosition(handPoints[i]), Color.Yellow, 0.001f).draw();
             }
 
             // foreArm (iisu)
             Vector foreArmPosition = videoHandle.getForearmPosition3D(1);
-            Point foreArmPoint = new Point(foreArmPosition, Color.Yellow, 0.005f);
+            Point3D foreArmPoint = new Point3D(foreArmPosition, Color.Yellow, 0.005f);
             foreArmPoint.draw();
 
             // finger (iisu)
@@ -88,14 +89,14 @@ namespace bbiwarg.Graphics
             {
                 if (fingerStatus[i] == DetectionStatus.Detected || fingerStatus[i] == DetectionStatus.Tracked)
                 {
-                    Point fingerPoint = new Point(fingerPositions[i], Color.Yellow, 0.005f);
+                    Point3D fingerPoint = new Point3D(fingerPositions[i], Color.Yellow, 0.005f);
                     fingerPoint.draw();
                 }
             }
 
             // palm
             Palm palm = videoHandle.getPalm(1);
-            Rectangle palmRect = new Rectangle(palm.getCorners(), Color.FromArgb(128, Color.Blue));
+            Rectangle3D palmRect = new Rectangle3D(palm.getCorners(), Color.FromArgb(128, Color.Blue));
             palmRect.draw();
 
             sw.Stop();

+ 3 - 4
bbiwarg/Graphics/OutputDepthImage.cs

@@ -10,6 +10,7 @@ using System.Diagnostics;
 
 using MathNet.Numerics.LinearAlgebra.Single;
 using bbiwarg.DataSource;
+using bbiwarg.Graphics.GraphicElements2D;
 
 namespace bbiwarg.Graphics
 {
@@ -89,10 +90,8 @@ namespace bbiwarg.Graphics
             }
 
             // draw palm origin
-            index = 3 * ((int) palmOrigin.y() * depthImage.getWidth() + (int) palmOrigin.x());
-            textureData[index + 0] = Int16.MaxValue;
-            textureData[index + 1] = 0;
-            textureData[index + 2] = 0;
+            Point2D palmPoint = new Point2D(palmOrigin, Color.Yellow);
+            palmPoint.draw(textureData, depthImage.getWidth());
 
             // draw rect points
             foreach (Vector v in points)

+ 6 - 3
bbiwarg/bbiwarg.csproj

@@ -80,10 +80,12 @@
     <Compile Include="DataSource\VectorExtender.cs" />
     <Compile Include="DataSource\VertexArray.cs" />
     <Compile Include="DataSource\VideoHandle.cs" />
+    <Compile Include="Graphics\GraphicElements2D\IGraphicElement2D.cs" />
+    <Compile Include="Graphics\GraphicElements2D\Point2D.cs" />
     <Compile Include="Graphics\OutputDepthImage.cs" />
-    <Compile Include="Graphics\Rectangle.cs" />
-    <Compile Include="Graphics\IGraphicElement.cs" />
-    <Compile Include="Graphics\Point.cs" />
+    <Compile Include="Graphics\GraphicElements3D\Rectangle3D.cs" />
+    <Compile Include="Graphics\GraphicElements3D\IGraphicElement3D.cs" />
+    <Compile Include="Graphics\GraphicElements3D\Point3D.cs" />
     <Compile Include="Main\OutputTest.cs" />
     <Compile Include="Graphics\Output.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
@@ -102,6 +104,7 @@
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.