How to display a volume with non-cubic voxels correctly in mayavi

别来无恙 提交于 2019-12-03 13:09:51

For this, it's easiest to explicitly create a scalar_field object from the input data.

I actually do this quite frequently, as we like to put things in depth (where positive is downwards) in geology. That means that you need a negative increment in the z-direction. It would be nice if it was just an argument to the various mlab functions, but its still not too hard to do.

from mayavi import mlab
import numpy as np

s=64
x,y,z = np.ogrid[0:s,0:s,0:s/2]

data = np.sqrt((x-s/2)**2 + (y-s/2)**2 + (2*z-s/2)**2)

grid = mlab.pipeline.scalar_field(data)
grid.spacing = [1.0, 1.0, 2.0]

contours = mlab.pipeline.contour_surface(grid, 
                         contours=[5,15,25], transparent=True)
mlab.show()

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