예제 #1
0
        private static unsafe void Precompute()
        {
            var samples = 128;
            var divideBy = 8;

            var globalBounds = new Cube(-6.5f, -6.5f, -6.5f, 13.0f);

            var tileWidth = globalBounds.Side / divideBy;
            var tiles = Enumerable.Range(0, divideBy)
                .SelectMany(x => Enumerable.Range(0, divideBy)
                    .SelectMany(y => Enumerable.Range(0, divideBy)
                        .Select(z => new
                        {
                            x = x,
                            y = y,
                            z = z,
                            bounds = new Cube(
                                globalBounds.X + x * tileWidth,
                                globalBounds.Y + y * tileWidth,
                                globalBounds.Z + z * tileWidth,
                                tileWidth)
                        })))
                .ToArray();

            Directory.CreateDirectory("data");

            tiles.AsParallel()
                .WithMergeOptions(ParallelMergeOptions.NotBuffered)
                .ForAll(tile =>
                {
                    Console.WriteLine("x:{0} y:{1} z:{2}", tile.x, tile.y, tile.z);
                    var buffer = new byte[samples * samples * samples]; // 1 sample per bit
                    unsafe
                    {
                        fixed (byte* bufferPtr = buffer)
                        {
                            compute(tile.bounds, samples, (IntPtr)bufferPtr);
                        }
                    }

                    using (var stream = new GZipStream(File.Create(string.Format("data/tile-{0}-{1}-{2}.bin", tile.x, tile.y, tile.z)), CompressionLevel.Fastest))
                    {
                        stream.Write(buffer, 0, buffer.Length);
                    }
                });
        }
예제 #2
0
 private static extern void compute(
     Cube bounds,
     int samples,
     IntPtr buffer);
예제 #3
0
 private static extern void compute(
     Cube bounds,
     int samples,
     IntPtr buffer);