Esempio n. 1
0
        public void RayIntersectVoxelGridPerformance()
        {
#if DEBUG
            // my laptop in High Performance mode
            const double minMillionRaysPerSec = 0.19;
            const double maxMillionRaysPerSec = 0.30;
#elif APPVEYOR_PERFORMANCE_MARGINS
            // AppVeyor build server
            const double minMillionRaysPerSec = 0.20;
            const double maxMillionRaysPerSec = 0.31;
#else
            // my laptop in High Performance mode
            const double minMillionRaysPerSec = 0.14;
            const double maxMillionRaysPerSec = 0.22;
#endif

            const int numRays       = 1000000;
            const int voxelGridSize = 32;

            var triList = new List <Triangle>();
            triList.Add(new Triangle(
                            new Vector(-0.5, -0.5, 0.001),
                            new Vector(0.5, 0.5, 0.001),
                            new Vector(-0.5, 0.5, 0.001),
                            Engine3D.Color.Cyan.ToARGB()));
            var voxels          = new VoxelGrid(voxelGridSize, "RayIntersectVoxelGridPerformance_voxels", "");
            int numFilledVoxels = TriMeshToVoxelGrid.Convert(triList, voxelGridSize, voxels);
            Assert.AreEqual(voxelGridSize * voxelGridSize, numFilledVoxels);

            var      numRaysHit = 0;
            DateTime startTime  = DateTime.Now;
            for (var i = 0; i < numRays; i++)
            {
                //var start = MakeRandomVector(-1, 1, -1, 1, -1, -0.5);
                var start = MakeRandomVector(-0.5, 0.5, -0.5, 0.5, -1, -0.5);
                var dir   = new Vector(0, 0, 1);

                //var start = MakeRandomVector(-2, 2, -2, 2, -2, 2);
                //var dir = MakeRandomVector(-1, 1, -1, 1, -1, 1);

                //var start = new Vector(0.5, 0.5, 0.5);
                //var start = MakeRandomVector(-0.3, 0.3, -0.3, 0.3, 0.5, 1);
                //var dir = MakeRandomVector(-0.5, 0.5, -0.5, 0.5, -1, -1);
                //var dir = MakeRandomVector(1, 1, -1);

                var info = voxels.IntersectRay(start, dir, context);
                if (info != null)
                {
                    numRaysHit++;
                }
            }
            var elapsedTime = DateTime.Now - startTime;
            // TODO: this should pass, but a bug in TriMeshToVoxelGrid.Convert makes this fail (930K)
            //Assert.IsTrue(numRays * 0.45 < numRaysHit && numRaysHit <= numRays * 0.55, "Num rays hit {0} should be roughly half of total rays {1}", numRaysHit, numRays);
            var millionRaysPerSec = numRays / 1000000.0 / elapsedTime.TotalSeconds;
            Assert.IsTrue(minMillionRaysPerSec < millionRaysPerSec && millionRaysPerSec < maxMillionRaysPerSec,
                          "Rays per second {0:f3} not between {1} and {2} (millions)", millionRaysPerSec, minMillionRaysPerSec, maxMillionRaysPerSec);
            Console.WriteLine("Performance: {0} million rays per second", millionRaysPerSec);
        }
Esempio n. 2
0
        public void BuildVoxelGridPerformance()
        {
#if DEBUG
            // my laptop in High Performance mode
            const double minMillionTriVoxelPerSec = 2.8;
            const double maxMillionTriVoxelPerSec = 4.0;
#elif APPVEYOR_PERFORMANCE_MARGINS
            // AppVeyor build server
            const double minMillionTriVoxelPerSec = 31.0;
            const double maxMillionTriVoxelPerSec = 46.0;
#else
            // my laptop in High Performance mode
            const double minMillionTriVoxelPerSec = 17.0;
            const double maxMillionTriVoxelPerSec = 26.0;
#endif

            const int numTriangles  = 1000;
            const int voxelGridSize = 32;

            const uint triangleColor = 0xffffffff;
            var        triList       = new List <Triangle>();
            for (int i = 0; i < numTriangles; i++)
            {
                triList.Add(new Triangle(
                                MakeRandomVector(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5),
                                MakeRandomVector(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5),
                                MakeRandomVector(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5),
                                triangleColor));
            }

            DateTime startTime       = DateTime.Now;
            var      voxels          = new VoxelGrid(voxelGridSize, "BuildVoxelGridPerformance_voxels", "");
            int      numFilledVoxels = TriMeshToVoxelGrid.Convert(triList, voxelGridSize, voxels);
            var      elapsedTime     = DateTime.Now - startTime;

            int totalVoxels = voxelGridSize * voxelGridSize * voxelGridSize;
            Assert.IsTrue(numFilledVoxels > 0.99 * totalVoxels);
            var millionTriVoxelPerSec = triList.Count * totalVoxels / 1000000.0 / elapsedTime.TotalSeconds;
            Assert.IsTrue(minMillionTriVoxelPerSec < millionTriVoxelPerSec && millionTriVoxelPerSec < maxMillionTriVoxelPerSec,
                          "Tri/voxel per second {0:f3} not between {1} and {2} (millions)", millionTriVoxelPerSec, minMillionTriVoxelPerSec, maxMillionTriVoxelPerSec);
            Console.WriteLine("Performance: {0} million tri/voxel built per second", millionTriVoxelPerSec);
        }