<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body 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<br>
<br>
On 10/26/2011 10:41 PM, Mr FancyPants wrote:
<blockquote
cite="mid:CAGqbCOQju-ho7psSfLb73qmmag9FsV-W20xnyt9UixpBcuYXCQ@mail.gmail.com"
type="cite">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 class="Apple-tab-span" style="white-space: pre;">
</span>for j in range(0,extent[3]+1):</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>for k in range(0,extent[5]+1):</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>tup=vtkVarray.GetTuple(i+j*(extent[1]+1)+k*(extent[1]+1)*(extent[3]+1))</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>pyVarray_x[i,j,k]=tup[0]</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>pyVarray_y[i,j,k]=tup[1]</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>pyVarray_z[i,j,k]=tup[2]<span class="Apple-tab-span"
style="white-space: pre;"> </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 class="Apple-tab-span" style="white-space: pre;">
</span>for j in range(0,extent[3]+1):</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>pyVarray_x_noz[i,j]=pyVarray_x[i,j,:].sum()</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>pyVarray_y_noz[i,j]=pyVarray_y[i,j,:].sum()</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</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 class="Apple-tab-span" style="white-space: pre;">
</span>for j in range(0,extent[3]+1):</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>for i in range(0,extent[1]+1):</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>tup0=pyVarray_x_noz[i,j]</b></div>
<div>
<b><span class="Apple-tab-span" style="white-space: pre;"> </span>tup1=pyVarray_y_noz[i,j]</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>tup2=pyVarray_z_noz[i,j]</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</span>tup=(tup0,tup1,tup2)</b></div>
<div><b><span class="Apple-tab-span" style="white-space: pre;">
</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>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a>
Visit other Kitware open-source projects at <a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the ParaView Wiki at: <a class="moz-txt-link-freetext" href="http://paraview.org/Wiki/ParaView">http://paraview.org/Wiki/ParaView</a>
Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.paraview.org/mailman/listinfo/paraview">http://www.paraview.org/mailman/listinfo/paraview</a>
</pre>
</blockquote>
<br>
</body>
</html>