Animating legacy VTK file series

From KitwarePublic
Revision as of 14:02, 3 September 2012 by Jourdain (talk | contribs) (→‎Making custom readers work with file series)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

It is now possible to animate legacy VTK file series. ParaView recognizes file series named using certain patterns including:

  • fooN.vtk
  • foo_N.vtk
  • foo-N.vtk
  • foo.N.vtk
  • Nfoo.vtk
  • N.foo.vtk
  • foo.vtk.N
  • foo.vtk-sN

Where N is an integer (with any number of leading zeros). To load a file series, first make sure that the file names match one of the patterns described above. Next, navigate to the directory where the file series is. The file browser should look like this:

Fileseries.png

You will see that the file series is collapsed into a group. The picture above shows the group after I clicked on the disclosure triangle. You don't have to do that. Simply select the group (in the picture named blow..vtk) and click ok. The reader will store all the filenames and treat each file as a time step. You can now animate, use annotate time filter, do anything you can do with readers that natively support time.

Making custom readers work with file series

We implemented a reader called vtkFileSeriesReader. This reader can work with any time-unaware reader to read file series as time-steps. For this to work, a vtkFileSeriesReader and a time-unaware reader are created. The vtkFileSeriesReader is what the pipeline sees. Internally, it stores a reference to the time-unaware reader. All file names in the series are passed to the vtkFileSeriesReader. As the time-step is changed, the vtkFileSeriesReader sets the right filename on the internal reader and forwards pipeline requests to it. To setup a vtkFileSeriesReader, all you have to do is to add a new proxy to your xml file. For example, here (/Servers/ServerManager/Resources/reader.xml) is how the VTK legacy reader is converted into a file series reader:

<source lang="xml">

 <ProxyGroup name="internal_sources">
  <SourceProxy name="legacyreader" 
               class="vtkPDataSetReader"
               label="Legacy VTK reader">
    <Documentation
      short_help="Read legacy VTK files."
      long_help="Read files stored in VTK's legacy file format.">
        The Legacy VTK reader loads files stored in VTK's legacy file format 
        (before VTK 4.2, although still supported). The expected file extension is .vtk. 
        The type of the dataset may be structured grid, 
        uniform rectilinear grid (image/volume), non-uniform rectiinear grid, 
        unstructured grid, or polygonal.
    </Documentation>
    <StringVectorProperty
       name="FileName"
       animateable="0"
       command="SetFileName"
       number_of_elements="1">
       <FileListDomain name="files"/>
       <Documentation>
         This property specifies the file name for the Legacy VTK reader.
       </Documentation>
    </StringVectorProperty>
    <Hints>
     <ReaderFactory extensions="vtk"
         file_description="Legacy VTK files" />
    </Hints>
  </SourceProxy>
 </ProxyGroup>
 ...
 <ProxyGroup name="sources">
 ...
  <SourceProxy name="LegacyVTKFileReader"
                         class="vtkFileSeriesReader"
                         si_class="vtkSIFileSeriesReaderProxy"
                         label="Legacy VTK reader"
                         file_name_method="SetFileName">
    <Documentation
      short_help="Read legacy VTK files."
      long_help="Read files stored in VTK's legacy file format.">
        The Legacy VTK reader loads files stored in VTK's legacy file format 
        (before VTK 4.2, although still supported). The expected file extension 
        is .vtk. The type of the dataset may be structured grid, 
        uniform rectilinear grid (image/volume), non-uniform rectiinear grid, 
        unstructured grid, or polygonal. This reader also supports file series.
    </Documentation>
     
    <SubProxy>
       <Proxy name="Reader"
         proxygroup="internal_sources" proxyname="legacyreader">
       </Proxy>
    </SubProxy>
     <StringVectorProperty name="FileNameInfo"
       command="GetCurrentFileName"
       information_only="1" >
       <SimpleStringInformationHelper />
    </StringVectorProperty>
    <StringVectorProperty
       name="FileNames"
       clean_command="RemoveAllFileNames"
       command="AddFileName"
       animateable="0"
       number_of_elements="0" 
       repeat_command="1">
       <FileListDomain name="files"/>
      <Documentation>
        The list of files to be read by the reader. If more than 1 file is specified, 
        the reader will switch to file series mode in which it will pretend that it 
        can support time and provide 1 file per time step.
      </Documentation>
    </StringVectorProperty>
    <DoubleVectorProperty 
       name="TimestepValues"
       repeatable="1"
       information_only="1">
       <TimeStepsInformationHelper/>
       <Documentation>
         Available timestep values.
       </Documentation>
    </DoubleVectorProperty>
    <Hints>
     <ReaderFactory extensions="vtk"
         file_description="Legacy VTK files" />
    </Hints>
  </SourceProxy>
 ...

</source>

Note that the reader xml is unchanged, other than being moved into another group (internal_sources). The name of this group is arbitrary. A SourceProxy with a si_class="vtkSIFileSeriesReaderProxy" element is put in the sources group. This proxy element has a few important attributes/elements:

  • file_name_method: this is the method used to set the file name of the internal reader. In this case, vtkPDataSetReader
  • SubProxy named reader: This should point to the time-unaware reader proxy group and name
  • FileNameInfo propery - copy this verbatim
  • FileNames property - copy this verbatim
  • TimestepValues property - copy this verbatim



ParaView: [Welcome | Site Map]