Hi,
You haven't configured your output, assuming rectilinear grid you need
to set the extent and provide coordinate arrays.
You are indexing a point based array with cell based index, so the
lookup you make into vtkVarray is incorrect. 'Extent' tells you the
number of cells, not the number of points, for that use 'Dimensions' or
add one in each direction. Your script would certainly be more readable
if you used some variables such as:
ncx = ext[1]-ext[0]+1
ncy = ext[3] -ext[2] +1
ncxy = nx*ny
ncz = ext[5]-ext[4] +1
cidx = k*nxy + j*nx+i
for number of cells and a cell array index.
In the two first loops you are treating 'i' as the slowest changing
direction when it is the fastest. That will kill your performance. Last
loop has correct order.
You may want to avoid the range function in your loop since if my
recollection is correct that explicitly constructs a list of values.
I hope this is helpful.
Burlen
On 10/26/2011 10:41 PM, Mr FancyPants wrote:
Hi there,
I am trying to write a programmable filter which will take my
RectilinearGrid data and modify one of the data arrays. Specifically I
want to sum over one dimension. I have written something to do this,
but my data comes out garbled.
Below is my code. Basically all I am doing is extracting all the data,
doing my sum over the z direction and then putting this data into
another rectilinear grid.
*data=self.GetInput()*
*out=self.GetOutput()*
*extent=data.GetExtent()*
*vtkVarray=data.GetPointData().GetArray('velocity')*
*
*
*import numpy*
*pyVarray_x = numpy.zeros([extent[1]+1,extent[3]+1,extent[5]+1])*
*pyVarray_y = numpy.zeros([extent[1]+1,extent[3]+1,extent[5]+1])*
*pyVarray_z = numpy.zeros([extent[1]+1,extent[3]+1,extent[5]+1])*
*
*
*for i in range(0,extent[1]+1):*
*for j in range(0,extent[3]+1):*
*for k in range(0,extent[5]+1):*
*tup=vtkVarray.GetTuple(i+j*(extent[1]+1)+k*(extent[1]+1)*(extent[3]+1))*
*pyVarray_x[i,j,k]=tup[0]*
*pyVarray_y[i,j,k]=tup[1]*
*pyVarray_z[i,j,k]=tup[2]*
*
*
*
*
*
*
*pyVarray_x_noz = numpy.zeros([extent[1]+1,extent[3]+1,1])*
*pyVarray_y_noz = numpy.zeros([extent[1]+1,extent[3]+1,1])*
*pyVarray_z_noz = numpy.zeros([extent[1]+1,extent[3]+1,1])*
*
*
*for i in range(0,extent[1]+1):*
*for j in range(0,extent[3]+1):*
*pyVarray_x_noz[i,j]=pyVarray_x[i,j,:].sum()*
*pyVarray_y_noz[i,j]=pyVarray_y[i,j,:].sum()*
*pyVarray_z_noz[i,j]=pyVarray_z[i,j,:].sum()*
*
*
*newArray=vtk.vtkDoubleArray()*
*newArray.SetName("test")*
*newArray.SetNumberOfComponents(3)*
*
*
*print newArray*
*
*
*for k in range(0,extent[5]+1):*
*for j in range(0,extent[3]+1):*
*for i in range(0,extent[1]+1):*
*tup0=pyVarray_x_noz[i,j]*
*tup1=pyVarray_y_noz[i,j]*
*tup2=pyVarray_z_noz[i,j]*
*tup=(tup0,tup1,tup2)*
*newArray.InsertNextTuple((tup0,tup1,tup2))*
*
*
*print newArray*
*print vtkVarray*
*
*
*out.GetCellData().AddArray(newArray)*
*
*
I have no idea whats going wrong with this. Any help is much
appreciated, new to using paraview.
Thanks, James
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the ParaView Wiki at:
http://paraview.org/Wiki/ParaView
Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the ParaView Wiki at:
http://paraview.org/Wiki/ParaView
Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview