Ejemplo n.º 1
0
        public void UpdateDirty()
        {
            if (!dirty)
            {
                return;
            }
            dirty = false;

            ((HermiteDataGrid)grid).Save(TWDir.Test.CreateSubdirectory("DualContouring").CreateFile("InteractiveGrid.txt"));


            lastSurfaceExtractionTime = PerformanceHelper.Measure(() =>
            {
                surfaceMesh = dcMeshBuilder.buildRawMesh(grid);
            });

            if (meshElement != null)
            {
                meshElement.Delete();
            }
            meshElement             = surfaceRenderer.CreateSurface(grid, Matrix.Identity);
            meshElement.WorldMatrix = Matrix.Scaling(new Vector3(CellSize));

            this.lines.ClearAllLines();
            addHermiteVertices(grid, CellSize, this.lines);
            addQEFPoints(surfaceMesh, CellSize, this.lines);
            addHermiteNormals(grid, CellSize, this.lines);

            lines.AddBox(new BoundingBox(new Vector3(), grid.Dimensions.ToVector3() * cellSize), Color.Black);
        }
Ejemplo n.º 2
0
        private void initDefaultWorld()
        {
            chunks = new Array3D <Chunk>(NumChunks);

            var totalTime = new TimeSpan(0);
            var i         = 0;

            chunks.ForEach((c, p) =>
            {
                i++;
                totalTime.Add(PerformanceHelper.Measure(() =>
                {
                    var grid = HermiteDataGrid.CopyGrid(new DensityFunctionHermiteGrid(v =>
                    {
                        v += (Vector3)p.ToVector3() * chunkSize;
                        return(20 - v.Y);
                    }, new Point3(chunkSize + 1, chunkSize + 1, chunkSize + 1)));

                    var chunk = new Chunk(p);
                    chunk.SetGrid(grid);
                    chunk.UpdateSurface(surfaceRenderer);
                    chunks[p] = chunk;
                }));
            });
            totalTime.Multiply(1f / i);
        }
Ejemplo n.º 3
0
        public void TestNFModSpeed()
        {
            var times = 10000000;

            var list = new int[times];
            var rand = new Random(0);

            for (int i = 0; i < times; i++)
            {
                list[i] = rand.Next(-times / 2, times / 2);
            }
            var b        = 8;
            var a        = 15;
            var modTwice = PerformanceHelper.Measure(() =>
            {
                for (int i = 0; i < times; i++)
                {
                    a       = list[i];
                    var mod = (a % b + b) % b;
                }
            });

            Console.WriteLine(modTwice.PrettyPrint());

            var modIf = PerformanceHelper.Measure(() =>
            {
                for (int i = 0; i < times; i++)
                {
                    a     = list[i];
                    int r = a % b;
                    r     = r < 0 ? r + b : r;
                }
            });

            Console.WriteLine(modIf.PrettyPrint());


            var floor = PerformanceHelper.Measure(() =>
            {
                for (int i = 0; i < times; i++)
                {
                    a = list[i];

                    var mod = (a - b * (int)Math.Floor(a / (double)b));
                }
            });

            Console.WriteLine(floor.PrettyPrint());

            Assert.Less(modIf, modTwice);
            Assert.Less(modIf, floor);
        }
Ejemplo n.º 4
0
        // Public Methods

        /// <summary>This method is the entry-point to this application.</summary>
        public static void Main(string[] args)
        {
            try
            {
                PerformanceHelper.Measure("\tTotal Execution Time", () =>
                {
                    CommandPlatform.Execute(args);
                });
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.Message);
            }
        }
        public void TestHermiteCopyingAllEdges()
        {
            int size    = 32;
            var srcGrid = new DelegateHermiteGrid(p => p.X % 2 == 0 || p.Y % 2 == 0 || p.Z % 2 == 0, (p, i) => new Vector4(), new Point3(size, size, size));
            int times   = 100;

            Console.WriteLine(PerformanceHelper.Measure(() =>
            {
                for (int i = 0; i < times; i++)
                {
                    HermiteDataGrid.CopyGrid(srcGrid);
                }
            }).Multiply(1f / times).PrettyPrint());
        }
