|
@@ -109,22 +109,34 @@ namespace bbiwarg.DataSource
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void create3DVertexFrom2D(float pixelX, float pixelY, int depth, Color c, int index, IntPtr vertexBuffer)
|
|
|
|
|
|
+ public Vector pixel2VertexPosition(Vector pixelPosition)
|
|
{
|
|
{
|
|
int width = depthImage.getWidth();
|
|
int width = depthImage.getWidth();
|
|
int height = depthImage.getHeight();
|
|
int height = depthImage.getHeight();
|
|
|
|
|
|
- float convertedDepth = depth / 1000f; // mm into m
|
|
|
|
|
|
+ float convertedDepth = pixelPosition[2] / 1000f; // mm into m
|
|
|
|
|
|
- float u = (pixelX / (float)width - 0.5f) * 2f;
|
|
|
|
- float v = ((1 - pixelY / (float)height) - 0.5f) * 2f;
|
|
|
|
|
|
+ float u = (pixelPosition[0] / (float)width - 0.5f) * 2f;
|
|
|
|
+ float v = ((1 - pixelPosition[1] / (float)height) - 0.5f) * 2f;
|
|
|
|
|
|
float relX = (u * maxU);
|
|
float relX = (u * maxU);
|
|
float relY = (v * maxV);
|
|
float relY = (v * maxV);
|
|
|
|
|
|
- float z = convertedDepth / (float)Math.Sqrt(1 + relX * relX + relY * relY);
|
|
|
|
- float x = relX * z;
|
|
|
|
- float y = relY * z;
|
|
|
|
|
|
+ Vector result = new DenseVector(3);
|
|
|
|
+ result[2] = -convertedDepth / (float)Math.Sqrt(1 + relX * relX + relY * relY);
|
|
|
|
+ result[0] = -relX * result[2];
|
|
|
|
+ result[1] = -relY * result[2];
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ private void create3DVertexFrom2D(float pixelX, float pixelY, int depth, Color c, int index, IntPtr vertexBuffer)
|
|
|
|
+ {
|
|
|
|
+ Vector pixelPosition = new DenseVector(3);
|
|
|
|
+ pixelPosition[0] = pixelX;
|
|
|
|
+ pixelPosition[1] = pixelY;
|
|
|
|
+ pixelPosition[2] = depth;
|
|
|
|
+ Vector vertexPosition = pixel2VertexPosition(pixelPosition);
|
|
|
|
+
|
|
|
|
|
|
int i4 = (3 * sizeof(float) + 4 * sizeof(byte)) / sizeof(float) * index;
|
|
int i4 = (3 * sizeof(float) + 4 * sizeof(byte)) / sizeof(float) * index;
|
|
int i16 = (3 * sizeof(float) + 4 * sizeof(byte)) * index;
|
|
int i16 = (3 * sizeof(float) + 4 * sizeof(byte)) * index;
|
|
@@ -133,9 +145,9 @@ namespace bbiwarg.DataSource
|
|
byte* vertexArrayB = (byte*)vertexBuffer.ToPointer();
|
|
byte* vertexArrayB = (byte*)vertexBuffer.ToPointer();
|
|
float* vertexArrayF = (float*)vertexBuffer.ToPointer();
|
|
float* vertexArrayF = (float*)vertexBuffer.ToPointer();
|
|
|
|
|
|
- vertexArrayF[i4 + 0] = x;
|
|
|
|
- vertexArrayF[i4 + 1] = y;
|
|
|
|
- vertexArrayF[i4 + 2] = -z;
|
|
|
|
|
|
+ vertexArrayF[i4 + 0] = vertexPosition[0];
|
|
|
|
+ vertexArrayF[i4 + 1] = vertexPosition[1];
|
|
|
|
+ vertexArrayF[i4 + 2] = vertexPosition[2];
|
|
|
|
|
|
vertexArrayB[i16 + 12] = c.R;
|
|
vertexArrayB[i16 + 12] = c.R;
|
|
vertexArrayB[i16 + 13] = c.G;
|
|
vertexArrayB[i16 + 13] = c.G;
|