예제 #1
0
        public void Export(TileModel model, TilePropagator tilePropagator, string filename, DeBroglieConfig config, ExportOptions exportOptions)
        {
            Vox vox;
            ITopoArray <byte> array;

            if (exportOptions is VoxExportOptions veo)
            {
                vox   = veo.Template;
                array = tilePropagator.ToValueArray <byte>();
            }
            else if (exportOptions is VoxSetExportOptions vseo)
            {
                vox = vseo.Template;
                var tileArray = tilePropagator.ToArray();
                var subTiles  = vseo.SubTiles.ToDictionary(x => x.Key, x => VoxUtils.ToTopoArray(x.Value));
                array = MoreTopoArrayUtils.ExplodeTiles(tileArray, subTiles, vseo.TileWidth, vseo.TileHeight, vseo.TileDepth);
            }
            else
            {
                throw new System.Exception($"Cannot export from {exportOptions.TypeDescription} to .vox");
            }

            VoxUtils.Save(vox, array);

            using (var stream = new FileStream(filename, FileMode.Create))
            {
                var br = new BinaryWriter(stream);
                VoxSerializer.Write(br, vox);
            }
        }
예제 #2
0
        public SampleSet Load(string filename)
        {
            var vox    = VoxUtils.Load(filename);
            var sample = VoxUtils.ToTopoArray(vox).ToTiles();

            return(new SampleSet
            {
                Directions = sample.Topology.Directions,
                Samples = new[] { sample },
                ExportOptions = new VoxExportOptions {
                    Template = vox
                },
            });
        }
예제 #3
0
 private static IDictionary <Tile, ITopoArray <byte> > GetSubTiles(VoxSetExportOptions vseo, out GridTopology subTileTopology)
 {
     subTileTopology = new GridTopology(vseo.TileWidth, vseo.TileHeight, vseo.TileDepth, false);
     return(vseo.SubTiles.ToDictionary(x => x.Key, x => VoxUtils.ToTopoArray(x.Value)));
 }
예제 #4
0
        private SampleSet LoadFileSet()
        {
            if (config.Tiles == null)
            {
                throw new ConfigurationException($"You must specify tile data when using SrcType {config.SrcType}.");
            }

            var filenames = new Dictionary <Tile, string>();

            foreach (var tile in config.Tiles)
            {
                if (tile.Value == null)
                {
                    tile.Value = new Guid().ToString();
                }
                if (tile.Src == null)
                {
                    throw new ConfigurationException($"All tiles must have a src set when using SrcType {config.SrcType}.");
                }
                filenames[Parse(tile.Value)] = tile.Src;
            }

            if (filenames.Count == 0)
            {
                throw new ConfigurationException($"Must supply at least one tile when using SrcType {config.SrcType}.");
            }

            if (config.SrcType == SrcType.BitmapSet)
            {
                var bitmaps = filenames.ToDictionary(x => x.Key, x => Image.Load(Path.Combine(config.BaseDirectory, x.Value)));
                var first   = bitmaps.First().Value;
                return(new SampleSet
                {
                    Directions = DirectionSet.Cartesian2d,
                    Samples = new ITopoArray <Tile> [0],
                    ExportOptions = new BitmapSetExportOptions
                    {
                        Bitmaps = bitmaps,
                        TileWidth = first.Width,
                        TileHeight = first.Height,
                    }
                });
            }
            else if (config.SrcType == SrcType.VoxSet)
            {
                var subtiles = filenames.ToDictionary(x => x.Key, x => VoxUtils.Load(Path.Combine(config.BaseDirectory, x.Value)));
                var first    = VoxUtils.ToTopoArray(subtiles.First().Value);
                return(new SampleSet
                {
                    Directions = DirectionSet.Cartesian3d,
                    Samples = new ITopoArray <Tile> [0],
                    ExportOptions = new VoxSetExportOptions
                    {
                        Template = subtiles.First().Value,
                        SubTiles = subtiles,
                        TileWidth = first.Topology.Width,
                        TileHeight = first.Topology.Height,
                        TileDepth = first.Topology.Depth,
                    }
                });
            }
            else
            {
                throw new NotImplementedException($"Unrecognized src type {config.SrcType}");
            }
        }