Hiya, I’m making a floor-plan-to-level system, and I need to detect the rooms. For reference, here’s what a average floor plan looks like:
Green for doors, black for walls, white for empty. Now, I thought i could detect each room by floodfilling from the doors, and adding a new room to the list of rooms with that flood list. Issue is, If a room’s got 2 doors, that means two floodfills, meaning 2 rooms are placed when there should only be the one. How can I fix this? What are some other methods?
When you floodfill a room from door #1, then go to floodfill it from door #2, you should notice that the room is already filled and simply attach a second entrance to that room.
I’ve done this approach in the past, just kept a big integer array corresponding to room number, and filled an initially-zero-filled array, first with “1”, then “2”, then “3” until I had everything non-wall floodfilled.
You should not even start from the doors. Just start at any corner and iterate until you find a white/empty pixel, then floodfill from there. Then proceed your iteration. If you actually change the values (no more white pixels in a room) it does not matter where you start.
I have done this to identify and track clouds in satellite images so every cloud got it’s own “index” as Kurt explained.
Maybe you just use the image to “design” the level but convert this to an integer or byte array and only work on this. Then you just have to compare the indices and not colors.