Kaynağa Gözat

cleanup namespaces

Alexander Hendrich 11 yıl önce
ebeveyn
işleme
6e32ee74a4

+ 1 - 1
bbiwarg/DataSource/CollisionDetection.cs → bbiwarg/Detectors/CollisionDetection.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 using MathNet.Numerics.LinearAlgebra.Single;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.Detectors
 {
     class CollisionDetection
     {

+ 4 - 3
bbiwarg/DataSource/ForeFingerDetection.cs → bbiwarg/Detectors/ForeFingerDetection.cs

@@ -1,14 +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;
-
-using System.Drawing;
+using bbiwarg.InputProviders;
+using bbiwarg.VideoHandles;
 
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.Detectors
 {
     class ForeFingerDetection
     {

+ 1 - 1
bbiwarg/DataSource/Palm.cs → bbiwarg/Detectors/Palm.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 using MathNet.Numerics.LinearAlgebra.Single;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.Detectors
 {
     class Palm
     {

+ 8 - 6
bbiwarg/DataSource/PalmDetection.cs → bbiwarg/Detectors/PalmDetection.cs

@@ -3,10 +3,12 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-
 using MathNet.Numerics.LinearAlgebra.Single;
+using bbiwarg.InputProviders;
+using bbiwarg.VideoHandles;
+using bbiwarg.Helpers;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.Detectors
 {
     class PalmDetection
     {
@@ -24,12 +26,12 @@ namespace bbiwarg.DataSource
         public Palm getPalm(uint handIndex)
         {
             DenseVector palmMiddle = (DenseVector) input.getPalmPosition3D(handIndex);
-            DenseVector tipPosition = (DenseVector)input.getTipPosition3D(handIndex);
-            DenseVector palmNormal = (DenseVector)input.getPalmNormal3D(handIndex);
+            DenseVector tipPosition = (DenseVector)input.getTipPosition3D(handIndex);
+            DenseVector palmNormal = (DenseVector)input.getPalmNormal3D(handIndex);
             //DenseVector thumbPosition = (DenseVector) input.getFingerTipPositions3D(handIndex)[0];
 
-            //DenseVector palmToThumb_2 = (thumbPosition - palmMiddle) / 2.0f;
-            DenseVector tipToForeFinger = tipPosition - palmMiddle;
+            //DenseVector palmToThumb_2 = (thumbPosition - palmMiddle) / 2.0f;
+            DenseVector tipToForeFinger = tipPosition - palmMiddle;
             DenseVector palmToThumb_2 = (DenseVector) tipToForeFinger.Cross(palmNormal) / 3.0f;
            
 

+ 1 - 1
bbiwarg/Graphics/GraphicElements2D/Point2D.cs

@@ -5,8 +5,8 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using OpenTK.Graphics.OpenGL;
-using bbiwarg.DataSource;
 using MathNet.Numerics.LinearAlgebra.Single;
+using bbiwarg.Helpers;
 
 namespace bbiwarg.Graphics.GraphicElements2D
 {

+ 3 - 2
bbiwarg/Graphics/Output2D.cs

@@ -7,10 +7,11 @@ using OpenTK;
 using OpenTK.Graphics.OpenGL;
 using System.Drawing;
 using System.Diagnostics;
-
 using MathNet.Numerics.LinearAlgebra.Single;
-using bbiwarg.DataSource;
 using bbiwarg.Graphics.GraphicElements2D;
+using bbiwarg.InputProviders;
+using bbiwarg.Images;
+using bbiwarg.Helpers;
 
 namespace bbiwarg.Graphics
 {

+ 3 - 1
bbiwarg/Graphics/Output3D.cs

@@ -8,8 +8,10 @@ using System.Threading.Tasks;
 using OpenTK;
 using OpenTK.Graphics.OpenGL;
 using MathNet.Numerics.LinearAlgebra.Single;
-using bbiwarg.DataSource;
+using bbiwarg.Detectors;
 using bbiwarg.Graphics.GraphicElements3D;
+using bbiwarg.VideoHandles;
+using bbiwarg.InputProviders;
 
 
 namespace bbiwarg.Graphics

+ 86 - 86
bbiwarg/DataSource/IVideoDataSource.cs → bbiwarg/Helpers/IVideoDataSource.cs

@@ -1,86 +1,86 @@
-using System;
-
-using MathNet.Numerics.LinearAlgebra.Single;
-
-namespace bbiwarg.DataSource
-{
-    public enum DetectionStatus
-    {
-        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();
-        float getHFOV();
-        float getVFOV();
-        /**
-         * The depth is given by the distance to the camera in millimeters. 
-         */
-        DepthImage getDepthImage();
-        ColorImage getColorImage();
-        ConfidenceImage getConfidenceImage();
-        UVImage getUVImage();
-        ImageData getImageData();
-        /*
-         * 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);
-        DetectionStatus[] getFingerStatus(uint handIndex);
-        DetectionStatus getHandStatus(uint handIndex);
-        Vector[] getFingerTipPositions3D(uint handIndex);
-        Vector[] getFingerTipPositions2D(uint handIndex);
-        HandSide getHandSide(uint handIndex);
-        void createVertexArray();
-        
-        //TODO: implement properly
-        void setVertexBuffer(IntPtr vertexBuffer);
-    }
-}
+using System;
+
+using MathNet.Numerics.LinearAlgebra.Single;
+
+namespace bbiwarg.DataSource
+{
+    public enum DetectionStatus
+    {
+        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();
+        float getHFOV();
+        float getVFOV();
+        /**
+         * The depth is given by the distance to the camera in millimeters. 
+         */
+        DepthImage getDepthImage();
+        ColorImage getColorImage();
+        ConfidenceImage getConfidenceImage();
+        UVImage getUVImage();
+        ImageData getImageData();
+        /*
+         * 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);
+        DetectionStatus[] getFingerStatus(uint handIndex);
+        DetectionStatus getHandStatus(uint handIndex);
+        Vector[] getFingerTipPositions3D(uint handIndex);
+        Vector[] getFingerTipPositions2D(uint handIndex);
+        HandSide getHandSide(uint handIndex);
+        void createVertexArray();
+        
+        //TODO: implement properly
+        void setVertexBuffer(IntPtr vertexBuffer);
+    }
+}

+ 1 - 1
bbiwarg/DataSource/VectorExtender.cs → bbiwarg/Helpers/VectorExtender.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 using MathNet.Numerics.LinearAlgebra.Single;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.Helpers
 {
     public static class VectorExtender
     {

+ 1 - 1
bbiwarg/DataSource/VertexArray.cs → bbiwarg/Helpers/VertexArray.cs

@@ -8,7 +8,7 @@ using bbiwarg.Graphics;
 
 using MathNet.Numerics.LinearAlgebra.Single;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.Helpers
 {
     class VertexArray
     {

+ 1 - 1
bbiwarg/DataSource/ColorImage.cs → bbiwarg/Images/ColorImage.cs

@@ -5,7 +5,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Drawing;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.Images
 {
     class ColorImage
     {

+ 1 - 1
bbiwarg/DataSource/ConfidenceImage.cs → bbiwarg/Images/ConfidenceImage.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.Images
 {
     /**
      * Represents an confidence image where the depth is given in distance to the camera in millimeters. 

+ 1 - 1
bbiwarg/DataSource/DepthImage.cs → bbiwarg/Images/DepthImage.cs

@@ -10,7 +10,7 @@ using System.Drawing;
 using Emgu.CV;
 using Emgu.CV.Structure;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.Images
 {
     /**
      * Represents an depth image where the depth is given in distance to the camera in millimeters. 

+ 1 - 1
bbiwarg/DataSource/UVImage.cs → bbiwarg/Images/UVImage.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.Images
 {
     class UVImage
     {

+ 16 - 2
bbiwarg/DataSource/IInputProvider.cs → bbiwarg/InputProvider/IInputProvider.cs

@@ -3,11 +3,25 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-
 using MathNet.Numerics.LinearAlgebra.Single;
+using bbiwarg.Images;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.InputProviders
 {
+    public enum DetectionStatus
+    {
+        Inactive,
+        Detected,
+        Tracked
+    }
+
+    public enum HandSide
+    {
+        Unknown,
+        Left,
+        Right
+    }
+
     interface IInputProvider
     {
         void init();

+ 378 - 378
bbiwarg/DataSource/IisuInputProvider.cs → bbiwarg/InputProvider/IisuInputProvider.cs

@@ -1,379 +1,379 @@
-using System;
-using System.Drawing;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using Iisu;
-using MathNet.Numerics.LinearAlgebra.Single;
-using bbiwarg.Graphics;
-
-namespace bbiwarg.DataSource
-{
-    class IisuInputProvider : IInputProvider
-    {
-        private IHandle handle;
-        private IDevice device;
-        private string moviePath;
-        private bool active;
-        private bool sourceIsMovie;
-
-        //parameters
-        private IParameterHandle<float> frameRate;
-        private IParameterHandle<float> hfov;
-        private IParameterHandle<float> vfov;
-        private int confidenceThreshold;
-
-        //data
-        private IDataHandle<int>[] handStatus = new IDataHandle<int>[2];
-        private IDataHandle<bool>[] handOpen = new IDataHandle<bool>[2];
-        private IDataHandle<int>[] handSides = new IDataHandle<int>[2];
-        private IDataHandle<int[]>[] fingerStatus = new IDataHandle<int[]>[2];
-        private IDataHandle<Iisu.Data.Vector3>[] palmPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
-        private IDataHandle<Iisu.Data.Vector2>[] palmPositions2D = new IDataHandle<Iisu.Data.Vector2>[2];
-        private IDataHandle<Iisu.Data.Vector3>[] tipPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
-        private IDataHandle<Iisu.Data.Vector3>[] forearmPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
-        private IDataHandle<Iisu.Data.Vector3>[] palmNormals3D = new IDataHandle<Iisu.Data.Vector3>[2];
-        private IDataHandle<Iisu.Data.Vector3[]>[] fingerTipPositions3D = new IDataHandle<Iisu.Data.Vector3[]>[2];
-        private IDataHandle<Iisu.Data.Vector2[]>[] fingerTipPositions2D = new IDataHandle<Iisu.Data.Vector2[]>[2];
-        private IDataHandle<Iisu.Data.IImageData> depthImage;
-        private IDataHandle<Iisu.Data.IImageData> confidenceImage;
-        private IDataHandle<Iisu.Data.IImageData> uvImage;
-        private IDataHandle<Iisu.Data.IImageData> colorImage;
-
-        public IisuInputProvider(String moviePath = "") 
-        {
-            if (moviePath.Length != 0)
-            {
-                this.moviePath = moviePath;
-                sourceIsMovie = true;
-            }
-            else
-            {
-                sourceIsMovie = false;
-            }
-            active = false;
-            confidenceThreshold = 100;
-        }
-
-        // control-methodes
-
-        public void init()
-        {
-            handle = Iisu.Iisu.Context.CreateHandle();
-
-            IDeviceConfiguration conf = handle.CreateDeviceConfiguration();
-            if (sourceIsMovie)
-                conf.MoviePath = moviePath;
-
-            device = handle.InitializeDevice(conf);
-
-            // parameters
-            if (sourceIsMovie)
-            {
-                //device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 0; // playMode = once
-                device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 1; // playMode = loop
-                //device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 2; // playMode = ping-pong
-            }
-            else
-            {
-                device.RegisterParameterHandle<int>("SOURCE.DEPTHSENSE.AmplitudeThreshold").Value = confidenceThreshold; // confidence-threshhold
-            }
-
-            frameRate = device.RegisterParameterHandle<float>("SOURCE.FrameRate");
-            hfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.HFOV");
-            vfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.VFOV");
-
-            // events
-            device.EventManager.RegisterEventListener("DEVICE.Status", new Iisu.EventDelegates.Device.Status(onDeviceStatusChanged));
-
-            // data
-            handStatus[0] = device.RegisterDataHandle<int>("CI.HAND1.Status");
-            handStatus[1] = device.RegisterDataHandle<int>("CI.HAND2.Status");
-
-            handOpen[0] = device.RegisterDataHandle<bool>("CI.HAND1.IsOpen");
-            handOpen[1] = device.RegisterDataHandle<bool>("CI.HAND2.IsOpen");
-
-            handSides[0] = device.RegisterDataHandle<int>("CI.HAND1.Side");
-            handSides[1] = device.RegisterDataHandle<int>("CI.HAND1.Side");
-            
-            fingerStatus[0] = device.RegisterDataHandle<int[]>("CI.HAND1.FingerStatus");
-            fingerStatus[1] = device.RegisterDataHandle<int[]>("CI.HAND2.FingerStatus");
-
-            palmPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.PalmPosition3D");
-            palmPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.PalmPosition3D");
-
-            palmPositions2D[0] = device.RegisterDataHandle<Iisu.Data.Vector2>("CI.HAND1.PalmPosition2D");
-            palmPositions2D[1] = device.RegisterDataHandle<Iisu.Data.Vector2>("CI.HAND2.PalmPosition2D");
-
-            tipPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.TipPosition3D");
-            tipPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.TipPosition3D");
-
-            forearmPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.ForearmPosition3D");
-            forearmPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.ForearmPosition3D");
-
-            palmNormals3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.PalmNormal3D");
-            palmNormals3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.PalmNormal3D");
-
-            fingerTipPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3[]>("CI.HAND1.FingerTipPositions3D");
-            fingerTipPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3[]>("CI.HAND2.FingerTipPositions3D");
-
-            fingerTipPositions2D[0] = device.RegisterDataHandle<Iisu.Data.Vector2[]>("CI.HAND1.FingerTipPositions2D");
-            fingerTipPositions2D[1] = device.RegisterDataHandle<Iisu.Data.Vector2[]>("CI.HAND2.FingerTipPositions2D");
-            
-            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");
-        }
-
-        private void onDeviceStatusChanged(string eventName, DeviceStatus status)
-        {
-            active = status.HasFlag(Iisu.DeviceStatus.Playing);
-        }
-
-        public void start()
-        {
-            device.Start();
-        }
-
-        public void stop()
-        {
-            device.Stop(true);
-        }
-
-        public void updateFrame()
-        {
-            device.UpdateFrame(true);
-        }
-
-        public void releaseFrame()
-        {
-            device.ReleaseFrame();
-        }
-
-        // Parameter-methodes
-
-        public float getFrameRate()
-        {
-            return frameRate.Value;
-        }
-
-        public float getHFOV()
-        {
-            return hfov.Value;
-        }
-
-        public float getVFOV()
-        {
-            return vfov.Value;
-        }
-
-        public int getConfidenceThreshold()
-        {
-            return confidenceThreshold;
-        }
-
-        public void setConfidenceThreshold(int value)
-        {
-            confidenceThreshold = value;
-        }
-
-        public bool isActive()
-        {
-            return active;
-        }
-
-
-        // Data-methodes
-        public DetectionStatus getHandStatus(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            int status = handStatus[handIndex - 1].Value;
-            DetectionStatus result = new DetectionStatus();
-            switch (status)
-            {
-                case 0:
-                    result = DetectionStatus.Inactive;
-                    break;
-                case 1:
-                    result = DetectionStatus.Detected;
-                    break;
-                case 2:
-                    result = DetectionStatus.Tracked;
-                    break;
-            }
-            return result;
-        }
-
-        public bool isHandOpen(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return handOpen[handIndex - 1].Value;
-        }
-
-        public HandSide getHandSide(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            int side = handSides[handIndex - 1].Value;
-            switch (side)
-            {
-                case 1:
-                    return HandSide.Left;
-                case 2:
-                    return HandSide.Right;
-                default:
-                    return HandSide.Unknown;
-            }
-        }
-
-        public DetectionStatus[] getFingerStatus(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            int[] status = fingerStatus[handIndex - 1].Value;
-            DetectionStatus[] result = new DetectionStatus[status.Length];
-            for (int i = 0; i < status.Length; ++i)
-            {
-                switch (status[i])
-                {
-                    case 0:
-                        result[i] = DetectionStatus.Inactive;
-                        break;
-                    case 1:
-                        result[i] = DetectionStatus.Detected;
-                        break;
-                    case 2:
-                        result[i] = DetectionStatus.Tracked;
-                        break;
-                }
-            }
-            return result;
-        }
-
-        public Vector getPalmPosition3D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return new DenseVector(swapXZYtoXYZ(palmPositions3D[handIndex - 1].Value.ToArray()));
-        }
-
-        public Vector getPalmPosition2D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return new DenseVector(palmPositions2D[handIndex - 1].Value.ToArray());
-        }
-
-        public Vector getTipPosition3D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return new DenseVector(swapXZYtoXYZ(tipPositions3D[handIndex - 1].Value.ToArray()));
-        }
-
-        public Vector getForearmPosition3D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return new DenseVector(swapXZYtoXYZ(forearmPositions3D[handIndex - 1].Value.ToArray()));
-        }
-
-        public Vector getPalmNormal3D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return new DenseVector(swapXZYtoXYZ(palmNormals3D[handIndex - 1].Value.ToArray()));
-        }
-
-        public Vector[] getFingerTipPositions3D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            Iisu.Data.Vector3[] positions = fingerTipPositions3D[handIndex - 1].Value;
-            Vector[] results = new DenseVector[positions.Length];
-            for (int i = 0; i < positions.Length; ++i)
-                results[i] = new DenseVector(swapXZYtoXYZ(positions[i].ToArray()));
-            return results;
-        }
-
-        public Vector[] getFingerTipPositions2D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            Iisu.Data.Vector2[] positions = fingerTipPositions2D[handIndex - 1].Value;
-            Vector[] results = new DenseVector[positions.Length];
-            for (int i = 0; i < positions.Length; ++i)
-                results[i] = new DenseVector(positions[i].ToArray());
-            return results;
-        }
-
-
-        public DepthImage getDepthImage()
-        {
-            Iisu.Data.IImageInfos imageInfos = depthImage.Value.ImageInfos;
-            int width = (int)imageInfos.Width;
-            int height = (int)imageInfos.Height;
-            int numBytes = (int)imageInfos.BytesRaw;
-
-            IntPtr imageData = depthImage.Value.Raw;
-
-            short[] depthData = new short[width * height];
-            Marshal.Copy(imageData, depthData, 0, width * height);
-
-            return new DepthImage(width, height, depthData);
-        }
-
-        public ConfidenceImage getConfidenceImage()
-        {
-            Iisu.Data.IImageInfos imageInfos = confidenceImage.Value.ImageInfos;
-            int width = (int)imageInfos.Width;
-            int height = (int)imageInfos.Height;
-            int numBytes = (int)imageInfos.BytesRaw;
-
-            IntPtr imageData = confidenceImage.Value.Raw;
-
-            short[] confidenceData = new short[width * height];
-            Marshal.Copy(imageData, confidenceData, 0, width * height);
-
-            return new ConfidenceImage(width, height, confidenceData);
-        }
-
-        public UVImage getUVImage()
-        {
-            Iisu.Data.IImageInfos imageInfos = uvImage.Value.ImageInfos;
-            int width = (int)imageInfos.Width;
-            int height = (int)imageInfos.Height;
-            int numBytes = (int)imageInfos.BytesRaw;
-
-            IntPtr imageData = uvImage.Value.Raw;
-
-            float[] uvData = new float[2 * width * height];
-            Marshal.Copy(imageData, uvData, 0, 2 * width * height);
-
-            return new UVImage(width, height, uvData);
-        }
-
-        public ColorImage getColorImage()
-        {
-            Iisu.Data.IImageInfos imageInfos = colorImage.Value.ImageInfos;
-            int width = (int)imageInfos.Width;
-            int height = (int)imageInfos.Height;
-            int numBytes = (int)imageInfos.BytesRaw;
-
-            IntPtr imageData = colorImage.Value.Raw;
-
-            byte[] colorData = new byte[numBytes];
-            Marshal.Copy(imageData, colorData, 0, numBytes);
-
-            return new ColorImage(width, height, colorData);
-        }
-
-        // other
-
-        private void checkHandIndex(uint handIndex)
-        {
-            if (handIndex < 1 || handIndex > 2)
-                throw new ArgumentOutOfRangeException("handIndex is out of range [0,1]");
-        }
-
-        private float[] swapXZYtoXYZ(float[] vector) 
-        {
-            float dummy = vector[1];
-            vector[1] = vector[2];
-            vector[2] = dummy;
-            return vector;
-        }
-
-    }
+using System;
+using System.Drawing;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using Iisu;
+using MathNet.Numerics.LinearAlgebra.Single;
+using bbiwarg.Images;
+
+namespace bbiwarg.InputProviders
+{
+    class IisuInputProvider : IInputProvider
+    {
+        private IHandle handle;
+        private IDevice device;
+        private string moviePath;
+        private bool active;
+        private bool sourceIsMovie;
+
+        //parameters
+        private IParameterHandle<float> frameRate;
+        private IParameterHandle<float> hfov;
+        private IParameterHandle<float> vfov;
+        private int confidenceThreshold;
+
+        //data
+        private IDataHandle<int>[] handStatus = new IDataHandle<int>[2];
+        private IDataHandle<bool>[] handOpen = new IDataHandle<bool>[2];
+        private IDataHandle<int>[] handSides = new IDataHandle<int>[2];
+        private IDataHandle<int[]>[] fingerStatus = new IDataHandle<int[]>[2];
+        private IDataHandle<Iisu.Data.Vector3>[] palmPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
+        private IDataHandle<Iisu.Data.Vector2>[] palmPositions2D = new IDataHandle<Iisu.Data.Vector2>[2];
+        private IDataHandle<Iisu.Data.Vector3>[] tipPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
+        private IDataHandle<Iisu.Data.Vector3>[] forearmPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
+        private IDataHandle<Iisu.Data.Vector3>[] palmNormals3D = new IDataHandle<Iisu.Data.Vector3>[2];
+        private IDataHandle<Iisu.Data.Vector3[]>[] fingerTipPositions3D = new IDataHandle<Iisu.Data.Vector3[]>[2];
+        private IDataHandle<Iisu.Data.Vector2[]>[] fingerTipPositions2D = new IDataHandle<Iisu.Data.Vector2[]>[2];
+        private IDataHandle<Iisu.Data.IImageData> depthImage;
+        private IDataHandle<Iisu.Data.IImageData> confidenceImage;
+        private IDataHandle<Iisu.Data.IImageData> uvImage;
+        private IDataHandle<Iisu.Data.IImageData> colorImage;
+
+        public IisuInputProvider(String moviePath = "") 
+        {
+            if (moviePath.Length != 0)
+            {
+                this.moviePath = moviePath;
+                sourceIsMovie = true;
+            }
+            else
+            {
+                sourceIsMovie = false;
+            }
+            active = false;
+            confidenceThreshold = 100;
+        }
+
+        // control-methodes
+
+        public void init()
+        {
+            handle = Iisu.Iisu.Context.CreateHandle();
+
+            IDeviceConfiguration conf = handle.CreateDeviceConfiguration();
+            if (sourceIsMovie)
+                conf.MoviePath = moviePath;
+
+            device = handle.InitializeDevice(conf);
+
+            // parameters
+            if (sourceIsMovie)
+            {
+                //device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 0; // playMode = once
+                device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 1; // playMode = loop
+                //device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 2; // playMode = ping-pong
+            }
+            else
+            {
+                device.RegisterParameterHandle<int>("SOURCE.DEPTHSENSE.AmplitudeThreshold").Value = confidenceThreshold; // confidence-threshhold
+            }
+
+            frameRate = device.RegisterParameterHandle<float>("SOURCE.FrameRate");
+            hfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.HFOV");
+            vfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.VFOV");
+
+            // events
+            device.EventManager.RegisterEventListener("DEVICE.Status", new Iisu.EventDelegates.Device.Status(onDeviceStatusChanged));
+
+            // data
+            handStatus[0] = device.RegisterDataHandle<int>("CI.HAND1.Status");
+            handStatus[1] = device.RegisterDataHandle<int>("CI.HAND2.Status");
+
+            handOpen[0] = device.RegisterDataHandle<bool>("CI.HAND1.IsOpen");
+            handOpen[1] = device.RegisterDataHandle<bool>("CI.HAND2.IsOpen");
+
+            handSides[0] = device.RegisterDataHandle<int>("CI.HAND1.Side");
+            handSides[1] = device.RegisterDataHandle<int>("CI.HAND1.Side");
+            
+            fingerStatus[0] = device.RegisterDataHandle<int[]>("CI.HAND1.FingerStatus");
+            fingerStatus[1] = device.RegisterDataHandle<int[]>("CI.HAND2.FingerStatus");
+
+            palmPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.PalmPosition3D");
+            palmPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.PalmPosition3D");
+
+            palmPositions2D[0] = device.RegisterDataHandle<Iisu.Data.Vector2>("CI.HAND1.PalmPosition2D");
+            palmPositions2D[1] = device.RegisterDataHandle<Iisu.Data.Vector2>("CI.HAND2.PalmPosition2D");
+
+            tipPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.TipPosition3D");
+            tipPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.TipPosition3D");
+
+            forearmPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.ForearmPosition3D");
+            forearmPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.ForearmPosition3D");
+
+            palmNormals3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.PalmNormal3D");
+            palmNormals3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.PalmNormal3D");
+
+            fingerTipPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3[]>("CI.HAND1.FingerTipPositions3D");
+            fingerTipPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3[]>("CI.HAND2.FingerTipPositions3D");
+
+            fingerTipPositions2D[0] = device.RegisterDataHandle<Iisu.Data.Vector2[]>("CI.HAND1.FingerTipPositions2D");
+            fingerTipPositions2D[1] = device.RegisterDataHandle<Iisu.Data.Vector2[]>("CI.HAND2.FingerTipPositions2D");
+            
+            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");
+        }
+
+        private void onDeviceStatusChanged(string eventName, DeviceStatus status)
+        {
+            active = status.HasFlag(Iisu.DeviceStatus.Playing);
+        }
+
+        public void start()
+        {
+            device.Start();
+        }
+
+        public void stop()
+        {
+            device.Stop(true);
+        }
+
+        public void updateFrame()
+        {
+            device.UpdateFrame(true);
+        }
+
+        public void releaseFrame()
+        {
+            device.ReleaseFrame();
+        }
+
+        // Parameter-methodes
+
+        public float getFrameRate()
+        {
+            return frameRate.Value;
+        }
+
+        public float getHFOV()
+        {
+            return hfov.Value;
+        }
+
+        public float getVFOV()
+        {
+            return vfov.Value;
+        }
+
+        public int getConfidenceThreshold()
+        {
+            return confidenceThreshold;
+        }
+
+        public void setConfidenceThreshold(int value)
+        {
+            confidenceThreshold = value;
+        }
+
+        public bool isActive()
+        {
+            return active;
+        }
+
+
+        // Data-methodes
+        public DetectionStatus getHandStatus(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            int status = handStatus[handIndex - 1].Value;
+            DetectionStatus result = new DetectionStatus();
+            switch (status)
+            {
+                case 0:
+                    result = DetectionStatus.Inactive;
+                    break;
+                case 1:
+                    result = DetectionStatus.Detected;
+                    break;
+                case 2:
+                    result = DetectionStatus.Tracked;
+                    break;
+            }
+            return result;
+        }
+
+        public bool isHandOpen(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return handOpen[handIndex - 1].Value;
+        }
+
+        public HandSide getHandSide(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            int side = handSides[handIndex - 1].Value;
+            switch (side)
+            {
+                case 1:
+                    return HandSide.Left;
+                case 2:
+                    return HandSide.Right;
+                default:
+                    return HandSide.Unknown;
+            }
+        }
+
+        public DetectionStatus[] getFingerStatus(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            int[] status = fingerStatus[handIndex - 1].Value;
+            DetectionStatus[] result = new DetectionStatus[status.Length];
+            for (int i = 0; i < status.Length; ++i)
+            {
+                switch (status[i])
+                {
+                    case 0:
+                        result[i] = DetectionStatus.Inactive;
+                        break;
+                    case 1:
+                        result[i] = DetectionStatus.Detected;
+                        break;
+                    case 2:
+                        result[i] = DetectionStatus.Tracked;
+                        break;
+                }
+            }
+            return result;
+        }
+
+        public Vector getPalmPosition3D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return new DenseVector(swapXZYtoXYZ(palmPositions3D[handIndex - 1].Value.ToArray()));
+        }
+
+        public Vector getPalmPosition2D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return new DenseVector(palmPositions2D[handIndex - 1].Value.ToArray());
+        }
+
+        public Vector getTipPosition3D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return new DenseVector(swapXZYtoXYZ(tipPositions3D[handIndex - 1].Value.ToArray()));
+        }
+
+        public Vector getForearmPosition3D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return new DenseVector(swapXZYtoXYZ(forearmPositions3D[handIndex - 1].Value.ToArray()));
+        }
+
+        public Vector getPalmNormal3D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return new DenseVector(swapXZYtoXYZ(palmNormals3D[handIndex - 1].Value.ToArray()));
+        }
+
+        public Vector[] getFingerTipPositions3D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            Iisu.Data.Vector3[] positions = fingerTipPositions3D[handIndex - 1].Value;
+            Vector[] results = new DenseVector[positions.Length];
+            for (int i = 0; i < positions.Length; ++i)
+                results[i] = new DenseVector(swapXZYtoXYZ(positions[i].ToArray()));
+            return results;
+        }
+
+        public Vector[] getFingerTipPositions2D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            Iisu.Data.Vector2[] positions = fingerTipPositions2D[handIndex - 1].Value;
+            Vector[] results = new DenseVector[positions.Length];
+            for (int i = 0; i < positions.Length; ++i)
+                results[i] = new DenseVector(positions[i].ToArray());
+            return results;
+        }
+
+
+        public DepthImage getDepthImage()
+        {
+            Iisu.Data.IImageInfos imageInfos = depthImage.Value.ImageInfos;
+            int width = (int)imageInfos.Width;
+            int height = (int)imageInfos.Height;
+            int numBytes = (int)imageInfos.BytesRaw;
+
+            IntPtr imageData = depthImage.Value.Raw;
+
+            short[] depthData = new short[width * height];
+            Marshal.Copy(imageData, depthData, 0, width * height);
+
+            return new DepthImage(width, height, depthData);
+        }
+
+        public ConfidenceImage getConfidenceImage()
+        {
+            Iisu.Data.IImageInfos imageInfos = confidenceImage.Value.ImageInfos;
+            int width = (int)imageInfos.Width;
+            int height = (int)imageInfos.Height;
+            int numBytes = (int)imageInfos.BytesRaw;
+
+            IntPtr imageData = confidenceImage.Value.Raw;
+
+            short[] confidenceData = new short[width * height];
+            Marshal.Copy(imageData, confidenceData, 0, width * height);
+
+            return new ConfidenceImage(width, height, confidenceData);
+        }
+
+        public UVImage getUVImage()
+        {
+            Iisu.Data.IImageInfos imageInfos = uvImage.Value.ImageInfos;
+            int width = (int)imageInfos.Width;
+            int height = (int)imageInfos.Height;
+            int numBytes = (int)imageInfos.BytesRaw;
+
+            IntPtr imageData = uvImage.Value.Raw;
+
+            float[] uvData = new float[2 * width * height];
+            Marshal.Copy(imageData, uvData, 0, 2 * width * height);
+
+            return new UVImage(width, height, uvData);
+        }
+
+        public ColorImage getColorImage()
+        {
+            Iisu.Data.IImageInfos imageInfos = colorImage.Value.ImageInfos;
+            int width = (int)imageInfos.Width;
+            int height = (int)imageInfos.Height;
+            int numBytes = (int)imageInfos.BytesRaw;
+
+            IntPtr imageData = colorImage.Value.Raw;
+
+            byte[] colorData = new byte[numBytes];
+            Marshal.Copy(imageData, colorData, 0, numBytes);
+
+            return new ColorImage(width, height, colorData);
+        }
+
+        // other
+
+        private void checkHandIndex(uint handIndex)
+        {
+            if (handIndex < 1 || handIndex > 2)
+                throw new ArgumentOutOfRangeException("handIndex is out of range [0,1]");
+        }
+
+        private float[] swapXZYtoXYZ(float[] vector) 
+        {
+            float dummy = vector[1];
+            vector[1] = vector[2];
+            vector[2] = dummy;
+            return vector;
+        }
+
+    }
 }

+ 2 - 1
bbiwarg/Main/OutputTest.cs

@@ -3,8 +3,9 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using bbiwarg.DataSource;
 using bbiwarg.Graphics;
+using bbiwarg.InputProviders;
+using bbiwarg.VideoHandles;
 
 namespace bbiwarg.Main
 {

+ 3 - 15
bbiwarg/DataSource/IVideoHandle.cs → bbiwarg/VideoHandle/IVideoHandle.cs

@@ -2,23 +2,11 @@
 using System.Collections.Generic;
 using System.Drawing;
 using MathNet.Numerics.LinearAlgebra.Single;
+using bbiwarg.Detectors;
+using bbiwarg.InputProviders;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.VideoHandles
 {
-    public enum DetectionStatus
-    {
-        Inactive,
-        Detected,
-        Tracked
-    }
-
-    public enum HandSide
-    {
-        Unknown,
-        Left,
-        Right
-    }
-
     interface IVideoHandle
     {
         void nextFrame();

+ 4 - 2
bbiwarg/DataSource/VideoHandle.cs → bbiwarg/VideoHandle/VideoHandle.cs

@@ -5,9 +5,11 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using MathNet.Numerics.LinearAlgebra.Single;
-using bbiwarg.Graphics;
+using bbiwarg.Images;
+using bbiwarg.InputProviders;
+using bbiwarg.Detectors;
 
-namespace bbiwarg.DataSource
+namespace bbiwarg.VideoHandles
 {
     class VideoHandle : IVideoHandle
     {

+ 14 - 14
bbiwarg/bbiwarg.csproj

@@ -66,20 +66,20 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="DataSource\CollisionDetection.cs" />
-    <Compile Include="DataSource\ForeFingerDetection.cs" />
-    <Compile Include="DataSource\IInputProvider.cs" />
-    <Compile Include="DataSource\Palm.cs" />
-    <Compile Include="DataSource\PalmDetection.cs" />
-    <Compile Include="DataSource\UVImage.cs" />
-    <Compile Include="DataSource\ColorImage.cs" />
-    <Compile Include="DataSource\ConfidenceImage.cs" />
-    <Compile Include="DataSource\DepthImage.cs" />
-    <Compile Include="DataSource\IisuInputProvider.cs" />
-    <Compile Include="DataSource\IVideoHandle.cs" />
-    <Compile Include="DataSource\VectorExtender.cs" />
-    <Compile Include="DataSource\VertexArray.cs" />
-    <Compile Include="DataSource\VideoHandle.cs" />
+    <Compile Include="Detectors\CollisionDetection.cs" />
+    <Compile Include="Detectors\ForeFingerDetection.cs" />
+    <Compile Include="InputProvider\IInputProvider.cs" />
+    <Compile Include="Detectors\Palm.cs" />
+    <Compile Include="Detectors\PalmDetection.cs" />
+    <Compile Include="Images\UVImage.cs" />
+    <Compile Include="Images\ColorImage.cs" />
+    <Compile Include="Images\ConfidenceImage.cs" />
+    <Compile Include="Images\DepthImage.cs" />
+    <Compile Include="InputProvider\IisuInputProvider.cs" />
+    <Compile Include="VideoHandle\IVideoHandle.cs" />
+    <Compile Include="Helpers\VectorExtender.cs" />
+    <Compile Include="Helpers\VertexArray.cs" />
+    <Compile Include="VideoHandle\VideoHandle.cs" />
     <Compile Include="Graphics\GraphicElements2D\IGraphicElement2D.cs" />
     <Compile Include="Graphics\GraphicElements2D\Point2D.cs" />
     <Compile Include="Graphics\Output2D.cs" />