Two Problems with Picking

27 views
Skip to first unread message

Andrew Davison

unread,
Feb 7, 2023, 8:04:13 AM2/7/23
to Jzy3d
I have two problems with the program I've included at the end, with the first one being very strange.

I'm using Jzy3D 2.2, running tests on Windows 10 and Windows 7 machines, with various versions of Java, all of them later than v.11.

1. The first problem is that when I pick a point in the scatter chart, a different point is highlighted at a different location, and that point's coordinate is passed to objectPicked(). The strange part of this is that the exact same code was working correctly earlier in the day (i.e. the actual picked point was turning red). This problem only appeared when I tried to add a legend overlay using the code:

    // add message window
    ((AWTChart)chart).addRenderer(new OverlayLegendRenderer() {
      public void paint(Graphics g, int w, int h)
      {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(java.awt.Color.LIGHT_GRAY);
        g2d.fillRect(20, 20, 220, 30);
        g2d.setColor(java.awt.Color.BLACK);
        g2d.setFont( new java.awt.Font("Helvetica",
                                java.awt.Font.BOLD, 18));
        g2d.drawString(msg, 30, 40);
      }
    });

When the problem first appeared, I deleted this code, and the problem continued! I tried restarting my test machine, but that didnt fix matters.

2. The other problem crops up when I've been picking points inside the window for some time. When I click the close box, it is more unresponsive the longer that I've been running the program. If I wait long enough, when I click the close box the following exception is raised:

