|
@@ -1,8 +1,9 @@
|
|
|
using System;
|
|
|
+using System.Drawing;
|
|
|
using System.Runtime.InteropServices;
|
|
|
-
|
|
|
using Iisu;
|
|
|
using MathNet.Numerics.LinearAlgebra.Single;
|
|
|
+using bbiwarg.Graphics;
|
|
|
|
|
|
namespace bbiwarg.DataSource
|
|
|
{
|
|
@@ -35,6 +36,8 @@ namespace bbiwarg.DataSource
|
|
|
private IParameterHandle<float> hfov;
|
|
|
private IParameterHandle<float> vfov;
|
|
|
|
|
|
+ private ImageData currentImage;
|
|
|
+
|
|
|
/*
|
|
|
* Creates an Iisu data source.
|
|
|
* params:
|
|
@@ -118,6 +121,7 @@ namespace bbiwarg.DataSource
|
|
|
public void start()
|
|
|
{
|
|
|
device.Start();
|
|
|
+ updateFrame();
|
|
|
}
|
|
|
|
|
|
public void stop()
|
|
@@ -128,6 +132,7 @@ namespace bbiwarg.DataSource
|
|
|
public void updateFrame()
|
|
|
{
|
|
|
device.UpdateFrame(true);
|
|
|
+ createImageData();
|
|
|
}
|
|
|
|
|
|
public void releaseFrame()
|
|
@@ -215,7 +220,11 @@ namespace bbiwarg.DataSource
|
|
|
|
|
|
public ImageData getImageData()
|
|
|
{
|
|
|
- return new ImageData(getDepthImage(), getConfidenceImage(), getColorImage(), getUVImage());
|
|
|
+ return currentImage;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createImageData() {
|
|
|
+ currentImage = new ImageData(getDepthImage(), getConfidenceImage(), getColorImage(), getUVImage());
|
|
|
}
|
|
|
|
|
|
private void checkHandIndex(uint handIndex)
|
|
@@ -337,5 +346,49 @@ namespace bbiwarg.DataSource
|
|
|
return HandSide.Unknown;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public VertexArray getVertexArray()
|
|
|
+ {
|
|
|
+ int width = currentImage.getWidth();
|
|
|
+ int height = currentImage.getHeight();
|
|
|
+
|
|
|
+ Vertex[] vertices = new Vertex[width * height];
|
|
|
+ Color[] colors = new Color[width * height];
|
|
|
+
|
|
|
+
|
|
|
+ int index = 0;
|
|
|
+ for (int x = 0; x < width; x++)
|
|
|
+ {
|
|
|
+ for (int y = 0; y < height; y++)
|
|
|
+ {
|
|
|
+ int depth = currentImage.getDepth(x, y);
|
|
|
+ vertices[index] = create3DVertexFrom2D(x, y, depth);
|
|
|
+ colors[index] = currentImage.getColor(x, y);
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new VertexArray(vertices, colors);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Vertex create3DVertexFrom2D(float pixelX, float pixelY, int depth)
|
|
|
+ {
|
|
|
+ int width = currentImage.getWidth();
|
|
|
+ int height = currentImage.getHeight();
|
|
|
+ float alphaX = hfov.Value;
|
|
|
+ float alphaY = vfov.Value;
|
|
|
+ float convertedDepth = depth / 1000f; // mm into m
|
|
|
+
|
|
|
+ float u = (pixelX / (float)width - 0.5f) * 2f;
|
|
|
+ float v = ((1 - pixelY / (float)height) - 0.5f) * 2f;
|
|
|
+
|
|
|
+ float relX = (float)(u * Math.Tan(alphaX / 2f));
|
|
|
+ float relY = (float)(v * Math.Tan(alphaY / 2f));
|
|
|
+
|
|
|
+ float z = (float)(convertedDepth / Math.Sqrt(1 + relX * relX + relY * relY));
|
|
|
+ float x = relX * z;
|
|
|
+ float y = relY * z;
|
|
|
+
|
|
|
+ return new Vertex(x, y, z );
|
|
|
+ }
|
|
|
}
|
|
|
}
|