pyvista.PolyDataFilters.decimate

pyvista.PolyDataFilters.decimate#

PolyDataFilters.decimate(
target_reduction,
volume_preservation: bool = False,
attribute_error: bool | None = None,
scalars: bool | None = None,
vectors: bool | None = None,
normals: bool | None = None,
tcoords: bool | None = None,
tensors: bool | None = None,
scalars_weight=0.1,
vectors_weight=0.1,
normals_weight=0.1,
tcoords_weight=0.1,
tensors_weight=0.1,
inplace: bool = False,
progress_bar: bool = False,
boundary_constraints: bool = False,
boundary_weight: float = 1.0,
enable_all_attribute_error: bool = False,
)[source]#

Reduce the number of triangles in a triangular mesh using vtkQuadricDecimation.

Changed in version 0.45: scalars, vectors, normals, tcoords and tensors are now disabled by default. They can be enabled all together using enable_all_attribute_error.

Parameters:
target_reductionfloat

Fraction of the original mesh to remove. If target_reduction is set to 0.9, this filter will try to reduce the data set to 10% of its original size and will remove 90% of the input triangles.

volume_preservationbool, default: False

Decide whether to activate volume preservation which greatly reduces errors in triangle normal direction. If False, volume preservation is disabled and if attribute_error is active, these errors can be large.

attribute_errorbool, default: False

Decide whether to include data attributes in the error metric. If False, then only geometric error is used to control the decimation. If True, the following flags are used to specify which attributes are to be included in the error calculation.

Deprecated since version 0.45.0.

scalarsbool, default: False

This flags control specifically if the scalar attributes are to be included in the error calculation.

vectorsbool, default: False

See scalars parameter.

normalsbool, default: False

See scalars parameter. .. versionchanged:: 0.45.0

tcoordsbool, default: False

See scalars parameter.

tensorsbool, default: False

See scalars parameter.

scalars_weightfloat, default: 0.1

The scaling weight contribution of the scalar attribute. These values are used to weight the contribution of the attributes towards the error metric.

vectors_weightfloat, default: 0.1

See scalars_weight parameter.

normals_weightfloat, default: 0.1

See scalars_weight parameter.

tcoords_weightfloat, default: 0.1

See scalars_weight parameter.

tensors_weightfloat, default: 0.1

See scalars_weight parameter.

inplacebool, default: False

Whether to update the mesh in-place.

progress_barbool, default: False

Display a progress bar to indicate progress.

boundary_constraints: bool, default: False

Use the legacy weighting by boundary_edge_length instead of by boundary_edge_length^2 for backwards compatibility. It requires vtk>=9.3.0.

Added in version 0.45.0.

boundary_weight: float, default: 1.0

A floating point factor to weigh the boundary quadric constraints by: higher factors further constrain the boundary. It requires vtk>=9.3.0.

Added in version 0.45.0.

enable_all_attribute_error: bool, default: False

This flag control the default value of all attribute metrics to eventually include them in the error calculation

Added in version 0.45.0.

Returns:
pyvista.PolyData

Decimated mesh.

See also

decimate_pro

Another option for triangular meshes.

decimate_polyline

For use with polylines.

Notes

If you encounter a segmentation fault or other error, consider using pyvista.PolyDataFilters.clean() to remove any invalid cells before using this filter.

Examples

Decimate a sphere. First plot the sphere.

>>> import pyvista as pv
>>> sphere = pv.Sphere(phi_resolution=60, theta_resolution=60)
>>> sphere.plot(show_edges=True, line_width=2)
../../../_images/pyvista-PolyDataFilters-decimate-1_00_00.png

Now decimate it by 75% and plot it.

>>> decimated = sphere.decimate(0.75)
>>> decimated.plot(show_edges=True, line_width=2)
../../../_images/pyvista-PolyDataFilters-decimate-1_01_00.png

Decimate taking scalars attributes into account:

>>> decimated = sphere.decimate(0.5, scalars=True)

Decimate taking all attributes except normals into account:

>>> decimated = sphere.decimate(
...     0.5, enable_all_attribute_error=True, normals=False
... )

See Decimation for more examples using this filter.