[vtkusers] vtkPicker + Tk problems solved.

Kevin Teich kteich at nmr.mgh.harvard.edu
Wed Sep 18 15:45:51 EDT 2002


In case anybody else was wondering about the same thing, I'm posting my
solution to my problems with vtkPicker. As a recap, I was trying to get
x,y coordinates from a texture mapped plane.

First it was suggested that I use a vtkCellPicker. This did what I 
wanted to get a 'pixel' out of the plane. Make the plane the same 
resolution as your texture and use modulus and regular division on the 
picked cell ID to get the x,y coordinates. In the picker call back (my 
resolution here is 256x256):

    set cellId [$picker GetCellId]
    if { $cellId >= 0 } {
	puts "coord: [expr $cellId % 256],[expr $cellId / 256]"
    }

This worked, but only if I was using a vtkInteractor. Onto problem two.

I wanted to use BindTkRenderWidget function so I could use my own Tk
bindings, and this is where I was running into problems, as it seemed to
be picking the wrong cell. Turns out, the picker bound by the
BindTkRenderWidget flips the y coordinate before sending it to the picker.  
You can use the following code to bind your own picker. First, bind your
pre-pick function to a key in your widget.

bind $rwRender <KeyPress-b> "PickCell %W %x %y"

You pre-pick function needs to do the y flip and then call the picker:

proc PickCell { widget x y } {
    global picker
    global renderer
    
    set WindowY [lindex [$widget configure -height] 4]
    picker Pick $x [expr $WindowY - $y - 1] 0.0 renderer
}

(This is almost straight out of 
VTK/Wrapping/Tcl/vtkinteraction/TkInteractor.tcl.) Then your picker 
callback function is called with the proper coordinates.

Thanks for your help!

-- 
Kevin Teich





More information about the vtkusers mailing list