Crate axiolid_levelset

Source
Expand description

Level-set extraction: a closed manifold mesh from a scalar field.

§Why tetrahedra rather than cubes

Classic marching cubes is not manifold. Its 256-entry table has genuinely ambiguous face configurations: two diagonally opposite corners inside the level, and the other two outside, can be joined in two different ways. Neighbouring cells that resolve the same shared face differently leave a hole, and the result is neither closed nor two-manifold. Fixing that needs the disambiguated MC33 table plus a consistent face-resolution rule.

This module decomposes each cell into six tetrahedra instead. A tetrahedron has four corners and therefore sixteen sign patterns, none of which is ambiguous: the surface crosses either three edges (one triangle) or four (two triangles), and the decomposition is forced.

The decomposition used is Kuhn’s: six tetrahedra sharing the cell’s main diagonal, one per permutation of the three axes. Each cell face is then split along the diagonal joining the two corners that differ in both of that face’s coordinates – and because that choice depends only on the global grid indices, the cell on the other side of the face splits it exactly the same way. Watertightness is therefore structural rather than a property of a table that must be kept correct.

The cost is more triangles than marching cubes for the same grid, and a slight directional bias from the diagonal. That is the price of the guarantee, and the guarantee is what this contract is for.

§What this is not

Extraction is an approximation. The mesh interpolates the field linearly along each edge, so a curved surface is faceted and the error shrinks with the grid, it does not vanish. This is not a certified path and does not claim to be.

§Exact tangency

A level set can pass exactly through a grid sample – a unit sphere in a half-extent of 1.4 does it at several edge lengths. Every edge meeting that sample then crosses at the same point, the triangles between those crossings collapse, and the surface tears.

This is resolved by simulation of simplicity rather than by special cases: symbolically each sample carries its own positive infinitesimal, so no sample sits exactly at the level and every crossing is strictly interior to its edge. See SOS_DELTA for the numeric stand-in and why its magnitude matters.

Enums§

LevelSetError
Why a level set could not be extracted.

Functions§

level_set
Extract the level set of a scalar field as a closed manifold mesh.