英文:
Reading field data from a vtk file
问题
在以下的vtk数据文件中,我不知道如何访问字段数据。我熟悉读取Polydata的函数,但不确定如何读取下面的字段数据。有人可以帮助我吗?
# vtk DataFile Version 2.0
sampleSurface
ASCII
DATASET POLYDATA
POINTS 3721 float
0 0 0 0 0.0139286 0 0 0.0278571 0 0 0.0417857
0 0 0.0557143 0 0 0.0696429 0 0 0.0835714 0
0 0 0.0975 0 0 0.111429 0 0 0.125357 0 0
0.139286 0 0 0.153214 0 0 0.167143 0 0 0.181071
0 0 0.195 0 0 0.208929 0 0 0.222857 0
0 0.236786 0 0 0.250714 0 0 0.264643 0 0
0.278571 0 0 0.2925 0 0 0.306429 0 0 0.320357
0 0 0.334286 0 0 0.348214 0 0 0.362143 0
POLYGONS 3600 18000
4 62 61 0 1 4 63 62 1 2 4
64 63 2 3 4 65 64 3 4 4
66 65 4 5 4 67 66 5 6 4
68 67 6 7 4 69 68 7 8 4
70 69 8 9 4 71 70 9 10 4
72 71 10 11 4 73 72 11 12 4
74 73 12 13 4 75 74 13 14 4
76 75 14 15 4 77 76 15 16 4
78 77 16 17 4 79 78 17 18 4
80 79 18 19 4 81 80 19 20 4
82 81 20 21 4 83 82 21 22 4
84 83 22 23 4 85 84 23 24 4
86 85 24 25 4 87 86 25 26 4
88 87 26 27 4 89 88 27 28 4
90 89 28 29 4 91 90 29 30 4
92 91 30 31 4 93 92 31 32 4
CELL_DATA 3600
FIELD attributes 2
p 1 3600 float
81.7602 82.0853 81.4747 81.251 80.6114 79.9061 79.044 78.027 76.8713 75.5719 74.1311
72.551 70.8329 68.9783 66.9892 64.8677 62.6162 60.2374 57.7347 55.1119 52.3734
49.5245 46.5713 43.5209 40.3816 37.163 33.8764 30.5347 27.1528 23.7481 20.3405
16.953 13.6121 10.3482 7.19618 4.19617 1.39389 -1.15773 -3.3983 -5.2636 -6.67261
-7.52487 -7.68399 -7.59999 -7.35818 -6.99297 -6.53171 -5.99927 -5.41668 -4.80168 -4.16905
-3.52961 -2.89437 -2.27506 -1.67807 -1.03211 -0.572529 -0.157589 1.07343 0.446295 82.0853
82.4052 81.7922 81.5632 80.9185 80.2079 79.3401 78.3174 77.1558 75.8504 74.4034
英文:
In the following vtk data file. I don't know how to access the field data. I am familiar with the functions to read the Polydata but not sure how to read the field data below it. Can somebody help me with it ?
# vtk DataFile Version 2.0
sampleSurface
ASCII
DATASET POLYDATA
POINTS 3721 float
0 0 0 0 0.0139286 0 0 0.0278571 0 0 0.0417857
0 0 0.0557143 0 0 0.0696429 0 0 0.0835714 0
0 0.0975 0 0 0.111429 0 0 0.125357 0 0
0.139286 0 0 0.153214 0 0 0.167143 0 0 0.181071
0 0 0.195 0 0 0.208929 0 0 0.222857 0
0 0.236786 0 0 0.250714 0 0 0.264643 0 0
0.278571 0 0 0.2925 0 0 0.306429 0 0 0.320357
0 0 0.334286 0 0 0.348214 0 0 0.362143 0
POLYGONS 3600 18000
4 62 61 0 1 4 63 62 1 2 4
64 63 2 3 4 65 64 3 4 4
66 65 4 5 4 67 66 5 6 4
68 67 6 7 4 69 68 7 8 4
70 69 8 9 4 71 70 9 10 4
72 71 10 11 4 73 72 11 12 4
74 73 12 13 4 75 74 13 14 4
76 75 14 15 4 77 76 15 16 4
78 77 16 17 4 79 78 17 18 4
80 79 18 19 4 81 80 19 20 4
82 81 20 21 4 83 82 21 22 4
84 83 22 23 4 85 84 23 24 4
86 85 24 25 4 87 86 25 26 4
88 87 26 27 4 89 88 27 28 4
90 89 28 29 4 91 90 29 30 4
92 91 30 31 4 93 92 31 32 4
CELL_DATA 3600
FIELD attributes 2
p 1 3600 float
81.7602 82.0853 81.4747 81.251 80.6114 79.9061 79.044 78.027 76.8713 75.5719 74.1311
72.551 70.8329 68.9783 66.9892 64.8677 62.6162 60.2374 57.7347 55.1119 52.3734
49.5245 46.5713 43.5209 40.3816 37.163 33.8764 30.5347 27.1528 23.7481 20.3405
16.953 13.6121 10.3482 7.19618 4.19617 1.39389 -1.15773 -3.3983 -5.2636 -6.67261
-7.52487 -7.68399 -7.59999 -7.35818 -6.99297 -6.53171 -5.99927 -5.41668 -4.80168 -4.16905
-3.52961 -2.89437 -2.27506 -1.67807 -1.03211 -0.572529 -0.157589 1.07343 0.446295 82.0853
82.4052 81.7922 81.5632 80.9185 80.2079 79.3401 78.3174 77.1558 75.8504 74.4034
答案1
得分: 1
考虑一个非常简单的 vtk 数据文件:data.vtk
:
import numpy as np
import pyvista as pv
# 从当前目录中读取在 Windows 中
data = pv.read(".\\data.vtk")
print(f'{data=}')
这是输出结果:
data=PolyData (0x19455cd0f40)
N Cells: 1
N Points: 3
N Strips: 0
X Bounds: 0.000e+00, 1.000e+00
Y Bounds: 0.000e+00, 1.000e+00
Z Bounds: 0.000e+00, 0.000e+00
N Arrays: 0
vtk 数据文件描述了一个具有顶点 (0,0,0)
, (1,0,0)
, (0,1,0)
的单个三角形:
POINTS 3 float
指定了有 3 个点,使用浮点数据类型,在数据集中。这 3 个点的坐标在以下 3 行中:0 0 0 1 0 0 0 1 0
POLYGONS 1 4
指定了数据集中有一个多边形,以及 4 个整数来索引这些点:3 0 1 2
3: 多边形中有 3 个点
0: 第一个点的索引是数据集中的索引 0,即(0,0,0)
1: 第二个点的索引是数据集中的索引 1,即(1,0,0)
2: 第三个点的索引是数据集中的索引 2,即(0,1,0)
你可以从 https://examples.vtk.org/site/VTKFileFormats/ 获取更多关于 vtk 数据格式的信息。
英文:
Consider a very simple vtk data file: data.vtk
:
# vtk DataFile Version 3.0
VTK example file
ASCII
DATASET POLYDATA
POINTS 3 float
0 0 0
1 0 0
0 1 0
POLYGONS 1 4
3 0 1 2
You can use the following code to read the vtk data file:
import numpy as np
import pyvista as pv
# Read from the current directory in Windows
data = pv.read(".\\data.vtk")
print(f'{data=}')
This is the output:
data=PolyData (0x19455cd0f40)
N Cells: 1
N Points: 3
N Strips: 0
X Bounds: 0.000e+00, 1.000e+00
Y Bounds: 0.000e+00, 1.000e+00
Z Bounds: 0.000e+00, 0.000e+00
N Arrays: 0
The vtk data file describes a single triangle with vertices at (0,0,0)
, (1,0,0)
, (0,1,0)
:
POINTS 3 float
specifies that there are 3 points, in floating point data type, in the datasets. The coordinates of the 3 points are in the following 3 lines:0 0 0 1 0 0 0 1 0
- The
POLYGONS 1 4
specifies that there is one polygon in the dataset, and 4 integers to index the points:3 0 1 2
3: There are 3 points in the polygon
0: The 1st point is at index 0 of datasets, i.e.,(0,0,0)
1: The 2nd point is at index 1 of datasets, i.e.,(1,0,0)
2: The 3rd point is at index 2 of datasets, i.e.,(0,1,0)
You can find out more about vtk data format from https://examples.vtk.org/site/VTKFileFormats/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论