[Translation] VTK official documentation - vtk file format

VTK provides a number of source and writer objects for reading and writing popular data file formats, in addition, VTK also provides its own file format. The main reason for creating a data file format is to provide a consistent data representation scheme for various dataset types and to provide an easy way to communicate data between software. Whenever possible, we recommend that you use a wider format, but if that's not possible, you can use the format described in this article instead. Note that these formats may not be supported by many other tools.

There are two different styles of file formats in VTK. The simplest are traditional serial formats that can be easily read and written by hand or program, however, these formats are not as flexible as the XML-based file formats described later in this section. The XML format supports random access, parallel I/O, and portable data compression, and this format is preferred when possible.

Traditional Simple Format
The traditional VTK file format consists of five basic parts:

  1. The first part is the file version and identifier. This section contains the single line # vtk DataFile Version xx , which must be exactly as shown, except for the version number xx, which changes for different releases of VTK. (Note: The current version is 3.0. Version 1.0 and 2.0 files are compatible with version 3.0)

  2. The second part is the title. The title consists of a string terminated by the end-of-line character \n. A maximum of 256 characters can be used to describe the data and include any other relevant information.

  3. The next part is the file format. The file format describes the type of file, which can be ASCII or binary. On this line, the single word ASCII or BINARY must appear.

  4. The fourth part is the dataset structure. The geometry section describes the geometry and topology of the dataset. This section begins with a line containing the keyword DATASET followed by a keyword describing the type of dataset. Then, depending on the type of dataset, other keyword/data combinations will define the actual data.

  5. The last section describes the dataset properties. This section begins with the keyword POINT_DATA or CELL_DATA, followed by an integer specifying the number of points or cells, respectively. (It doesn't matter if POINT_DATA or CELL_DATA appears first). Other keyword/data combinations then define the actual dataset property values ​​(i.e. scalars, vectors, tensors, normals, texture coordinates or field data).

An overview of the file format is shown in Figure 1. The first three parts are required, while the other two parts are optional. So you can flexibly mix and match geometry, dataset properties by combining data via OS files or using VTK filters. Keywords are not case sensitive and can be separated by spaces.

Figure 1. Overview of the five parts of the VTK data file format
Before describing the data file format, please note the following points.

dataType is one of the types of bit, unsigned_char, char, unsigned_short, short, unsigned_int, int, unsigned_long, long, float or double. These keywords are used to describe the form of the data, either read from a file or construct an appropriate internal object. Not all classes support all data types.
All keyword phrases are written in ASCII, whether the file is binary or ASCII.
The binary part of the file (if in binary form) is the appropriate data; i.e. numbers that define point coordinates, scalars, cell indices, etc.
The index is 0 offset. So the first point is point ID 0.
If both data attributes and geometry/topology sections exist in the file, the number of data values ​​defined in the data attributes section must exactly match the number of points or cells defined in the geometry/topology section.
The cell type and index are of type int.
Binary data must be placed immediately after the "newline" (\n) character in the previous ASCII keyword and argument sequence.
The geometry/topology description must precede the data attribute description.
Binaries Binaries
in VTK are portable between different computer systems as long as two conditions are observed. First, make sure that the byte order of the data is correct, and second, make sure that each data type has a consistent length.

Most of the time, VTK manages the byte order of the binary for you. When you write a binary file on one computer and read it from another computer, the bytes representing the data are automatically swapped as needed. For example, binary files written on Sun are stored in big endian, while those on PC are stored in little endian. So files written on Sun workstations require byte swapping when read on a PC. (See class vtkByteSwap for implementation details) The VTK data files described here are written in big-endian format.

However, some file formats do not explicitly define the endian form. You will find that data read or written by external programs or classes vtkVolume16Reader, vtkMCubesReader and vtkMCubesWriter may have different endianness depending on the original system. In this case, VTK allows you to specify the endianness using the method:

SetDataByteOrderToBigEndian() Another problem with
SetDataByteOrderToLittleEndian()
binaries is that systems may use different numbers of bytes to represent integers or other native types. For example, some 64-bit systems will represent an 8-byte integer, while others will represent a 4-byte integer. Currently, VTK cannot handle binary file transfers across systems with incompatible data lengths. In this case, use the ASCII file format instead.

The Dataset Format
visualization toolkit supports five different dataset formats: structured points, structured grid, rectilinear grid, unstructured grid (unstructured grid) and polygonal data. The order of data with implicit topology (structured data such as vtkImageData and vtkStructuredGrid) is that x grows fastest, then y, then z.

These formats are as follows:

Structured points: The
file format supports 1D, 2D and 3D structured point datasets. Dimensions nx, ny, nz must be greater than or equal to 1. Data spacing sx, sy, sz must be greater than 0. (Note: In version 1.0 data files, spacing is called "aspect ratio". ASPECT_RATIO can still be used in version 2.0 data files, but is deprecated.)

DATASET STRUCTURED_POINTS
DIMENSIONS nx ny nz
ORIGIN xyz
SPACING sx sy sz
structured grid:
This file format supports 1D, 2D and 3D structured grid datasets. Dimensions nx, ny, nz must be greater than or equal to 1. Point coordinates are defined by data in the POINTS section. This consists of xyz coordinate data values ​​for each point.

DATASET STRUCTURED_GRID
DIMENSIONS nx ny nz
POINTS n dataType
p0x p0y
p0z p1x p1y p1z

p(n-1)xp(n-1)yp(n-1)z
Rectilinear Grid:
Rectilinear Grid definition has regular topology and a dataset of semi-regular geometries aligned along the xyz axis. The geometry is defined by three monotonically increasing lists of coordinate values, one for each xyz axis. Define the topology by specifying the mesh size (must be greater than or equal to 1).

DATASET RECTILINEAR_GRID
DIMENSIONS nx ny nz
X_COORDINATES nx dataType
x0 x1 … x(nx-1)
Y_COORDINATES ny dataType
y0 y1 … y(ny-1)
Z_COORDINATES nz dataType
z0 z1 … z(nz-1)
Polygonal Data Polygonal
Data Sets consist of any combination of surface graphics primitive vertices (and multi-vertices), lines (and polylines), polygons (of various types), and triangle strips. Polygon data is defined by POINTS, VERTICES, LINES, POLYGONS or TRIANGLE_STRIPS sections. The POINTS definition is the same as we have seen with structured grid datasets. The VERTICES, LINES, POLYGONS or TRIANGLE_STRIPS keywords define polygon dataset topology.

Each of these keywords takes two arguments: the number of cells, n, and size, the size of the cell list. The cell list size is the total number of integer values ​​required to represent the list (i.e. the sum of numPoints and connectivity indices on each cell). The keywords VERTICES, LINES, POLYGONS or TRIANGLE_STRIPS are optional.

DATASET POLYDATA
POINTS n dataType
p0x p0y p0z
p1x p1y p1z

p(n-1)x p(n-1)y p(n-1)z
VERTICES n size
numPoints0, i0, j0, k0, …
numPoints1, i1, j1, k1, …

numPointsn-1, in-1, jn-1, kn-1, …
LINES n size
numPoints0, i0, j0, k0, …
numPoints1, i1, j1, k1, …

numPointsn-1, in-1, jn-1, kn-1, …
POLYGONS n size
numPoints0, i0, j0, k0, …
numPoints1, i1, j1, k1, …

numPointsn-1, in-1, jn-1, kn-1, …
TRIANGLE_STRIPS n size
numPoints0, i0, j0, k0, …
numPoints1, i1, j1, k1, …

numPointsn-1, in-1, jn-1, kn-1, …
Unstructured Grid
An unstructured grid dataset consists of any combination of any possible element types. Defined by points, cells and cell_types.

The cells keyword takes two arguments: 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. the sum of numPoints and connectivity indices on each cell). The CELL_TYPES keyword requires one parameter: the number of cells, n. The value should match the value specified by the CELLS keyword. Cell type data is a single integer value that specifies each cell type (see vtkCell.h or Figure 2)

