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 incell_data
, is1
for cells inside and0
outside.- Parameters:
- mesh
pyvista.DataSet
Mesh to voxelize.
- density
float
| 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.
- mesh
- 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)
Slice the voxel volume to view
InsideMesh
.>>> slices = vox.slice_orthogonal() >>> slices.plot(scalars='InsideMesh', show_edges=True)
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)
Slice the unequal density voxel volume to view
InsideMesh
.>>> slices = vox.slice_orthogonal() >>> slices.plot(scalars='InsideMesh', show_edges=True, cpos=cpos)