简体   繁体   中英

How to simplify a marching squares mesh?

I'm running a marching squares (relative of the marching cubes) algorithm over an iso plane, then translating the data into a triangular mesh.

This works, but creates very complex mesh data. I would like to simplify this to the minimum triangles required, as seen illustrated below:

在此输入图像描述

I have tried looping around contours (point -> segment -> point -> ...), but the contour can become inverted if a point has more than 2 attaching segments.

Ideally the solution should be fairly fast so that it can be done at runtime. The language I'm using is C#, but could probably port it from most other C-like languages.

This is a very common problem in 3D computer graphics. Algorithms solving this problem are called mesh simplification algorithms. The problem is however much simpler to solve in the 2D case, as no surface normals need to be considered.

The first important thing is to have a reliable mesh data structure, that provides operations to modify the mesh. A set of operations, that can produce and modify any mesh is for instance the set of "Euler Operators".

To simplify a 2D mesh provide a dense version of the 2D mesh. You can simply convert your quad mesh to a triangle mesh by splitting each quad at its diagonal.

Dense triangle mesh :

在此输入图像描述

Then iteratively collapse the shortest edges, which are not at the boundary. " Edge collapse " is a typical mesh operation, depicted here: 边缘崩溃操作

After some steps your mesh will look like that: 在此输入图像描述

Simplifying a mesh generated by marching squares (like suggested in the answers above) is highly inefficient. To get a polygon out of a scalar field (eg a bitmap) you should first run a modified version of marching squares that only generates the polygon contour (ie in the 16 cases of marching squares you don't generate geometry, you just add points to a polygon), and after that you run a triangulation algorithm (eg Delaunay or Ear Clipping).

Do it with an immediate step, go from your volume representation to the grid representation.

After that you can then group the areas with case 3,6,9,12 into bigger/longer versions.

You can aslo try to group squares into bigger squares, but its a NP problem so an ideal optimization could take a long time.

Then you can convert it into the polygon version.

After converting it to polygons you can fuse the edges.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM