ParaView Programmable Source with vtkImageData output

The code below is based on


I try to create ParaView Programmable Source by the code below. I can see the correct properties on ParaView “Information” tab and there are no errors but the actual geometry isn’t available. What is the problem?

import vtk, h5py
from vtk.util import numpy_support

filename = “/Users/mbg/Documents/PVGeo-Examples/h5/data60.h5”
f = h5py.File(filename, ‘r’)
data = f[‘RTData’][:]

__depthImageData = vtk.vtkImageData()
depthArray = numpy_support.numpy_to_vtk(data.ravel(), deep=True, array_type=vtk.VTK_FLOAT)
__depthImageData.SetDimensions(data.shape)
__depthImageData.SetSpacing([1,1,1])
__depthImageData.SetOrigin([0,0,0])
__depthImageData.GetPointData().SetScalars(depthArray)

self.GetImageDataOutput().ShallowCopy(__depthImageData)

This code could be rewritten by many documented ways but all of them still doesn’t work:

import vtk, h5py
from vtk.util import numpy_support

filename = “/Users/mbg/Documents/PVGeo-Examples/h5/data60.h5”
f = h5py.File(filename, ‘r’)
data = f[‘RTData’][:]

__depthImageData = self.GetImageDataOutput()
#__depthImageData = vtk.vtkImageData()
depthArray = numpy_support.numpy_to_vtk(data.ravel(), deep=True, array_type=vtk.VTK_FLOAT)
__depthImageData.SetDimensions(data.shape)
__depthImageData.SetSpacing([1,1,1])
__depthImageData.SetOrigin([0,0,0])
__depthImageData.GetPointData().AddArray(depthArray)
depthArray.SetName(“unit array”)
#self.GetImageDataOutput().ShallowCopy(__depthImageData)

I found a solution for this ParaView bug. We need to turn off checkbox “Map scalars” and edit script and click “Apply” (ignore all error messages) and turn on the checkbox again. Without this magic we can’t see the output geometries!

Hi, this is the VTK forum. ParaView has it’s own forum at discourse.paraview.org.

1 Like