How to speed up marching cubes?

I'm using this marching cube algorithm to draw 3D isosurfaces (ported into C#, outputting MeshGeomtry3D s, but otherwise the same). The resulting surfaces look great, but are taking a long time to calculate.

Are there any ways to speed up marching cubes? The most obvious one is to simply reduce the spatial sampling rate, but this reduces the quality of the resulting mesh. I'd like to avoid this.

I'm considering a two-pass system, where the first pass samples space much more coarsely, eliminating volumes where the field strength is well below my isolevel. Is this wise? What are the pitfalls?

Edit: the code has been profiled, and the bulk of CPU time is split between the marching cubes routine itself and the field strength calculation for each grid cell corner. The field calculations are beyond my control, so speeding up the cubes routine is my only option...

I'm still drawn to the idea of trying to eliminate dead space, since this would reduce the number of calls to both systems considerably.


I know this is a bit old, but I recently implemented Marching Cubes based on much the same source. There is a LOT of inefficiency here. At a minimum if you were doing something like

for (int x=0; x<densityArrayWidth; x++)
  for (int z=0; z<densityArrayLength; z++)
    for (int y=0; y<densityArrayHeight; y++)
      Polygonize(Gridcell, isolevel, Triangles)

Look at how many times you'd be reallocating the edgeTable and Tritable! Those immediately need to move out to the overall class. I ditched the gridCell object as well, going directly from the points/values to the triangles.

In short it isn't just the algorithmic complexity, memory allocations (and in the base this does a huge amount of them) take time also.


Just in case anyone else ends up here, dead-space elimination through a coarser sampling rate makes virtually no difference at all. Any remotely safe (ie: allowing a border for sampling artifacts) coarser sampling ends up grabbing most of the grid anyway in any remotely non-trivial field.

Speeding up the underlying field evaluation (with heavy memoisation) seemed to mostly solve the performance problems.


尝试推进四面体 - 数学更简单,使您可以考虑每个单元更少的情况。

链接地址: http://www.djcxy.com/p/37242.html

上一篇: 使用噪音来生成行进立方体地形?

下一篇: 如何加快行军立方体?