Standalone marching cubes implementation and Python bindings
Standalone marching cubes implementation and Python bindings
Creates a 3D iso surface from a 3D volume.
0.3:
volume.T with C-order data to march.
This should not be done anymore.
march works with C- and F-order data now.0.2:
1.
So instead of e.g. march(volume, 4), go for march(volume, 3).skimage
vtk
update: vtk started supporting Python 3.2-3.5 with version 7, Python 3.5-3.8 with version 9
Mesh generation:
from marching_cubes import march
from numpy import load
volume = load("test/data/input/sample.npy") # 128x128x128 uint8 volume
# extract the mesh where the values are larger than or equal to 1
# everything else is ignored
vertices, normals, faces = march(volume, 0) # zero smoothing rounds
smooth_vertices, smooth_normals, faces = march(volume, 3) # 3 smoothing rounds
# mesh statistics:
# 82464 vertices
# 82464 normals
# 165048 faces(triangles)
# duration: 0.158s
# smoothing: +0.254s
# [CPU: AMD A8-4500M 1.9 GHz]Displaying:
from pyqtgraph.opengl import GLViewWidget, MeshData
from pyqtgraph.opengl.items.GLMeshItem import GLMeshItem
from PyQt4.QtGui import QApplication
app = QApplication([])
view = GLViewWidget()
mesh = MeshData(vertices / 100, faces) # scale down - because camera is at a fixed position
# or mesh = MeshData(smooth_vertices / 100, faces)
mesh._vertexNormals = normals
# or mesh._vertexNormals = smooth_normals
item = GLMeshItem(meshdata=mesh, color=[1, 0, 0, 1], shader="normalColor")
view.addItem(item)
view.show()
app.exec_()No smoothing
3 smoothing rounds
Todo:
No open issues yet, or sync has not completed.