Browse Source

Added getUVImage().
Removed getVertexArray().

Daniel Kauth 11 years ago
parent
commit
8c95903f5b

+ 76 - 76
bbiwarg/DataSource/IVideoDataSource.cs

@@ -1,77 +1,77 @@
-using System;
-
-using MathNet.Numerics.LinearAlgebra.Single;
-
-namespace bbiwarg.DataSource
-{
-    public enum FingerStatus
-    {
-        Inactive,
-        Detected,
-        Tracked
-    }
-
-    public enum HandSide
-    {
-        Unknown,
-        Left,
-        Right
-    }
-
-    /*
-     * Interface get data from a camera or a video file.
-     * Completely independent of iisu.
-     */
-    interface IVideoDataSource
-    {
-        /*
-         * Initializes the data source.
-         */
-        void init();
-
-        /*
-         * Starts the recording of data.
-         */
-        void start();
-        /*
-         * Stops the recording of data.
-         */
-        void stop();
-
-        /*
-         * Updates the data for the current frame.
-         * Needs to be called before any method to read data.
-         */
-        void updateFrame();
-        /*
-         * Lets the data source process the next frame.
-         */
-        void releaseFrame();
-
-        /*
-         * Returns true iff new data is generated.
-         * (e.g camera is running or video hasn't ended)
-         */
-        bool isActive();
-        int getFrameRate();
-        /**
-         * The depth is given by the distance to the camera in millimeters. 
-         */
-        DepthImage getDepthImage();
-        ColorImage getColorImage();
-        ConfidenceImage getConfidenceImage();
-        VertexArray getVertexArray();
-        /*
-         * all handIndices have to be 1 or 2
-         */
-        bool isHandOpen(uint handIndex);
+using System;
+
+using MathNet.Numerics.LinearAlgebra.Single;
+
+namespace bbiwarg.DataSource
+{
+    public enum FingerStatus
+    {
+        Inactive,
+        Detected,
+        Tracked
+    }
+
+    public enum HandSide
+    {
+        Unknown,
+        Left,
+        Right
+    }
+
+    /*
+     * Interface get data from a camera or a video file.
+     * Completely independent of iisu.
+     */
+    interface IVideoDataSource
+    {
+        /*
+         * Initializes the data source.
+         */
+        void init();
+
+        /*
+         * Starts the recording of data.
+         */
+        void start();
+        /*
+         * Stops the recording of data.
+         */
+        void stop();
+
+        /*
+         * Updates the data for the current frame.
+         * Needs to be called before any method to read data.
+         */
+        void updateFrame();
+        /*
+         * Lets the data source process the next frame.
+         */
+        void releaseFrame();
+
+        /*
+         * Returns true iff new data is generated.
+         * (e.g camera is running or video hasn't ended)
+         */
+        bool isActive();
+        int getFrameRate();
+        /**
+         * The depth is given by the distance to the camera in millimeters. 
+         */
+        DepthImage getDepthImage();
+        ColorImage getColorImage();
+        ConfidenceImage getConfidenceImage();
+        UVImage getUVImage();
+        /*
+         * all handIndices have to be 1 or 2
+         */
+        bool isHandOpen(uint handIndex);
         Vector getPalmPosition3D(uint handIndex);
-        Vector getPalmPosition2D(uint handIndex);
-        Vector getTipPosition3D(uint handIndex);
-        Vector getForearmPosition3D(uint handIndex);
-        Vector getPalmNormal3D(uint handIndex);
-        FingerStatus[] getFingerStatus(uint handIndex);
-        Vector[] getFingerTipPositions3D(uint handIndex);
-        HandSide getHandSide(uint handIndex);
-    }
-}
+        Vector getPalmPosition2D(uint handIndex);
+        Vector getTipPosition3D(uint handIndex);
+        Vector getForearmPosition3D(uint handIndex);
+        Vector getPalmNormal3D(uint handIndex);
+        FingerStatus[] getFingerStatus(uint handIndex);
+        Vector[] getFingerTipPositions3D(uint handIndex);
+        HandSide getHandSide(uint handIndex);
+    }
+}

+ 12 - 22
bbiwarg/DataSource/IisuDataSource.cs

@@ -29,7 +29,7 @@ namespace bbiwarg.DataSource
         private IDataHandle<Iisu.Data.IImageData> depthImage;
         private IDataHandle<Iisu.Data.IImageData> colorImage;
         private IDataHandle<Iisu.Data.IImageData> confidenceImage;
-        private IDataHandle<Iisu.Data.Vertex[]> vertexArray;
+        private IDataHandle<Iisu.Data.IImageData> uvImage;
 
         /*
          * Creates an Iisu data source.
@@ -68,7 +68,8 @@ namespace bbiwarg.DataSource
             depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
             colorImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.COLOR.Image");
             confidenceImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.CONFIDENCE.Image");
-           
+            uvImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.COLOR.REGISTRATION.UV.Image");
+
             handOpen[0] = device.RegisterDataHandle<bool>("CI.HAND1.IsOpen");
             handOpen[1] = device.RegisterDataHandle<bool>("CI.HAND2.IsOpen");
 
@@ -100,8 +101,6 @@ namespace bbiwarg.DataSource
         private void onDeviceStatusChanged(string eventName, DeviceStatus status)
         {
             active = status.HasFlag(Iisu.DeviceStatus.Playing);
-            if (vertexArray != null && !vertexArray.Valid && active)
-                vertexArray = device.RegisterDataHandle<Iisu.Data.Vertex[]>("SCENE.VertexArray");
         }
 
         public void start()
@@ -179,28 +178,19 @@ namespace bbiwarg.DataSource
             return new ConfidenceImage(width, height, confidenceData);
         }
 
-        public VertexArray getVertexArray()
+        public VertexArray getUVImage()
         {
-            if (vertexArray != null && vertexArray.Valid)
-            {
-                int numVertices = vertexArray.Value.Length;
+            Iisu.Data.IImageInfos imageInfos = uvImage.Value.ImageInfos;
+            int width = (int)imageInfos.Width;
+            int height = (int)imageInfos.Height;
+            int numBytes = (int)imageInfos.BytesRaw;
 
-                Vector[] positions = new Vector[numVertices];
-                Color4[] colors = new Color4[numVertices];
+            IntPtr imageData = uvImage.Value.Raw;
 
-                for (int i = 0; i < numVertices; ++i)
-                {
-                    positions[i] = new DenseVector(vertexArray.Value[i].Position.ToArray());
-                    Iisu.Data.Color4C color = vertexArray.Value[i].Color;
-                    colors[i] = new Color4(color.A, color.R, color.G, color.B);
-                }
+            float[] uvData = new float[width * height];
+            Marshal.Copy(imageData, uvData, 0, width * height);
 
-                return new VertexArray(positions, colors);
-            }
-            else
-            {
-                return new VertexArray(new DenseVector[0], new Color4[0]);
-            }
+            return new UVImage(width, height, uvData);
         }
 
         private void checkHandIndex(uint handIndex) 

+ 31 - 0
bbiwarg/DataSource/UVImage.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace bbiwarg.DataSource
+{
+    class UVImage
+    {
+        private int width, height;
+        private float[] data;
+
+        public UVImage(int width, int height, float[] data)
+        {
+            this.width = width;
+            this.height = height;
+            this.data = data;
+        }
+
+        public float getU(int x, int y)
+        {
+            return data[2 * (y * width + x) + 0];
+        }
+
+        public float getV(int x, int y)
+        {
+            return data[2 * (y * width + x) + 1];
+        }
+    }
+}