So instead of storing every data we have in yet another format to make it displayable by ParaView, I wanted to use the python interface ParaView offers to directly load our data from our current file format and display it.
To test this out I wanted to create a simple ProgrammableSource filter that outputs a vtkImageData and fill it with some data.
I encountered three issues:
- First, the data is not displayed (not even as an outline representation)
- I could not find a way to set the values without looping
- I did not find a good online source that could help me
Here is what I have so far. No complaints from ParaView, but also nothing is rendered.
import numpy as np
import vtk
import vtk.util.numpy_support as ns
img = self.GetImageDataOutput()
img.SetDimensions(3,4,5)
img.AllocateScalars(vtk.VTK_DOUBLE, 1)
dims = img.GetDimensions()
img.SetOrigin(0,0,0)
img.SetSpacing(0.55, 0.55, 0.55)
for z in range(dims[2]):
for y in range(dims[1]):
for x in range(dims[0]):
img.SetScalarComponentFromDouble(x,y,z,0, 1.0*x*y*z)
NOTE: If it is easier to use the python shell of ParaView directly instead of the ProgrammableSource, this would also be ok.