pyvista.PolyDataFilters.merge

pyvista.PolyDataFilters.merge#

PolyDataFilters.merge(
dataset,
merge_points: bool = True,
tolerance=0.0,
inplace: bool = False,
main_has_priority: bool | None = None,
progress_bar: bool = False,
)[source]#

Merge this mesh with one or more datasets.

Note

The behavior of this filter varies from the PolyDataFilters.boolean_union() filter. This filter does not attempt to create a manifold mesh and will include internal surfaces when two meshes overlap.

Note

The + operator between two meshes uses this filter with the default parameters. When the other mesh is also a pyvista.PolyData, in-place merging via += is similarly possible.

Changed in version 0.39.0: Before version 0.39.0, if all input datasets were of type pyvista.PolyData, the VTK vtkAppendPolyData and vtkCleanPolyData filters were used to perform merging. Otherwise, DataSetFilters.merge(), which uses the VTK vtkAppendFilter filter, was called. To enhance performance and coherence with merging operations available for other datasets in pyvista, the merging operation has been delegated in 0.39.0 to DataSetFilters.merge() only, irrespectively of input datasets types. This induced that points ordering can be altered compared to previous pyvista versions when merging only PolyData together. To obtain similar results as before 0.39.0 for multiple PolyData, combine PolyDataFilters.append_polydata() and PolyDataFilters.clean().

Warning

The merge order of this filter depends on the installed version of VTK. For example, if merging meshes a, b, and c, the merged order is bca for VTK<9.5 and abc for VTK>=9.5. This may be a breaking change for some applications. If only merging two meshes, it may be possible to maintain some backwards compatibility by swapping the input order of the two meshes, though this may also affect the merged arrays and is therefore not fully backwards-compatible.

Parameters:
datasetpyvista.DataSet

PyVista dataset to merge this mesh with.

merge_pointsbool, optional

Merge equivalent points when True.

tolerancefloat, default: 0.0

The absolute tolerance to use to find coincident points when merge_points=True.

inplacebool, default: False

Updates grid inplace when True if the input type is a pyvista.PolyData. For other input meshes the result is a pyvista.UnstructuredGrid which makes in-place operation impossible.

main_has_prioritybool, optional

When this parameter is True and merge_points=True, the arrays of the merging grids will be overwritten by the original main mesh.

Deprecated since version 0.46: This keyword will be removed in a future version. The main mesh always has priority with VTK 9.5.0 or later.

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
pyvista.DataSet

pyvista.PolyData if dataset is a pyvista.PolyData, otherwise a pyvista.UnstructuredGrid.

Examples

>>> import pyvista as pv
>>> sphere_a = pv.Sphere()
>>> sphere_b = pv.Sphere(center=(0.5, 0, 0))
>>> merged = sphere_a.merge(sphere_b)
>>> merged.plot(style='wireframe', color='lightblue')
../../../_images/pyvista-PolyDataFilters-merge-1_00_00.png