注釈
Go to the end to download the full example code.
ファイルからロードおよびプロットする#
既知のファイルタイプからデータセットを読み取ります.
メッシュのロードは簡単です.- データが多くのサポートされているファイルフォーマットの1つである場合は, pyvista.read()
を使用して空間的に参照されるデータセットをPyVistaメッシュオブジェクトにロードします.
次のコードブロックでは,組み込みのサンプルファイルを使用して,飛行機のメッシュを表示します.
from __future__ import annotations
import pyvista as pv
from pyvista import examples
次のコードブロックでは,組み込みのサンプルファイルを使用して,飛行機のメッシュを表示し,カメラの位置を取得します.
# Get a sample file
filename = examples.planefile
filename
'/home/runner/work/pyvista-docs-dev-ja/pyvista-docs-dev-ja/pyvista-doc-translations/pyvista/pyvista/examples/airplane.ply'
上記のファイル名に注意してください.これは .ply
ファイルで,PyVistaでサポートされている多くのフォーマットの1つです.

Plotter
を使用して,インタラクティブなプロットウィンドウを作成せずにスクリーンショットを撮ることもできます.
plotter = pv.Plotter(off_screen=True)
plotter.add_mesh(mesh)
plotter.show(screenshot='myscreenshot.png')

メッシュのポイントは,NumPy配列として直接アクセスできます.
mesh.points
pyvista_ndarray([[896.994 , 48.7601 , 82.2656 ],
[906.593 , 48.7601 , 80.7452 ],
[907.539 , 55.4902 , 83.6581 ],
...,
[806.665 , 627.363 , 5.11482],
[806.665 , 654.432 , 7.51998],
[806.665 , 681.537 , 9.48744]], dtype=float32)
メッシュの面は,NumPy配列として直接アクセスできます.
mesh.faces.reshape(-1, 4)[:, 1:] # triangular faces
array([[ 0, 1, 2],
[ 0, 2, 3],
[ 4, 5, 1],
...,
[1324, 1333, 1323],
[1325, 1216, 1334],
[1325, 1334, 1324]])
他のファイルタイプのロードも同じくらい簡単です.ファイルパスを pyvista.read()
関数に渡すだけです.
その他の例をいくつか紹介します - examples.download_*
を pyvista.read('path/to/you/file.ext')
で置き換えています.
STLファイルの例:

OBJファイルの例:
mesh = examples.download_doorman()
mesh.plot(cpos='xy')

BYUファイルの例:
mesh = examples.download_teapot()
mesh.plot(cpos=[-1, 2, -5], show_edges=True)

VTKファイルの例:

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