pyvista.voxelize_volume

pyvista.voxelize_volume#

voxelize_volume(
mesh,
density=None,
check_surface: bool = True,
enclosed: bool = False,
fit_bounds: bool = False,
)[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.

enclosedbool, default: False

If True, the voxel bounds will be outside the mesh. If False, the voxel bounds will be at or inside the mesh bounds.

fit_boundsbool, default: False

If enabled, the end bound of the input mesh is used as the end bound of the voxel grid and the density is updated to the closest compatible one. Otherwise, the end bound is excluded. Has no effect if enclosed is enabled.

Returns:
pyvista.RectilinearGrid

RectilinearGrid as voxelized volume with discretized cells.

See also

pyvista.voxelize

Similar function that returns a pyvista.UnstructuredGrid of VOXEL cells.

pyvista.PolyDataFilters.voxelize_binary_mask

Similar function that returns a pyvista.ImageData with point data.

pyvista.DataSetFilters.select_enclosed_points

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

Create an equal density voxel volume without enclosing input mesh.

>>> vox = pv.voxelize_volume(mesh, density=0.15)
>>> vox = vox.select_enclosed_points(mesh, tolerance=0.0)
>>> vox.plot(scalars='SelectedPoints', show_edges=True, cpos=cpos)
../../../_images/pyvista-voxelize_volume-1_04_00.png

Create an equal density voxel volume enclosing input mesh.

>>> vox = pv.voxelize_volume(mesh, density=0.15, enclosed=True)
>>> vox = vox.select_enclosed_points(mesh, tolerance=0.0)
>>> vox.plot(scalars='SelectedPoints', show_edges=True, cpos=cpos)
../../../_images/pyvista-voxelize_volume-1_05_00.png

Create an equal density voxel volume that does not fit the input mesh’s bounds.

>>> mesh = pv.examples.load_nut()
>>> vox = pv.voxelize_volume(mesh=mesh, density=2.5)
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh=vox, show_edges=True)
>>> _ = pl.add_mesh(mesh=mesh, show_edges=True, opacity=1)
>>> pl.show()
../../../_images/pyvista-voxelize_volume-1_06_00.png

Create an equal density voxel volume that fits the input mesh’s bounds.

>>> vox = pv.voxelize_volume(mesh=mesh, density=2.5, fit_bounds=True)
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh=vox, show_edges=True)
>>> _ = pl.add_mesh(mesh=mesh, show_edges=True, opacity=1)
>>> pl.show()
../../../_images/pyvista-voxelize_volume-1_07_00.png