浏览代码

changed 3dto2d conversion to floats

Alexander Hendrich 11 年之前
父节点
当前提交
6b366ca554
共有 1 个文件被更改,包括 18 次插入9 次删除
  1. 18 9
      bbiwarg/DataSource/IisuDataSource.cs

+ 18 - 9
bbiwarg/DataSource/IisuDataSource.cs

@@ -38,8 +38,8 @@ namespace bbiwarg.DataSource
         private IParameterHandle<float> vfov;
 
         private ImageData currentImage;
-        private double maxU;
-        private double maxV;
+        private float maxU;
+        private float maxV;
         private int width;
         private int height;
 
@@ -74,8 +74,8 @@ namespace bbiwarg.DataSource
             frameRate = device.RegisterParameterHandle<float>("SOURCE.FrameRate");
             hfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.HFOV");
             vfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.VFOV");
-            maxU = Math.Tan(hfov.Value / 2f);
-            maxV = Math.Tan(vfov.Value / 2f);
+            maxU = (float)Math.Tan(hfov.Value / 2f);
+            maxV = (float)Math.Tan(vfov.Value / 2f);
 
             // events
             device.EventManager.RegisterEventListener("DEVICE.Status", new Iisu.EventDelegates.Device.Status(onDeviceStatusChanged));
@@ -358,6 +358,9 @@ namespace bbiwarg.DataSource
 
         public VertexArray getVertexArray()
         {
+            Stopwatch sw = new Stopwatch();
+            sw.Start();
+
             Vertex[] vertices = new Vertex[width * height];
             Color[] colors = new Color[width * height];
 
@@ -369,10 +372,16 @@ namespace bbiwarg.DataSource
                     int depth = currentImage.getDepth(x, y);
                     vertices[index] = create3DVertexFrom2D(x, y, depth);
                     colors[index] = currentImage.getColor(x, y);
+
                     index++;
                 }
+
+
             }
 
+            sw.Stop();
+            Console.WriteLine(sw.ElapsedMilliseconds);
+
 
             return new VertexArray(vertices, colors);
         }
@@ -384,12 +393,12 @@ namespace bbiwarg.DataSource
             float u = (pixelX / (float)width - 0.5f) * 2f;
             float v = ((1 - pixelY / (float)height) - 0.5f) * 2f;
 
-            double relX = (u * maxU);
-            double relY = (v * maxV);
+            float relX = (u * maxU);
+            float relY = (v * maxV);
 
-            float z = (float)(convertedDepth / Math.Sqrt(1 + relX * relX + relY * relY));
-            float x = (float)(relX * z);
-            float y = (float)(relY * z);
+            float z = convertedDepth / (float)Math.Sqrt(1 + relX * relX + relY * relY);
+            float x = relX * z;
+            float y = relY * z;
 
             return new Vertex(x, y, z);
         }