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
PIXELandVOXELcells fromImageDataorRectilinearGridare preserved. Useto_quadsorto_hexahedrainstead to convert the cell type for these cases.- Returns:
pyvista.UnstructuredGridDataset 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 underlyingvtkAppendFilterdetects 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. ARectilinearGridis cast to double precision when any of its coordinate arrays is double; anImageDatais 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/19965Examples
Cast a
pyvista.PolyDatato apyvista.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'>