[vtkusers] update render window

Luis Concha lconcha at gmail.com
Fri Oct 22 02:40:04 EDT 2004


Hello fellow vtk users.

I am new to this wonderful tool, and I am creating a simple MRI
viewer.  The idea is to have a window (written in wxPython) with
controls for the slice number (in 3 planes).  I want to be able to
load slices one at a time and the render window should update
automatically.  So far, I can only pre-set what slices I want to see,
and render them;  then, if I want to add another one, the render
window crashes.  I just need to know how to update the render window
in Python.  Here's my code.  I will appreciate all the help and
patience you  may have for this newbie.

Sincerely,

Luis Concha




###############################################################
import vtk

class MyViewer:
    """MyViewer.  Class to view an image volume with 1 to 3 ortho slices."""
    global aRenderer
    aRenderer=vtk.vtkRenderer()
    aRenderer.SetBackground(.2,.2,.3)

    def ReadVolume(self,filename,xmin,xmax,ymin,ymax,zmin,zmax):
        """read image volume.  Needs data set dimensions.
           ReadVolume(filename,xmin,xmax,ymin,ymax,zmin,zmax)"""
        global reader
        reader=vtk.vtkImageReader()
        reader.SetFileDimensionality(3)
        reader.SetFileName(filename)
        reader.SetDataExtent(xmin,xmax,ymin,ymax,zmin,zmax)
        reader.SetDataOrigin(0,0,0)
        reader.SetDataSpacing(.5,.5,1)
        reader.UpdateWholeExtent()
        global extent
        extent=reader.GetDataExtent()
        

    def LUT(self,mindata,maxdata):
        """create a lookup table.  mindata and maxdata are extreme values.
        LUT(mindata,maxdata)"""
        global bwlut        
        bwlut=vtk.vtkLookupTable()
        bwlut.SetTableRange(mindata,maxdata)
        bwlut.SetSaturationRange(0,0)
        bwlut.SetHueRange(0,0)
        bwlut.SetValueRange(0,1)
        bwlut.Build()
        

    def axialslice(self,axialnum):
        """get axial slice.  axialnum is the slice to display.
        axialslice(axialnum)"""
        axialcolors=vtk.vtkImageMapToColors()
        axialcolors.SetInput(reader.GetOutput())
        axialcolors.SetLookupTable(bwlut)
        axial=vtk.vtkImageActor()
        axial.SetInput(axialcolors.GetOutput())
        axial.SetDisplayExtent(extent[0],extent[1],extent[2],extent[3],axialnum,axialnum)
        aRenderer.AddActor(axial)        

    def sagitalslice(self,sagnum):
        """get sagital slice.  sagnum is the slice to display.
        sagitalslice(sagnum)"""
        sagcolors=vtk.vtkImageMapToColors()
        sagcolors.SetInput(reader.GetOutput())
        sagcolors.SetLookupTable(bwlut)
        sagital=vtk.vtkImageActor()
        sagital.SetInput(sagcolors.GetOutput())
        sagital.SetDisplayExtent(sagnum,sagnum,extent[2],extent[3],extent[4],extent[5])
        aRenderer.AddActor(sagital)

    def coronalslice(self,cornum):
        """get coronal slice. cornum is the slice to display.
        coronalslice(cornum)"""
        corcolors=vtk.vtkImageMapToColors()
        corcolors.SetInput(reader.GetOutput())
        corcolors.SetLookupTable(bwlut)
        coronal=vtk.vtkImageActor()
        coronal.SetInput(corcolors.GetOutput())
        coronal.SetDisplayExtent(extent[0],extent[1],cornum,cornum,extent[4],extent[5])
        aRenderer.AddActor(coronal)
        
    def display(self,x,y):
        """Display the slices the render window. x and y are window
size (pixels)
        display()"""
        aRenderer.ResetCamera()
        renwin=vtk.vtkRenderWindow()
        renwin.AddRenderer(aRenderer)
        renwin.SetSize(x,y)
        renwin.Render()                 #start!
        #set the interactor
        global iren
        iren=vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(renwin)
        style=vtk.vtkInteractorStyleTrackballCamera()
        iren.SetInteractorStyle(style)
        iren.Initialize()
        iren.Start()
        key=iren.GetKeySym()
        if key=="q":
           iren.TerminateApp()
        iren.ExitCallback()



More information about the vtkusers mailing list