DataSetFilters.extract_cells_by_type#
- DataSetFilters.extract_cells_by_type(
- cell_types: int | VectorLikeInt,
- *,
- progress_bar: bool = False,
Extract cells of a specified type.
Given an input dataset and a list of cell types, produce an output dataset containing only cells of the specified types. Note that if the input dataset is homogeneous (for example, all cells are of the same type) and the cell type is one of the cells specified, then the input dataset is shallow copied to the output.
The type of output dataset is always the same as the input type. Since structured types of data (that is,
pyvista.ImageData,pyvista.StructuredGrid,pyvista.RectilinearGrid) are all composed of a cell of the same type, the output is either empty, or a shallow copy of the input. Unstructured data (pyvista.UnstructuredGrid,pyvista.PolyData) input may produce a subset of the input data (depending on the selected cell types).- Parameters:
- cell_types
int|VectorLikeInt The cell types to extract. Must be a single or list of integer cell types. See
pyvista.CellType.- progress_barbool, default:
False Display a progress bar to indicate progress.
- cell_types
- Returns:
pyvista.DataSetDataset with the extracted cells. Type is the same as the input.
Notes#
Unlike pyvista.DataSetFilters.extract_cells() which always
produces a pyvista.UnstructuredGrid output, this filter
produces the same output type as input type.
A PointSet has no cells, so extracting from one raises
PointSetCellOperationError.
Changed in version 0.50: A PointSet raises instead of giving an empty dataset.
Examples#
Download Python source code | Download Jupyter notebook
Create an unstructured grid with both hexahedral and tetrahedral cells and then extract each individual cell type.
>>> import pyvista as pv
>>> from pyvista import examples
>>> beam = examples.load_hexbeam()
>>> beam = beam.translate([1, 0, 0])
>>> ugrid = beam + examples.load_tetbeam()
>>> hex_cells = ugrid.extract_cells_by_type(pv.CellType.HEXAHEDRON)
>>> tet_cells = ugrid.extract_cells_by_type(pv.CellType.TETRA)
>>> pl = pv.Plotter(shape=(1, 2))
>>> _ = pl.add_text('Extracted Hexahedron cells')
>>> _ = pl.add_mesh(hex_cells, show_edges=True)
>>> pl.subplot(0, 1)
>>> _ = pl.add_text('Extracted Tetrahedron cells')
>>> _ = pl.add_mesh(tet_cells, show_edges=True)
>>> pl.show()