pyvista.DataSetFilters.merge

pyvista.DataSetFilters.merge#

DataSetFilters.merge(
grid: DataSet | _vtk.vtkDataSet | MultiBlock | Sequence[DataSet | _vtk.vtkDataSet] | None = None,
merge_points: bool = True,
tolerance: float = 0.0,
inplace: bool = False,
main_has_priority: bool | None = None,
progress_bar: bool = False,
)[source]#

Join one or many other grids to this grid.

Can be used to merge points of adjacent cells when no grids are input.

Note

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

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:
gridvtkUnstructuredGrid | list[vtkUnstructuredGrid], optional

Grids to merge to this grid.

merge_pointsbool, default: True

Points in exactly the same location will be merged between the two meshes. Warning: this can leave degenerate point data.

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 an pyvista.UnstructuredGrid.

main_has_prioritybool, default: True

When this parameter is true and merge_points is 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.UnstructuredGrid

Merged grid.

Notes

When two or more grids are joined, the type and name of each array must match or the arrays will be ignored and not included in the final merged mesh.

Examples

Merge three separate spheres into a single mesh.

>>> import pyvista as pv
>>> sphere_a = pv.Sphere(center=(1, 0, 0))
>>> sphere_b = pv.Sphere(center=(0, 1, 0))
>>> sphere_c = pv.Sphere(center=(0, 0, 1))
>>> merged = sphere_a.merge([sphere_b, sphere_c])
>>> merged.plot()
../../../_images/pyvista-DataSetFilters-merge-1_00_00.png