Ejemplo n.º 6
0
        public void TestCacheTrashingByteArray()
        {
            var size = 100;
            var arr  = new Array3D <byte[]>(new Point3(size, size, size));

            arr.ForEach((v, p) => arr[p] = new byte[1024]);


            byte add = 2;

            PerformanceHelper.Measure(() =>
            {
                for (int x = 0; x < size; x++)
                {
                    for (int y = 0; y < size; y++)
                    {
                        for (int z = 0; z < size; z++)
                        {
                            var value = arr.GetFast(x, y, z);
                            for (int i = 0; i < value.Length; i++)
                            {
                                add += value[i];
                            }
                        }
                    }
                }
            }).PrettyPrint().With(s => Console.WriteLine("xyz: " + s));

            PerformanceHelper.Measure(() =>
            {
                for (int z = 0; z < size; z++)
                {
                    for (int y = 0; y < size; y++)
                    {
                        for (int x = 0; x < size; x++)
                        {
                            var value = arr.GetFast(x, y, z);
                            for (int i = 0; i < value.Length; i++)
                            {
                                add += value[i];
                            }
                        }
                    }
                }
            }).PrettyPrint().With(s => Console.WriteLine("zyx: " + s));
        }
        private void testDensityFunction(Func <Vector3, float> densityFunction, Point3 dimensions)
        {
            AbstractHermiteGrid grid = null;

            grid = new DensityFunctionHermiteGrid(densityFunction, dimensions);
            var terrGen = PerformanceHelper.Measure(() =>
            {
                grid = HermiteDataGrid.CopyGrid(grid);
            });



            var testEnv = new DualContouringTestEnvironment();

            testEnv.Grid = grid;

            testEnv.AdditionalText = "Terrain to Hermite: " + terrGen.PrettyPrint();


            testEnv.AddToEngine(EngineFactory.CreateEngine());
        }
Ejemplo n.º 8
0
        public void TestCacheTrashing()
        {
            var size = 100 * 2;
            var arr  = new Array3D <int>(new Point3(size, size, size));

            arr.ForEach((v, p) => arr[p] = p.X + p.Y + p.Z);


            int add = 2;

            PerformanceHelper.Measure(() =>
            {
                for (int x = 0; x < size; x++)
                {
                    for (int y = 0; y < size; y++)
                    {
                        for (int z = 0; z < size; z++)
                        {
                            var value = arr.GetFast(x, y, z);
                            add       = (add + value) % 1654654;
                        }
                    }
                }
            }).PrettyPrint().With(s => Console.WriteLine("xyz: " + s));

            PerformanceHelper.Measure(() =>
            {
                for (int z = 0; z < size; z++)
                {
                    for (int y = 0; y < size; y++)
                    {
                        for (int x = 0; x < size; x++)
                        {
                            var value = arr.GetFast(x, y, z);
                            add       = (add + value) % 1654654;
                        }
                    }
                }
            }).PrettyPrint().With(s => Console.WriteLine("zyx: " + s));
        }
        private static void testExtractSurface(DelegateHermiteGrid srcGrid)
        {
            var grid  = HermiteDataGrid.CopyGrid(srcGrid);
            int times = 40;

            var vertices  = new List <Vector3>(10 * 1000 * 1000);
            var indices   = new List <int>(10 * 1000 * 1000);
            var extractor = new DualContouringAlgorithm();

            var time = PerformanceHelper.Measure(() =>
            {
                for (int i = 0; i < times; i++)
                {
                    vertices.Clear();
                    indices.Clear();
                    extractor.GenerateSurface(vertices, indices, srcGrid);
                }
            });

            Console.WriteLine("Time: " + time.Multiply(1f / times).PrettyPrint());
            Console.WriteLine("{0:#.0}x{0:#.0}x{0:#.0} grid per second", Math.Pow(srcGrid.Dimensions.X * srcGrid.Dimensions.Y * srcGrid.Dimensions.Z / (time.TotalSeconds / times), 1 / 3f));
        }
        private static void estimateSamplingPerformance(int extraSimulate, int numIts, TerrainLodEnvironment env, int numMeshes)
        {
            var perf = PerformanceHelper.Measure(() =>
            {
                for (int j = 0; j < extraSimulate; j++)
                {
                    for (int x = 0; x < numIts; x++)
                    {
                        for (int y = 0; y < numIts; y++)
                        {
                            for (int z = 0; z < numIts; z++)
                            {
                                var value = env.densityFunction(new Vector3(x, y, z));
                            }
                        }
                    }
                }
            });


            Console.WriteLine("Time for {0}x{0}x{0}: {1}", numIts, perf.Multiply(1f / extraSimulate).PrettyPrint());
            Console.WriteLine("Time for 32*1024 with lod: " + perf.Multiply((float)numMeshes / extraSimulate).PrettyPrint());
        }
