DataObjectFilters.slice_along_line

DataObjectFilters.slice_along_line#

DataObjectFilters.slice_along_line(
line: pv.PolyData,
*,
generate_triangles: bool = False,
contour: bool = False,
progress_bar: bool = False,
) → PolyData | MultiBlock[source]#

Slice a dataset using a polyline/spline as the path.

This also works for lines generated with pyvista.Line().

Parameters:
linepyvista.PolyData

A PolyData object containing one single PolyLine cell.

generate_trianglesbool, default: False

When True, the output will be triangles. Otherwise the output will be the intersection polygons.

Note

PyVista’s default differs from vtkCutter (which defaults to True). The polygon path is ~5x slower on UnstructuredGrids. Pass generate_triangles=True for the fast path. See slice_implicit() for details.

contourbool, default: False

If True, apply a contour filter after slicing.

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
pyvista.PolyData | pyvista.MultiBlock

Sliced dataset. Every dataset gives a PolyData, and a MultiBlock gives a MultiBlock of PolyData blocks, nested blocks included.

Notes#

A PointSet has no cells to slice, so slicing one raises PointSetDimensionReductionError, whether it is sliced directly or as a block of a MultiBlock.

Changed in version 0.50: A PointSet block raises instead of giving an empty block.

Examples#

Download Python source code | Download Jupyter notebook

Slice the random hills dataset along a circular arc.

>>> import numpy as np
>>> import pyvista as pv
>>> from pyvista import examples
>>> hills = examples.load_random_hills()
>>> center = np.array(hills.center)
>>> point_a = center + np.array([5, 0, 0])
>>> point_b = center + np.array([-5, 0, 0])
>>> arc = pv.CircularArc(
...     pointa=point_a, pointb=point_b, center=center, resolution=100
... )
>>> line_slice = hills.slice_along_line(arc)

Plot the circular arc and the hills mesh.

>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(hills, smooth_shading=True, style='wireframe')
>>> _ = pl.add_mesh(
...     line_slice,
...     line_width=10,
...     render_lines_as_tubes=True,
...     color='k',
... )
>>> _ = pl.add_mesh(arc, line_width=10, color='grey')
>>> pl.show()
../../../_images/pyvista-DataObjectFilters-slice_along_line-e8aed35c0380ab97_00_00.png

See Also#

slice
slice_implicit
slice_orthogonal
slice_along_axis
slice_index()