如何在 mayavi 中正确显示具有非立方体素的体积

发布于 2024-11-08 14:03:35 字数 777 浏览 2 评论 0原文

我正在使用 mayavi (3.3.2) 来显示体积等值面。

一般来说,我的体积没有立方体素;例如,采样网格在 X 和 Y 方向上可能为 1mm x 1mm,但在 Z 方向上为 1.4mm。

如何使用 mayavi 的 mlab.contour3dmlab.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦开始←不甜 2024-11-15 14:03:35

为此,最简单的方法是从输入数据显式创建一个 scalar_field 对象。

实际上我经常这样做,因为我们喜欢在地质学中深入研究(积极的是向下的)。这意味着您需要在 z 方向上增加负增量。如果它只是各种 mlab 函数的参数,那就太好了,但它仍然不太难做到。

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

具有非立方体素的球壳

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

Spherical shell with non-cubic voxels

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文