DATASET UNSTRUCTURED_GRID
POINTS n dataType
p0x p0y
p0z p1x p1y p1z

p(n-1)xp(n-1)yp(n-1)z
CELLS n size
numPoints0, i, j, k, l, …
numPoints1, i, j , k, l, …
numPoints2, i, j, k, l, …

numPointsn-1, i, j, k, l, …
CELL_TYPES n
type0
type1
type2

typen-1
field data
field data is without topology and geometry , and there is no universal format for a specific dimension. Typically, field data is associated with points or cells of a dataset. However, if the FIELD type is specified as the dataset type (see Figure 1), a regular VTK data object will be defined. Define the fields using the format described in the next section.

The dataset attribute format
VTK supports the following dataset attributes: scalars (1 to 4 components), vectors, normals, texture coordinates (1D, 2D and 3D), tensors and field data. In addition, lookup tables that use the RGBA color specification can be defined and associated with scalar data. Dataset properties are supported for both points and cells.

Each type of attribute data has a dataName associated with it. This is a string (no embedded spaces) used to identify specific data. The VTK reader uses dataName to extract data. As a result, one file can contain multiple attribute data of the same type. For example, two different scalar fields (pressure and temperature) defined on a dataset point can be included in the same file. (If the appropriate dataName is not specified in the VTK reader, the first data of that type will be extracted from the file.)

