mesh.Mesh.voxelize#

Mesh.voxelize(div=10, full_grid=False, return_mask=False)#

Voxelize a Mesh into a hexahedral mesh.

The method can be applied to:

  • volumetric meshes (level=3), or

  • surface meshes (level=2) that form a closed, orientable manifold surface.

Parameters#

divint or array-like of length 3, optional

Number of divisions along each spatial direction. If a single integer is provided, the same number of divisions is used for all directions. The voxel spacing is computed from the mesh bounding box size divided by div.

full_gridbool, optional

If True, return the full voxel grid, including voxels outside the original mesh. If False (default), only voxels inside the mesh are returned.

return_maskbool, optional

If True, also return the voxel mask indicating which voxels are inside (1) or outside (0) the original mesh. Default is False.

Returns#

Mesh

A volumetric mesh with eltype='hex8'. By default, this contains only voxels inside the original mesh. If full_grid=True, the full voxel grid is returned.

(Mesh, ndarray)

If return_mask=True, returns a tuple (mesh, mask), where mask is an array of 0s and 1s indicating outside/inside voxels in the full voxel grid.

Examples#

>>> surf = shapes.sphere()
>>> vox = surf.voxelize(div=20)
>>> print(vox.level())
3
>>> vox, mask = surf.voxelize(div=(20, 10, 10), return_mask=True)
>>> print(vox.n_elems() == (mask == 1).sum())
True
>>> grid, mask = surf.voxelize(div=20, full_grid=True, return_mask=True)
>>> print(grid.n_elems() == len(mask))
True