pyvista.UnstructuredGrid#

class UnstructuredGrid(*args, **kwargs)[source]#

Dataset used for arbitrary combinations of all possible cell types.

Can be initialized by the following:

  • Creating an empty grid

  • From a vtk.vtkPolyData or vtk.vtkStructuredGrid object

  • From cell, cell types, and point arrays

  • From a file

Parameters:
argsstr, vtk.vtkUnstructuredGrid, iterable

See examples below.

deepbool, default: False

Whether to deep copy a vtkUnstructuredGrid object. Default is False. Keyword only.

Examples

>>> import pyvista as pv
>>> from pyvista import examples
>>> import vtk

Create an empty grid

>>> grid = pv.UnstructuredGrid()

Copy a vtk.vtkUnstructuredGrid

>>> vtkgrid = vtk.vtkUnstructuredGrid()
>>> grid = pv.UnstructuredGrid(vtkgrid)

From a filename.

>>> grid = pv.UnstructuredGrid(examples.hexbeamfile)
>>> grid.plot(show_edges=True)
../../../_images/pyvista-UnstructuredGrid-1_00_00.png

From arrays. Here we create a single tetrahedron.

>>> cells = [4, 0, 1, 2, 3]
>>> celltypes = [pv.CellType.TETRA]
>>> points = [
...     [1.0, 1.0, 1.0],
...     [1.0, -1.0, -1.0],
...     [-1.0, 1.0, -1.0],
...     [-1.0, -1.0, 1.0],
... ]
>>> grid = pv.UnstructuredGrid(cells, celltypes, points)
>>> grid.plot(show_edges=True)
../../../_images/pyvista-UnstructuredGrid-1_01_00.png

See the Creating an Unstructured Grid example for more details on creating unstructured grids within PyVista.

Methods

UnstructuredGrid.cast_to_explicit_structured_grid()

Cast to an explicit structured grid.

UnstructuredGrid.linear_copy([deep])

Return a copy of the unstructured grid containing only linear cells.

Attributes

UnstructuredGrid.cell_connectivity

Return a the vtk cell connectivity as a numpy array.

UnstructuredGrid.cells

Return the cell data as a numpy object.

UnstructuredGrid.cells_dict

Return a dictionary that contains all cells mapped from cell types.

UnstructuredGrid.celltypes

Return the cell types array.

UnstructuredGrid.offset

Return the cell locations array.