百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

marching_cubes

> 编程语言
开源

独立的行进立方体实现和 Python 绑定

100 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

独立的行进立方体实现和 Python 绑定

Marching cubes implementation for the volumina 3D viewer

Creates a 3D iso surface from a 3D volume.

Release Notes:

0.3:

  • fixed fortran order expectation (#26) Note: previously data was expected in fortran order. A workaround was to supply 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:

  • fixed number of smoothing rounds off by one error (#23) Note: in order to get consistent results with older versions, you'll have to decrement the number of smoothing rounds by 1. So instead of e.g. march(volume, 4), go for march(volume, 3).

Why not these? (time of writing July 2016)

  • skimage

    1. too slow (factor 10 - 20)
    2. incorrect normals (shading looks ugly)
  • vtk

    1. huge dependency
    2. does not support python3.x

    update: vtk started supporting Python 3.2-3.5 with version 7, Python 3.5-3.8 with version 9

Example usage

Mesh generation:

python
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:

python
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_()

Example images

No smoothing

3 smoothing rounds

This library is work in progress

Todo:

  • repair workaround for volumes with different shapes

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言