Using vtkPicker with Python/Vtk
David Gobbi
dgobbi at irus.rri.on.ca
Sun Jan 9 13:59:01 EST 2000
Hi Vetle,
The line in your code which is at fault is
renderWidget.__ActorPicker = new_picker
This doesn't work because __ActorPicker is a private attribute.
In python, this is true of any attribute that starts with '__'.
Unfortunately, trying to set a private attribute in Python doesn't
raise an exception.
What you should do instead is edit vtkRenderWidget.py and add
the following two methods:
def SetPicker(self,picker):
self.__ActorPicker = picker
def GetPicker(self):
return self.__ActorPicker
I'll try to get these changes into the nightly releases, as well.
- David
--
David Gobbi, MSc dgobbi at irus.rri.on.ca
Advanced Imaging Research Group
Robarts Research Institute, University of Western Ontario
On Sun, 9 Jan 2000, Vetle Roeim wrote:
> I'm trying to use vtkPicker and its associated sub-classes in a project,
> using Python and vtkRenderWidget.
> This is not described in "Vtk User's Guide", but I understand that
> vtkRenderWidget is rather new, so it is understandable.
>
> On page 62 of the User's Guide, it says how to use vtkPicker with
> vtkRenderWindowInteractor. Although it is possible to use
> vtkRenderWindowInteractor in Python, it is not possible to do so if you
> wish to use the renderwindow as a Tk widget (I experienced strange
> behaviour when I tried this).
>
> Fortunately, vtkRenderWidget implements most of the
> vtkRenderWindowInteractor's functionality, but it seems to dislike
> picking.
>
> There does not exist a "SetPicker()" method in vtkRenderWidget, so I tried
> setting the picker explicitly, like this:
> picker = vtkCellPicker()
> picker.SetPickMethod( foo )
> renderWidget.__ActorPicker = new_picker
>
> It does not work as expected. 'foo' is a function that prints a string to
> standard output. Here is the complete script I used to test the feature:
>
> #!/usr/bin/env python
>
> import Tkinter
> from VTK import *
>
> root = Tkinter.Tk()
>
> ren = vtkRenderer()
> renderWidget = vtkTkRenderWidget( root )
> renderWidget.pack()
> renWin = renderWidget.GetRenderWindow()
> renWin.AddRenderer( ren )
>
> def foo():
> print 'foobar'
>
> picker = vtkCellPicker()
> picker.SetPickMethod( foo )
> renderWidget.__ActorPicker = picker
>
> coneSource = vtkConeSource()
> coneMapper = vtkPolyDataMapper()
> coneMapper.SetInput( coneSource.GetOutput() )
> coneActor = vtkActor()
> coneActor.SetMapper( coneMapper )
>
> ren.AddActor( coneActor )
> picker.AddPickList( coneActor )
>
> root.mainloop()
>
> So, my question is; how should I do this? How is it possible to use
> picking together with vtkRenderWidget?
>
>
>
> Thanks,
> Vetle Roeim
> Student at Department of Informatics, University of Oslo, Norway
>
>
>
>
> -----------------------------------------------------------------------------
> This is the private VTK discussion list. Please keep messages on-topic.
> Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
> To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
> <majordomo at gsao.med.ge.com>. For help, send message body containing
> "info vtkusers" to the same address. Live long and prosper.
> -----------------------------------------------------------------------------
>
-----------------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>. For help, send message body containing
"info vtkusers" to the same address. Live long and prosper.
-----------------------------------------------------------------------------
More information about the vtkusers
mailing list