marching_cubes_lewiner(volume, level=None, spacing=(1.0, 1.0, 1.0), gradient_direction='descent', step_size=1, allow_degenerate=True, use_classic=False, mask=None)
In contrast to marching_cubes_classic()
, this algorithm is faster, resolves ambiguities, and guarantees topologically correct results. Therefore, this algorithm generally a better choice, unless there is a specific need for the classic algorithm.
The algorithm [1] is an improved version of Chernyaev's Marching Cubes 33 algorithm. It is an efficient algorithm that relies on heavy use of lookup tables to handle the many different cases, keeping the algorithm relatively easy. This implementation is written in Cython, ported from Lewiner's C++ implementation.
To quantify the area of an isosurface generated by this algorithm, pass verts and faces to skimage.measure.mesh_surface_area
.
Regarding visualization of algorithm output, to contour a volume named :None:None:`myvolume`
about the level 0.0, using the mayavi
package:
>>> from mayavi import mlab # doctest: +SKIP >>> verts, faces, normals, values = marching_cubes_lewiner(myvolume, 0.0) # doctest: +SKIP >>> mlab.triangular_mesh([vert[0] for vert in verts], ... [vert[1] for vert in verts], ... [vert[2] for vert in verts], ... faces) # doctest: +SKIP >>> mlab.show() # doctest: +SKIP
Similarly using the visvis
package:
>>> import visvis as vv # doctest: +SKIP >>> verts, faces, normals, values = marching_cubes_lewiner(myvolume, 0.0) # doctest: +SKIP >>> vv.mesh(np.fliplr(verts), faces, normals, values) # doctest: +SKIP >>> vv.use().Run() # doctest: +SKIP
Input data volume to find isosurfaces. Will internally be converted to float32 if necessary.
Contour value to search for isosurfaces in :None:None:`volume`
. If not given or None, the average of the min and max of vol is used.
Voxel spacing in spatial dimensions corresponding to numpy array indexing dimensions (M, N, P) as in :None:None:`volume`
.
Controls if the mesh was generated from an isosurface with gradient descent toward objects of interest (the default), or the opposite, considering the left-hand rule. The two options are: * descent : Object was greater than exterior * ascent : Exterior was greater than object
Step size in voxels. Default 1. Larger steps yield faster but coarser results. The result will always be topologically correct though.
Whether to allow degenerate (i.e. zero-area) triangles in the end-result. Default True. If False, degenerate triangles are removed, at the cost of making the algorithm slower.
If given and True, the classic marching cubes by Lorensen (1987) is used. This option is included for reference purposes. Note that this algorithm has ambiguities and is not guaranteed to produce a topologically correct result. The results with using this option are not generally the same as the marching_cubes_classic()
function.
Boolean array. The marching cube algorithm will be computed only on True elements. This will save computational time when interfaces are located within certain region of the volume M, N, P-e.g. the top half of the cube-and also allow to compute finite surfaces-i.e. open surfaces that do not end at the border of the cube.
Spatial coordinates for V unique mesh vertices. Coordinate order matches input :None:None:`volume`
(M, N, P).
Define triangular faces via referencing vertex indices from verts
. This algorithm specifically outputs triangles, so each face has exactly three indices.
The normal direction at each vertex, as calculated from the data.
Gives a measure for the maximum value of the data in the local region near each vertex. This can be used by visualization tools to apply a colormap to the mesh.
Lewiner marching cubes algorithm to find surfaces in 3d volumetric data.
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them