Basic 3D voxel grid in Mayavi

点点圈 提交于 2021-01-27 10:19:55

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/37388254/basic-3d-voxel-grid-in-mayavi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!