Multiple .VTR files

Hello,

I am after some guidance on where to go with my project…

I currently have a python pre processing file that reads a netCDF and generates a .vtr rectilinear grid which I then read in, to another python vtk file where I use contour filter to successfully render the isosurfaces.

However, I know want to render a ‘video’. I understand that rectilinear grid cannot take a 4th dimension or a timestep. So my pre processing file is going to have to output a .vtr file for each timestep. Is it then possible to read in many .vtr files into my visualisation app and to render them together as a video…

I understand this is not really a question, I am more looking for some pointer or guidance on how to combine multiple rectilinear grids to output my video

Thanks

You should try downloading ParaView then open all of the files at once as a time series. You can then press the play button in ParaView to preview the simulation and then select File->Save Animation to make a video. Here is a demo of what this looks like for a totally different data set (note I only open one file in this video but ParaView handles file series like yours with ease).

Hi,

This is exactly want I want to recreate but using VTK. I’ve currently got it all working in para view and can see how it should look :slight_smile:

I understand it may seem pointless what I am doing, when I can just do it para view , but it’s for my project

Look at the loop in this example.

You could save an image to a file in this loop. Use vtkWindowToImageFilter after the render and an image writer to save the contents of the window.
https://lorensen.github.io/VTKExamples/site/Python/IO/ImageWriter/

Ah, I thought this could be a bit of a programming endeavor and figured ParaView might be simpler.

We do exactly this in vtki. @S97: if you like Python, you could follow one of our gif or movie creation examples:

or do something like this (which I hacked together quickly - there should be a more elegant way to build a reader pipeline):

import vtk
import vtki

# All the VTR file names
filenames = ['foo-{}.vtr'.format(i) for i in range(4)]

reader = vtk.vtkXMLRectilinearGridReader()

def update_reader(fname):
    reader.SetFileName(fname)
    reader.Modified()
    reader.Update()

update_reader(filenames[0])
grid = vtki.wrap(reader.GetOutput())


# Create a plotter object and set the scalars to the Z height
plotter = vtki.Plotter()
plotter.add_mesh(grid, name='foo')

# setup camera and close
plotter.plot(auto_close=False)

# Open a gif
plotter.open_gif('frames.gif')

# Update Z and write a frame for each updated position
nframe = 15
for fname in filenames:
    update_reader(fname)
    print(fname)
    grid = vtki.wrap(reader.GetOutput())
    plotter.add_mesh(grid, name='foo')
    plotter.write_frame()

# Close movie and delete object
plotter.close()