間引き#

メッシュを縮小する

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
decimated = mesh.decimate(target_reduction)

decimated.plot(cpos=cpos, **dargs)
decimate
pro_decimated = mesh.decimate_pro(target_reduction, preserve_topology=True)

pro_decimated.plot(cpos=cpos, **dargs)
decimate

並べて比較:

pl = pv.Plotter(shape=(1, 3))
pl.add_mesh(mesh, **dargs)
pl.add_text("Input mesh", font_size=24)
pl.camera_position = cpos
pl.reset_camera()
pl.subplot(0, 1)
pl.add_mesh(decimated, **dargs)
pl.add_text("Decimated mesh", font_size=24)
pl.camera_position = cpos
pl.reset_camera()
pl.subplot(0, 2)
pl.add_mesh(pro_decimated, **dargs)
pl.add_text("Pro Decimated mesh", font_size=24)
pl.camera_position = cpos
pl.reset_camera()
pl.link_views()
pl.show()
decimate

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

Sphinx-Galleryによるギャラリー