[vtkusers] Combining vtk and paraview python scripts

Jeff Becker jeffrey.c.becker at nasa.gov
Tue Jul 14 14:59:56 EDT 2015


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


More information about the vtkusers mailing list