DataObjectFilters.slice_along_line#
- DataObjectFilters.slice_along_line(
- line: pv.PolyData,
- *,
- generate_triangles: bool = False,
- contour: bool = False,
- progress_bar: bool = False,
Slice a dataset using a polyline/spline as the path.
This also works for lines generated with
pyvista.Line().- Parameters:
- line
pyvista.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. Passgenerate_triangles=Truefor the fast path. Seeslice_implicit()for details.- contourbool, default:
False If
True, apply acontourfilter after slicing.- progress_barbool, default:
False Display a progress bar to indicate progress.
- line
- Returns:
pyvista.PolyData|pyvista.MultiBlockSliced dataset. Every dataset gives a
PolyData, and aMultiBlockgives aMultiBlockofPolyDatablocks, 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()
See Also#
Used In#
Gallery Examples