Marching Cubes
This function uses a vectorized version of the marching cubes algorithm to compute a triangulated mesh of the isosurface within a given 3D matrix of scalar values at a given isosurface value. The output is a triangulated mesh specified in terms of a face list and a vertex list. The orientation of the triangles is chosen such that the normals point from the higher values to the lower values. Optional arguments COLORS ans COLS can be used to produce interpolated mesh face colors.
This function was used to create a surface mesh from the CT scan dataset for the Stanford bunny (see uploaded image). Elapsed time on a Pentium 4, 32-bit computer with 3 GB of RAM is approx 30 seconds.
This function was adapted for Matlab by Peter Hammer in 2011 by making minor syntax changes to an Octave function written by Martin Helm in 2009 (http://www.mhelm.de/octave/m/marching_cube.m)
Revised 30 September, 2011 to add code by Oliver Woodford for removing
duplicate vertices.