UnstructuredGrid.cells

UnstructuredGrid.cells#

property UnstructuredGrid.cells: NDArray[np.signedinteger][source]#

Return the cell data as a NumPy object.

This is the old style VTK data layout:

[n0, p0_0, p0_1, ..., p0_n, n1, p1_0, p1_1, ..., p1_n, ...]

where n0 is the number of points in cell 0, and pX_Y is point Y in cell X.

For example, a triangle and a line might be represented as:

[3, 0, 1, 2, 2, 0, 1]

Where the two individual cells would be [3, 0, 1, 2] and [2, 0, 1].

Notes#

The array returned cannot be modified in place and will raise a ValueError if attempted.

You can, however, set the cells directly. See the example.

For POLYHEDRON cells, only the points of each cell are stored here. The faces are stored separately, so this array is not the connectivity array used to define the cell. Use polyhedron_faces and polyhedron_face_locations to get them.

Examples#

Download Python source code | Download Jupyter notebook

Return the indices of the first two cells from the example hex beam. Note how the cells have “padding” indicating the number of points per cell.

>>> import pyvista as pv
>>> from pyvista import examples
>>> grid = examples.load_hexbeam()
>>> grid.cells[:18]
array([ 8,  0,  2,  8,  7, 27, 36, 90, 81,  8,  2,  1,  4,  8, 36, 18, 54,
       90]...)

While you cannot change the array inplace, you can overwrite it. For example:

>>> grid.cells = [8, 0, 1, 2, 3, 4, 5, 6, 7]

Create a grid with a single tetrahedron defined as a polyhedron. The cells only contain its four points and not its faces.

>>> points = [[0, 0, 0], [1, 0, 0], [0.5, 0.5, 0], [0, 0, 1]]
>>> faces = [4, 3, 0, 1, 2, 3, 0, 1, 3, 3, 0, 2, 3, 3, 1, 2, 3]
>>> grid = pv.UnstructuredGrid(
...     [len(faces), *faces], [pv.CellType.POLYHEDRON], points
... )
>>> grid.cells
array([4, 0, 1, 2, 3]...)

See Also#

pyvista.DataSet.get_cell
pyvista.UnstructuredGrid.cell_connectivity
pyvista.UnstructuredGrid.cell_offsets
pyvista.UnstructuredGrid.polyhedron_faces
pyvista.UnstructuredGrid.polyhedron_face_locations