I am completely new to dealing with vtk(/vtr/vtu/..) outside of paraview but I want to make my workflow a bit easier so I want to do some data transformation outside of paraview. Basically I have two simulations but the origin and the axis are different. The origin difference changes every time step so I want to transform my files such that they are aligned before opening them in paraview such that I not constantly have to change the values in the transform filter when I want to look at a different time step. I was first trying to achieve this by just rotating and transforming one file.
My approach is as such (based on a lot of other webpages so unfortunately I cannot track down anymore what came form where):
import vtk
reader = vtk.vtkXMLRectilinearGridReader()
reader.SetFileName(file_name)
reader.Update()
data = reader.GetOutput()
transform = vtk.vtkTransform()
transform.RotateZ(90)
transform.Translate(2.34375, 4.6875, 2.34375)
transformFilter=vtk.vtkTransformFilter()
transformFilter.SetTransform(transform)
transformFilter.SetInputData(data)
transformFilter.Update()
writer = vtk.vtkXMLRectilinearGridWriter()
writer.SetInputData(transformFilter.GetOutput())
writer.SetFileName("Output.vtr")
writer.Update()
Now I don't get any errors but also there is no file created and I don't know where I go wrong. Any help is highly appreciated. (btw I tried this answer and that actually does create a file)
EDIT; Maybe I found why it goes wrong but still I don't know how to fix it. If I print data
it says vtkRectilinearGrid
while if I print transformFilter.GetOutput()
it says vtkStructuredGrid
. I thought the transform filter would keep the same grid type but apparantly not. Somebody any idea to let it keep the same grid type?
A vtkRectilinearGrid is oriented along the main axis. It allows some optimizations, like having implicit coordinates.
The output of the Transform filter cannot be converted to a vtkRectlinearGrid, mainly because you cannot assume its orientation. Points cannot be implicit as with the RectilinearGrid, the object store each of them.
As you said, your solution is to change how you write your data. You can write a .vts
file with a vtkXMLStructuredGridWriter
.