間引き#

メッシュを縮小する

from __future__ import annotations

import numpy as np

import pyvista as pv
from pyvista import examples

mesh = examples.download_face()

# Define a camera position that shows this mesh properly
cpos = [(0.4, -0.07, -0.31), (0.05, -0.13, -0.06), (-0.1, 1, 0.08)]
dargs = dict(show_edges=True, color=True)

# Preview the mesh
mesh.plot(cpos=cpos, **dargs)
decimate

ここで,削減目標を定義し, pyvista.PolyDataFilters.decimate() フィルタと pyvista.PolyDataFilters.decimate_pro() フィルタを比較してみましょう.

target_reduction = 0.7
print(f'Reducing {target_reduction * 100.0} percent out of the original mesh')
Reducing 70.0 percent out of the original mesh
decimate
decimate

並べて比較:

decimate

ポリラインメッシュを分解する#

かなり遅いスパイラルポリラインメッシュを生成します。

将来使用するために、再利用可能なプロット関数を構します。

def compare_decimation(spiral, decimated):
    pl = pv.Plotter()
    pl.add_mesh(spiral, line_width=5, color='r', label='Original')
    pl.add_mesh(decimated, line_width=3, color='k', label='Decimated')
    pl.view_xy()
    pl.add_legend(face='line', size=(0.25, 0.25))

pyvista.PolyDataFilters.decimate_polyline() フィルタを使用して、50%を目標にデシメートします。

decimated = spiral.decimate_polyline(0.5)
print(f'Original # of points:  {spiral.n_points}')
print(f'Decimated # of points: {decimated.n_points}')
Original # of points:  100
Decimated # of points: 50

この程度ならデシメーションは問題なさそうです。

compare_decimation(spiral, decimated)
decimate

80%という大きな削減レベルを使用すると、表現がより粗くなります。

decimated = spiral.decimate_polyline(0.8)
print(f'Original # of points:  {spiral.n_points}')
print(f'Decimated # of points: {decimated.n_points}')
Original # of points:  100
Decimated # of points: 20

渦巻きの内側の構造は完全に失われています。

compare_decimation(spiral, decimated)
decimate

素早く変化するフィーチャーのエラーを避けるには、 maximum_error パラメータを使用します。 単位はバウンディングボックスの最大長の何分の一かです。 これは、達成される削減のレベルを制限することに注意してください。

decimated = spiral.decimate_polyline(0.8, maximum_error=0.5)
print(f'Original # of points:  {spiral.n_points}')
print(f'Decimated # of points: {decimated.n_points}')
Original # of points:  100
Decimated # of points: 45

The structure of the inner part of the spiral is captured adequately.

compare_decimation(spiral, decimated)
decimate

Tags: filter

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

Sphinx-Galleryによるギャラリー