[Paraview] PVPython: paraview.vtk not the same as vtk
Hal Canary
hal at cs.unc.edu
Mon Apr 2 14:40:46 EDT 2012
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:
#!/usr/bin/env python
import vtk
da = vtk.vtkFloatArray()
da.SetName('myarray')
da.SetNumberOfComponents(1)
da.SetNumberOfTuples(1000)
for i in xrange(1000):
da.SetComponent(i,0,99.9)
print da.GetClassName()
image = vtk.vtkImageData()
image.SetDimensions(10,10,10)
image.GetPointData().AddArray(da)
writer = vtk.vtkXMLImageDataWriter()
fn = '/tmp/out.vti'
writer.SetFileName(fn)
writer.SetInput(image)
writer.Update()
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.
#####################
## run with pvpython
#####################
import paraview.vtk.dataset_adapter
import paraview.vtk
import numpy
na = numpy.zeros((1000,), dtype=numpy.float32)
na[:] = 99.9
da = paraview.vtk.dataset_adapter.numpyTovtkDataArray(na)
da.SetName('myarray')
print da.GetClassName()
image = paraview.vtk.vtkImageData()
image.SetDimensions(10,10,10)
image.GetPointData().AddArray(da)
writer = paraview.vtk.vtkXMLImageDataWriter()
writer.SetFileName('/tmp/out.vti')
writer.SetInput(image)
writer.Update()
#####################
Unfortunately, this tends to fail because
paraview.vtk.vtkXMLImageDataWriter does not exist.
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?
Thanks,
--
Hal Canary
More information about the ParaView
mailing list