[vtkusers] pipeline update through wxPython

rharder at uiuc.edu rharder at uiuc.edu
Mon Feb 16 15:14:07 EST 2004


Hi,
This learning process has been fun.  I have wrapped a bunch
of c code with swig and managed to read in data with these
wrapped codes and get it into vtk imagedata to look at.
Now I want to start playing with GUI stuff and have been
trying to use wxPython.  I have a wxVTKRenderWindow inside
a wxFrame as well as a wxButton.  On button press I would
like the original data structure, from a package called sp4
to be FFTed by that packages FFT routine and the result be
shown in place of the original image in the wxVTKRenderWindow
within the wxFrame.  The original image is displayed fine.
I think the FFT is being done but the display is not being
updated.

thanks for your continued support.
Here is what I have:


from wxPython.wx import *
import _sp4 as sp4
import vtk
from vtk.wx.wxVTKRenderWindow import *
import sys

DOFFT=1000

app = wxPySimpleApp()

#typical vis pipeline stuff. some is not necessary
p=sp4.new_Sp4Array()
pr=sp4.new_Sp4Array()
sp4.Sp4ArrayLoad(p,"poly.sp4")
sp4.Sp4ArrayMakeReal(pr, p, "", 1001)
datastring = sp4.PyString_FromSp4( pr )
data = vtk.vtkDoubleArray()
data.SetVoidArray(datastring,len(datastring)/data.GetDataTypeSize(),1)
data.CreateDefaultLookupTable()
id = vtk.vtkImageData()
id.GetPointData().SetScalars(data)
id.SetDimensions(256,256,1)
#id.SetScalarTypeToUnsignedChar()
id.SetSpacing(1.0,1.0,0.0)
id.SetOrigin(0.0,0.0,0.0)
ss = vtk.vtkImageShiftScale()
ss.SetInput( id )
ss.SetShift(0)
ss.SetScale(1.0)
ss.SetOutputScalarTypeToUnsignedChar()
im = vtk.vtkImageMapper()
im.SetInput( ss.GetOutput() )
#im.SetInput( id )
im.SetColorWindow( 1.0 )
im.SetColorLevel( .5 )

#gui stuff
class MyFrame(wxFrame):
  def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title,
                        wxDefaultPosition, wxSize(400,400))

        #graphics pipeline stuff
        self.widget = wxVTKRenderWindow(self, -1)

        ren = vtk.vtkRenderer()
        self.widget.GetRenderWindow().AddRenderer(ren)

        ia = vtk.vtkActor2D()
        ia.SetMapper( im )
        ren.AddActor(ia)

        b=wxButton(self, id=DOFFT, label="FFT")

        EVT_BUTTON(self, DOFFT, self.OnButton)

  def OnButton(self,event):
        print "do fft"
        sp4.Sp4ArrayFFT(p,1)
        sp4.Sp4ArrayMakeReal(pr, p, "", sp4.AMP)
        #gotta do something to update the vis pipeline and the frame!
        self.widget.Render()
        self.Refresh()


frame=MyFrame(NULL,-1, "wxRenderWindow")
frame.Show(true)
app.MainLoop()



More information about the vtkusers mailing list