pyvista.DataSetFilters.extract_cells_by_type#
- DataSetFilters.extract_cells_by_type(cell_types, progress_bar=False)[source]#
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 type(s). Note that if the input dataset is homogeneous (e.g., 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 (i.e.,
pyvista.ImageData
,pyvista.StructuredGrid
, :class`pyvista.RectilnearGrid`) 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:
- Returns:
pyvista.DataSet
Dataset with the extracted cells. Type is the same as the input.
Notes
Unlike
pyvista.DataSetFilters.extract_cells()
which always produces apyvista.UnstructuredGrid
output, this filter produces the same output type as input type.Examples
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()