[vtkusers] Multiple instances of vtkPropPicker

Janna balling at diego.sci.utah.edu
Mon Jul 21 19:07:47 EDT 2003

I found a solution and and explanation to this problem:

> I want to declare more than one vtkPropPicker in a process.  Each propPicker would have a
> separate renderer and renderwindow.  I tried the following (where labelPick is my own procedure
> for displaying text with a picked actor):

> set variable value1

> vtkRenderer  renderer1-->vtkRenderWindow  renWin1-->vtkRenderWindowInteractor  iren1-->

> vtkPropPicker   picker1
>    picker1 AddObserver EndPickEvent labelPick;
> iren1   SetPicker   picker1

> proc labelPick {} {puts $variable}

> set variable value2

> vtkRenderer  renderer2-->vtkRenderWindow  renWin2-->vtkRenderWindowInteractor  iren2-->
> vtkPropPicker   picker2
>    picker2 AddObserver EndPickEvent labelPick;
> iren2   SetPicker   picker2

> proc labelPick {} {puts $variable}

> This results in variable always having value2 regardless of which window is being picked.  Why?

  In this code, the vtkPropPicker assigns the AddObserver Event to the procedure labelPick.  The
labelPick procedure uses variables assigned before this code.  These variables will contain the
value that was most recently assigned (in this case, value2) even though picker1 and picker2 call
labelPick separately.  (vtk quirk I suppose)

  Define proc labelPick every time before picking.  (not too fun if this is automated.)
  Create environment variables to be used in labelPick with:
global env
array set env [list variable value1]
  Change labelPick to:
proc labelPick {} {global env;  puts $env(variable);}
   Now every time you do a pick, you only need to change the environment variable with:
global env
array set env [list variable value2]
   This still is no help if you want to use the keypress "P" to pick things, but you can use the
vtkPropPicker  Pick command (given coordinates) to pick from either instance.  For example:
picker1 Pick 100 100 75 renderer1
picker1 Pick x y z renderer2

Hope this helps
Janna Balling
SCI Institute, University of Utah
balling at sci.utah.edu

More information about the vtkusers mailing list