等値移動#

ボリュームデータセットを使用して等値のアニメーションを作成する

import numpy as np

import pyvista as pv
from pyvista import examples

vol = examples.download_brain()
vol
HeaderData Arrays
ImageDataInformation
N Cells6998400
N Points7109137
X Bounds0.000e+00, 1.800e+02
Y Bounds0.000e+00, 2.160e+02
Z Bounds0.000e+00, 1.800e+02
Dimensions181, 217, 181
Spacing1.000e+00, 1.000e+00, 1.000e+00
N Arrays1
NameFieldTypeN CompMinMax
image_dataPointsuint810.000e+002.550e+02


次に,表示するすべての等値の配列を作成します.

values = np.linspace(5, 150, num=25)

次に,プロットして移動できる最初の等値面を作成します.

surface = vol.contour(values[:1])

サーフェスを事前計算します

surfaces = [vol.contour([v]) for v in values]

1つのサーフェスを上書き可能な印刷対象として設定する

surface = surfaces[0].copy()
filename = "isovalue.gif"

plotter = pv.Plotter(off_screen=True)
# Open a movie file
plotter.open_gif(filename)

# Add initial mesh
plotter.add_mesh(
    surface,
    opacity=0.5,
    clim=vol.get_data_range(),
    show_scalar_bar=False,
)
# Add outline for reference
plotter.add_mesh(vol.outline_corners(), color='k')

print('Orient the view, then press "q" to close window and produce movie')
plotter.camera_position = [
    (392.9783280407326, 556.4341372317185, 235.51220650196404),
    (88.69563012828344, 119.06774369173661, 72.61750326143748),
    (-0.19275936948097383, -0.2218876327549124, 0.9558293278131397),
]

# initial render and do NOT close
plotter.show(auto_close=False)

# Run through each frame
for surf in surfaces:
    surface.copy_from(surf)
    plotter.write_frame()  # Write this frame
# Run through backwards
for surf in surfaces[::-1]:
    surface.copy_from(surf)
    plotter.write_frame()  # Write this frame

# Be sure to close the plotter when finished
plotter.close()
isovalue
Orient the view, then press "q" to close window and produce movie

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

Sphinx-Galleryによるギャラリー