Hi Hal,<br><br>You can import <a href="http://paraview.vtk.io">paraview.vtk.io</a> to access the xml writer. I agree with you, it's annoying, paraview's vtk module should be same as the standard vtk module. Otherwise, most scripts don't work when transitioning to pvpython. I'll go file a bug report.<br>
<br>Pat<br><br><div class="gmail_quote">On Mon, Apr 2, 2012 at 2:40 PM, Hal Canary <span dir="ltr"><<a href="mailto:hal@cs.unc.edu">hal@cs.unc.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I've got a question concerning ParaView and VTK Python scripts. My goal is to generate some test data in the form of .vti files. Using the VTK Python module, I can run the following script to generate a test datafile:<br>
<br>
#!/usr/bin/env python<br>
import vtk<br>
<br>
da = vtk.vtkFloatArray()<br>
da.SetName('myarray')<br>
da.SetNumberOfComponents(1)<br>
da.SetNumberOfTuples(1000)<br>
for i in xrange(1000):<br>
da.SetComponent(i,0,99.9)<br>
print da.GetClassName()<br>
<br>
image = vtk.vtkImageData()<br>
image.SetDimensions(10,10,10)<br>
image.GetPointData().AddArray(<u></u>da)<br>
<br>
writer = vtk.vtkXMLImageDataWriter()<br>
fn = '/tmp/out.vti'<br>
writer.SetFileName(fn)<br>
writer.SetInput(image)<br>
writer.Update()<br>
<br>
<br>
To speed things up, I want to use the vtk.dataset_adapter submodule from the ParaView Python libraries. The function numpyTovtkDataArray will translate a numpy array into a vtkDataArray. This should speed thigns up considerably.<br>
<br>
#####################<br>
## run with pvpython<br>
#####################<br>
import paraview.vtk.dataset_adapter<br>
import paraview.vtk<br>
import numpy<br>
<br>
na = numpy.zeros((1000,), dtype=numpy.float32)<br>
na[:] = 99.9<br>
da = paraview.vtk.dataset_adapter.<u></u>numpyTovtkDataArray(na)<br>
da.SetName('myarray')<br>
print da.GetClassName()<br>
<br>
image = paraview.vtk.vtkImageData()<br>
image.SetDimensions(10,10,10)<br>
image.GetPointData().AddArray(<u></u>da)<br>
<br>
writer = paraview.vtk.<u></u>vtkXMLImageDataWriter()<br>
writer.SetFileName('/tmp/out.<u></u>vti')<br>
writer.SetInput(image)<br>
writer.Update()<br>
#####################<br>
<br>
Unfortunately, this tends to fail because paraview.vtk.<u></u>vtkXMLImageDataWriter does not exist.<br>
<br>
The only way I can get this to work is to install both VTK and ParaView and mix calls to the paraview.vtk the vtk modules. This seems redundant. Is there a better way?<br>
<br>
Thanks,<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Hal Canary<br>
<br>
______________________________<u></u>_________________<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/<u></u>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView" target="_blank">http://paraview.org/Wiki/<u></u>ParaView</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.paraview.org/mailman/listinfo/paraview" target="_blank">http://www.paraview.org/<u></u>mailman/listinfo/paraview</a><br>
</font></span></blockquote></div><br>