# Problem displaying Structured Grid when loading from Programmable Source

**URL:** https://discourse.paraview.org/t/problem-displaying-structured-grid-when-loading-from-programmable-source/3051
**Category:** ParaView Support
**Created:** [November 26, 2019, 3:48pm UTC](https://discourse.paraview.org/t/problem-displaying-structured-grid-when-loading-from-programmable-source/3051 "2019-11-26T15:48:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kenneth-loenbaek](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ba8739/32.png) [@kenneth-loenbaek](https://discourse.paraview.org/u/kenneth-loenbaek)
#### Post date: [November 26, 2019, 3:48pm UTC](https://discourse.paraview.org/t/problem-displaying-structured-grid-when-loading-from-programmable-source/3051/1 "2019-11-26T15:48:43Z")

</div>

Hi,

I am trying to make a file reader for a structured grid file that is not currently supported, but I can read it into a numpy array.  
To start simple I tried to make a programmable source which just creates a cube (Output Data Set Type: _vtkStructuredGrid_)

```python
import numpy as np

# Cube
xs = np.linspace(0,1,10)
ys = np.linspace(0,1,10)
zs = np.linspace(0,1,10)
dims = [len(xs),len(ys),len(zs)]

# Setting S-Grid extent
output.SetExtent([0,len(xs)-1,0,len(ys)-1,0,len(zs)-1])

# VTK points
points = vtk.vtkPoints()
points.Allocate(dims[0] * dims[1] * dims[2])

# Adding grid points 
for iz, z in enumerate(zs):
    for iy, y in enumerate(ys):        
        for ix, x in enumerate(xs):
            fi = iz*len(xs)*len(ys)+iy*len(xs)+ix # Flat index
            points.InsertPoint(fi,[x,y,z])
            
# Adding points to vtkStructuredGrid
output.SetPoints(points)

```

Which does not through any error. From the information tab I find:

* * *

Number of Cells: 729  
Number of Points: 1000

* * *

As expected. But I do not get any output in the RenderView.  
Does anybody have an idea why?

I tried to create a table with the following script (Output Data Set Type: _vtkTable_):

```python
import numpy as np

# Cube
xs = np.linspace(0,1,10)
ys = np.linspace(0,1,10)
zs = np.linspace(0,1,10)

# Flattining cube in index
out = np.zeros([len(xs)*len(ys)*len(zs),3])
for iz, z in enumerate(zs):
    for iy, y in enumerate(ys):        
        for ix, x in enumerate(xs):
            fi = iz*len(xs)*len(ys)+iy*len(xs)+ix # Flat index
            out[xis,:] = [x,y,z]

# Adding points to vtkTable
output.RowData.append(out[:,0],"x")
output.RowData.append(out[:,1],"y")
output.RowData.append(out[:,2],"z")

```

It creates the expected table. Then using the _Table to Structured Grid_ filter to make it into a grid. This way works with out any problem.

When comparing the two methods above from the information tab the only difference I find is that the memory usage is different:

* * *

Memory (StructuredGrid): 0.012 MB  
Memory (Table): 0.024 MB

* * *

I would love to hear if anybody has an idea for what I am missing?!

---

<div class="post-metadata">

### Author: ![jfavre](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jfavre](https://discourse.paraview.org/u/jfavre)
#### Post date: [November 26, 2019, 5:11pm UTC](https://discourse.paraview.org/t/problem-displaying-structured-grid-when-loading-from-programmable-source/3051/2 "2019-11-26T17:11:02Z")

</div>

There are two parts you must program. See page 167-168 of the ParaView Guide.  
You are missing a script for the RequestInformation part. It basically advertizes what the source can produce. This is where you set the dimensions of your grid.

> executive = self.GetExecutive()  
> outInfo = executive.GetOutputInformation(0)  
> dims = [10, 10, 10] # x-dims, y-dims, z-dims  
> outInfo.Set(executive.WHOLE\_EXTENT(), 0, dims[0]-1 , 0, dims[1]-1 , 0, dims[2]-1)

Then the execution part called “Script” is a modified version of your original test

> import numpy as np  
> executive = self.GetExecutive()  
> outInfo = executive.GetOutputInformation(0)  
> exts = [executive.UPDATE\_EXTENT().Get(outInfo, i) for i in range(6)]  
> dims=[exts[1]+1, exts[3]+1, exts[5]+1]  
> #Cube  
> xs = np.linspace(0,1,dims[0])  
> ys = np.linspace(0,1,dims[1])  
> zs = np.linspace(0,1,dims[2])  
> #Setting S-Grid extent  
> output.SetExtent(exts)  
> #vtk points  
> points = vtk.vtkPoints()  
> points.Allocate(dims[0] \* dims[1] \* dims[2])  
> #Adding grid points  
> for iz, z in enumerate(zs):  
> &nbsp;&nbsp;&nbsp;&nbsp;for iy, y in enumerate(ys):  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for ix, x in enumerate(xs):  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi = iz\*len(xs)_len(ys)+iy_len(xs)+ix # Flat index  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;points.InsertPoint(fi,[x,y,z])  
> #Adding points to vtkStructuredGrid  
> output.SetPoints(points)

---

<div class="post-metadata">

### Author: ![kenneth-loenbaek](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ba8739/32.png) [@kenneth-loenbaek](https://discourse.paraview.org/u/kenneth-loenbaek)
#### Post date: [November 27, 2019, 9:18am UTC](https://discourse.paraview.org/t/problem-displaying-structured-grid-when-loading-from-programmable-source/3051/3 "2019-11-27T09:18:02Z")

</div>

Thank you so much Jean. It works right out of the box. (except that for some reason the multiplication (\*) is lost for the flat index (`fi`), it might be that if you make the code cell, a python code cell it would look and copy as expected)

With that said, it seems that this relatively simple example is fairly convoluted and I do not understand why _RequestInformation_ is needed. I did look at chapter 12 in the ParaView Guide. Taking example 12.2.3 _Reading a CSV file with particles_ no _RequestInformation_ is needed and the example seems to be similar.  
Is it because it is required by the _vtkStructuredGrid_ to set _WHOLE\_EXTENT_?  
Could you point me to any documentation about this?
