static void PrintCorridorMap(Map map, XY initial, int blueThreshold) { BinaryMatrix discovered = new BinaryMatrix(map.Width, map.Height); BinaryMatrix corridors = new BinaryMatrix(map.Width, map.Height); BinaryMatrix obstacles = map.ScanObstacles(blueThreshold); Queue <XY> queue = new Queue <XY>(); queue.Enqueue(initial); discovered[initial.X, initial.Y] = true; while (queue.Count > 0) { XY point = queue.Dequeue(); corridors[point] = true; foreach (XY neighbor in point.GetNeighbors()) { if ( neighbor.IsInsideBox(map.Box) && !discovered[neighbor] && !obstacles[neighbor] ) { discovered[neighbor] = true; queue.Enqueue(neighbor); } } } corridors.ToBitmap(Color.Black, Color.Green).Save(FILE_BASE + "background-corridors.jpg"); }
static void PrintSegmentMap(Map map, int blueThreshold) { BinaryMatrix discovered = new BinaryMatrix(map.Width, map.Height); BinaryMatrix obstacles = map.ScanObstacles(blueThreshold); List <Cluster> clusters = new List <Cluster>(); for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { if (!discovered[x, y] && obstacles[x, y]) { discovered[x, y] = true; Cluster cluster = new Cluster(); Queue <XY> queue = new Queue <XY>(); queue.Enqueue(new XY(x, y)); while (queue.Count > 0) { XY point = queue.Dequeue(); cluster.AddPoint(point); foreach (XY neighbor in point.GetNeighbors()) { if ( neighbor.IsInsideBox(map.Box) && !discovered[neighbor] && obstacles[neighbor] ) { discovered[neighbor] = true; queue.Enqueue(neighbor); } } } clusters.Add(cluster); } } } Console.WriteLine("Discovered {0} clusters", clusters.Count); Bitmap clustersMap = new Bitmap(map.Width, map.Height); for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { clustersMap.SetPixel(x, y, Color.Black); } } foreach (Cluster cluster in clusters) { for (int x = cluster.Left; x <= cluster.Right; x++) { for (int y = cluster.Top; y <= cluster.Bottom; y++) { clustersMap.SetPixel(x, y, Color.Red); } } } clustersMap.Save(FILE_BASE + "background-segments.jpg"); }