简体   繁体   English

网格到填充体素网格

[英]Mesh to filled voxel grid

I'm trying to work with voxels.我正在尝试使用体素。 I have a closed mesh object, but here I'll use the supplied example mesh.我有一个封闭的网格 object,但在这里我将使用提供的示例网格。 What I would like to do is convert the mesh to a filled voxel grid.我想做的是将网格转换为填充的体素网格。

The below code takes a mesh and turns it into a voxel grid using pyvista, however internally the voxel grid is hollow.下面的代码获取一个网格并使用 pyvista 将其转换为体素网格,但在内部体素网格是空心的。

import numpy as np
import pyvista as pv
from pyvista import examples

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

voxels = pv.voxelize(surface, density=surface.length / 500)
voxels.plot(opacity=1.00)

Is there a way to fill the internal hollows with cells?有没有办法用细胞填充内部空洞? If not I assume there would be a numpy way to fill in the array and then convert that to a filled voxel grid?如果不是,我假设会有一种 numpy 方法来填充数组,然后将其转换为填充的体素网格?

I believe you are misled by the representation of the voxels.我相信您被体素的表示误导了。 Since the voxels are tightly packed in the plot, you cannot see internal surfaces even with partial opacity.由于体素在 plot 中紧密堆积,因此即使部分不透明也看不到内表面。 In other words, the voxelisation is already dense.换句话说,体素化已经很密集了。

We can extract the center of each cell in the voxelised grid, and notice that it's dense in the mesh:我们可以提取体素化网格中每个单元格的中心,并注意到它在网格中是密集的:

voxels.cell_centers().plot(render_points_as_spheres=True)

(you might have to manually activate the scalars on the mesh to also get the colourmap). (您可能必须手动激活网格上的标量才能获得颜色图)。

This produces something like this when zoomed in:放大时会产生类似这样的东西: 绘制的细胞中心的特写,密集地占据了网格轮廓

If the voxel mesh were hollow, we would only see spheres along the surface of the mesh.如果体素网格是空心的,我们只能看到网格表面的球体。 Instead we have densely packed points filling up the entire space.相反,我们有密集的点填满了整个空间。


For more concrete proof, consider a voxelised tetrahedron:如需更具体的证明,请考虑体素化四面体:

import pyvista as pv

tetra = pv.voxelize(pv.Tetrahedron(), density=0.1)
tetra.plot(scalars='vtkOriginalCellIds')

具有紧密堆积体素的体素化四面体图

Now if we run this (slow and undocumented) internal helper called atomize on it, it will shrink each voxel, allowing us to peek through them:现在,如果我们在其上运行这个名为atomize的(缓慢且未记录的)内部帮助程序,它将缩小每个体素,让我们能够窥视它们:

from pyvista.demos.logo import atomize  # undocumented, don't rely on it

atomized = atomize(tetra, scale=0.5)
atomized.plot()

具有收缩细胞的体素化四面体图,内部细胞可见

Especially moving the mesh around in 3d makes it obvious that all the internal voxels are there, they are merely obscured by the outermost voxels.特别是在 3d 中四处移动网格可以明显看出所有内部体素都在那里,它们只是被最外面的体素遮挡了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM