Hi,<div><br></div><div>Thanks for your help both of you. </div><div><br></div><div>Cheers for pointing out my Cell-Point mistake Burlen, I actually am increasing my extents (extent[1]+1 for example) to compensate for this, but I did make a mistake in my final call </div>
<div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><b>out.GetCellData().AddArray(newArray)</b></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><b><br>
</b></span></div><div>which should be getting PointData, not CellData. My filter now works as planned :)</div><div><br></div><div>However I am interested in some of your comments. Being a new Python/Paraview/VTK programmer I would appreciate a bit of further advice:</div>
<div><br></div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">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.</span></blockquote>
<div><br></div><div>I agree that i should be the fastest changing index in some sense, but because I have to step over all values of i,j,k to read the entire array into my python array, I don't see why any other looping direction would be quicker?</div>
<div><br></div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">You may want to avoid the range function in your loop since if my recollection is correct that explicitly constructs a list of values</span></blockquote>
<div><br></div><div>I think you're right, it does seem to construct a list explicitly, but I don't really know what the alternative is?</div><div><br></div><div>Thanks again.</div><div><br></div><div>Looking forward to seeing that new filter built in!</div>
<br><div class="gmail_quote">On Sat, Oct 29, 2011 at 3:08 AM, Burlen Loring <span dir="ltr"><<a href="mailto:bloring@lbl.gov">bloring@lbl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<u></u>
<div bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
You haven't configured your output, assuming rectilinear grid you
need to set the extent and provide coordinate arrays.<br>
<br>
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:<br>
<br>
ncx = ext[1]-ext[0]+1<br>
ncy = ext[3] -ext[2] +1<br>
ncxy = nx*ny<br>
ncz = ext[5]-ext[4] +1<br>
cidx = k*nxy + j*nx+i<br>
<br>
for number of cells and a cell array index.<br>
<br>
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.<br>
<br>
You may want to avoid the range function in your loop since if my
recollection is correct that explicitly constructs a list of values.<br>
<br>
I hope this is helpful.<br>
Burlen<div><div></div><div class="h5"><br>
<br>
On 10/26/2011 10:41 PM, Mr FancyPants wrote:
</div></div><blockquote type="cite"><div><div></div><div class="h5">Hi there,
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>
<div><br>
</div>
<div><b>data=self.GetInput()</b></div>
<div><b>out=self.GetOutput()</b></div>
<div><b>extent=data.GetExtent()</b></div>
<div><b>vtkVarray=data.GetPointData().GetArray('velocity')</b></div>
<div><b><br>
</b></div>
<div><b>import numpy</b></div>
<div><b>pyVarray_x =
numpy.zeros([extent[1]+1,extent[3]+1,extent[5]+1])</b></div>
<div><b>pyVarray_y =
numpy.zeros([extent[1]+1,extent[3]+1,extent[5]+1])</b></div>
<div><b>pyVarray_z =
numpy.zeros([extent[1]+1,extent[3]+1,extent[5]+1])</b></div>
<div><b><br>
</b></div>
<div><b>for i in range(0,extent[1]+1):</b></div>
<div><b><span style="white-space:pre-wrap">
</span>for j in range(0,extent[3]+1):</b></div>
<div><b><span style="white-space:pre-wrap">
</span>for k in range(0,extent[5]+1):</b></div>
<div><b><span style="white-space:pre-wrap">
</span>tup=vtkVarray.GetTuple(i+j*(extent[1]+1)+k*(extent[1]+1)*(extent[3]+1))</b></div>
<div><b><span style="white-space:pre-wrap">
</span>pyVarray_x[i,j,k]=tup[0]</b></div>
<div><b><span style="white-space:pre-wrap">
</span>pyVarray_y[i,j,k]=tup[1]</b></div>
<div><b><span style="white-space:pre-wrap">
</span>pyVarray_z[i,j,k]=tup[2]<span style="white-space:pre-wrap"> </span></b></div>
<div><b><br>
</b></div>
<div><b><br>
</b></div>
<div><b><br>
</b></div>
<div><b>pyVarray_x_noz =
numpy.zeros([extent[1]+1,extent[3]+1,1])</b></div>
<div><b>pyVarray_y_noz =
numpy.zeros([extent[1]+1,extent[3]+1,1])</b></div>
<div>
<b>pyVarray_z_noz = numpy.zeros([extent[1]+1,extent[3]+1,1])</b></div>
<div><b><br>
</b></div>
<div><b>for i in range(0,extent[1]+1):</b></div>
<div><b><span style="white-space:pre-wrap">
</span>for j in range(0,extent[3]+1):</b></div>
<div><b><span style="white-space:pre-wrap">
</span>pyVarray_x_noz[i,j]=pyVarray_x[i,j,:].sum()</b></div>
<div><b><span style="white-space:pre-wrap">
</span>pyVarray_y_noz[i,j]=pyVarray_y[i,j,:].sum()</b></div>
<div><b><span style="white-space:pre-wrap">
</span>pyVarray_z_noz[i,j]=pyVarray_z[i,j,:].sum()</b></div>
<div><b><br>
</b></div>
<div><b>newArray=vtk.vtkDoubleArray()</b></div>
<div><b>newArray.SetName("test")</b></div>
<div><b>newArray.SetNumberOfComponents(3)</b></div>
<div><b><br>
</b></div>
<div><b>print newArray</b></div>
<div><b><br>
</b></div>
<div><b>for k in range(0,extent[5]+1):</b></div>
<div><b><span style="white-space:pre-wrap">
</span>for j in range(0,extent[3]+1):</b></div>
<div><b><span style="white-space:pre-wrap">
</span>for i in range(0,extent[1]+1):</b></div>
<div><b><span style="white-space:pre-wrap">
</span>tup0=pyVarray_x_noz[i,j]</b></div>
<div>
<b><span style="white-space:pre-wrap"> </span>tup1=pyVarray_y_noz[i,j]</b></div>
<div><b><span style="white-space:pre-wrap">
</span>tup2=pyVarray_z_noz[i,j]</b></div>
<div><b><span style="white-space:pre-wrap">
</span>tup=(tup0,tup1,tup2)</b></div>
<div><b><span style="white-space:pre-wrap">
</span>newArray.InsertNextTuple((tup0,tup1,tup2))</b></div>
<div><b><br>
</b></div>
<div><b>print newArray</b></div>
<div><b>print vtkVarray</b></div>
<div><b><br>
</b></div>
<div><b>out.GetCellData().AddArray(newArray)</b></div>
</div>
<div><b><br>
</b></div>
<div>I have no idea whats going wrong with this. Any help is much
appreciated, new to using paraview.</div>
<div><br>
</div>
<div>Thanks, James</div>
</div></div><pre><fieldset></fieldset>
_______________________________________________
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><div class="im">
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView" target="_blank">http://paraview.org/Wiki/ParaView</a>
Follow this link to subscribe/unsubscribe:
<a href="http://www.paraview.org/mailman/listinfo/paraview" target="_blank">http://www.paraview.org/mailman/listinfo/paraview</a>
</div></pre>
</blockquote>
<br>
</div>
</blockquote></div><br>