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