# ParaView Programmable Source with vtkImageData output

**URL:** https://discourse.vtk.org/t/paraview-programmable-source-with-vtkimagedata-output/2341
**Category:** Support
**Created:** [December 26, 2019, 1:22pm UTC](https://discourse.vtk.org/t/paraview-programmable-source-with-vtkimagedata-output/2341 "2019-12-26T13:22:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MBG](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/7ab992/32.png) [@MBG](https://discourse.vtk.org/u/MBG)
#### Post date: [December 26, 2019, 1:22pm UTC](https://discourse.vtk.org/t/paraview-programmable-source-with-vtkimagedata-output/2341/1 "2019-12-26T13:22:42Z")

</div>

The code below is based on

> **[Developing HDF5 readers using vtkPythonAlgorithm - Kitware Blog](https://blog.kitware.com/developing-hdf5-readers-using-vtkpythonalgorithm/)**
>
> In my last article, I introduced the new vtkPythonAlgorithm and showed how it can be used to developed fully functional VTK algorithms in Python. In ... Read More

  

> <https://stackoverflow.com/questions/45395269/numpy-uint8-t-arrays-to-vtkimagedata>

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)

---

<div class="post-metadata">

### Author: ![MBG](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/7ab992/32.png) [@MBG](https://discourse.vtk.org/u/MBG)
#### Post date: [December 26, 2019, 2:53pm UTC](https://discourse.vtk.org/t/paraview-programmable-source-with-vtkimagedata-output/2341/2 "2019-12-26T14:53:41Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![MBG](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/7ab992/32.png) [@MBG](https://discourse.vtk.org/u/MBG)
#### Post date: [December 28, 2019, 7:16am UTC](https://discourse.vtk.org/t/paraview-programmable-source-with-vtkimagedata-output/2341/3 "2019-12-28T07:16:18Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [January 2, 2020, 10:56pm UTC](https://discourse.vtk.org/t/paraview-programmable-source-with-vtkimagedata-output/2341/4 "2020-01-02T22:56:14Z")

</div>

Hi, this is the VTK forum. ParaView has it’s own forum at [discourse.paraview.org](http://discourse.paraview.org).

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [January 2, 2020, 10:56pm UTC](https://discourse.vtk.org/t/paraview-programmable-source-with-vtkimagedata-output/2341/5 "2020-01-02T22:56:21Z")

</div>


