[vtkusers] Picking questions

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Wed Oct 23 13:07:36 EDT 2002


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