pyvista.DataSet.point_neighbors_levels

pyvista.DataSet.point_neighbors_levels#

DataSet.point_neighbors_levels(
ind: int,
n_levels: int = 1,
) Generator[list[int], None, None][source]#

Get consecutive levels of point neighbors.

Parameters:
indint

Point ID.

n_levelsint, default: 1

Number of levels to search for point neighbors. When equal to 1, it is equivalent to pyvista.DataSet.point_neighbors().

Returns:
generator[list[[int]]

A generator of list of neighbor points IDs for the ind-th point.

Examples

Get the point neighbors IDs starting from the 0-th point up until the third level.

>>> import pyvista as pv
>>> mesh = pv.Sphere(theta_resolution=10)
>>> pt_nbr_levels = mesh.point_neighbors_levels(0, 3)
>>> pt_nbr_levels = list(pt_nbr_levels)
>>> pt_nbr_levels[0]
[2, 226, 198, 170, 142, 114, 86, 30, 58, 254]
>>> pt_nbr_levels[1]
[3, 227, 255, 199, 171, 143, 115, 87, 59, 31]
>>> pt_nbr_levels[2]
[256, 32, 4, 228, 200, 172, 144, 116, 88, 60]

Visualize these points IDs.

>>> from functools import partial
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh, show_edges=True)
>>>
>>> # Define partial function to add point labels
>>> add_point_labels = partial(
...     pl.add_point_labels,
...     text_color="white",
...     font_size=40,
...     point_size=10,
... )
>>>
>>> # Add the first point label
>>> _ = add_point_labels(
...     mesh.points[0], labels=["0"], text_color="blue"
... )
>>>
>>> # Add the neighbors to the plot
>>> neighbors = mesh.point_neighbors_levels(0, n_levels=3)
>>> for i, ids in enumerate(neighbors, start=1):
...     _ = add_point_labels(
...         mesh.points[ids],
...         labels=[f"{i}"] * len(ids),
...         text_color="red",
...     )
...
>>>
>>> pl.view_xy()
>>> pl.camera.zoom(4.0)
>>> pl.show()
../../../_images/pyvista-DataSet-point_neighbors_levels-1_00_00.png