[Paraview] PVPython: paraview.vtk not the same as vtk

Pat Marion pat.marion at kitware.com
Mon Apr 2 16:45:33 EDT 2012


Hi Hal,

You can import paraview.vtk.io  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.

Pat

On Mon, Apr 2, 2012 at 2:40 PM, Hal Canary <hal at cs.unc.edu> wrote:

>
> 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
>
> ______________________________**_________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/**
> opensource/opensource.html<http://www.kitware.com/opensource/opensource.html>
>
> Please keep messages on-topic and check the ParaView Wiki at:
> http://paraview.org/Wiki/**ParaView <http://paraview.org/Wiki/ParaView>
>
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/**mailman/listinfo/paraview<http://www.paraview.org/mailman/listinfo/paraview>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20120402/296d1dc4/attachment.htm>


More information about the ParaView mailing list