コード例 #1
0
        public override Schematic WriteSchematic()
        {
            float minX = _blocks.MinBy(t => t.X).X;
            float minY = _blocks.MinBy(t => t.Y).Y;
            float minZ = _blocks.MinBy(t => t.Z).Z;

            float maxX = _blocks.MaxBy(t => t.X).X;
            float maxY = _blocks.MaxBy(t => t.Y).Y;
            float maxZ = _blocks.MaxBy(t => t.Z).Z;

            Schematic schematic = new Schematic()
            {
                Length = (ushort)(Math.Abs(maxZ - minZ)),
                Width  = (ushort)(Math.Abs(maxX - minX)),
                Heigth = (ushort)(Math.Abs(maxY - minY)),
                Blocks = new HashSet <Block>()
            };

            LoadedSchematic.LengthSchematic = schematic.Length;
            LoadedSchematic.WidthSchematic  = schematic.Width;
            LoadedSchematic.HeightSchematic = schematic.Heigth;
            List <Block> list = Quantization.ApplyQuantization(_blocks);

            list.ApplyOffset(new Vector3(minX, minY, minZ));
            HashSet <Block> hashSet = list.ToHashSet();

            //RemoveHoles(ref hashSet, schematic);
            schematic.Blocks = hashSet;

            return(schematic);
        }
コード例 #2
0
        public override Schematic WriteSchematic()
        {
            float minX = _blocks.MinBy(t => t.X).X;
            float minY = _blocks.MinBy(t => t.Y).Y;
            float minZ = _blocks.MinBy(t => t.Z).Z;

            Schematic schematic = new Schematic();

            List <Voxel> list = Quantization.ApplyQuantization(_blocks, _colorLimit);

            list.ApplyOffset(new Vector3(minX, minY, minZ));
            HashSet <Voxel> hashSet = list.ToHashSet();

            if (_holes)
            {
                hashSet = FillHoles(hashSet.To3DArray(schematic), schematic);
            }
            if (_flood)
            {
                hashSet = FillInvisiblesVoxels(hashSet.To3DArray(schematic), schematic);
            }
            if (_lonely)
            {
                hashSet = FixLonelyVoxels(hashSet.To3DArray(schematic), schematic);
            }
            schematic.Blocks = hashSet;

            return(schematic);
        }
コード例 #3
0
        public override Schematic WriteSchematic()
        {
            List <Voxel> list      = Quantization.ApplyQuantization(mSchematic.GetAllVoxels(), ColorLimit);
            Schematic    schematic = new Schematic(list);

            return(schematic);
        }
コード例 #4
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);
        }
コード例 #5
0
        public override Schematic WriteSchematic()
        {
            float minX = _blocks.MinBy(t => t.X).X;
            float minY = _blocks.MinBy(t => t.Y).Y;
            float minZ = _blocks.MinBy(t => t.Z).Z;

            float maxX = _blocks.MaxBy(t => t.X).X;
            float maxY = _blocks.MaxBy(t => t.Y).Y;
            float maxZ = _blocks.MaxBy(t => t.Z).Z;

            Schematic schematic = new Schematic()
            {
                Length = (ushort)(Math.Abs(maxZ - minZ) + 1),
                Width  = (ushort)(Math.Abs(maxX - minX) + 1),
                Height = (ushort)(Math.Abs(maxY - minY) + 1),
                Blocks = new HashSet <Block>()
            };

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

            list.ApplyOffset(new Vector3(minX, minY, minZ));
            HashSet <Block> hashSet = list.ToHashSet();

            if (_holes)
            {
                hashSet = FillHoles(hashSet.To3DArray(schematic), schematic);
            }
            if (_flood)
            {
                hashSet = FillInvisiblesVoxels(hashSet.To3DArray(schematic), schematic);
            }
            if (_lonely)
            {
                hashSet = FixLonelyVoxels(hashSet.To3DArray(schematic), schematic);
            }
            schematic.Blocks = hashSet;

            return(schematic);
        }
コード例 #6
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);
        }