pyvista.voxelize#

voxelize(mesh, density=None, check_surface=True)[source]#

Voxelize mesh to UnstructuredGrid.

Parameters:
meshpyvista.DataSet

Mesh to voxelize.

densityfloat | array_like[float]

The uniform size of the voxels when single float passed. A list of densities along x,y,z directions. Defaults to 1/100th of the mesh length.

check_surfacebool, default: True

Specify whether to check the surface for closure. If on, then the algorithm first checks to see if the surface is closed and manifold. If the surface is not closed and manifold, a runtime error is raised.

Returns:
pyvista.UnstructuredGrid

Voxelized unstructured grid of the original mesh.

Notes

Prior to version 0.39.0, this method improperly handled the order of structured coordinates.

Examples

Create an equal density voxelized mesh.

>>> import pyvista as pv
>>> from pyvista import examples
>>> mesh = examples.download_bunny_coarse().clean()
>>> vox = pv.voxelize(mesh, density=0.01)
>>> vox.plot(show_edges=True)
../../../_images/pyvista-voxelize-1_00_00.png

Create a voxelized mesh using unequal density dimensions.

>>> vox = pv.voxelize(mesh, density=[0.01, 0.005, 0.002])
>>> vox.plot(show_edges=True)
../../../_images/pyvista-voxelize-1_01_00.png