Scalar
A scalar definition includes the specification of a lookup table. The definition of the lookup table is optional. If not specified, the default VTK table (tableName "default") will be used. Also note that the numComp variable is optional, by default the number of components is equal to 1. (The parameter numComp must be between [1,4]; in VTK versions prior to vtk2.3, this parameter is not supported.)

SCALARS dataName dataType numComp
LOOKUP_TABLE tableName
s0
s1
...
sn-1
The definition of color scalars (i.e. unsigned char values ​​that map directly to colors) varies according to the number of values ​​(nvalues) for each scalar. If the file format is ASCII, the color scalar is defined using nValues ​​floating point values ​​between (0,1). If the file format is BINARY, the data stream consists of unsigned char values ​​for each scalar value of nValues.

COLOR_SCALARS dataName nValues
​​c00 c01 … c0(nValues-1)
c10 c11 … c1(nValues-1)

c(n-1)0 c(n-1)1 … c(n-1)(nValues-1)
lookup table
The tableName field is a string (with no embedded spaces) that identifies the lookup table. The VTK reader uses this tag to extract a specific table.

Each entry in the lookup table is an rgba[4] array (transparent when alpha=0). If the file format is ASCII, the lookup table value must be a floating point value between (0,1). If the file format is binary, the data stream must be four unsigned char values ​​per entry.

LOOKUP_TABLE tableName size
r0 g0 b0 a0
r1 g1 b1 a1

rsize-1 gsize-1 bsize-1 asize-1
vector
VECTORS dataName dataType
v0x v0y v0z
v1x v1y v1z

v(n-1)xv(n-1)yv(n -1) z
normal
Normals are assumed to be normalized |n|=1.

NORMALS dataName dataType
n0x n0y n0z
n1x n1y n1z

n(n-1)xn(n-1)yn(n-1)z
texture coordinates
Supports 123-dimensional texture coordinates.

TEXTURE_COORDINATES dataName dim dataType
t00 t01 … t0(dim-1)
t10 t11 … t1(dim-1)

t(n-1)0 t(n-1)1 … t(n-1)(dim-1)
sheets Quantity
currently only supports real-valued symmetric tensors.

TENSORS dataName dataType
t0 00 t0 01 t0 02
t0 10 t0 11 t0 12
t0 20 t0 21 t0 22
t1 00 t1 01 t1 02
t1 10 t1 11 t1 12
t1 20 t1 21 t1 22

01 n-1 t1 n-1 01 n-1 00 t n-1 02
t n-1 10 t n-1 11 t n-1 12
t n-1 20 t n-1 21 t n-1 22
field data
Field data is essentially an array of data. Defining field data means giving the field a name and specifying the number of arrays it contains. For each array, the following quantities are defined: the name of the array arrayName(i), the dimension of the array numComponents, the number of tuples in the array numTuples, and the data type dataType.

FIELD dataName numArrays
arrayName0 numComponents numTuples dataType
f00 f01 … f0(numComponents-1)
f10 f11 … f1(numComponents-1)

f(numTuples-1)0 f(numTuples-1)1 … f(numTuples-1)(numComponents-1)
arrayName1 numComponents numTuples dataType
f00 f01 … f0(numComponents-1)
f10 f11 … f1(numComponents-1)

f(numTuples-1)0 f(numTuples-1)1 … f(numTuples-1)(numComponents-1)

arrayName(numArrays-1) numComponents numTuples dataType
f00 f01 … f0(numComponents-1)
f10 f11 … f1(numComponents-1)

f(numTuples-1)0 f(numTuples-1)1 … f(numTuples-1)(numComponents-1)
例子
The first example is a cube represented by six polygonal faces. We define a one-component scalar, normal and field data on six faces. There is scalar data associated with eight vertices. A lookup table for the eight colors associated with the point scalar is also defined.

vtk DataFile Version 2.0