Ejemplo n.º 11
0
        public void TestAccessPerformance()
        {
            var size  = 100;
            var times = 10000;


            var arr = new float[size, size, size];

            var multiDim = PerformanceHelper.Measure(() =>
            {
                for (int j = 0; j < times; j++)
                {
                    for (int i = 0; i < size - 2; i++)
                    {
                        var val  = arr[i, i + 1, i + 2];
                        var val2 = arr[i + 1, i + 2, i];
                    }
                }
            });

            Console.WriteLine("Multidim: " + multiDim.PrettyPrint());


            var arr2 = new float[size * size * size];

            var singleDim = PerformanceHelper.Measure(() =>
            {
                for (int j = 0; j < times; j++)
                {
                    for (int i = 0; i < size - 2; i++)
                    {
                        var val  = arr2[(i + (i + 1) * size) * size + i + 2];
                        var val2 = arr2[(i + (i + 2) * size) * size + i + 1];
                    }
                }
            });

            Console.WriteLine("SingleDim: " + singleDim.PrettyPrint());


            Assert.Less(singleDim, multiDim);

            var arr3d      = new Array3D <float>(new Point3(size, size, size));
            var arr3DSpeed = PerformanceHelper.Measure(() =>
            {
                for (int j = 0; j < times; j++)
                {
                    for (int i = 0; i < size - 2; i++)
                    {
                        var val  = arr3d[new Point3(i, i + 1, i + 2)];
                        var val2 = arr3d[new Point3(-i, -i + 1, -i + 2)];
                    }
                }
            });

            Console.WriteLine("arr3d[]: " + arr3DSpeed.PrettyPrint());

            var arr3DFastSpeed = PerformanceHelper.Measure(() =>
            {
                for (int j = 0; j < times; j++)
                {
                    for (int i = 0; i < size - 2; i++)
                    {
                        var val  = arr3d.GetFast(i, i + 1, i + 2);
                        var val2 = arr3d.GetFast(i, i + 2, i + 1);
                    }
                }
            });

            Console.WriteLine("arr3d.GetFast:" + arr3DFastSpeed.PrettyPrint());

            var arr3DTiled = PerformanceHelper.Measure(() =>
            {
                for (int j = 0; j < times; j++)
                {
                    for (int i = 0; i < size - 2; i++)
                    {
                        var val  = arr3d.GetTiled(new Point3(i, i + 1, i + 2));
                        var val2 = arr3d.GetTiled(new Point3(i, i + 2, i + 1));
                    }
                }
            });

            Console.WriteLine("arr3d.GetTiled:" + arr3DTiled.PrettyPrint());

            var arr3DTiledFast = PerformanceHelper.Measure(() =>
            {
                for (int j = 0; j < times; j++)
                {
                    for (int i = 0; i < size - 2; i++)
                    {
                        var val  = arr3d.GetTiledFast(i, i + 1, i + 2);
                        var val2 = arr3d.GetTiledFast(i, i + 2, i + 1);
                    }
                }
            });

            Console.WriteLine("arr3d.GetTiledFast:" + arr3DTiledFast.PrettyPrint());

            var arr3DTiledCacheSize = PerformanceHelper.Measure(() =>
            {
                for (int j = 0; j < times; j++)
                {
                    for (int i = 0; i < size - 2; i++)
                    {
                        var a1   = TWMath.nfmod(i, size);
                        var a2   = TWMath.nfmod(i + 1, size);
                        var a3   = TWMath.nfmod(i + 2, size);
                        var a4   = TWMath.nfmod(i, size);
                        var a5   = TWMath.nfmod(i + 2, size);
                        var a6   = TWMath.nfmod(i + 1, size);
                        var val  = arr3d.GetFast(a1, a2, a3);
                        var val2 = arr3d.GetFast(a4, a5, a6);
                    }
                }
            });

            Console.WriteLine("arr3d.GetTiledCacheSize:" + arr3DTiledCacheSize.PrettyPrint());


            var internalArr = arr3d.GetInternalField <float[, , ]>("arr");
            var methodGet   = PerformanceHelper.Measure(() =>
            {
                for (int j = 0; j < times; j++)
                {
                    for (int i = 0; i < size - 2; i++)
                    {
                        var val  = Val(internalArr, i, i + 1, i + 2);
                        var val2 = Val(internalArr, i, i + 2, i + 1);
                    }
                }
            });

            Console.WriteLine("DirectMethod: " + methodGet.PrettyPrint());

            Assert.Less(arr3DFastSpeed, arr3DSpeed);
        }