[vtkusers] Issues with picking in VTK Java on Mac OS X

Kevin Milner kmilner at usc.edu
Wed Feb 1 19:19:03 EST 2017

Hello. I develop a VTK Java application for visualizing georeferenced 
earthquake data, SCEC-VDO (http://scecvdo.usc.edu/). One of the 
important features of this software is the ability to click on elements 
of the 3D view to perform actions or view information. This works 
perfectly on Windows and Linux, but does not work on Macs. I believe 
that this is due to an internal bug in the Mac version of VTK. We use 
the vtkJoglPanelComponent to embed the 3D view into our Java application.

Here is the code that I use to pick items (where renderWindow is a 

         renderWindow.getComponent().addMouseListener(new MouseAdapter() {
             public void mousePressed(MouseEvent e) {
                 int[] clickPos = 

                 int x = clickPos[0];
                 int y = clickPos[1];

                 cellPicker.Pick(x, y, 0, renderWindow.getRenderer());
                 if (cellPicker.GetActor() != null) {
                     // do stuff

The first bug is that the y value of 
getRenderWindowInteractor().GetEventPosition() is just flat out wrong on 
the Mac (correct on Windows and Linux). For example, if I click near the 
top of my window with height 700, if will give me a y value that is 
greater than 1300! It should actually be very small, as y should be zero 
at the top of the window and 700 at the bottom of the window. I can get 
around this, and make it match the position on Linux/Windows with the 
following fix using the mouseEvent (e) and the height of the 3D view 

                 int height = renderWindow.getComponent().getHeight();
                 int calcY = (height - e.getY()) - 1;
                 int x = e.getX();
                 int y = calcY;

Now when I click on a location in the 3D viewer, the x/y coordinates 
match the results on Linux/Windows. But picking actors still doesn't 
work. Instead, VTK thinks that I have clicked somewhere roughly between 
where I actually clicked and the bottom left corner. So if I click on 
the top right corner of the viewer, it thinks that I clicked in the 
middle. If I click on the top left, if thinks that I clicked middle 
left. If I click on the middle of the viewer, it thinks that I clicked 
1/4 up and right of the lower left corner. I have posted a video which 
demonstrates this bug:


In this video, whatever actor is clicked turns red. This works as 
expected on Windows/Linux, both with and without the x/y fix mentioned 
above. Without the previous fix on a Mac, the behavior is similar but 
centered around the top left corner and sometimes doesn't detect clicks 
at all (due to y values which make no sense).

Any ideas what could be going on? I have experienced this behavior on 
all 4 Mac's on which I have tried the software.

Kevin Milner

More information about the vtkusers mailing list