pyvista.PolyDataFilters.decimate_polyline

pyvista.PolyDataFilters.decimate_polyline#

PolyDataFilters.decimate_polyline(
reduction: float,
*,
maximum_error: float = 10.0,
inplace: bool = False,
progress_bar: bool = False,
)[source]#

Reduce the number of lines in a polyline mesh.

This filter uses vtkDecimatePolylineFilter.

Added in version 0.45.0.

Parameters:
reductionfloat

Reduction factor. A value of 0.9 will leave 10% of the original number of vertices.

maximum_errorfloat, default: 10.

Fraction of the maximum length of the input data bounding box to limit reduction. This might prevent the full reduction from being achieved. Default of 10. should not limit reduction.

inplacebool, default: False

Whether to update the mesh in-place.

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
pyvista.PolyData

Decimated mesh.

Warning

From vtkDecimatePolylineFilter documentation: this algorithm is a very simple implementation that overlooks some potential complexities. For example, if a vertex is multiply connected, meaning that it is used by multiple distinct polylines, then the extra topological constraints are ignored. This can produce less than optimal results.

See also

decimate

For use with triangular meshes.

decimate_pro

Another option for triangular meshes.

Examples

Generate a circle, builtin function returns a Polygon cell.

>>> import pyvista as pv
>>> circle = pv.Circle(resolution=30)

Convert to a Polyline. A polyline requires duplicating reference to initial point to close the circle.

>>> circle_polyline = pv.PolyData(
...     circle.points, lines=[31] + list(range(30)) + [0]
... )
>>> circle_polyline.n_points
30

Decimate ~50% of points.

>>> decimate_some = circle_polyline.decimate_polyline(0.5)
>>> decimate_some.n_points
14

Decimate more points.

>>> decimate_more = circle_polyline.decimate_polyline(0.75)
>>> decimate_more.n_points
6

Compare decimated polylines.

>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(circle_polyline, label='Circle', color='red', line_width=5)
>>> _ = pl.add_mesh(
...     decimate_some,
...     label='Decimated some',
...     color='blue',
...     line_width=5,
... )
>>> _ = pl.add_mesh(
...     decimate_more,
...     label='Decimated more',
...     color='black',
...     line_width=5,
... )
>>> pl.view_xy()
>>> _ = pl.add_legend(face='line', size=(0.25, 0.25))
>>> pl.show()
../../../_images/pyvista-PolyDataFilters-decimate_polyline-1_00_00.png

See Decimation for more examples using this filter.