_mc
Marching cubes wrapper.
Thin wrapper over the pure-numpy classic MC implementation in _mc_numpy.
The classic algorithm has well-known topological ambiguities at saddle points
that the Lewiner variant resolves at the cost of a ~1500-LOC state machine —
for the smooth scalar fields chmpy works with (promolecule densities,
Hirshfeld stockholder weights, void surfaces, etc.) the difference is
negligible in practice.
The previous implementation was a port of scikit-image's Lewiner cython module; the public API kept here matches what those callers expected.
Acknowledgement
The CASESCLASSIC lookup table used by the underlying _mc_numpy
module is derived from the scikit-image project (BSD-3 licensed).
marching_cubes(volume, level=None, spacing=(1.0, 1.0, 1.0), gradient_direction='descent', step_size=1, allow_degenerate=True, use_classic=True)
Extract a triangular isosurface from a 3D scalar volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
|
required | |
level
|
contour value to extract; defaults to the midpoint of the volume's value range. |
None
|
|
spacing
|
voxel spacing along each axis |
(1.0, 1.0, 1.0)
|
|
gradient_direction
|
|
'descent'
|
|
step_size
|
take every Nth voxel along each axis. |
1
|
|
allow_degenerate
|
kept for backwards compatibility; currently has no effect — the numpy implementation does not generate zero-area triangles in the first place under typical inputs. |
True
|
|
use_classic
|
kept for backwards compatibility; the only available algorithm now is classic Marching Cubes. |
True
|
Returns:
| Type | Description |
|---|---|
|
A 4-tuple |
|
|
|
|
|
|
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
input volume isn't 3-D, has any axis < 2, or |
RuntimeError
|
no isosurface found at the given level. |