PolyDataFilters.decimate_binned

PolyDataFilters.decimate_binned#

PolyDataFilters.decimate_binned(
target_reduction: float | None = None,
*,
target_points: int | None = None,
divisions: int | VectorLikeInt | None = None,
point_generation: _BinnedPointGenerationOptions = 'bin_points',
inplace: bool = False,
progress_bar: bool = False,
) → PolyData[source]#

Reduce the number of triangles by merging points that share a spatial bin.

The bounds of the mesh are split into a regular grid of bins, every bin collapses to a single point, and a triangle survives only when its three points land in three different bins. This uses vtkBinnedDecimation, which is threaded and typically orders of magnitude faster than decimate() and decimate_pro() on large meshes, at the cost of not preserving topology. It suits previews and level-of-detail rendering of very large surfaces.

Give exactly one of target_reduction, target_points or divisions.

Added in version 0.50.

Parameters:
target_reductionfloat, optional

Fraction of the points to remove, from 0 up to but not including 1. A value of 0.9 leaves about 10% of the points. The grid is then sized as for target_points.

target_pointsint, optional

Approximate number of points in the output. Cubic bins are sized over a few passes until the output is within about 5 percent of the target. Small targets can land further off, since each bin then covers a large part of the surface, and very large ones stop short when the grid reaches 2**28 bins.

divisionsint | VectorLikeInt, optional

Number of bins along each axis. A single integer applies to the longest axis of the bounds and the other axes get proportionally fewer, with at least one per axis. Three integers set each axis explicitly.

point_generationstr, default: ‘bin_points’

How the point of each bin is chosen.

  • 'bin_points': keep one of the input points in the bin along with its point data.

  • 'bin_averages': average the points in the bin and their point data. Smoother, and slightly slower. Integer point arrays become floating point and non-numeric point arrays are dropped.

  • 'bin_centers': place the point at the center of the bin, giving a voxelized look, with the point data of one input point.

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.

Warns:
UserWarning

When target_reduction or target_points is given and the output has fewer than half of the target points, or of the input points if there are fewer.

Notes#

The filter allocates one integer per bin, so memory grows with the product of the divisions rather than with the size of the mesh: about 1 GB at the 2**28 bins a target stops at. Explicit divisions are not limited.

The bins span the bounds of the points used by the mesh, so a part far from the rest coarsens the whole grid and parts smaller than a bin merge away.

Points created by 'bin_centers' and 'bin_averages' are single precision.

Examples#

Download Python source code | Download Jupyter notebook

Decimate a sphere to roughly 2000 points and plot it.

>>> import pyvista as pv
>>> sphere = pv.Sphere(theta_resolution=200, phi_resolution=200)
>>> decimated = sphere.decimate_binned(target_points=2000)
>>> decimated.plot(show_edges=True, line_width=2)
../../../_images/pyvista-PolyDataFilters-decimate_binned-bf77da8d873c9ace_00_00.png

Remove about 90% of the points.

Use an explicit bin grid, averaging the points in each bin.

>>> decimated = sphere.decimate_binned(
...     divisions=20, point_generation='bin_averages'
... )

See Also#

decimate

Quadric decimation, slower and closer to the input.

decimate_pro

Topology-aware decimation of triangular meshes.