Difference between revisions of "XYZ Data with VTK"

From Core Physics Wiki
Jump to: navigation, search
Line 58: Line 58:
* The remaining lines are the (x,y,z) coordinates for each of the 2082 data points.
* The remaining lines are the (x,y,z) coordinates for each of the 2082 data points.
=== Data ===
=== Datasets ===
The next step is to define the data at each grid point.
The next step is to define the data at each grid point.

Revision as of 12:14, 2 April 2015

Visualizing XYZ data vith VTK files

VTK is a visualization toolkit produced by Kitware VTK.

This page does not describe using the VTK toolkit itself, but instead discusses how you can convert your data into one of the VTK data file formats, which can then be imported into one of the visualization tools like Visit or Paraview.

I'm sure the VTK toolkit is very useful, but I usually prefer to create the VTK data files directly from my programs that create the data (usually Fortran or Python).

There are several VTK data file formats. I will describe the ASCII format. There is also a binary file format and an XML file format.

There are two parts to visualizing the data. The first part is to generate the "grid" and the second part is to write the data itself. This page only describes "point" data with (x,y,z) coordinates. VTK is very powerful and can handle other grids easily, but this page will only describe point data.

I may write other tutorials describing these data formats in the future.


For this example, I will start with a text file that has a list of (x,y,z) coordinates that define the outline of a teapot. The text data file was downloaded from the VTK website at Teapot Data. The data file includes 2082 coordinates.


The first step in creating the VTK file is to write the file header and data point description to a text file:

# vtk DataFile Version 2.0
Example Teapot data file
   3.50000E+00   2.19615E+00   1.80000E+01
   3.45947E+00   2.28939E+00   1.80538E+01
   3.45117E+00   2.35599E+00   1.80923E+01
   3.46924E+00   2.39596E+00   1.81154E+01
   3.50781E+00   2.40928E+00   1.81230E+01
   3.56103E+00   2.39596E+00   1.81154E+01
   3.62305E+00   2.35600E+00   1.80923E+01
   3.68799E+00   2.28939E+00   1.80538E+01
   3.75000E+00   2.19615E+00   1.80000E+01
   3.43000E+00   1.83959E+00   1.86176E+01

  (continue with remainder of 2082 data coordinates)
  • The first line defines this file as a VTK data file.
  • The second line is an arbitrary title
  • The third line defines this file as ASCII format
  • The fourth line defines the data as POLYDATA. There are many different data types available, but this format is used to define point data.
  • The fifth line defines how many data points there are and that they are type FLOAT.
  • The remaining lines are the (x,y,z) coordinates for each of the 2082 data points.


The next step is to define the data at each grid point. In the visualization, the data will correspond to the color of each data point.

If you just want to see the grid, you can simply add values of "1.0" for each data point. In this example, I will assign the data as the z-coordinate of the point.

SCALARS Z-dimension float

 (continue with remainder of 2082 data values in the first dataset)
  • the first line of this block says that 2082 data points will follow. These data points correspond to the 2082 coordinates listed above.
  • the second line defines these as SCALAR values, gives a user-defined title of "Z-dimension", and then defines the type as "float"
  • the third line shows that the data is a LOOKUP_TABLE (i.e. one-to-one correspondence between data points and coordinates)
  • the fourth and remaining lines are the data itself

There can be multiple data sets in the same file. In this example, we wil will include another data set that shows the X-dimensions of the data points.

Additional datsets are added by including more data blocks, but without the "POINTS_DATA" line. This "POINTS_DATA" line should only be included once per file.

SCALARS X-dimension float

  (continue with remainder of 2082 data values in the second dataset)

This is it! You can include as many sets of data that you need.

Complete output

The complete VTK output file is found at teapot.vtk

Visualizing data with Visit

Once the VTK file has been created, it can be visualized in several different visualization software packages including Visit, Paraview, or many other packages.

To view the data with Visit, look at the Visit quick start

The final teapot image:

Teapot Image

Other Examples

Some other VTK example files are at John Burkardt homepage (scroll to bottom of page for examples)