文件格式

文件内容简介

第一行是数据版本声明,说明文件版本。

第二行是自己定义的一个标题,最多256个字符,以回车符\n结束。

第三行是文件格式生命,由两个选择,ACSII或者二进制BINARY

1
2
3
# vtk DataFile Version 1.0
Model_1
ASCII

之后就是最重要的数据集了。是以DATASET type 格式来体现的。其中type 可以是

  • STRUCTURED_POINTS
  • STRUCTURED_GRID
  • UNSTRUCTURED_GRID
  • POLYDATA
  • RECTILINEAR_GRID
  • FIELD

如果使用UNSTRCTURED_GRID:

‘The unstructured grid dataset consists of arbitrary combinations of any possible cell type. Unstructured grids are defined by points, cells, and cell types. The CELLS keyword requires two parameters: the number of cells n and the size of the cell list size. The cell list size is the total number of integer values required to represent the list (i.e., sum of numPoints and connectivity indices over each cell). The CELL_TYPES keyword requires a single parameter: the number of cells n. This value should match the value specified by the CELLS keyword. The cell types data is a single
integer value per cell that specified cell type.’

非结构化网格数据集由任何可能的单元格类型的任意组合组成。非结构化网格由点、单元格和单元格类型定义。CELLS关键字需要两个参数:cell的数量n和cell列表的大小。单元格列表的大小是表示列表所需的整数值的总数(例如,每个单元格上numPoints和连接性指数的总和)。CELL TYPES关键字需要一个参数:CELL的数量n。这个值应该与CELLS关键字指定的值匹配。单元格类型数据是每个指定单元格类型的单个整数值。

其中.vtk文件中最重要的就是物理量,包含了节点上的值和单元上的值,分别用POINT_DATACELL_DATA表示。可以表示多个物理量。这些物理量可以是标量(scalar),向量(vector),或者是张量(tensor)。例如,节点上的颜色,可以用标量来表示。

1
2
3
4
5
POINT_DATA n
数据

CELL_DATA n
数据

例如 SCALAR 或者 VECTORS 数据的话,可以表示为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
POINT_DATA 27
SCALARS scalars float 1
LOOKUP_TABLE default
0.0 1.0 2.0 3.0 4.0 5.0
6.0 7.0 8.0 9.0 10.0 11.0
12.0 13.0 14.0 15.0 16.0 17.0
18.0 19.0 20.0 21.0 22.0 23.0
24.0 25.0 26.0
VECTORS vectors float
1 0 0 1 1 0 0 2 0 1 0 0 1 1 0 0 2 0
1 0 0 1 1 0 0 2 0 1 0 0 1 1 0 0 2 0
0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1
0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1
0 0 1 0 0 1 0 0 1
...

格式为:

1
2
SCALARS dataName dataType numComp 
LOOKUP_TABLE tableName

其中 dataName 数据名字,dataTypedouble, float之类的,numComp一般是1。tableName是表名。

节点顺序

节点顺序和使用的类型决定了模型是否存在畸变。下面两个图表明了线性和非线性的CELLS表达。可以观察到组成CELLS的节点顺序根据不同的type,排列顺序也是不一样的。比如VTK_VOXEL 和VTK_HEXAHEDRON,按照逆时针表达的话,一个是01324576,另一个是01234567。

Linear cell types found in VTK

Nonlinear cell types found in VTK