DataSetFilters.remove_cells

DataSetFilters.remove_cells#

DataSetFilters.remove_cells(
ind: int | VectorLikeInt | VectorLikeBool,
*,
inplace: bool = False,
invert: bool = False,
pass_point_ids: bool = True,
pass_cell_ids: bool = True,
progress_bar: bool = False,
) → PolyData | UnstructuredGrid[source]#

Remove cells from a mesh.

Only points used by a remaining cell are kept. The output is PolyData for PolyData input and an UnstructuredGrid otherwise. With invert=True this removes every cell except those specified, which is extract_cells() with the input type kept:

# UnstructuredGrid, whatever the input
extracted = mesh.extract_cells(ind)

# PolyData for PolyData input, UnstructuredGrid otherwise
extracted = mesh.remove_cells(ind, invert=True)

Changed in version 0.49: This filter is available for all datasets, including StructuredGrid, and the invert, pass_point_ids, pass_cell_ids, and progress_bar keywords were added. Points no remaining cell uses are dropped, the 'vtkOriginalPointIds' and 'vtkOriginalCellIds' arrays are added by default, and negative and out-of-range indices raise IndexError.

Parameters:
indint | VectorLikeInt | VectorLikeBool

Cell indices to remove. Can be a single int or a vector of ints. A bool vector is also supported; the vector size should match the number of cells.

inplacebool, default: False

Update the mesh in-place. This is only possible when the output has the same type as the input.

invertbool, default: False

Invert the selection and remove all cells except those specified.

pass_point_idsbool, default: True

Add a point array 'vtkOriginalPointIds' that identifies the original points the remaining points correspond to.

pass_cell_idsbool, default: True

Add a cell array 'vtkOriginalCellIds' that identifies the original cells the remaining cells correspond to.

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
pyvista.UnstructuredGrid | pyvista.PolyData

Mesh with the specified cells removed.

Examples#

Download Python source code | Download Jupyter notebook

Remove 20 cells from an unstructured grid.

>>> from pyvista import examples
>>> import pyvista as pv
>>> hex_mesh = pv.read(examples.hexbeamfile)
>>> removed = hex_mesh.remove_cells(range(10, 20))
>>> removed.plot(color='lightblue', show_edges=True, line_width=3)
../../../_images/pyvista-DataSetFilters-remove_cells-eb1727a3a6379368_00_00.png

Remove cells from PolyData. The output is also PolyData.

>>> sphere = pv.Sphere()
>>> removed = sphere.remove_cells(range(100))
>>> removed.n_cells, sphere.n_cells
(1580, 1680)
>>> type(removed)
<class 'pyvista.core.pointset.PolyData'>

See Also#

extract_cells, remove_points