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)
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):
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?!