[vtkusers] how to get he mouse position when pressed on vtkimageviewer window

Mathieu Malaterre mathieu.malaterre at kitware.com
Tue Feb 8 16:01:47 EST 2005


Moti Freiman wrote:
> 
> Hello!
> i want to get the position of the mouse on image coordinates when the 
> left button of the mouse pressed on imageviewer window, or general 
> vtkRenderWindow.
> I did not find any function that do that. can someone give some help on 
> this?
> Thanks!
> moti
> 

You need to setup a vtkRenderWindowInteractor for this purpose

from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

reader = vtk.vtkPNGReader ()
reader.SetDataSpacing (0.8, 0.8, 1.5)
reader.SetFileName ( VTK_DATA_ROOT + "/Data/fullhead15.png")

iren = vtk.vtkRenderWindowInteractor()
viewer = vtk.vtkImageViewer()
viewer.SetInput ( reader.GetOutput() )
viewer.SetupInteractor (iren)

iren.Initialize()
iren.Start()

Once you have a vtkRenderWindowInteractor you can have a look at 
GetEventPosition, be carefull with the Y orientation flip (whether the y 
start at bottom of screen or from the top).

HTH
Mathieu



More information about the vtkusers mailing list