Exception in thread "AWT-EventQueue-0" com.jogamp.opengl.GLException: Caught GLException: Context still current after 512 releases: WindowsWGLContext [Version 4.6 (Compat profile, arb, compat[ES2, ES3, ES31, ES32], FBO, hardware) - 4.6.0 NVIDIA 474.11 [GL 4.6.0, vendor 474.11.0 (NVIDIA 474.11)], options 0x7c03, this 0xc93354c, handle 0x20000, isShared false, jogamp.opengl. gl4.GL4bcImpl@2c9cd48b,....

--------------------------------------------------

public class PickScatter extends JPanel
{
  private static final int P_WIDTH = 700;
  private static final int P_HEIGHT = 600;

  private static final int NUM_POINTS = 500;

  private org.jzy3d.colors.Color[] scatterColors;
  private int pickIdx = -1;
  private int currIdx = -1;
  private org.jzy3d.colors.Color origColor;


  public PickScatter()
  {
    setLayout( new BorderLayout());
    setPreferredSize(new java.awt.Dimension(P_WIDTH, P_HEIGHT));

    // create scatter plot data
    Coord3d[] coords = new Coord3d[NUM_POINTS];

    org.jzy3d.colors.Color[] colors =
               new org.jzy3d.colors.Color[NUM_POINTS];

    PickablePoint[] ppts = new PickablePoint[NUM_POINTS];

    Random r = new Random();
    // r.setSeed(0);
    float x, y, z;
    for(int i = 0; i < NUM_POINTS; i++) {
      x = r.nextFloat() - 0.5f;
      y = r.nextFloat() - 0.5f;
      z = r.nextFloat() - 0.5f;
      coords[i] = new Coord3d(x, y, z);
      colors[i] = new org.jzy3d.colors.Color(x, y, z, 0.25f);
      ppts[i] =  new PickablePoint(coords[i]);
      ppts[i].setPickingId(i);
    }

    Scatter scatter = new Scatter(coords, colors, 10f);
    scatterColors = scatter.getColors();

    // Create the chart
    Quality quality = Quality.Advanced();
    quality.setAnimated(true);   // so changes are drawn

    IChartFactory factory = new SwingChartFactory();
    Chart chart = factory.newChart(quality);

    chart.getScene().getGraph().add(scatter);

    AxisLayout axl = chart.getAxisLayout();
    axl.setFont( org.jzy3d.painters.Font.Helvetica_18);
    axl.setMainColor(org.jzy3d.colors.Color.GRAY);

    FixedDecimalTickRenderer ren2dp = new
                        FixedDecimalTickRenderer(2);
    axl.setXTickRenderer(ren2dp);
    axl.setYTickRenderer(ren2dp);
    axl.setZTickRenderer(ren2dp);

    // allow user interaction
    chart.addMouse();
    chart.addKeyboard();

    // set up mouse picking
    AWTMousePickingController mp =
               new AWTMousePickingController(chart);
    PickingSupport pickSupport = mp.getPickingSupport();

    // register all the coordinates for picking
    for(int i = 0; i < NUM_POINTS; i++)
      pickSupport.registerDrawableObject(ppts[i], ppts[i]);

    pickSupport.addObjectPickedListener(
      new IObjectPickedListener() {
        public void objectPicked(
             java.util.List<? extends Object> verts,  PickingSupport ps)
        {
          for (Object v: verts) {
            PickablePoint pp = (PickablePoint)v;      
            pickIdx = pp.getPickingId();

            if (pickIdx != currIdx) {  // selected a new point?
              if (currIdx != -1)
                scatterColors[currIdx] = origColor;  // undo previous pick color change

              currIdx = pickIdx;    // update current index and color
              origColor = scatterColors[currIdx];

              System.out.println("Picked: " + pp.getCoord());   // change picked color
              scatterColors[currIdx] = org.jzy3d.colors.Color.RED;
            }
          }
        }
    });

    add((JPanel)chart.getCanvas(), BorderLayout.CENTER);
  } // end of PickScatter()


  // -------------------------------------------

  public static void main(String[] args)
  {
    PickScatter pane = new PickScatter();

    JFrame f = new JFrame("PickScatter");
    f.getContentPane().add(pane, BorderLayout.CENTER);

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setResizable(false);
    f.setVisible(true);
  } // end of main()

}  // end of PickScatter class

Andrew Davison

unread,
Feb 8, 2023, 9:09:22 PM2/8/23
to Jzy3d
An update on the problems.

Problem 1 disappeared as mysteriously as it appeared while I was rearranging blocks of code in the program. Note, that I wasn't adding any functionality while I was doing this editing. However, problem 2 is still occurring.

I should also mention that I am calling the program from the command line, by explicitly calling a subset of the jzy3d libraries:

commons-collections4-4.4.jar
jogamp-fat.jar
jzy3d-core-2.2.0.jar
jzy3d-core-awt-2.2.0.jar
jzy3d-native-jogl-awt-2.2.0.jar
jzy3d-native-jogl-core-2.2.0.jar
jzy3d-native-jogl-swing-2.2.0.jar
log4j-1.2-api-2.19.0.jar
log4j-api-2.19.0.jar
log4j-core-2.19.0.jar

Also, more details on my setup:

Jogl Version: -----------------------------------------------------------------------------------------------------
Package: com.jogamp
Extension Name: com.jogamp
Specification Title: JogAmp Java Bindings Specification
Specification Vendor: JogAmp Community
Specification Version: 2.4
Implementation Title: JogAmp Java Bindings Fat Jar
Implementation Vendor: JogAmp Community
Implementation Vendor ID: com.jogamp
Implementation URL: http://jogamp.org/
Implementation Version: 2.4.0
Implementation Build: 2.4-b952-20230201
Implementation Branch: origin/master
Implementation Commit: 9dce06050a8a607b8c4ab83bd3aba8460d9ca593
Implementation SHA Sources: null
Implementation SHA Classes: null
Implementation SHA Classes-this: null
Implementation SHA Natives: null
Implementation SHA Natives-this: null
-----------------------------------------------------------------------------------------------------

Platform Info: -----------------------------------------------------------------------------------------------------
Platform: WINDOWS / Windows 7 6.1 (6.1.0), amd64 (X86_64, GENERIC_ABI), 8 cores, littleEndian true
MachineDataInfo: runtimeValidated true, 32Bit false, primitive size / alignment:
  int8    1 / 1, int16   2 / 2
  int     4 / 4, long    4 / 4
  int32   4 / 4, int64   8 / 8
  float   4 / 4, double  8 / 8, ldouble 16 / 16
  pointer 8 / 8, page    4096
Platform: Java Version: 17.0.4 (17.0.4u0), VM: OpenJDK 64-Bit Server VM, Runtime: OpenJDK Runtime Environment
Platform: Java Vendor: Microsoft, https://www.microsoft.com, Java17, dynamicLib: true, AWT enabled: true
----------------------------------------------------------------------------------------------------

GLProfile Default Device: WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[obj 0x21f662cb]]
GLProfile Default: GLProfile[GL4bc/GL4bc.hw

Andrew Davison

unread,
Feb 12, 2023, 3:45:11 AM2/12/23
to Jzy3d
I may have stumbled onto a clue about Problem 1. It has something to do with my use of multiple monitors with different screen resolutions. On one screen, the mouse does pick the right point, while on the other it doesn't, and this occurs inside the same executing code when I drag the window from one screen to the other one.
Reply all
Reply to author
Forward
0 new messages