Skip to main content

Crate axiolid_levelset

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.

§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.

§Known limitation: grid tangency

The closed-manifold guarantee holds when the surface passes BETWEEN grid samples. It does not currently hold when the level set is exactly tangent to a grid plane – a sphere of radius 1 with samples landing exactly on 1.0, for instance. Two edges of the same tetrahedron then interpolate to the same point, the triangle between them has zero area, and the surface is left with unmatched edges.

Measured, so the boundary of the guarantee is known rather than assumed: a unit sphere in bounds of half-extent 1.45 is closed at edge lengths 0.4, 0.2 and 0.1, while the same sphere in half-extent 1.4 is closed at 0.4 and open at 0.2 and 0.1 – exactly the resolutions whose samples land on the radius.

Two fixes were tried and rejected. Offsetting an exactly-zero sample by Scalar::MIN_POSITIVE produced vertices a SUBNORMAL distance apart: distinct in bits, identical in geometry, so it reproduced the degeneracy it was meant to remove. Offsetting by a fraction of the cell instead flips the sample’s side and changes the topology, which broke the general case to patch the special one. The remaining candidate is symbolic perturbation (simulation of simplicity), which decides ties by index rather than by value; that is a larger change and is not done here.

A caller who needs the guarantee unconditionally should offset the bounds so no grid plane is tangent to the surface.

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.