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,
Remove cells from a mesh.
Only points used by a remaining cell are kept. The output is
PolyDataforPolyDatainput and anUnstructuredGridotherwise. Withinvert=Truethis removes every cell except those specified, which isextract_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 theinvert,pass_point_ids,pass_cell_ids, andprogress_barkeywords 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 raiseIndexError.- Parameters:
- ind
int|VectorLikeInt|VectorLikeBool Cell indices to remove. Can be a single
intor a vector ofints. Aboolvector 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.
- ind
- Returns:
pyvista.UnstructuredGrid|pyvista.PolyDataMesh 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)
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#
Used In#
Gallery Examples