PolyData.line_connectivity

PolyData.line_connectivity#

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

Return the connectivity array of the line cells.

The connectivity array stores the point ids of every line, one line after another and without any padding. Use line_offsets to determine where each line begins and ends.

Vertices, lines, faces, and strips are held in four separate cell arrays, each with its own offsets and connectivity.

Added in version 0.49.

Returns:
numpy.ndarray

Point ids that define the lines.

Notes#

The returned array is read-only and cannot be modified in place. To change the connectivity, assign a new array to this property. The input is copied, so the mesh never aliases an array that may be modified later. To replace the offsets and connectivity together, assign a pyvista.CellArray to lines.

Where that copy is too expensive, assign a pyvista.CellArray built with from_arrays() and deep=False to lines, and keep a reference to the connectivity array. The mesh then wraps that array, so writing to it changes the lines without any copy. Nothing validates the point ids written this way.

Examples#

Download Python source code | Download Jupyter notebook

>>> import pyvista as pv
>>> mesh = pv.Line()
>>> mesh.line_connectivity
array([0, 1]...)

The array is read-only and writing to it raises a ValueError.

>>> mesh.line_connectivity.flags['WRITEABLE']
False

Assign a new array instead. Here the line is reversed.

>>> mesh.line_connectivity = [1, 0]
>>> mesh.line_connectivity
array([1, 0]...)

For a mesh large enough that the copy matters, keep the connectivity array and edit it in place.

>>> import numpy as np
>>> connectivity = np.array([0, 1], dtype=pv.ID_TYPE)
>>> mesh.lines = pv.CellArray.from_arrays([0, 2], connectivity, deep=False)
>>> connectivity[:] = [1, 0]
>>> mesh.line_connectivity
array([1, 0]...)

See Also#

line_offsets

Index into this array at which each line begins.

n_lines

Number of line cells.

lines

Lines in the legacy padded format.

vert_connectivity, face_connectivity, strip_connectivity

Connectivity arrays of the other PolyData cell types.