Mayavi 中的基本 3D 体素网格 [英] Basic 3D voxel grid in Mayavi
问题描述
我正在尝试在 Python 中通过 Mayavi 可视化一个 3D 数组.我只是想创建一个结构化的 3D 体素网格,我可以在其中显示一些预先指定的体素空间填充点.我不认为我想要
我能找到的唯一一个我认为相对相关的例子是 如您所见,并非所有的边都生成,即使这些点与生成的框的边具有相同的值.
有没有办法可视化 numpy 数组中每个值等于 1 的点?如果没有等值面可视化,我很好——事实上,我更喜欢一些 Minecraft 风格的块状体素可视化.
嗨
import mayavi.mlab导入 numpy数据 = (100, 100, 100)数据 = numpy.zeros(数据)数据[0:50, 50:70, 0:50] = 1数据[0:50, 0:20, 0:50] = 1xx, yy, zz = numpy.where(data == 1)mayavi.mlab.points3d(xx, yy, zz,模式=立方体",颜色=(0, 1, 0),scale_factor=1)mayavi.mlab.show()
I'm trying to visualize a 3D array through Mayavi in Python. I simply want to create a structured 3D voxel grid in which I can show some pre-specified voxel-space-filling points. I do not think that I want
The only example that I can find that I think is relatively relevant is this MRI example. I can use the following code to get a somewhat workable example:
import numpy as np
from mayavi import mlab
data = (100, 100, 100)
data = np.zeros(data)
data[0:50, 50:70, 0:50] = 1
data[0:50, 0:20, 0:50] = 1
src = mlab.pipeline.scalar_field(data)
outer = mlab.pipeline.iso_surface(src)
mlab.show()
This is able to generate the following images: As you can see, not all sides of the boxes are generated, even though those points have the same value as the sides of the boxes that are generated.
Is there a way to visualize every single point in the numpy array that has value equal to 1? I am fine if there is no iso-surface visualization -- in fact, I would prefer some Minecraft-esque blocky voxel visualization.
Hi
import mayavi.mlab
import numpy
data = (100, 100, 100)
data = numpy.zeros(data)
data[0:50, 50:70, 0:50] = 1
data[0:50, 0:20, 0:50] = 1
xx, yy, zz = numpy.where(data == 1)
mayavi.mlab.points3d(xx, yy, zz,
mode="cube",
color=(0, 1, 0),
scale_factor=1)
mayavi.mlab.show()
这篇关于Mayavi 中的基本 3D 体素网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!