[vtkusers] Picking questions
Sherwood, P (Paul)
P.Sherwood at dl.ac.uk
Wed Oct 23 14:49:40 EDT 2002
Prabhu,
thanks for this.
I have played around and ended up passing the
molecule and atom picked by declaring the observer with
something like
# actor a represents atom at in molecule m
a.AddObserver('PickEvent', \
lambda obj,ev,s=self,mol=m,atom=at : s.mypick(mol,atom,obj,ev)
I still feel it looks like a rather complicated way of providing
some user data for when the pick event happens. It seems to work, but
if there is a nicer way I'd like to know!
thanks again
Paul
>> -----Original Message-----
>> From: Prabhu Ramachandran [mailto:prabhu at aero.iitm.ernet.in]
>> Sent: 23 October 2002 18:08
>> To: Sherwood, P (Paul)
>> Cc: vtkusers at public.kitware.com
>> Subject: Re: [vtkusers] Picking questions
>>
>>
>> hi,
>>
>> >>>>> "PS" == P Sherwood <Sherwood> writes:
>>
>> PS> I am just experimenting with picking and I am unsure how to
>> PS> efficiently work out which atom was picked. I am working in
>> PS> Python.
>>
>> PS> I can identify the picked property (Actor) using
>> PS> picker.GetPath().GetFirstNode(), by I am not sure
>> of the best
>> PS> way to find out which atom in my model was picked.
>> Is there a
>> PS> user data component of an actor I could set when it
>> is created
>> PS> and access to indicate what it represents when it is picked?
>>
>> If you are using VTK 4.0+ then you can use observers to do this
>> easily. Here is a quick example using MayaVi's ivtk module (for
>> convenience).
>>
>> from mayavi import ivtk
>> import vtk
>> cs = vtk.vtkConeSource()
>> m = vtk.vtkPolyDataMapper()
>> a = vtk.vtkActor()
>> m.SetInput(cs.GetOutput())
>> a.SetMapper(m)
>> v = ivtk.viewer()
>> v.AddActors(a)
>>
>> def test(obj, event):
>> print "Event", event, "occured"
>> print repr(obj)
>>
>> a.AddObserver('PickEvent', test)
>>
>> Now press 'p' on the viewer window near one of the vertices of the
>> cone and see your test function in action.
>>
>> PS> Also, is there any way to pick multiple actors
>> using something
>> PS> like the rubberband selection tools many programs use these
>> PS> days?
>>
>> No clue if there is something to do this already but I guess you can
>> write some code to do this. However it might take some work.
>>
>> cheers,
>> prabhu
>>
More information about the vtkusers
mailing list