0

我有一个 VTK 文件,我可以使用pyvista. 当我在任何 3D 查看器应用程序(例如 Paraview)中打开此文件时,我可以看到点及其值(在 X、Y、Z 中分布有许多点,每个点都有自己的值)。

pyvista我只能看到点坐标并且不知道如何访问每个坐标处的值(或标签)。

import pyvista as pv
pd = pv.read('data.vtk')
pd.points

# UnstructuredGrid (0x20fef143e28)
#  N Cells: 0
#  N Points:    80851
#  X Bounds:    -2.570e+03, 2.550e+03
#  Y Bounds:    -1.280e+03, 1.280e+03
#  Z Bounds:    -1.075e+03, 2.048e+02
#  N Arrays:    0
4

1 回答 1

0

You're referring to the point_arrays property, which you can use to access scalars associated with each point.

If you've assigned a value to each point within a mesh, you can access it with the point_arrays property, which behaves like a python dictionary. For example, when generating a Sphere within pyvista, the normals are included with the mesh and can be accessed with:

>>> import pyvista as pv
>>> mesh =  pv.Sphere()
>>> mesh.point_arrays['Normals']
pyvista_ndarray([[ 0.        ,  0.        ,  1.        ],
                 [ 0.        ,  0.        , -1.        ],
                 [ 0.10811902,  0.        ,  0.99413794],
                 ...,
                 [ 0.31232402, -0.06638652, -0.9476532 ],
                 [ 0.21027282, -0.04469487, -0.97662055],
                 [ 0.10575636, -0.02247921, -0.99413794]], dtype=float32)

See the Basic API Usage for more details.

于 2020-09-27T19:40:31.160 回答