[vtkusers] update pipeline

David Froger david.froger at gmail.com
Sun Oct 23 15:12:54 EDT 2011


Hi,

I'm new  to vtk.  I'm trying to  use Vtk+Python+Tkinter to  read MultiBlock from
Ensight files,  plot unstructrued  data that are extracted  from the MultiBlock,
and interactively select a time to re-read and re-draw the data.

Here is what I did:

import Tkinter as Tk

import vtk
from vtk.tk.vtkTkRenderWindowInteractor import vtkTkRenderWindowInteractor

# Read the source file
reader = vtk.vtkGenericEnSightReader()
reader.SetCaseFileName('data.case')
reader.SetTimeValue(0.1)
reader.Update()

# Extract the block 1
multiBlock = reader.GetOutput()
triangularData = multiBlock.GetBlock(1)

# Create the Mapper
mapper = vtk.vtkDataSetMapper()
mapper.SetInput(triangularData)

# Create the Actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Create the Renderer
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1) # Set background to white

# create root window
root = Tk.Tk()

# create the WindowInteractor
win = vtkTkRenderWindowInteractor(root, width=300, height=300)
win.Initialize()
win.GetRenderWindow().AddRenderer(renderer)
style = vtk.vtkInteractorStyleTrackballCamera()
win.SetInteractorStyle(style)
win.pack(fill='both', expand=1, side='bottom')
win.Start()

# Function called when Button "Ok" is pressed.
# Get the time value from the Entry widget, and
# pass it to the vtkGenericEnSightReader
def update():
    text = entry.get()
    try: 
        time = float(text)
        reader.SetTimeValue(time)
        reader.Update()
    except ValueError:
        print "Float recquired"
    
# Create Label, a Entry and a Button where user inputs time value.
Tk.Label(text='time=').pack(side='left')
entry = Tk.Entry()
entry.pack(side='left')
button = Tk.Button(text='Ok',command=update).pack(side='left')

root.mainloop()

Inputing  a  time  in  the  tkinter  widget  updates  the  Reader,  but  not the
vtkTkRenderWindowInteractor.  Obviously,  the pipe is broken when the block 1 is
extracted.  I've tried to  use the vtkExtractBlock filter,  but  it only returns
MultiBlock, and the mapper input has to be a Block.

How can I do?

Thanks for reading and for any suggestion that could help me!

Best,
David.
-- 



More information about the vtkusers mailing list