How to create line segments from tile map outlines

Started by
6 comments, last by Finalspace 9 years, 5 months ago

Hi there,

i successfully implemented the "Moore Neighborhood" algorythmn to calculate the contours of a tile map, which gives me every tile-outline in clockwise direction. Now i want to create line segments out of it - from edge to edge, but have trouble to figure a algorythmn to solve this. A tile may create/continue two lines in parallel, change directions...

This is what i have:

TilemapOutlineContour_.png

The black number with the arrow beneath indicates the starting tile including the direction to the next tile.

The colored lines indicates the "tile outline" detected by the algorythmn - i call this "chain" and this goes around clockwise until a tile already visited is found.

A chain have just a list of tile coords in vec2 format, something like this:

chain {

tiles: [Vec2, Vec2, Vec2,...]

};

This is what i somehow want:

TilemapLines.png

Any idea?

Advertisement

I'm not sure how the "Moore Neighborhood" algorithm helps you here.

I just implemented something similar to what you want. It basically takes a tilemap and generates a contour line for each independent "collection" of tiles (I'm using this to generate a 3d model based off the tile map).

It sounds like you want something slightly different though. What's the logic behind your choices of starting numbers in the above diagram? What's the logic behind joining two or more different colored contours?

I'm not sure how the "Moore Neighborhood" algorithm helps you here.

I just implemented something similar to what you want. It basically takes a tilemap and generates a contour line for each independent "collection" of tiles (I'm using this to generate a 3d model based off the tile map).

It sounds like you want something slightly different though. What's the logic behind your choices of starting numbers in the above diagram? What's the logic behind joining two or more different colored contours?

The algorythmn is just a way to identify the outline tiles but nothing more. All the colored lines in my second picture are defined by every tile a line for 4 directions, but only when there are no neighbors in that direction.

But my overall target is to generate Box2D chain shapes (joined line segments) based on a tile map (solid/not solid). Using boxes for every tile is a bad idea - cause of internal edge isses.

Have you tried taking your chaining information and walking along the edges until you complete the shape?

Start from the first tile and find a corner that doesn't share a corner with any other. Then move clockwise from one edge to another. Making sure you don't incorporate shared edges?

Then you can connect any contiguous lines that share an axis.

From my phone. Or I'd try to show a picture or something.

Ok i implemented a much better algorythmn which detects all the outlines perfectly... but i still havent figured out a way to traverse the created edges and create the chain-edges / line segments yet.

There are two things which needs to be done i thing to get this thing to work.

First of, the connected edges should be fixed, so that that shared vertices get removed.

Secondly, built a algoryhtmn that traverse the tile in the directions and create line segments out of it.

What i have created is:

- A list of edges. A edge is pair of two indices to the actual vertices + the actual tile position + the edge index (is it a left, right, top, ot bottom edge)

- A list of vertices without any duplicates.

Does someone have an idea?

Here is a image from all the tile edges drawing its vertices (blue) just connected with a red line and displaying each tile position for every edge center.

TilemapContourWithTilecoords.png

Greetings Final.

Marching squares

http://devblog.phillipspiess.com/better%20know%20an%20algorithm/2010/02/23/better-know-marching-squares.html

There's also the DCEL structure if you need to quickly retrieve the separate tile regions (called "faces"). Useful for containment tests etc.

- http://leonardofischer.com/dcel-data-structure-c-plus-plus-implementation/
- http://cs.stackexchange.com/questions/2450/constructing-of-double-connected-edge-list-dcel

I did it, it works - Now i just need to remove the vertices between the corners and i am done!

The best thing was it was just two more steps in my state-based contour tracing system... :-)

This topic is closed to new replies.

Advertisement