how to get the image postion


as the graph.I show a picture in a renderer, and I know the renderer size and the picture size.when I press left button down, I can get a point position in the renderer. I want to judge if the point locate on picture. how can I get the picture position on renderer?

You need to use vtkCoordinate

That’s how I got it working on my 3D viewer

viewerposition = interactor.GetEventPosition()
vc = vtk.vtkCoordinate()
vc.SetCoordinateSystemToViewport()
vc.SetValue(viewerposition[0:2] + (0.0,))

# pick position in World Coordinates
pickPosition = list(vc.GetComputedWorldValue(renderer))

Then I work out the location on the image by the origin and spacing. Notice that I set to 0 the third coordinate that I’m passing to vc as the viewerposition is in viewer coordinates (so 2D).

Hope this helps

Edo

1 Like

hi, Edo

thank you very much. I have solved my question according to your code.