[vtkusers] [Paraview] Combining vtk and paraview python scripts

Berk Geveci berk.geveci at kitware.com
Mon Jul 20 20:43:59 EDT 2015


You probably need to update vtkImageExport and shallow copy its output to
the programmable source's output. You also need to add something to the
RequestInformation setting the whole extent. You need something like:

from paraview import util

util.SetOutputWholeExtent(self, [0,nx-1,0,ny-1,0,nz-1])

By the way, there are better ways of getting numpy arrays into VTK than the
image import stuff. See some of the earlier blogs here:

http://www.kitware.com/blog/home/user/53/2

Best,
-berk

On Mon, Jul 20, 2015 at 2:08 PM, Jeff Becker <jeffrey.c.becker at nasa.gov>
wrote:

>  Hi,
>
> On 07/18/2015 05:17 PM, Berk Geveci wrote:
>
> To elaborate on what Andy said, you can stick your entire VTK script in
> side the programmable source. Which you can use in batch mode as well. If
> you want to keep your VTK script as a reusable code, I recommend making it
> a module that you import from the programmable source.
>
>
> So if the last thing my VTK script does is set up a vtkImageImport object
> should that work as a programmable source (I tried but ParaView didn't get
> any bounds or scalar field name even though I set them up)? If not, what
> else do I need to do? Thanks.
>
> -jeff
>
>
>
>  Best,
> -berk
>
> On Tue, Jul 14, 2015 at 3:43 PM, Jeff Becker <jeffrey.c.becker at nasa.gov>
> wrote:
>
>>  On 07/14/2015 12:20 PM, Andy Bauer wrote:
>>
>> ParaView's Python Programmable Filter and Python Programmable Source use
>> VTK Python wrapping to do the work while making it available in Paraview.
>> Check out http://www.paraview.org/Wiki/Python_Programmable_Filter.
>>
>>
>>  Thanks. That's pretty neat, but what I'd really like is a standalone
>> script I can run in batch mode (no interaction) to generate one png file
>> per timestep for all the timesteps in the data set. Essentially I'd like a
>> way to construct a pipeline between the vtk.vtkImageImport()  object and
>> the ParaView renderView1.
>>
>> -jeff
>>
>>
>> On Tue, Jul 14, 2015 at 2:59 PM, Jeff Becker <jeffrey.c.becker at nasa.gov>
>> wrote:
>>
>>> Hi.
>>>
>>> As a proof of concept, I have a vtk script that reads some binary data,
>>> and produces a vti file. I then have a second script that I generated using
>>> ParaView's tracing facility while viewing the data. Now I'd like to combine
>>> them, so as to eliminate the intermediate file, i.e., go from binary data
>>> directly to rendering. To be specific, my vtk script ends like this:
>>>
>>> steinbmag = steinbmag.reshape(nx,ny,nz).T
>>>
>>> vtkImporter = vtk.vtkImageImport()
>>> vtkImporter.CopyImportVoidPointer(steinbmag, steinbmag.nbytes)
>>>
>>> vtkImporter.SetDataScalarTypeToFloat()
>>> vtkImporter.SetNumberOfScalarComponents(1)
>>> vtkImporter.SetDataExtent(0, nx-1, 0, ny-1, 0, nz-1)
>>> vtkImporter.SetWholeExtent(0, nx-1, 0, ny-1, 0, nz-1)
>>> vtkImporter.SetScalarArrayName('B field magnitude')
>>>
>>> writer=vtk.vtkXMLImageDataWriter()
>>> writer.SetFileName(out_fname)
>>> writer.SetInputConnection(vtkImporter.GetOutputPort())
>>> writer.Write()
>>>
>>> and the ParaView script starts like this:
>>>
>>> from paraview.simple import *
>>>
>>> paraview.simple._DisableFirstRenderCameraReset()
>>>
>>> filepfx = '/nobackup/jcbecker/steinBmag_0'
>>> infile = filepfx+'.vti'
>>> # create a new 'XML Image Data Reader'
>>> steinBmag_ = XMLImageDataReader(FileName=infile)
>>> steinBmag_.CellArrayStatus = []
>>> steinBmag_.PointArrayStatus = ['B field magnitude']
>>>
>>> # get animation scene
>>> animationScene1 = GetAnimationScene()
>>>
>>> # update animation scene based on data timesteps
>>> animationScene1.UpdateAnimationUsingDataTimeSteps()
>>>
>>> # get active view
>>> renderView1 = GetActiveViewOrCreate('RenderView')
>>> # uncomment following to set a specific view size
>>> renderView1.ViewSize = [1090, 761]
>>>
>>> I'm looking at the VTK examples and pvpython documentation, but any help
>>> is appreciated.
>>>
>>> Thanks.
>>>
>>> -jeff
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the ParaView Wiki at:
>>> http://paraview.org/Wiki/ParaView
>>>
>>> Search the list archives at: http://markmail.org/search/?q=ParaView
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/paraview
>>>
>>
>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the ParaView Wiki at:
>> http://paraview.org/Wiki/ParaView
>>
>> Search the list archives at: http://markmail.org/search/?q=ParaView
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/paraview
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150720/10564079/attachment.html>


More information about the vtkusers mailing list