Exemplo n.º 1
0
        private List <OSCADObject> processImage()
        {
            var    rawImg = Image.FromFile(this.imagePath);
            Bitmap img;

            if (this.resizeWidth != null || this.resizeHeight != null)
            {
                img = resizeWithAspectRatio(rawImg);
            }
            else
            {
                img = new Bitmap(rawImg);
            }

            this.setColorArray(img);

            var simplifier = new ImageSimplifier(img.Width, img.Height, pixels);

            simplifier.BasicResample(this.simplificationAmount);

            this.htMapper = new HeightMapper(img.Width, img.Height, pixels, this.heightMode);
            this.htMapper.SetHeightMappings();

            this.ImageBounds = new Bounds(new Vector3(), new Vector3(img.Width, img.Height, 1));

            List <OSCADObject> cubes = new List <OSCADObject>();

            bool[,] visited = new bool[img.Width, img.Height];
            this.height     = img.Height;
            this.width      = img.Width;

            Point?start = this.getNextPoint(ref visited, img.Width - 1, img.Height - 1);

            do
            {
                System.Drawing.Color color = pixels[((Point)start).X, ((Point)start).Y];
                var cube = this.traverseIterative((Point)start, ref visited, color);
                if (cube != null)
                {
                    markVisited(ref visited, cube, (Point)start);
                    if (color.A != 0)
                    {
                        this.htMapper.SetHeight(color, cube);
                        string cubeColor = String.Format("[{0}, {1}, {2}]", color.R == 0 ? 0 : color.R / 255.0, color.G == 0 ? 0 : color.G / 255.0, color.B == 0 ? 0 : color.B / 255.0);
                        cubes.Add(cube.Translate(((Point)start).X, ((Point)start).Y, this.htMapper.GetZTranslation(cube.Size.Z))
                                  .Color(cubeColor, color.A));
                    }
                }

                start = this.getNextPoint(ref visited, img.Width - 1, img.Height - 1);
            } while (start != null);

            return(cubes);
        }
Exemplo n.º 2
0
        private List<OSCADObject> processImage()
        {
            var rawImg = Image.FromFile(this.imagePath);
            Bitmap img;

            if(this.resizeWidth != null || this.resizeHeight != null)
            {
                img = resizeWithAspectRatio(rawImg);
            }
            else
            {
                img = new Bitmap(rawImg);
            }

            this.setColorArray(img);

            var simplifier = new ImageSimplifier(img.Width, img.Height, pixels);
            simplifier.BasicResample(this.simplificationAmount);

            this.htMapper = new HeightMapper(img.Width, img.Height, pixels, this.heightMode);
            this.htMapper.SetHeightMappings();
            
            this.ImageBounds = new Bounds(new Vector3(), new Vector3(img.Width, img.Height, 1));            
            
            List<OSCADObject> cubes = new List<OSCADObject>();
            bool[,] visited = new bool[img.Width, img.Height];
            this.height = img.Height;
            this.width = img.Width;

            Point? start = this.getNextPoint(ref visited, img.Width - 1, img.Height - 1);
            do
            {
                System.Drawing.Color color = pixels[((Point)start).X, ((Point)start).Y];
                var cube = this.traverseIterative((Point)start, ref visited, color);
                if (cube != null)
                {
                    markVisited(ref visited, cube, (Point)start);
                    if (color.A != 0)
                    {
                        this.htMapper.SetHeight(color, cube);
                        string cubeColor = String.Format("[{0}, {1}, {2}]", color.R == 0 ? 0 : color.R / 255.0, color.G == 0 ? 0 : color.G / 255.0, color.B == 0 ? 0 : color.B / 255.0);
                        cubes.Add(cube.Translate(((Point)start).X, ((Point)start).Y, this.htMapper.GetZTranslation(cube.Size.Z))
                        .Color(cubeColor, color.A));
                    }
                }

                start = this.getNextPoint(ref visited, img.Width - 1, img.Height - 1);
            } while (start != null);

            return cubes;
        }