DataSet.cast_to_unstructured_grid

DataSet.cast_to_unstructured_grid#

DataSet.cast_to_unstructured_grid() pv.UnstructuredGrid[source]#

Get a new representation of this object as a UnstructuredGrid.

Note

Casting preserves the cell type(s) of the input. This means that any PIXEL and VOXEL cells from ImageData or RectilinearGrid are preserved. Use to_quads or to_hexahedra instead to convert the cell type for these cases.

Returns:
pyvista.UnstructuredGrid

Dataset cast into a pyvista.UnstructuredGrid.

Notes

The coordinate precision of the input is preserved. This requires special handling for datasets with implicit geometry (RectilinearGrid, ImageData). The underlying vtkAppendFilter detects point precision by inspecting the input’s stored points, but these datasets store their geometry implicitly (per-axis coordinates, or origin and spacing) and have no such points. The filter would otherwise default to single precision and silently downcast double coordinates. A RectilinearGrid is cast to double precision when any of its coordinate arrays is double; an ImageData is always cast to double since its origin and spacing are always stored in double precision. See the upstream VTK bug: https://gitlab.kitware.com/vtk/vtk/-/work_items/19965

Examples

Cast a pyvista.PolyData to a pyvista.UnstructuredGrid.

>>> import pyvista as pv
>>> mesh = pv.Sphere()
>>> type(mesh)
<class 'pyvista.core.pointset.PolyData'>
>>> grid = mesh.cast_to_unstructured_grid()
>>> type(grid)
<class 'pyvista.core.pointset.UnstructuredGrid'>