pyvista.DataSet.cell_neighbors#
- DataSet.cell_neighbors(ind: int, connections: str = 'points') List[int] [ソース]#
ind番目のセルの近傍セルを返します.
vtkDataSet の GetCellNeighbors の具体的な実装です.
- パラメータ:
- 戻り値:
List
[int
]ind番目のセルの近隣セルIDのリスト.
例
>>> from pyvista import examples >>> mesh = examples.load_airplane()
0番目のセルと少なくとも1点の共通点を持つ隣セルidを返します.
>>> mesh.cell_neighbors(0, "points") [1, 2, 3, 388, 389, 11, 12, 395, 14, 209, 211, 212]
0番目のセルと少なくとも1点の共通エッジを持つ隣セルidを返します.
>>> mesh.cell_neighbors(0, "edges") [1, 3, 12]
3次元のセルを持つ非構造格子(例えば四面体)の場合,セルの近傍は面を使って定義することができます.
>>> mesh = examples.download_tetrahedron() >>> mesh.cell_neighbors(0, "faces") [1, 5, 7]
視覚的な例を示します.
>>> from functools import partial >>> import pyvista as pv >>> mesh = pv.Sphere(theta_resolution=10) >>> >>> pl = pv.Plotter(shape=(1, 2)) >>> pl.link_views() >>> add_point_labels = partial( ... pl.add_point_labels, ... text_color="white", ... font_size=20, ... shape=None, ... show_points=False, ... ) >>> >>> for i, connection in enumerate(["points", "edges"]): ... pl.subplot(0, i) ... pl.view_xy() ... _ = pl.add_title( ... f"{connection.capitalize()} neighbors", ... color="red", ... shadow=True, ... font_size=8, ... ) ... ... # Add current cell ... i_cell = 0 ... current_cell = mesh.extract_cells(i_cell) ... _ = pl.add_mesh( ... current_cell, show_edges=True, color="blue" ... ) ... _ = add_point_labels( ... current_cell.cell_centers().points, ... labels=[f"{i_cell}"], ... ) ... ... # Add neighbors ... ids = mesh.cell_neighbors(i_cell, connection) ... cells = mesh.extract_cells(ids) ... _ = pl.add_mesh(cells, color="red", show_edges=True) ... _ = add_point_labels( ... cells.cell_centers().points, ... labels=[f"{i}" for i in ids], ... ) ... ... # Add other cells ... ids.append(i_cell) ... others = mesh.extract_cells(ids, invert=True) ... _ = pl.add_mesh(others, show_edges=True) ... >>> pl.show()