pyvista.voxelize#
- voxelize( )[source]#
Voxelize mesh to UnstructuredGrid.
- Parameters:
- mesh
pyvista.DataSet
Mesh to voxelize.
- density
float
| 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.
- 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.
- mesh
- Returns:
pyvista.UnstructuredGrid
Voxelized unstructured grid of the original mesh.
See also
pyvista.voxelize_volume
Similar function that returns a
pyvista.RectilinearGrid
with cell data.pyvista.PolyDataFilters.voxelize_binary_mask
Similar function that returns a
pyvista.ImageData
with point data.
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)
Create a voxelized mesh using unequal density dimensions.
>>> vox = pv.voxelize(mesh, density=[0.01, 0.005, 0.002]) >>> vox.plot(show_edges=True)
Create an equal density voxel volume without enclosing input mesh.
>>> vox = pv.voxelize(mesh, density=0.01) >>> vox = vox.select_enclosed_points(mesh, tolerance=0.0) >>> vox.plot(scalars='SelectedPoints', show_edges=True)
Create an equal density voxel volume enclosing input mesh.
>>> vox = pv.voxelize(mesh, density=0.01, enclosed=True) >>> vox = vox.select_enclosed_points(mesh, tolerance=0.0) >>> vox.plot(scalars='SelectedPoints', show_edges=True)
Create a voxelized mesh that does not fit the input mesh’s bounds. Notice the cropped rectangular box.
>>> mesh = pv.Cube(x_length=0.25) >>> vox = pv.voxelize(mesh=mesh, density=0.2) >>> pl = pv.Plotter() >>> _ = pl.add_mesh(mesh=vox, show_edges=True, color='yellow') >>> _ = pl.add_mesh(mesh=mesh, show_edges=True, line_width=5, opacity=0.4) >>> pl.show()
Create a voxelized mesh that fits the input mesh’s bounds. The rectangular mesh is now complete. Notice that the voxel size was updated to fit the bounds in the first direction.
>>> vox = pv.voxelize(mesh=mesh, density=0.2, fit_bounds=True) >>> pl = pv.Plotter() >>> _ = pl.add_mesh(mesh=vox, show_edges=True, color='yellow') >>> _ = pl.add_mesh(mesh=mesh, show_edges=True, line_width=5, opacity=0.4) >>> pl.show()