注釈
Go to the end to download the full example code.
サーフェイススムージング#
サーフェスメッシュの粗いエッジをスムージングする
from __future__ import annotations
import pyvista as pv
from pyvista import examples
大まかに定義されたエッジを持つデータセットのボリュームサブセットを抽出するとします.おそらく,そのモデル領域をスムーズに表現する必要があります.これは,ボリュームの境界サーフェスを抽出し, pyvista.PolyDataFilters.smooth()
フィルタを適用することで実現できます.
次のコードスニペットは,サンプルの大まかなエッジのボリュームデータセットをロードします.

pyvista.DataSetFilters.extract_geometry()
フィルタを使用してボリュームの外側サーフェスを抽出し,次にスムージングフィルタを適用します.

滑らかさが足りませんか?Laplacianスムージングアルゴリズムの反復回数を増やしてみます.

まだ滑らかではありませんか?ラプラシアン平滑化アルゴリズムの反復回数を非常に高い値に増やします.これにより,メッシュが "shrink" されることに注意してください.
# Smooth the surface EVEN MORE
smooth = surf.smooth(n_iter=1000)
# extract the edges of the original unsmoothed mesh
orig_edges = surf.extract_feature_edges()
pl = pv.Plotter()
pl.add_mesh(smooth, show_edges=True, show_scalar_bar=False)
pl.camera_position = cpos
pl.add_mesh(orig_edges, show_scalar_bar=False, color='k', line_width=2)
pl.show()

Taubin スムージング#
smooth()
で実装されているデフォルトのラプラシアンスムージングではなく,タウビンスムージングを使用すると,表面の縮小の量を減らすことができます.この例では,タウビンスムージングが元のメッシュに対してどのようにボリュームを維持しているかを見ることができます.
また,反復回数を減らすことで,同じ程度の平滑化量を得ることができることに注意してください.これは,タウバンスムージングがより効率的であるためです.
smooth_w_taubin = surf.smooth_taubin(n_iter=50, pass_band=0.05)
pl = pv.Plotter()
pl.add_mesh(smooth_w_taubin, show_edges=True, show_scalar_bar=False)
pl.camera_position = cpos
pl.add_mesh(orig_edges, show_scalar_bar=False, color='k', line_width=2)
pl.show()
# output the volumes of the original and smoothed meshes
print(f'Original surface volume: {surf.volume:.1f}')
print(f'Laplacian smoothed volume: {smooth.volume:.1f}')
print(f'Taubin smoothed volume: {smooth_w_taubin.volume:.1f}')

Original surface volume: 597.0
Laplacian smoothed volume: 402.1
Taubin smoothed volume: 589.8
Total running time of the script: (0 minutes 1.349 seconds)