pyvista.voxelize_volume#

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

Voxelize mesh to create a RectilinearGrid voxel volume.

Creates a voxel volume that encloses the input mesh and discretizes the cells within the volume that intersect or are contained within the input mesh. InsideMesh, an array in cell_data, is 1 for cells inside and 0 outside.

Parameters:
meshpyvista.DataSet

Mesh to voxelize.

densityfloat | array_like[float]

The uniform size of the voxels when single float passed. Nonuniform voxel size if a list of values are passed 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.RectilinearGrid

RectilinearGrid as voxelized volume with discretized cells.

Examples

Create an equal density voxel volume from input mesh.

>>> import pyvista as pv
>>> import numpy as np

Load file from PyVista examples.

>>> from pyvista import examples
>>> mesh = examples.download_cow()

Create an equal density voxel volume and plot the result.

>>> vox = pv.voxelize_volume(mesh, density=0.15)
>>> cpos = [(15, 3, 15), (0, 0, 0), (0, 0, 0)]
>>> vox.plot(scalars='InsideMesh', show_edges=True, cpos=cpos)
../../../_images/pyvista-voxelize_volume-1_00_00.png

Slice the voxel volume to view InsideMesh.

>>> slices = vox.slice_orthogonal()
>>> slices.plot(scalars='InsideMesh', show_edges=True)
../../../_images/pyvista-voxelize_volume-1_01_00.png

Create a voxel volume from unequal density dimensions and plot result.

>>> vox = pv.voxelize_volume(mesh, density=[0.15, 0.15, 0.5])
>>> vox.plot(scalars='InsideMesh', show_edges=True, cpos=cpos)
../../../_images/pyvista-voxelize_volume-1_02_00.png

Slice the unequal density voxel volume to view InsideMesh.

>>> slices = vox.slice_orthogonal()
>>> slices.plot(scalars='InsideMesh', show_edges=True, cpos=cpos)
../../../_images/pyvista-voxelize_volume-1_03_00.png