之前显示mesh都是用三角网格的方式,其实也可以把每个坐标当做一个像素点,那么点的值就是像素值。
这种显示方法和“统一网格UniformGrid”很像,UniformGrid更像是三维的显示一个三维矩阵,就像打印一张二维图像一样,不是mask,但是UniformGrid是不好吧0值变成透明的,而这个显示表明是透明的,体素化显示就可以看做打印3d mask。

下面分别看一下三角表明,体素化的区别:

1. 三角网格显示

# sphinx_gallery_thumbnail_number = 2
from pyvista import examples
import pyvista as pv
import numpy as np

# Load a surface to voxelize
surface = examples.download_foot_bones()
surface

cpos = [(7.656346967151718, -9.802071079151158, -11.021236183314311),
 (0.2224512272564101, -0.4594554282112895, 0.5549738359311297),
 (-0.6279216753504941, -0.7513057097368635, 0.20311105371647392)]

surface.plot(cpos=cpos, opacity=0.75)

2. 体素化显示

voxels = pv.voxelize(surface, density=surface.length/200)

p = pv.Plotter()
p.add_mesh(voxels, color=True, show_edges=True, opacity=0.5)
p.add_mesh(surface, color="lightblue", opacity=0.5)
p.show(cpos=cpos)

2.1 给体素赋值

当然这里也可以是别的值

voxels["density"] = np.full(voxels.n_cells, 3.65) # g/cc
voxels
voxels.plot(scalars="density", cpos=cpos) ## 指定scalars是什么,他会通过字典去索引

链接

  • https://docs.pyvista.org/examples/01-filter/voxelize.html#sphx-glr-examples-01-filter-voxelize-py