pyvista.DataSet.cell_neighbors_levels#

DataSet.cell_neighbors_levels(ind: int, connections: str = 'points', n_levels: int = 1) Generator[List[int], None, None][ソース]#

セル近傍の連続したレベルを返します.

パラメータ:
indint

セルID.

connectionsstr, default: "points"

隣接する(複数の)セルが現在のセルとどのように接続されていれば,隣接しているとみなされるかを記述する. 'points', 'edges' または 'faces' のいずれかを指定することができる.

n_levelsint, default: 1

セルの近傍を検索するレベルの数.1であれば, pyvista.DataSet.cell_neighbors() と同じです.

戻り値:
generator[list[int]]

各レベルのセルIDのリストを生成するジェネレータです.

0番目のセルから3番目のレベルまでの近傍のセルIDを返します.

>>> import pyvista as pv
>>> mesh = pv.Sphere(theta_resolution=10)
>>> nbr_levels = mesh.cell_neighbors_levels(
...     0, connections="edges", n_levels=3
... )
>>> nbr_levels = list(nbr_levels)
>>> nbr_levels[0]
[1, 21, 9]
>>> nbr_levels[1]
[2, 8, 74, 75, 20, 507]
>>> nbr_levels[2]
[128, 129, 3, 453, 7, 77, 23, 506]

このセルIDを可視化します.

>>> from functools import partial
>>> pv.global_theme.color_cycler = [
...     'red',
...     'green',
...     'blue',
...     'purple',
... ]
>>> pl = pv.Plotter()
>>>
>>> # Define partial function to add point labels
>>> add_point_labels = partial(
...     pl.add_point_labels,
...     text_color="white",
...     font_size=40,
...     shape=None,
...     show_points=False,
... )
>>>
>>> # Add the 0-th cell to the plotter
>>> cell = mesh.extract_cells(0)
>>> _ = pl.add_mesh(cell, show_edges=True)
>>> _ = add_point_labels(cell.cell_centers().points, labels=["0"])
>>> other_ids = [0]
>>>
>>> # Add the neighbors to the plot
>>> neighbors = mesh.cell_neighbors_levels(
...     0, connections="edges", n_levels=3
... )
>>> for i, ids in enumerate(neighbors, start=1):
...     cells = mesh.extract_cells(ids)
...     _ = pl.add_mesh(cells, show_edges=True)
...     _ = add_point_labels(
...         cells.cell_centers().points, labels=[f"{i}"] * len(ids)
...     )
...     other_ids.extend(ids)
...
>>>
>>> # Add the cell IDs that are not neighbors (ie. the rest of the sphere)
>>> cells = mesh.extract_cells(other_ids, invert=True)
>>> _ = pl.add_mesh(cells, color="white", show_edges=True)
>>>
>>> pl.view_xy()
>>> pl.camera.zoom(6.0)
>>> pl.show()
../../../_images/pyvista-DataSet-cell_neighbors_levels-1_00_00.png