Looks like this:<br><br>import numpy<br>from vtk.util import numpy_support<br><br># Reorder the data and flatten it so that it comes out in the order that VTK expects<br># NOTE that we need to keep this numpy array stored so that python doesn&#39;t do garbage cleanup on it<br>
# and thereby trash the VTK array as well unexpectedly (causes segfaults)<br><br># Create a bunch of data into a numpy array. Here I use the ordering Data[x,y,z]<br>Data = numpy.array([[[1,2,3],[4,5,6],[7,8,9]],[[11,12,13],[14,15,16],[17,18,19]]],&#39;f&#39;)<br>
<br># Need to transpose x and z coordinate because VTK&#39;s data ordering is different<br>flat_data_array = Data.transpose(2,1,0).flatten();<br>        <br>vtk_data_array = numpy_support.numpy_to_vtk(self.data_array)<br>
<br>points = image.GetPointData()<br>points.SetScalars(vtk_data_array)<br><br>image = vtk.vtkImageData() <br>image.SetDimensions(Data.shape)<br>image.Update()<br>        <br>Make sure you keep flat_data_array alive in your namespace somewhere, because it actually shares memory with the corresponding VTK Array. If Python does garbage cleanup on flat_data_array then you&#39;ll lose the VTK array, and possibly your mind.<br>
<br>Back the other way:<br><br><br>vtk_data = image.GetPointData().GetScalars()<br>numpy_data = numpy_support.vtk_to_numpy(vtk_data)<br><br>dims = image.GetDimensions()<br><br>numpy_data = numpy_data.reshape(dims[2], dims[1], dims[0])<br>
numpy_data = numpy_data.transpose(2,1,0)<br><br>numpy_data[x,y,z]...<br><br><br>Paul<br><br><div class="gmail_quote">On Mon, Mar 23, 2009 at 12:36 PM, Mathias Franzius <span dir="ltr">&lt;<a href="mailto:Mathias.Franzius@web.de">Mathias.Franzius@web.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Dear ng,<br>
<br>
I want to render offscreen into a numpy array. So far it works with writing to disk with a vtkWindowToImageFilter and an ImageWriter and then reloading it with PIL and converting via scipy.misc.fromimage.<br>
However, the vtk.util.vtk_to_numpy seems much more straight-forward and efficient.<br>
My problem is: how do I get the rendered image in vtk_data format? Now I use the renderWindow like this:<br>
fil = vtk.vtkWindowToImageFilter()<br>
fil.SetInput(renderWindow);<br>
<br>
Thanks!<br>
   Mathias<br>
_______________________________________________________________________<br>
DSL zum Nulltarif + 20 Euro Extraprämie bei Online-Bestellung über die<br>
DSL Freundschaftswerbung! <a href="http://dsl.web.de/?ac=OM.AD.AD008K15279B7069a" target="_blank">http://dsl.web.de/?ac=OM.AD.AD008K15279B7069a</a><br>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
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><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br>