PolyData.line_offsets

PolyData.line_offsets#

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

Return the offsets array of the line cells.

The offsets array has n_lines + 1 values and stores the index into line_connectivity at which each line begins. The point ids of line i are line_connectivity[line_offsets[i]:line_offsets[i + 1]].

Vertices, lines, faces, and strips are held in four separate cell arrays, each with its own offsets and connectivity. len(line_offsets) - 1 is therefore n_lines, not n_cells.

Added in version 0.49.

Returns:
numpy.ndarray

Array of line offsets with n_lines + 1 values.

Notes#

The returned array is read-only and cannot be modified in place. To change the offsets, assign a new array to this property. The new offsets must remain consistent with the current line_connectivity; to replace both at once, assign a pyvista.CellArray to lines. See the examples below.

Examples#

Download Python source code | Download Jupyter notebook

>>> import pyvista as pv
>>> points = [[0.0, 0.0, 0.0], [1.0, 1.0, 0.0], [2.0, 0.0, 0.0]]
>>> mesh = pv.Spline(points, 10)
>>> mesh.line_offsets
array([ 0, 10]...)

The offsets and connectivity together describe each line.

>>> mesh.line_connectivity[mesh.line_offsets[0] : mesh.line_offsets[1]]
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]...)

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

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

Assign a new array instead. Here the single polyline is split into two.

>>> mesh.line_offsets = [0, 5, 10]
>>> mesh.n_lines
2

To replace the offsets and connectivity together, assign a pyvista.CellArray to lines.

>>> mesh.lines = pv.CellArray.from_arrays([0, 2], [0, 9])
>>> mesh.n_lines
1

See Also#

line_connectivity

Point ids that define the lines.

n_lines

Number of line cells, one less than the size of this array.

lines

Lines in the legacy padded format.

vert_offsets, face_offsets, strip_offsets

Offsets arrays of the other PolyData cell types.