Exemplo n.º 1
0
        //private void DrawLabelsOutput(Grid grid)
        //{
        //    const int SIZE = 20;
        //    Bitmap outputImg = new Bitmap(grid.Width * SIZE, grid.Height * SIZE);
        //    Graphics outputGC = Graphics.FromImage(outputImg);
        //    Sector sector = grid[0, 0].Sector;
        //    for (int row = 0; row < sector.AreaOnGrid.Height; row++)
        //    {
        //        for (int col = 0; col < sector.AreaOnGrid.Width; col++)
        //        {
        //            Rectangle cellRect = new Rectangle(col * SIZE, row * SIZE, SIZE, SIZE);
        //            if (sector.Labels[col, row] != 0)
        //            {
        //                outputGC.DrawRectangle(Pens.Black, cellRect);
        //                outputGC.DrawString(sector.Labels[col, row].ToString(), SystemFonts.CaptionFont, Brushes.Blue, cellRect.Left + 2, cellRect.Top + 2);
        //            }
        //            else
        //            {
        //                outputGC.FillRectangle(Brushes.Black, cellRect);
        //            }
        //        }
        //    }
        //    outputGC.Dispose();
        //    outputImg.Save("labels.png");
        //    outputImg.Dispose();
        //}

        private void DrawRegion(MC.Region region, Color color)
        {
            foreach (Cell cellOfRegion in region.AllCells)
            {
                this.resultImage.SetPixel(cellOfRegion.Coords.X, cellOfRegion.Coords.Y, color);
            }
        }
Exemplo n.º 2
0
        private void DrawRegionsToOutput(int objectSize, Grid grid)
        {
            Random random = new Random();
            //Dictionary<MC.Region, Color> colorsPerRegion = new Dictionary<MC.Region, Color>();
            Dictionary <MC.Region, Brush> colorsPerRegion = new Dictionary <MC.Region, Brush>();
            Bitmap   outputImg = new Bitmap(grid.Width * OUTPUT_CELLSIZE, grid.Height * OUTPUT_CELLSIZE);
            Graphics outputGC  = Graphics.FromImage(outputImg);

            for (int row = 0; row < grid.Height; row++)
            {
                for (int col = 0; col < grid.Width; col++)
                {
                    Rectangle cellRect     = new Rectangle(col * OUTPUT_CELLSIZE, row * OUTPUT_CELLSIZE, OUTPUT_CELLSIZE, OUTPUT_CELLSIZE);
                    Cell      cell         = grid[col, row];
                    MC.Region regionOfCell = cell.GetRegion(objectSize);
                    if (regionOfCell == null)
                    {
                        outputGC.FillRectangle(Brushes.Black, cellRect);
                        //outputImg.SetPixel(col, row, Color.Black);
                    }
                    else
                    {
                        if (!colorsPerRegion.ContainsKey(regionOfCell))
                        {
                            colorsPerRegion[regionOfCell] = new SolidBrush(Color.FromArgb(random.Next(100, 256), random.Next(100, 256), random.Next(100, 256)));
                            //colorsPerRegion[regionOfCell] = Color.FromArgb(random.Next(100, 256), random.Next(100, 256), random.Next(100, 256));
                        }
                        List <int> exitDirections = new List <int>();
                        for (int direction = 0; direction < GridDirections.DIRECTION_COUNT; direction++)
                        {
                            if (regionOfCell.ExitCells[direction].Contains(cell))
                            {
                                exitDirections.Add(direction);
                            }
                        }
                        Brush colorOfRegion = colorsPerRegion[regionOfCell];
                        outputGC.FillRectangle(colorOfRegion, cellRect);
                        outputGC.DrawRectangle(Pens.Black, cellRect);
                        //outputImg.SetPixel(col, row, Color.FromArgb(colorOfRegion.R - 60, colorOfRegion.G - 60, colorOfRegion.B - 60));
                        foreach (int exitDirection in exitDirections)
                        {
                            Point lineBegin = new Point(cellRect.Left + EXITVECTOR_BEGIN[exitDirection].X, cellRect.Top + EXITVECTOR_BEGIN[exitDirection].Y);
                            //Point lineBegin = new Point((cellRect.Left + cellRect.Right) / 2, (cellRect.Top + cellRect.Bottom) / 2);
                            Size  directionVector = GridDirections.DIRECTION_VECTOR[exitDirection];
                            Point lineEnd         = new Point(lineBegin.X + directionVector.Width * OUTPUT_CELLSIZE / 2, lineBegin.Y + directionVector.Height * OUTPUT_CELLSIZE / 2);
                            outputGC.DrawLine(Pens.Yellow, lineBegin, lineEnd);
                            outputGC.DrawEllipse(Pens.Yellow, new Rectangle(lineBegin.X - 2, lineBegin.Y - 2, 5, 5));
                        }
                    }
                }
            }
            outputGC.Dispose();
            outputImg.Save("regions_" + objectSize + ".png");
            outputImg.Dispose();
        }