pyvista.PolyData.faces

Contents

pyvista.PolyData.faces#

property PolyData.faces: NumpyArray[int][source]#

Return the connectivity array of the faces of this PolyData.

The faces array is organized as:

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

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

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

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

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

Faces can also be set by assigning a pyvista.CellArray object instead of an array.

Returns:
numpy.ndarray

Array of face connectivity.

Notes

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

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

Examples

>>> import pyvista as pv
>>> plane = pv.Plane(i_resolution=2, j_resolution=2)
>>> plane.faces
array([4, 0, 1, 4, 3, 4, 1, 2, 5, 4, 4, 3, 4, 7, 6, 4, 4, 5, 8, 7])

Note how the faces contain a “padding” indicating the number of points per face:

>>> plane.faces.reshape(-1, 5)
array([[4, 0, 1, 4, 3],
       [4, 1, 2, 5, 4],
       [4, 3, 4, 7, 6],
       [4, 4, 5, 8, 7]])

Set the faces directly. The following example creates a simple plane with a single square faces and modifies it to have two triangles instead.

>>> mesh = pv.Plane(i_resolution=1, j_resolution=1)
>>> mesh.faces = [3, 0, 1, 2, 3, 3, 2, 1]
>>> mesh.faces
array([3, 0, 1, 2, 3, 3, 2, 1])