DataSetFilters.extract_points

DataSetFilters.extract_points#

DataSetFilters.extract_points(
ind: int | VectorLike[int] | VectorLike[bool],
adjacent_cells: bool = True,
include_cells: bool | None = None,
pass_cell_ids: bool = True,
pass_point_ids: bool = True,
progress_bar: bool = False,
*,
invert: bool = False,
)[source]#

Return a subset of the grid (with cells) that contains any of the given point indices.

The output is an UnstructuredGrid. Use remove_points() with invert=True and mode='all' to extract the same points and their cells while keeping the input type:

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

# PolyData for PolyData input, PointSet for PointSet input
extracted = mesh.remove_points(ind, mode='all', invert=True)

Changed in version 0.49: Negative and out-of-range indices raise IndexError.

Parameters:
indint | VectorLike[int] | VectorLike[bool]

Point indices to extract. Can be a single int or a vector of ints. A bool vector is also supported; the vector size should match the number of points.

adjacent_cellsbool, default: True

If True, extract the cells that contain at least one of the extracted points. If False, extract the cells that contain exclusively points from the extracted points list. Has no effect if include_cells is False.

include_cellsbool, default: None

Specifies if the cells shall be returned or not. By default, this value is True if the input has at least one cell and False otherwise, so PointSet input returns the selected points.

pass_point_idsbool, default: True

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

Added in version 0.47.

pass_cell_idsbool, default: True

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

Added in version 0.47.

progress_barbool, default: False

Display a progress bar to indicate progress.

invertbool, default: False

Invert the selection.

Added in version 0.49.

Returns:
pyvista.UnstructuredGrid | pyvista.PointSet

Subselected points. A PointSet input returns a PointSet.

Examples#

Download Python source code | Download Jupyter notebook

Extract all the points of a sphere with a Z coordinate greater than 0

>>> import pyvista as pv
>>> sphere = pv.Sphere()
>>> extracted = sphere.extract_points(
...     sphere.points[:, 2] > 0, include_cells=False
... )
>>> extracted.clear_data()  # clear for plotting
>>> extracted.plot()
../../../_images/pyvista-DataSetFilters-extract_points-f5dec45018f3d0d8_00_00.png

See Also#

extract_cells, extract_values, remove_points