[vtkusers] observer coords to world: vtkImagePlaneWidget

John Hunter jdhunter at ace.bsd.uchicago.edu
Fri Mar 28 16:40:19 EST 2003


I have an observer of a vtkImagePlaneWidget that displays the plane
slice in a separate render window.  I would like to click in the
observer render window and get the coordinates of the underlying image
data.  I This works ok, if the plane widget is Z slice, where x and y
in the viewport correspond to x and y in the data, but I am getting
fouled up for the X and Y image plane widgets.

I am doing something like:

    ren = ...the viewport renderer...
    coord = vtk.vtkCoordinate()
    coord.SetCoordinateSystemToDisplay()
    coord.SetValue( event.x, 200.0-event.y, 0)
    world =  coord.GetComputedWorldValue(ren)

200 is the maximum of the vertical dimension of the viewport, and my
viewport events have the minimum at the upper left, rather than lower
left, so I am subtracting the y event coord from the viewport max .

For the X slice, the observer shows the world yw,zw on the xv,yv axis
For the Y slice, the observer shows the world xw,zw on the xv,yv axis and
For the Z slice, the observer shows the world xw,yw on the xv,yv axis 
where w is for world and v is for view.

With the code above, I can get the proper yw coordinate for the x
slice as world[0], but not the zw coordinate.  I can get the proper xw
coordinate as world[1] for the Y slice, but again not the zw
coordinate.  For the Z slice I get xy and yw as world[0] and world[1].
So I am clearly bungling something for the z coordinate.

I have also tried setting the z coordinate in the Display system, but
am not sure how to do this right.  I tried many variants of

    ren = self.GetCurrentRenderer()
    camera = self.GetCurrentCamera()
    pPoint0,pPoint1,pPoint2 = camera.GetPosition()
    fPoint0,fPoint1,fPoint2 = camera.GetFocalPoint()
    #ren.SetWorldPoint(pPoint0,pPoint1,pPoint2,1.0)
    ren.SetWorldPoint(fPoint0,fPoint1,fPoint2, 1.0)
    ren.WorldToDisplay()
    fx, fy, fz = ren.GetDisplayPoint()                
    ren.SetDisplayPoint(event.x, 200.0-event.y, fz)
    ren.DisplayToWorld()
    world =  ren.GetWorldPoint()
    return gtk.TRUE

but couldn't get the right answer, where 'right' is what I get from
the cursor over the same point in the vtkImagePlaneWidget render
window.

Any suggestions?

John Hunter

Here is the meat of the observer code

class PlaneWidgetObserver(GtkGLExtVTKRenderWindow):
    def __init__(self, planeWidget, planeWidgetRenderer, orientation):
        GtkGLExtVTKRenderWindow.__init__(self)
        self.pw = planeWidget
        self.pwRenderer = planeWidgetRenderer
        self.orientation = orientation
        
        self.colorMap = vtk.vtkImageMapToColors()
        self.colorMap.PassAlphaToOutputOff()
        self.colorMap.SetActiveComponent(0)
        self.colorMap.SetOutputFormatToLuminance()

        self.colorMap.SetInput(self.pw.GetResliceOutput())

        self.imageActor = vtk.vtkImageActor()
        self.imageActor.SetInput(self.colorMap.GetOutput())

        ren = vtk.vtkRenderer()
        self.GetRenderWindow().AddRenderer(ren)
        ren.AddActor(self.imageActor)
        self.set_size_request(200, 200)



VTK 4.2



More information about the vtkusers mailing list