Cube example
ASCII
DATASET POLYDATA
POINTS 8 float
0.0 0.0 0.0
1.0 0.0 0.0
1.0 1.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
1.0 0.0 1.0
1.0 1.0 1.0
0.0 1.0 1.0
POLYGONS 6 30
4 0 1 2 3
4 4 5 6 7
4 0 1 5 4
4 2 3 7 6
4 0 4 7 3
4 1 2 6 5
CELL_DATA 6
SCALARS cell_scalars int 1
LOOKUP_TABLE default
0
1
2
3
4
5
NORMALS cell_normals float
0 0 -1
0 0 1
0 -1 0
0 1 0
-1 0 0
1 0 0
FIELD FieldData 2
cellIds. 1. 6 int
0. 1 2. 3. 4. 5
faceAttributes 2. 6 a float
0.0 1.0 1.0 2.0 2.0 3.0 3.0 4.0 4.0 5.0 5.0 6.0
POINT_DATA. 8
Scalars sample_scalars a float. 1
lookup_table my_table
0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
lookup_table my_table. 8
0.0 0.0 0.0 1.0
1.0 0.0 0.0 1.0
0.0 1.0 0.0 1.0
1.0 1.0 0.0 1.0
0.0 0.0 1.0 1.0
1.0 0.0 1.0 1.0
0.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
The next example is a 3×4×5 dimensional structured point dataset. Since there is no lookup table defined, the user must create a lookup table in VTK, otherwise the default lookup table will be used.

vtk DataFile Version 2.0

Volume example
ASCII
DATASET STRUCTURED_POINTS
DIMENSIONS 3 4 6
ASPECT_RATIO 1 1 1
ORIGIN 0 0 0
POINT_DATA 72
SCALARS volume_scalars char 1
LOOKUP_TABLE default
0 0 0 0 0 0 0 0 0 0 0 0
0 5 10 15 20 25 5 0 20 15
0 10 20 30 40 50 50 40 30 20 10 0
0 10 20 30 40 50 50 40 30 20 10 0
0 5 10 15 20 25 25 20 15 10 5 0
0 0 0 0 0 0 0 0 0 0
0 The example is an unstructured grid containing 12 of the 19 VTK cell types (see Figures 2 and 3). The file contains scalar and vector data.

vtk DataFile Version 2.0

Unstructured Grid Example
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 27 float
0 0 0 1 0 0 2 0 0 0 1 0 1 1 0 2 1 0
0 0 1 1 0 1 2 0 1 0 1 1 1 1 1 2 1 1
0 1 2 1 1 2 2 1 2 0 1 3 1 1 3 2 1 3
0 1 4 1 1 4 2 1 4 0 1 5 1 1 5 2 1 5
0 1 6 1 1 6 2 1 6
CELLS 11 60
8 0 1 4 3 6 7 10 9
8 1 2 5 4 7 8 11 10
4 6 10 9 12
4 5 11 10 14
6 15 16 17 14 13 12
6 18 15 19 16 20 17
4 22 23 20 19
3 21 22 18
3 22 19 18
2 26 25
1 24
CELL_TYPES 11
12
12
10
10
7
6
9
5
5
3
1
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

Figure 2 Linear element types in VTK. Use the include file CellType.h to manipulate cell types

Figure 3 Nonlinear element types in VTK The
fourth and final example is data represented by fields. You may also want to see "Working with Field Data" on page 158 to learn how to manipulate this data.

(The data file shown below can be found in $VTK_data_ROOT/data/financial.vtk.)

vtk DataFile Version 2.0

Financial data in vtk field format
ASCII
FIELD financialData 6
TIME_LATE 1 3188 float
29.14 0.00 0.00 11.71 0.00 0.00 0.00 0.00
…(more stuff — 3188 total values)…
MONTHLY_PAYMENT 1 3188 float
7.26 5.27 8.01 16.84 8.21 15.75 10.62 15.47
…(more stuff)…
UNPAID_PRINCIPLE 1 3188 float
430.70 380.88 516.22 1351.23 629.66 1181.97 888.91 1437.83
…(more stuff)…
LOAN_AMOUNT 1 3188 float
441.50 391.00 530.00 1400.00 650.00 1224.00 920.00 1496.00
…(more stuff)…
INTEREST_RATE 1 3188 float
13.875 13.875 13.750 11.250 11.875 12.875 10.625 10.500
…(more stuff)…
MONTHLY_INCOME 1 3188 unsigned_short
39 51 51 38 35 49 45 56
…(more stuff)…
In this example, a field is represented by six arrays. Each array has one component and 3188 tuples. Five of the six arrays are of type float, and the last array is of type unsigned_short. Additional examples are available in the data directory.

The XML file format
VTK provides another set of data formats using XML syntax. And these formats support more functions than the traditional VTK format. The main motivation for its development is to facilitate data streaming and parallel I/O, including compression, portable binary encoding, random access, big- and little-endian byte order, multi-file representation of artifact data, and different VTK dataset types. Support for new file extensions. XML also provides many features, notably the ability to extend the file format with application-specific markup.

There are two types of vtkxml data files: parallel and serial, as described below...

【over】

translate it here. Finally, put this document online editing address, welcome to add.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324343820&siteId=291194637