注釈
Go to the end to download the full example code.
サーフェスを使用したクリップ#
pyvista.DataSetFilters.clip_surface()
フィルタを使用して pyvista.PolyData
サーフェスメッシュによってPyVistaデータセットをクリップします.
最初に,暗黙的な距離を計算してメッシュを閾値設定することにより,クリッピングを実行する方法を説明します.この閾値設定は,サーフェスでクリップし,指定されたメッシュの元のジオメトリを保持する1つの方法ですが,多くのユーザは clip_surface
フィルタを利用して,クリップに沿ってメッシュジオメトリを3角形化/面分割します.
from __future__ import annotations
import numpy as np
import pyvista as pv
from pyvista import examples
surface = pv.Cone(direction=(0, 0, -1), height=3.0, radius=1, resolution=50, capping=False)
# Make a gridded dataset
n = 51
xx = yy = zz = 1 - np.linspace(0, n, n) * 2 / (n - 1)
dataset = pv.RectilinearGrid(xx, yy, zz)
# Preview the problem
p = pv.Plotter()
p.add_mesh(surface, color='w', label='Surface')
p.add_mesh(dataset, color='gold', show_edges=True, opacity=0.75, label='To Clip')
p.add_legend()
p.show()

pyvista.DataSetFilters.compute_implicit_distance()
フィルタを使用してサーフェスクリッピングを実行する際に使用される暗黙的な関数を確認してください. implicit_distance
フィールドが0であるクリッピング操作フィールドが実行され, invert
フラグが0のどちら側を保持するかを制御します.
dataset.compute_implicit_distance(surface, inplace=True)
inner = dataset.threshold(0.0, scalars='implicit_distance', invert=True)
outer = dataset.threshold(0.0, scalars='implicit_distance', invert=False)
p = pv.Plotter()
p.add_mesh(surface, color='w', label='Surface', opacity=0.75)
p.add_mesh(
inner,
scalars='implicit_distance',
show_edges=True,
opacity=0.75,
label='Inner region',
clim=[-1, 1],
cmap='bwr',
)
p.add_legend()
p.show()

p = pv.Plotter()
p.add_mesh(surface, color='w', label='Surface', opacity=0.75)
p.add_mesh(
outer,
scalars='implicit_distance',
show_edges=True,
opacity=0.75,
label='Outer region',
clim=[-1, 1],
cmap='bwr',
)
p.add_legend()
p.show()

pyvista.DataSetFilters.clip_surface()
フィルタを介して pyvista.PolyData
サーフェスメッシュを使用して,直線グリッドデータセットをクリップします.これにより,クリップに沿ってメッシュジオメトリが3角形化/面分割されます.
clipped = dataset.clip_surface(surface, invert=False)
# Visualize the results
p = pv.Plotter()
p.add_mesh(surface, color='w', opacity=0.75, label='Surface')
p.add_mesh(clipped, color='gold', show_edges=True, label='clipped', opacity=0.75)
p.add_legend()
p.show()

次に,サーフェスでメッシュをクリップする別の例を示します.今回は,地形サーフェスの周囲に pyvista.ImageData
を生成し,サーフェスを使用してグリッドをクリップして,サーフェスの閉じた3 Dモデルを作成します.
surface = examples.load_random_hills()
# Create a grid around that surface
grid = pv.create_grid(surface)
# Clip the grid using the surface
model = grid.clip_surface(surface)
# Compute height and display it
model.elevation().plot()

Total running time of the script: (0 minutes 24.201 seconds)