如何在 mayavi 中正确显示具有非立方体素的体积
我正在使用 mayavi (3.3.2) 来显示体积等值面。
一般来说,我的体积没有立方体素;例如,采样网格在 X 和 Y 方向上可能为 1mm x 1mm,但在 Z 方向上为 1.4mm。
如何使用 mayavi 的 mlab.contour3d
或 mlab.pipeline.iso_surface
使此类体积以正确的空间比例显示?我真的不想将体积重新采样为立方网格。
陈述问题的另一种方式:我该怎么做才能让下面的代码显示球体而不是展平的椭球体(将 volume
与预期的 1:1:2 纵横比体素作为给定,并且无需重新生成或重新采样体积)。
import numpy as np
from enthought.mayavi import mlab
def sqr(x): return x*x
s=64
x,y,z = np.ogrid[0:s,0:s,0:s/2]
volume = np.sqrt(sqr(x-s/2)+sqr(y-s/2)+sqr(2*z-s/2))
isos = mlab.contour3d(volume,contours=[5,15,25],transparent=True)
mlab.show()
我猜测应该有某种方法可以获取底层 VTK 图形管道(其变换等)并插入适当的各向异性缩放(如果没有某种方法可以通过 mlab API 更直接地执行此操作)。
I'm using mayavi (3.3.2) to display volume isosurfaces.
Generally, my volumes do not have cubic voxels; for example, the sampling grid might be 1mm x 1mm in X and Y, but 1.4mm in the Z direction.
How can I get such volumes to display with the correct spatial proportions using mayavi's mlab.contour3d
or mlab.pipeline.iso_surface
? I'd really prefer to not resample the volumes to a cubic grid.
Another way of stating the problem: what can I do to get the below code to display a sphere instead of a flattened elipsoid (taking the volume
with it's intended 1:1:2 aspect-ratio voxels as a given, and without regenerating or resampling the volume).
import numpy as np
from enthought.mayavi import mlab
def sqr(x): return x*x
s=64
x,y,z = np.ogrid[0:s,0:s,0:s/2]
volume = np.sqrt(sqr(x-s/2)+sqr(y-s/2)+sqr(2*z-s/2))
isos = mlab.contour3d(volume,contours=[5,15,25],transparent=True)
mlab.show()
I'm guessing there ought to be some way of getting at the underlying VTK graphics pipeline (its transforms etc) and inserting the appropriate anisotropic scaling (if there isn't some way of doing it more directly through the mlab API).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,最简单的方法是从输入数据显式创建一个
scalar_field
对象。实际上我经常这样做,因为我们喜欢在地质学中深入研究(积极的是向下的)。这意味着您需要在 z 方向上增加负增量。如果它只是各种 mlab 函数的参数,那就太好了,但它仍然不太难做到。
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.