[vtkusers] wxpython + vtkAxesActor + wxVTKRenderWindow
Michael Scarpa
m.scarpa at uva.nl
Mon Apr 23 04:01:27 EDT 2007
Hi Richard,
yes, you can use the wxVTKRenderWindowInteractor object. Simply put:
it is implemented such, that all relevant attribute access is
forwarded to the interactor object. As to your code, the problem is
that the object `marker' that you create is destroyed by the garbage
collector after the instantiation of `MainWindow'. If you replace
`marker' with `self.marker' in your code (in lines 33 to 39), the
python object becomes an attribute of the `MainWindow' instance, and
is not destroyed anymore. I hope this helps.
With kind regards,
Michael
On 20 Apr, 2007, at 20:17, Richard A Rowe wrote:
> Dear vtkusers,
>
> I hope someone can help me with this problem... I'm using wxpython
> to create a GUI for two vtk windows. Firstly is this a good choice
> or would a different GUI choice or another language other than
> python be more straight forward?
>
> I'd like to display xyz orientation widgets within the display
> windows. I have coded a simple example of how to display the
> vtkAxesActor within a vtkRenderWindow.
>
> However, since I'm currently using wxpython, I've been using
> wxVTKRenderWindow(). I'm not sure how to set the interactor of this
> or even if you can? I read somewhere that you should not use both
> wxVTKRenderWindow() and wxVTKRenderWindowInteractor() together,
> plus my efforts have resulted in no progress by doing so... It is
> my understanding that to use the vtkAxesActor with the
> vtkOrientationMarkerWidget one should set the interactor of the
> vtkOrientationMarkerWidget to the window interactor.
>
> Is this possible with wxVTKRenderWindow()? A simple program is
> below illustrating the problem.
>
> I will be very thankful if someone can help me out here.
>
> Kind Regards,
>
> Richard A Rowe.
>
> import wx
> from math import *
> import vtk
> from vtk.wx.wxVTKRenderWindowInteractor import
> wxVTKRenderWindowInteractor
>
> class MainWindow(wx.Frame):
> def __init__(self,parent,id,title):
> wx.Frame.__init__(self,parent,wx.ID_ANY,title,size =
> (600,600),
> style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
>
> panel = wx.Panel(self)
>
> widget = wxVTKRenderWindowInteractor(panel, -1)
>
> ren = vtk.vtkRenderer()
>
> renWin = widget.GetRenderWindow()
> renWin.AddRenderer(ren)
>
> sphere = vtk.vtkSphereSource()
>
> sphereMapper = vtk.vtkPolyDataMapper()
> sphereMapper.SetInputConnection(sphere.GetOutputPort())
>
> sphereActor = vtk.vtkActor()
> sphereActor.SetMapper(sphereMapper)
>
> # AxesActor
> axes = vtk.vtkAxesActor()
> axes.SetShaftTypeToCylinder()
>
> # Orientation marker to be used with vtkAxesActor.
> marker = vtk.vtkOrientationMarkerWidget()
> marker.SetOrientationMarker(axes)
> marker.SetViewport(0,0,0.2,0.2)
>
> marker.SetInteractor(widget)
> marker.EnabledOn()
> marker.InteractiveOff()
>
> ren.AddActor(sphereActor)
>
> sizer = wx.BoxSizer(wx.VERTICAL)
> sizer.Add(widget, 1, wx.EXPAND | wx.ALL, 5)
> self.SetSizer(sizer)
> self.Layout()
>
> self.Show(True)
>
>
> app = wx.PySimpleApp()
> frame = MainWindow(None, -1, "wxPython with vtk")
> app.MainLoop()
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/
> Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list