Introduction
The VTK XML formats store the datasets of the Visualization Toolkit and ParaView. A .vtu file is an
unstructured grid; sister extensions hold other dataset kinds, split them into pieces or group them. All of them
share one root element and one way of encoding arrays. The older legacy .vtk format
is a different, line-based syntax.
File types
| Extension | type value | Contents |
|---|---|---|
.vtu, .pvtu | UnstructuredGrid, PUnstructuredGrid | Points and cells of any type |
.vtp, .pvtp | PolyData, PPolyData | Vertices, lines, triangle strips and polygons |
.vti, .pvti | ImageData, PImageData | Regular grid |
.vtr, .pvtr | RectilinearGrid, PRectilinearGrid | Axis-aligned grid with varying spacing |
.vts, .pvts | StructuredGrid, PStructuredGrid | Curvilinear grid |
.vtm | vtkMultiBlockDataSet | Tree of other files |
.vtpd | vtkPartitionedDataSet | List of partition files |
.vtpc | vtkPartitionedDataSetCollection | List of partitioned datasets |
.vth | vtkOverlappingAMR, vtkNonOverlappingAMR | Adaptive mesh refinement levels |
.htg, .phtg | HyperTreeGrid, PHyperTreeGrid | Grid of refinement trees |
.vtt, .pvtt | Table, PTable | Columns of values |
.vtstat | StatisticalModel | Statistics results |
File layout
The root element is VTKFile. Its child named after the type value is the dataset. An
optional AppendedData element follows the dataset.
| Root attribute | Meaning |
|---|---|
type | Dataset type, from the table above. |
version | major.minor. The reader only warns about a version newer than its own. |
byte_order | LittleEndian or BigEndian, for all binary values and headers. |
header_type | UInt32 or UInt64: the integer type of binary headers. |
compressor | Class name of the compressor. Absent when data is not compressed. |
Versions
| Version | Meaning |
|---|---|
| 0.1 | What VTK writes for most datasets with 32-bit headers. |
| 1.0 | The same with 64-bit headers; also the partitioned dataset files. |
| 1.1 | Overlapping and non-overlapping AMR files. |
| 2.0 | Default of the hyper tree grid writer. In files before version 2, an array named vtkGhostLevels is renamed to vtkGhostType. |
| 2.1 | Current node order of higher-order hexahedra. |
| 2.3 | Polyhedra stored in four arrays. |
| 2.4 | Side data. |
| 2.5 | Faces shared between polyhedra. |
The writer uses the newest version for tables and statistical models, and for grids that have both ghost arrays, higher-order hexahedra or polyhedra.
Dataset elements
| Dataset | Its attributes | Piece attributes | Geometry inside Piece |
|---|---|---|---|
ImageData | WholeExtent, Origin, Spacing, Direction (9 numbers, a 3×3 matrix) | Extent | None |
RectilinearGrid | WholeExtent | Extent | Coordinates: three arrays, x, y and z |
StructuredGrid | WholeExtent | Extent | Points |
PolyData | NumberOfPoints, NumberOfVerts, NumberOfLines, NumberOfStrips, NumberOfPolys | Points, Verts, Lines, Strips, Polys | |
UnstructuredGrid | NumberOfPoints, NumberOfCells | Points, Cells |
An extent is six point indices, x1 x2 y1 y2 z1 z2. Points holds one array of three
components. Each piece may also have PointData and CellData; their attributes
Scalars, Vectors, Normals, TCoords, Tensors,
GlobalIds, PedigreeIds, EdgeFlag, Tangents,
RationalWeights, HigherOrderDegrees and ProcessIds name the array that
plays that role.
The dataset element may contain FieldData, arrays that belong to the whole dataset and carry
NumberOfTuples. Its TimeValues attribute lists the times of a file with several time
steps; each array then marks its step or steps with TimeStep.
Data arrays
Numeric arrays are DataArray elements; the writer uses Array for others, such as
strings.
| Attribute | Meaning |
|---|---|
type | Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float32, Float64, String or Bit. |
Name | Array name. |
NumberOfComponents | Values per tuple; default 1. |
ComponentName0, ComponentName1, … | Optional component names. |
NumberOfTuples | Given where the count does not follow from the piece, as in field data. |
format | ascii, binary or appended. |
offset | Position in the appended data. |
RangeMin, RangeMax | Value range, written for information. |
IdType | 1 marks point or cell identifiers. |
TimeStep | Time step or steps the values belong to. |
With ascii, values are the element’s text, separated by white space; inf,
-inf and nan are accepted in any letter case. Strings are written as the decimal codes
of their bytes with a 0 after each string. In binary form strings are their bytes, each followed by a zero
byte. Bit values are packed eight to a byte, first value in the most significant bit.
Information keys
An array may contain InformationKey elements with name and location (the
class that defines the key). A scalar value is the element’s text (old files use a value
attribute). A vector has a length attribute and Value index="i" children. The key types
read are double, integer, id, unsigned long and string values, double, integer and string vectors, and the
quadrature scheme dictionary (name="DICTIONARY", location="vtkQuadratureSchemeDefinition").
Each of its vtkQuadratureSchemeDefinition children holds CellType,
NumberOfNodes and NumberOfQuadraturePoints, each with a value attribute,
and ShapeFunctionWeights and QuadratureWeights as space-separated numbers.
Binary data and compression
With format="binary" the element’s text is base64. With format="appended" the bytes are
in <AppendedData encoding="base64"> or encoding="raw". Appended data starts
after an underscore, and offset counts from the first character after it; in base64 files it counts
encoded characters. Raw bytes can make the file invalid XML, so a reader must stop XML parsing at this
element. VTK’s writer defaults to appended, base64-encoded, zlib-compressed data.
All header integers below have the header_type size and the file’s byte order. Without a
compressor, an array is one integer, its length in bytes, followed by the values; both are base64-encoded as
one run.
With a compressor the values are cut into blocks (32768 bytes by default) that are compressed separately:
| Header integer | Meaning |
|---|---|
| 1 | Number of blocks, n |
| 2 | Uncompressed size of a block |
| 3 | Uncompressed size of the last block if it is partial, otherwise 0 |
| 4 to n + 3 | Compressed size of each block |
The compressed blocks follow, back to back. In base64 data the header is encoded on its own and the blocks as a second base64 run.
compressor | Each block is |
|---|---|
vtkZLibDataCompressor | A zlib stream |
vtkLZ4DataCompressor | A raw LZ4 block |
vtkLZMADataCompressor | An xz stream |
Cells
Verts, Lines, Strips and Polys each hold two arrays:
connectivity, the point indices of all cells one after another, and offsets, the
position in it where each cell ends. The leading 0 is not stored. Cells in an unstructured grid adds
types, one byte per cell with a VTK cell type number.
Polyhedra
Since version 2.3 polyhedron cells (type 42) are described by two more cell lists:
| Arrays | Meaning |
|---|---|
face_connectivity, face_offsets | The point indices of each face and where each face ends |
polyhedron_to_faces, polyhedron_offsets | The face indices of each cell and where each cell’s list ends |
Face indices are local to the piece. Since version 2.5 a face shared by two cells is stored once, and the cell that traverses it in reverse lists it as −(n + 1).
Earlier files use faces and faceoffsets. For each polyhedron, faces holds
the number of faces, then for each face its number of points and the point indices.
faceoffsets gives where each cell’s record ends, and −1 for other cells.
Higher-order hexahedra
In files before version 2.1, the node blocks of the third and fourth edges parallel to the third axis are in the opposite order in higher-order, Lagrange and Bézier hexahedra. With orders (p, q, r), the first such block starts at node 8 + 4(p − 1 + q − 1) + 2(r − 1) and each block has r − 1 nodes; readers swap the two blocks.
Side data
Since version 2.4 an unstructured grid piece may have SideData, with one tuple per cell side (a
side shared by two cells has one tuple), and SideIds with the attributes NumberOfSides
and NumberOfHalfSides and an array HalfSideToSide, listed cell by cell in the local
side order of each cell type. The reader uses side data only when it reads a single piece.
Parallel files
A file with a P type describes pieces held in other files. Its dataset element has
GhostLevel; PImageData also has WholeExtent, Origin and
Spacing, and the other structured types WholeExtent. PPointData and
PCellData declare arrays with PDataArray (type, name and component count, no values).
Unstructured and structured grids and polygon data declare PPoints with one array; rectilinear grids
declare PCoordinates with three. Each Piece names a file in Source, with
its Extent for structured data.
PTable declares its columns in PRowData, and it and PHyperTreeGrid list
files with Piece Source.
Composite files
These files list other VTK XML files in the file attribute of DataSet elements. A
name is relative to the listing file unless it is absolute. FieldData directly inside
VTKFile belongs to the whole collection; VTK stores the time there as TimeValue.
| Dataset element | Children |
|---|---|
vtkMultiBlockDataSet | Block (a nested group), Piece (a group of pieces, with optional whole_extent) and DataSet, each with index and optional name; DataSet may add bounding_box and extent. A missing index follows the highest one so far. Files before version 1 are a flat list of DataSet with group and dataset numbers. |
vtkPartitionedDataSet | DataSet index file |
vtkPartitionedDataSetCollection | Partitions index name, each holding DataSet index file; an optional DataAssembly encoding="base64" holds a named hierarchy as encoded XML. |
vtkOverlappingAMR, vtkNonOverlappingAMR | Block level holding DataSet index file. Overlapping AMR adds origin and grid_description (XYZ, XY, YZ or XZ) on the dataset element, spacing on each block and amr_box (xlo xhi ylo yhi zlo zhi) on each dataset. |
The older type vtkHierarchicalBoxDataSet, version 1.0, uses the same block structure; VTK converts
it to vtkOverlappingAMR 1.1 by adding origin and grid_description.
Hyper tree grids
The HyperTreeGrid element has BranchFactor (2 or 3), Dimensions (points
per axis) and TransposedRootIndexing, and optionally InterfaceNormalsName and
InterfaceInterceptsName. Version 0 adds Dimension, Orientation and
NumberOfVertices. Grid holds the arrays XCoordinates,
YCoordinates and ZCoordinates. Each coarse cell is the root of a tree; with cell counts
cx, cy, cz the tree index of cell (i, j, k) is i + cx(j + cy·k), or k + cz(j + cy·i) when indexing is
transposed. A refined cell has BranchFactor children along each used axis, the first axis varying
fastest. In two dimensions orientation 0, 1 and 2 mean the YZ, XZ and XY planes.
A descriptor is a bit array in breadth-first order: 1 for a refined cell, 0 for a leaf. A mask bit of 1 hides a cell.
| Version | Contents of Trees |
|---|---|
| 0 | Tree elements with Index, GlobalOffset (start of the tree’s values) and NumberOfVertices, holding Descriptor (one bit per cell), optional Mask and the tree’s CellData. |
| 1 | Tree elements with Index, NumberOfLevels and NumberOfVertices, holding Descriptor and Mask with trailing zeros dropped, NbVerticesByLevel and CellData in breadth-first order. |
| 2 | Four arrays for all trees: Descriptors, concatenated, leaving out the bits of each tree’s deepest level; NumberOfVerticesPerDepth, cell counts level by level, tree after tree; TreeIds; and DepthPerTree, how many of those counts each tree uses. An optional Mask and one CellData after Trees follow the same cell order. |
Tables and statistical models
A Table holds Piece NumberOfRows elements, each with RowData containing
one DataArray or Array per column.
A StatisticalModel holds a Piece with NumberOfLearnedTables and
NumberOfDerivedTables, and in it StatisticalModelData:
AlgorithmParameters as text, then ModelTables with Type
(Learned, Derived or Test) and NumberOfTables. Each
ModelTable has Name and Length, and its text is a complete ASCII table file
in base64.
Example
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfPoints="4" NumberOfCells="2">
<Points>
<DataArray type="Float32" NumberOfComponents="3" format="ascii">
0 0 0 1 0 0 0 1 0 1 1 0
</DataArray>
</Points>
<Cells>
<DataArray type="Int32" Name="connectivity" format="ascii">0 1 2 2 1 3</DataArray>
<DataArray type="Int32" Name="offsets" format="ascii">3 6</DataArray>
<DataArray type="UInt8" Name="types" format="ascii">5 5</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
.vtu file.Recognising a file
The XML root element is VTKFile and has a type attribute. The XML declaration is not a
reliable sign, and a file with raw appended data cannot be loaded by a general XML parser as a whole.
Not described
The explorer has no VTK XML viewer; a dropped file shows as text or bytes.
Known, not yet covered
- Reference: the point order within each cell type, and the local side order that
HalfSideToSidefollows. - Reference: the XML inside
DataAssembly. - Reference: the meaning of the array names and component layouts inside statistical model tables.
- Viewer: there is no VTK XML plugin.
Links
Software
- ParaView – visualisation program built on VTK (Windows, Linux, macOS)
Developers
- Visualization Toolkit – the library that defines the formats (C++, Python)
Reference
- VTK XML file formats – the official description
- VTK IO/XML – the readers and writers
- vtkXMLDataParser.cxx – binary, appended and compressed data