Here is a modification of the MultiColorScatterDemo demo. I think the reason you might not have noticed before is because all the scatter plot demos in the api use very small dots. But when using larger dots, it becomes apparent how the lower quality setting affects their appearance. Specifically, it has to do with polygon shading and how the point is rounded out. The setting that allows for proper distance rendering unfortunately also results in jagged edges around the point. It's harder to describe than it is to see, so here is a way to reproduce it.
In order to "correct" the problem, I've modified a few classes (and I'm using the 0.9 source, which I finally figured out how to compile in Netbeans): Chart, CanvasSwing, and CanvasAWT. They've all been modified in a similar manner - adding a constructor to allow for a GLCapabilities object to be passed (this is where one can optionally turn on sampleBuffers before the underlying GLJPanel canvas is instantiated. The changes still leave the original constructors in place, in case they are called from other parts of the API that I don't want to break.
CanvasSwing:public CanvasSwing(Scene scene, Quality quality) {
this(scene, quality, org.jzy3d.global.Settings.getInstance().getGLCapabilities());
}
public CanvasSwing(Scene scene, Quality quality, GLCapabilitiesImmutable glci) {
super(glci);
view = scene.newView(this, quality);
renderer = new Renderer3d(view);
addGLEventListener(renderer);
setFocusable(true);
requestFocusInWindow();
}
CanvasAWT:public CanvasAWT(Scene scene, Quality quality, GLCapabilitiesImmutable glci){
this(scene, quality, false, false, glci);
}
/** Initialize a Canvas3d attached to a {@link Scene}, with a given rendering {@link Quality}.*/
public CanvasAWT(Scene scene, Quality quality, boolean traceGL, boolean debugGL){
this(scene, quality, traceGL, debugGL, org.jzy3d.global.Settings.getInstance().getGLCapabilities());
}
public CanvasAWT(Scene scene, Quality quality, boolean traceGL, boolean debugGL, GLCapabilitiesImmutable glci){
super(glci);
view = scene.newView(this, quality);
renderer = new Renderer3d(view, traceGL, debugGL);
addGLEventListener(renderer);
animator = new Animator(this);
animator.start();
setAutoSwapBufferMode(true);
}
Chart:
private GLCapabilities capabilities; // Add this variable
public Chart(Quality quality, String chartType) {
this(quality, chartType, org.jzy3d.global.Settings.getInstance().getGLCapabilities());
}
// New constructor to allow for a modified GLCapabilities instance.
public Chart(Quality quality, String chartType, GLCapabilities capabilities) {
this.capabilities = capabilities;
controllers = new ArrayList<ChartCameraController>(1);
// Set up the scene and 3d canvas
scene = initializeScene(quality.isAlphaActivated());
canvas = initializeCanvas(scene, quality, chartType);
// Set up the view
view = (ChartView) canvas.getView();
view.setBackgroundColor(Color.WHITE);
}
protected ICanvas initializeCanvas(Scene scene, Quality quality, String chartType) {
if ("awt".compareTo(chartType) == 0) {
return new CanvasAWT(scene, quality, capabilities);
} else if ("swing".compareTo(chartType) == 0) {
return new CanvasSwing(scene, quality, capabilities);
} else if ("offscreen".compareTo(chartType) == 0) {
return new OffscreenCanvas(scene, quality, GLProfile.getDefault());
} else {
throw new RuntimeException("unknown chart type:" + chartType);
}
}
Now here is a modified version of the
MultiColorScatterDemo that illustrates the difference.
public MultiColorScatterDemo2(){
// Create the dot cloud scene and fill with data
int size = 20000;
float x;
float y;
float z;
Coord3d[] points = new Coord3d[size];
for(int i=0; i<size; i++){
x = (float)Math.random() - 0.5f;
y = (float)Math.random() - 0.5f;
z = (float)Math.random() - 0.5f;
points[i] = new Coord3d(x, y, z);
}
Quality quality = new Quality(true, true, true, true, true, true, false);
GLCapabilities capabilities = org.jzy3d.global.Settings.getInstance().getGLCapabilities();
capabilities.setSampleBuffers(false); // false = ragged edges around large points. true = smooth rounding.
capabilities.setNumSamples(2);
MultiColorScatter scatter = new MultiColorScatter( points, new ColorMapper( new ColorMapRainbow(), -0.5f, 0.5f ) );
scatter.setWidth(6);
chart = new Chart(quality, "awt", capabilities);
chart.getAxeLayout().setMainColor(Color.WHITE);
chart.getView().setBackgroundColor(Color.BLACK);
chart.getScene().add(scatter);
scatter.setLegend( new ColorbarLegend(scatter, chart.getView().getAxe().getLayout(), Color.WHITE, null) );
scatter.setLegendDisplayed(true);
}