Time and Cycle in VTK files

From VisItusers.org

Jump to: navigation, search

VisIt supports visualization of all types of VTK files. Users creating VTK files for visualization with VisIt often have the need to encode a simulation's cycle and time values into the VTK file. Since VTK files do not have a specific construct for doing so, VisIt implements a convention where CYCLE and TIME values can be added as FieldData in the file. FieldData is data that is not problem-sized such as cell and point data in the VTK file. You may add CYCLE or TIME or both to your file in order to get those values into VisIt.

Note that since VTK files can only contain a single time step, VisIt will not by default read the time and cycle values for all VTK files that have been grouped into a virtual database. If you want VisIt to read all of the time and cycle values then you will need to use "Try harder to get cycles and times" from the Preferences window before you open your set of VTK files.

Contents

[edit] Legacy VTK files

Here is an example of a small ASCII legacy VTK file that shows how to add CYCLE and TIME values in such a way that VisIt will display the values in the plot legends. Note that the CYCLE and TIME values are stored as arrays in the dataset's FieldData.

# vtk DataFile Version 3.0
vtk output
ASCII
DATASET POLYDATA
FIELD FieldData 2
TIME 1 1 double
1.23456789
CYCLE 1 1 int
123
POINTS 13 float
0 2 0 2 0 0 1.5 1.5 0 
2.5 1.5 0 4 2 0 2 1.5 0 
1.5 2 0 2 2 0 2.5 2 0 
1.5 2.5 0 2 2.5 0 2.5 2.5 0 
2 4 0 
POLYGONS 12 56
3 0 1 2 
3 1 4 3 
3 0 9 12 
3 12 11 4 
4 0 2 6 9 
4 2 1 3 5 
4 3 4 11 8 
4 9 10 11 12 
4 2 5 7 6 
4 5 3 8 7 
4 6 7 10 9 
4 7 8 11 10 

CELL_DATA 12
SCALARS p float
LOOKUP_TABLE default
1.17851 1.17851 1.17851 1.17851 0.875 0.875 0.875 0.875 0.353553 
0.353553 0.353553 0.353553 
POINT_DATA 13

The FIELD FieldData 2 line indicates that there will be 2 field data arrays. If you add cycle only or time only then you'd only add 1 array and you'd replace the 2 with a 1. Pay attention that the field data comes right after the DATASET type in the VTK file.

Adding time Adding cycle
TIME 1 1 double
1.23456789
CYCLE 1 1 int
123

[edit] XML VTK files

You can include cycle or time information in an XML-based VTK file by including a data array named CYCLE orTIME in the field data. The format for including that information in the XML file is given below (add the DataArray block into your mesh's FieldData):

 ...
  <UnstructuredGrid>
    <FieldData>
      <DataArray type="Float32" Name="TIME" NumberOfTuples="1" format="ascii">
       10.543
      </DataArray>
    </FieldData>
    <Piece NumberOfPoints="13" NumberOfCells="12">
 ...

[edit] Adding Time and CYCLE from C++

Here are some routines that you can call from your C++ code to add time and cycle values the vtkDataSet that you write out for visualization with VisIt.

// Add "time" value to a VTK dataset.
void
AddTimeToVTK(vtkDataSet *ds, double time)
{
    vtkDoubleArray *t = vtkDoubleArray::New();
    t->SetName("TIME");
    t->SetNumberOfTuples(1);
    t->SetTuple1(0, time);
    ds->GetFieldData()->AddArray(t);
}
 
// Add "cycle" value to a VTK dataset.
void
AddCycleToVTK(vtkDataSet *ds, int cycle)
{
    vtkIntArray *c = vtkIntArray::New();
    c->SetName("CYCLE");
    c->SetNumberOfTuples(1);
    c->SetTuple1(0, cycle);
    ds->GetFieldData()->AddArray(c);
}

[edit] Using the time in an annotation

VisIt can display the time and cycle reported by a database plugin in the upper left hand corner of the visualization window. In addition, VisIt has two annotation objects that can display the time. The 2D text annotation and time slider annotations can display time if you include $time in the text that they will display. These annotations are created using the Controls->Annotation window. The Object tab contains buttons that let you create new annotations. From there, you can set their text.

Personal tools