コード例 #1
0
        public override Schematic WriteSchematic()
        {
            int height = mImages.Count;

            Console.WriteLine("[INFO] Total images to process: " + mImages.Count);

            List <Voxel> blocks      = new List <Voxel>();
            Bitmap       bitmapColor = null;

            if (mInputColorFile != null)
            {
                bitmapColor = new Bitmap(mInputColorFile);
                if (bitmapColor.Width > 256 || bitmapColor.Height > 1)
                {
                    throw new ArgumentException("[ERROR] The input color file must have a dimension of 256x1 px");
                }
            }

            for (int i = 0; i < mImages.Count; i++)
            {
                string file = mImages[i];
                Console.WriteLine("[INFO] Reading file: " + file);
                Bitmap       bitmap       = new Bitmap(file);
                DirectBitmap directBitmap = new DirectBitmap(bitmap, 1);
                for (int x = 0; x < directBitmap.Width; x++)
                {
                    for (int y = 0; y < directBitmap.Length; y++)
                    {
                        Color color = directBitmap.GetPixel(x, y);
                        if (color != Color.Empty && color != Color.Transparent && color != Color.Black && (color.R != 0 && color.G != 0 && color.B != 0))
                        {
                            if (mInputColorFile != null)
                            {
                                double distance = Math.Sqrt(Math.Pow((height / 2) - x, 2) + Math.Pow((height / 2) - y, 2));
                                float  range    = (float)Math.Abs(distance / (height / 2));                             //
                                range = range > 1 ? 1 : range;
                                color = bitmapColor.GetPixel((int)(range * (bitmapColor.Width - 1)), 0);
                            }

                            if (mExcavate)
                            {
                                CheckNeighbor(ref blocks, directBitmap, color, i, x, y);
                            }
                            else
                            {
                                blocks.Add(new Voxel((ushort)x, (ushort)i, (ushort)y, color.ColorToUInt()));
                            }
                        }
                    }
                }
                directBitmap.Dispose();
            }

            List <Voxel> list      = Quantization.ApplyQuantization(blocks, mColorLimit);
            Schematic    schematic = new Schematic(list);

            Console.WriteLine("[INFO] Done.");
            return(schematic);
        }
コード例 #2
0
        public override Schematic WriteSchematic()
        {
            int height = Directory.GetFiles(_path, "*.*", SearchOption.AllDirectories).Count(s => s.EndsWith(".png"));

            Console.WriteLine("[INFO] Count files in the folder : " + height);

            List <Block> blocks      = new List <Block>();
            Bitmap       bitmapColor = null;

            if (_inputColorFile != null)
            {
                bitmapColor = new Bitmap(_inputColorFile);
                if (bitmapColor.Width > 256 || bitmapColor.Height > 1)
                {
                    throw new ArgumentException("[ERROR] The input color file must have a dimension of 256x1 px");
                }
            }

            int maxWidth  = 0;
            int maxLength = 0;

            using (ProgressBar progressbar = new ProgressBar())
            {
                string[] files = Directory.GetFiles(_path);
                for (int i = 0; i < files.Length; i++)
                {
                    string       file         = files[i];
                    Bitmap       bitmap       = new Bitmap(file);
                    DirectBitmap directBitmap = new DirectBitmap(bitmap);
                    for (int x = 0; x < directBitmap.Width; x++)
                    {
                        for (int y = 0; y < directBitmap.Height; y++)
                        {
                            Color color = directBitmap.GetPixel(x, y);
                            if (color != Color.Empty && color != Color.Transparent && color != Color.Black && (color.R != 0 && color.G != 0 && color.B != 0))
                            {
                                if (_inputColorFile != null)
                                {
                                    double distance = Math.Sqrt(Math.Pow((height / 2) - x, 2) + Math.Pow((height / 2) - y, 2));
                                    float  range    = (float)Math.Abs(distance / (height / 2));      //
                                    range = range > 1 ? 1 : range;
                                    color = bitmapColor.GetPixel((int)(range * (bitmapColor.Width - 1)), 0);
                                }

                                maxWidth  = maxWidth < directBitmap.Width ? directBitmap.Width : maxWidth;
                                maxLength = maxLength < directBitmap.Height ? directBitmap.Height : maxLength;
                                if (_excavate)
                                {
                                    CheckNeighbor(ref blocks, directBitmap, color, i, x, y);
                                }
                                else
                                {
                                    blocks.Add(new Block((ushort)x, (ushort)i, (ushort)y, color.ColorToUInt()));
                                }
                            }
                        }
                    }
                    directBitmap.Dispose();
                    progressbar.Report(i / (float)files.Length);
                }
            }

            Schematic schematic = new Schematic();

            schematic.Height = (ushort)height;
            schematic.Width  = (ushort)maxWidth;
            schematic.Length = (ushort)maxLength;

            LoadedSchematic.HeightSchematic = schematic.Height;
            LoadedSchematic.LengthSchematic = schematic.Length;
            LoadedSchematic.WidthSchematic  = schematic.Width;
            List <Block> list = Quantization.ApplyQuantization(blocks, _colorLimit);

            schematic.Blocks = list.ToHashSet();

            Console.WriteLine("[LOG] Done.");
            return(schematic);
        }