Proposing 3d lib for extending Jfree capabilities
-
- Posts: 11
- Joined: Sun Dec 27, 2009 4:18 pm
- antibot: No, of course not.
Proposing 3d lib for extending Jfree capabilities
Hi all,
I love simplicity and design of JFreeChart, but was disappointed few years ago by the lack of an equivalent 3d plotting library.
I've developped such a tool for my company that let me publish it as open source recently.
If either users or developpers of jfreechart are interested in re-using this code, feel free to visit:
http://code.google.com/p/jzy3d/
With jzy3d, you are able to rapidly plot a 3d mathematical model (surface, scatter plot, etc), and control viewpoint, scaling or even coloring with mouse. It supports layering with java2d renderers, and provides facilities to integrate in AWT, SWT, and Swing.
Enjoy it,
Martin
I love simplicity and design of JFreeChart, but was disappointed few years ago by the lack of an equivalent 3d plotting library.
I've developped such a tool for my company that let me publish it as open source recently.
If either users or developpers of jfreechart are interested in re-using this code, feel free to visit:
http://code.google.com/p/jzy3d/
With jzy3d, you are able to rapidly plot a 3d mathematical model (surface, scatter plot, etc), and control viewpoint, scaling or even coloring with mouse. It supports layering with java2d renderers, and provides facilities to integrate in AWT, SWT, and Swing.
Enjoy it,
Martin
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Proposing 3d lib for extending Jfree capabilities
Hi Martin,
Looks fantastic! I'll dig into your code as soon as I can, most likely next week, and get in touch!
Looks fantastic! I'll dig into your code as soon as I can, most likely next week, and get in touch!
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: Proposing 3d lib for extending Jfree capabilities
This looks amazing! It would be truly great if this library could be integrated into JFreeChart.
My thanks to Martin Pernollet and his employer
My thanks to Martin Pernollet and his employer

Creator of Glotaran, a software program developed for global and target analysis of time-resolved spectroscopy and microscopy data. Big fan of JFreeChart.
-
- Posts: 11
- Joined: Sun Dec 27, 2009 4:18 pm
- antibot: No, of course not.
Re: Proposing 3d lib for extending Jfree capabilities
Hi all,
Thanks for your feedbacks!
I opened this Google Group for sharing interesting discussions:
http://groups.google.com/group/jzy3d
Regards,
Martin
Thanks for your feedbacks!
I opened this Google Group for sharing interesting discussions:
http://groups.google.com/group/jzy3d
Regards,
Martin
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Proposing 3d lib for extending Jfree capabilities
I have downloaded the sources and played with it. it is really an impressive library.
I have always been a little afraid of using real 3D libraries, but jzy3d has changed that.
However, I wonder how easily that would fit into JFreeChart. JFreeChart offers the rendering on any Graphics2D implementation, w/o the need to create something that derives from java.awt.Component, and I haven´t seen such an option in jzy3d (at least this option was not very obvious). While I could create a PDF by painting a CanvasAWT on a suitable Graphics2D, using a CanvasSwing failed (the app froze).
If more people are willing to develop a 3D extension for JFreeChart, maybe we can create a seperate sticky thread for this topic, and share our experiences? Or is the google group considered the place to discuss?
Regards, Peter

I have always been a little afraid of using real 3D libraries, but jzy3d has changed that.
However, I wonder how easily that would fit into JFreeChart. JFreeChart offers the rendering on any Graphics2D implementation, w/o the need to create something that derives from java.awt.Component, and I haven´t seen such an option in jzy3d (at least this option was not very obvious). While I could create a PDF by painting a CanvasAWT on a suitable Graphics2D, using a CanvasSwing failed (the app froze).
If more people are willing to develop a 3D extension for JFreeChart, maybe we can create a seperate sticky thread for this topic, and share our experiences? Or is the google group considered the place to discuss?
Regards, Peter
-
- Posts: 11
- Joined: Sun Dec 27, 2009 4:18 pm
- antibot: No, of course not.
Re: Proposing 3d lib for extending Jfree capabilities
Nice, that's part of the goalparadoxoff wrote:I have downloaded the sources and played with it. it is really an impressive library.![]()
I have always been a little afraid of using real 3D libraries, but jzy3d has changed that.

Do you mean being able to call java.awt.Component.getGraphics()? The CanvasAWT and CanvasSwing are respectively extentions of:paradoxoff wrote:However, I wonder how easily that would fit into JFreeChart. JFreeChart offers the rendering on any Graphics2D implementation, w/o the need to create something that derives from java.awt.Component, and I haven´t seen such an option in jzy3d (at least this option was not very obvious). While I could create a PDF by painting a CanvasAWT on a suitable Graphics2D, using a CanvasSwing failed (the app froze).
http://circee.univ-fcomte.fr/Docs/Java/ ... anvas.html
http://circee.univ-fcomte.fr/Docs/Java/ ... Panel.html
which are themselves extentions of java.awt.Canvas and javax.swing.JPanel.
Could you send the eclipse project or demo code exhbiting the bug on CanvasSwing?
For info, CanvasSwing has another known bug: post renderers are blinking. Post renderers are not used in the sample graphics (see homepage), but are very important for displaying metadata. I'll add soon documentation on the wiki regarding their use.
The google group can be a good place for discussing pure jzy questions. Some of them started by mail, and some nice features may come up, such as random point tesselation (delaunay triangulation, see early screenshot http://jzy3d.googlecode.com/issues/atta ... G&inline=1) and selection of points in a scatter plotparadoxoff wrote:If more people are willing to develop a 3D extension for JFreeChart, maybe we can create a seperate sticky thread for this topic, and share our experiences? Or is the google group considered the place to discuss?

Discussing faisability of reusing jzy in jfree could be done on jfree's forum. I am eager to be aware of all features required to be jfree-compliant. I for example thought that having an applet-ready Jzy Canvas requires a bit of work, since one need to embed and select appropriate JOGL binaries according to target OS (on this point, guys of JOGL may have think about such a feature; moreover, JOGL has pretty advanced since Jzy started, so I'm using v1.1 while their trunk is at v2)
There might be plenty of other requirements Jzy's not able to fullfill, but that would be nice to identify all them!
Martin
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Proposing 3d lib for extending Jfree capabilities
Hi Martin,
here is the snippet that I tried to export a 3d plot to pdf:
Some observations:
When I run this snippet for the first time using a CanvasSwing and a FrameSwing, the chart is renderer on screen, and I even get a pdf output. However, when I run it for a second time, the application hangs. The pdf file is created, but has a size of 0 kB. The rendering on screen is also not working.
When I then use a CanvasAWT and a FrameAWT, rendering on screen is working again. I also get a pdf that can be opened in a reader, but its size is just 1 kB and it doesn´t contain any graphical information.
The successfully created pdf is clearly not a vector graphic but simply contains the chart as a bitmap. This is not surprising, since I hadn´t expected the FrameAWT or FrameSwing to render its content directly on the Graphics2D but rather construct it from a buffer (what it apparently does).
One of JFreeChart greatest benefits is that its classes do not derive from Component or JComponent, and that the charts can be renderer on any Graphics2D implementation. There are freely available Graphics2D implementation that create PNG, SVG, PDF, EPS, and EMF graphics, and exporting a JFreeChart in these formats is thus easily possible (which is crucial in hedless server environments). The outputs for the latter four are real vector graphics that can be zoomed w/o quality loss.
I have tried to understand how a CanvasSwing and a CanvasAWT do perform the rendering, and I even had a look at the source code of GLJPanel in the hope of finding a way to plug in custom Graphics2D implementations and to enforce a direct rendering onto the Graphics2D via the usual graphical primitives, but that was not successful. I saw that GLJPanel containes a couple of inner classes that functions as some kind of backend, but I haven´t really understood how this works.
IMHO, offering a way to directly render on an arbitrary, user supplied Graphics2D implementation would be a very major achievement.
In the meantime, I have got the book that David has used for his work on JFreeChart 3D (Ammeraal, Zhang, Computer Graphics for Java Programmers). Though the approach used in this book (implement the algorithms for coordinate transformation, perspective, hidden line elimination etc. and then create a Java2D output) will probably be slower than an engine based on jogl or Java3D, it will maintain the possibility to keep away from Component and JComponent and render on any Graphics2D.
And though a real 3D engine will offer more features than something "self made", the question is whether all these features are needed!
Personally, I only need a limited collection of 3D charts:
- a 3D bar chart with two category axes along the x and y direction and a value axis along the z axis. This would probably mean to render a few hundreds of bars (or cylinders or pyramides or...
), and I think that this will be possible using a "self made", Java2D based engine.
- a 3D scatter chart with three value axis along the x, y and z coordinates. Conceptually, I hope that this case will be conceptually simpler than the first case since we only have to translate the 3D coordinates of the scatter points to Java2D coordinates and draw circles at the respective positions, probably with varying diameters calculated based on the distance of the scatter point to the eye. In this case we will probably not need to worry about triangulation and hidden lines/faces.
- a 3D surface chart. This is probably the most complex case as we will frist have to do some tesselation and worry about how to transform the triangles from 3D to 2D. However, the package for Delauney tesselation that was mentioned in the recent "issue" entry will probably be useful as well. And the second step (to convert the resulting triangles to Java2D coordinates) should also be manageable by a "self-made" 3D engine.
In any case, I am very much looking forward the future discussions, because a JFreeChart with a 3D engine could probably blow away some commercial packages!
here is the snippet that I tried to export a 3d plot to pdf:
Code: Select all
package net.masagroup.jzy3d.demos;
import com.lowagie.text.DocumentException;
import com.lowagie.text.FontFactory;
import com.lowagie.text.pdf.DefaultFontMapper;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JFrame;
import net.masagroup.jzy3d.bridge.ChartLauncher;
import net.masagroup.jzy3d.chart.Chart;
import net.masagroup.jzy3d.chart.ChartScene;
import net.masagroup.jzy3d.bridge.awt.FrameAWT;
import net.masagroup.jzy3d.bridge.swing.FrameSwing;
import net.masagroup.jzy3d.chart.controllers.ChartMouseController;
import net.masagroup.jzy3d.chart.controllers.ChartThreadController;
import net.masagroup.jzy3d.chart.controllers.ControllerEvent;
import net.masagroup.jzy3d.chart.controllers.ControllerEventListener;
import net.masagroup.jzy3d.chart.controllers.ControllerType;
import net.masagroup.jzy3d.colors.Color;
import net.masagroup.jzy3d.colors.ColorMapper;
import net.masagroup.jzy3d.colors.colormaps.ColorMapRainbow;
import net.masagroup.jzy3d.colors.colormaps.ColorMap;
import net.masagroup.jzy3d.colors.colormaps.ColorMapWhiteRed;
import net.masagroup.jzy3d.demos.charts.surface.SurfaceDemo;
import net.masagroup.jzy3d.demos.charts.histogram.HistogramDemo;
import net.masagroup.jzy3d.demos.charts.scatter.ScatterDemo;
import net.masagroup.jzy3d.maths.Coord3d;
import net.masagroup.jzy3d.maths.Range;
import net.masagroup.jzy3d.maths.Scale;
import net.masagroup.jzy3d.plot3d.builder.Builder;
import net.masagroup.jzy3d.plot3d.builder.Mapper;
import net.masagroup.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import net.masagroup.jzy3d.plot3d.primitives.Disk;
import net.masagroup.jzy3d.plot3d.rendering.Scene;
import net.masagroup.jzy3d.plot3d.rendering.canvas.Canvas;
import net.masagroup.jzy3d.plot3d.rendering.canvas.CanvasAWT;
import net.masagroup.jzy3d.plot3d.rendering.canvas.CanvasSwing;
import net.masagroup.jzy3d.plot3d.rendering.canvas.Quality;
import net.masagroup.jzy3d.plot3d.primitives.Shape;
import net.masagroup.jzy3d.plot3d.primitives.faces.ColorbarFace;
public class SurfacePanel {
static Shape surface;
public static void main(String[] args){
JFrame frame = new JFrame("Surface demo");
//ChartLauncher.openChart(getChart(), new Rectangle(0,200,800,800), "Surface");
// Setup chart controllers and listeners
Chart chart = getSurfaceChart();
ChartMouseController mouse = new ChartMouseController();
ChartThreadController thread = new ChartThreadController();
mouse.addSlaveThreadController(thread);
mouse.addControllerEventListener(new ControllerEventListener(){
public void controllerEventFired(ControllerEvent e) {
if(e.getType()==ControllerType.ROTATE){
//System.out.println("Mouse[ROTATE]:" + (Coord3d)e.getValue());
}
}
});
chart.addController(mouse);
chart.addController(thread);
chart.render();
FrameAWT graphFrame = new FrameAWT(chart, new Rectangle(0,200,800,800), "Surface");
int width = 800;
int height = 800;
com.lowagie.text.Rectangle rect = new com.lowagie.text.Rectangle((float)width,(float)height);
com.lowagie.text.Document document = new com.lowagie.text.Document(rect);
PdfWriter writer = null;
try{
writer = PdfWriter.getInstance(document, new FileOutputStream("Surface_2.pdf"));
}
catch(Exception e){
e.printStackTrace();
}
document.open();
DefaultFontMapper mapper = new DefaultFontMapper();
FontFactory.registerDirectories();
mapper.insertDirectory("C:\\WINNT\\Fonts");
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(width, height);
Graphics2D g2d = tp.createGraphics(width, height, mapper);
tp.setWidth(width);
tp.setHeight(height);
graphFrame.paint(g2d);
g2d.dispose();
cb.addTemplate(tp, 0, 0);
document.close();
}
/*************************************************************************/
public static Chart getSurfaceChart(){
// Define a function to plot
Mapper mapper = new Mapper(){
public double f(double x, double y) {
return 10*Math.sin(x/10)*Math.cos(y/20)*x;
}
};
// Define range and precision for the function to plot
Range range = new Range(-150,150);
int steps = 50;
// Create the object to represent the function over the given range.
surface = (Shape)Builder.buildOrthonormal(new OrthonormalGrid(range, steps, range, steps), mapper);
surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1,1,1,.5f)));
surface.setFaceDisplayed(true);
surface.setWireframeDisplayed(true);
surface.setWireframeColor(Color.BLACK);
surface.setFace(new ColorbarFace(surface));
surface.setFace2dDisplayed(true); // opens a colorbar on the right part of the display
// Create a chart that updates the surface colormapper when scaling changes
Chart chart = new Chart(){
public void setScale(Scale scale){
super.setScale(scale);
ColorMapper cm = surface.getColorMapper();
cm.setScale(scale);
surface.setColorMapper(cm);
//surface.setFaceDisplayed(true);
}
/*public Canvas initializeCanvas(Scene scene, Quality quality){
return new CanvasSwing(scene, quality);
}*/
};
chart.getScene().getGraph().add(surface);
return chart;
}
}
When I run this snippet for the first time using a CanvasSwing and a FrameSwing, the chart is renderer on screen, and I even get a pdf output. However, when I run it for a second time, the application hangs. The pdf file is created, but has a size of 0 kB. The rendering on screen is also not working.
When I then use a CanvasAWT and a FrameAWT, rendering on screen is working again. I also get a pdf that can be opened in a reader, but its size is just 1 kB and it doesn´t contain any graphical information.
The successfully created pdf is clearly not a vector graphic but simply contains the chart as a bitmap. This is not surprising, since I hadn´t expected the FrameAWT or FrameSwing to render its content directly on the Graphics2D but rather construct it from a buffer (what it apparently does).
One of JFreeChart greatest benefits is that its classes do not derive from Component or JComponent, and that the charts can be renderer on any Graphics2D implementation. There are freely available Graphics2D implementation that create PNG, SVG, PDF, EPS, and EMF graphics, and exporting a JFreeChart in these formats is thus easily possible (which is crucial in hedless server environments). The outputs for the latter four are real vector graphics that can be zoomed w/o quality loss.
I have tried to understand how a CanvasSwing and a CanvasAWT do perform the rendering, and I even had a look at the source code of GLJPanel in the hope of finding a way to plug in custom Graphics2D implementations and to enforce a direct rendering onto the Graphics2D via the usual graphical primitives, but that was not successful. I saw that GLJPanel containes a couple of inner classes that functions as some kind of backend, but I haven´t really understood how this works.
IMHO, offering a way to directly render on an arbitrary, user supplied Graphics2D implementation would be a very major achievement.
In the meantime, I have got the book that David has used for his work on JFreeChart 3D (Ammeraal, Zhang, Computer Graphics for Java Programmers). Though the approach used in this book (implement the algorithms for coordinate transformation, perspective, hidden line elimination etc. and then create a Java2D output) will probably be slower than an engine based on jogl or Java3D, it will maintain the possibility to keep away from Component and JComponent and render on any Graphics2D.
And though a real 3D engine will offer more features than something "self made", the question is whether all these features are needed!
Personally, I only need a limited collection of 3D charts:
- a 3D bar chart with two category axes along the x and y direction and a value axis along the z axis. This would probably mean to render a few hundreds of bars (or cylinders or pyramides or...

- a 3D scatter chart with three value axis along the x, y and z coordinates. Conceptually, I hope that this case will be conceptually simpler than the first case since we only have to translate the 3D coordinates of the scatter points to Java2D coordinates and draw circles at the respective positions, probably with varying diameters calculated based on the distance of the scatter point to the eye. In this case we will probably not need to worry about triangulation and hidden lines/faces.
- a 3D surface chart. This is probably the most complex case as we will frist have to do some tesselation and worry about how to transform the triangles from 3D to 2D. However, the package for Delauney tesselation that was mentioned in the recent "issue" entry will probably be useful as well. And the second step (to convert the resulting triangles to Java2D coordinates) should also be manageable by a "self-made" 3D engine.
In any case, I am very much looking forward the future discussions, because a JFreeChart with a 3D engine could probably blow away some commercial packages!

-
- Posts: 11
- Joined: Sun Dec 27, 2009 4:18 pm
- antibot: No, of course not.
Re: Proposing 3d lib for extending Jfree capabilities
Hi,
I have proposed to guys of JOGL to read your post because they might have much more relevant responses than me.
My very approximative feeling is that since a raw use of JOGL will natively use OpenGL, it might be difficult to directly print results of these GL primitive in a Graphic2D. I currently don't even know if it is possible to render a 3d scene in a picture without opening a canvas.
However, a trick would be to use the gluProject method (http://www.opengl.org/sdk/docs/man/xhtml/gluProject.xml), which basically allows using the projection matrix and viewport configuration to convert 3d coordinates into 2d screen coordinates, with an additional z information indicating the deapness of the point as a ratio between the near and far clipping plane of the camera.
Such a trick would allow to have a kind of vectorized 2d projection but I am still wondering on several questions:
1) Simple primitives such as points and polygons would be easy to flatten, but I am still wondering how to flatten a Jzy3d Sphere or Disks since they rely on OpenGL primitives.
2) One should "translate" some work done by OpenGL into direct Java2d. For example color and alpha interpolation in a n-point polygon should be handled by java/jfreechart gradients. I don't know if it is possible to define gradients with more than two values to interpolate from?
3) Maybe it is not very important, but we may not garantee there would be a perfect alignement of the raw 3d rendering with the 2d flattened rendering, since for example:
a) the antialiasing algorithm may not be same in OpenGl and in Java2d.
b) the way text are rendered in Jzy3d relies on the OpenGl glutBitmapString method which uses a predefined set of ASCII characters with only few character sizes and fonts provided by GLUT (http://code.google.com/p/jzy3d/source/b ... itmap.java). Maybe a graphic2d.drawText would not render a text exactly the same but is that really important? Maybe not that much. I also implemented an alternative strategy where the bitmap data representing a character are user defined and could be reused for 2d conversion (http://code.google.com/p/jzy3d/source/b ... board.java)
The main issue is point 1, but according to your wish list for JFree (histogram, scatter, and surface), we have no real limitation since all of these chart types can be rendered using points or polygons primitive (jzy's histogram demo uses bars made out of polygons only).
The last difficult point would be to render without displaying on a screen. I'll try to gather informations on that.
Regards,
Martin
I have proposed to guys of JOGL to read your post because they might have much more relevant responses than me.
My very approximative feeling is that since a raw use of JOGL will natively use OpenGL, it might be difficult to directly print results of these GL primitive in a Graphic2D. I currently don't even know if it is possible to render a 3d scene in a picture without opening a canvas.
However, a trick would be to use the gluProject method (http://www.opengl.org/sdk/docs/man/xhtml/gluProject.xml), which basically allows using the projection matrix and viewport configuration to convert 3d coordinates into 2d screen coordinates, with an additional z information indicating the deapness of the point as a ratio between the near and far clipping plane of the camera.
Such a trick would allow to have a kind of vectorized 2d projection but I am still wondering on several questions:
1) Simple primitives such as points and polygons would be easy to flatten, but I am still wondering how to flatten a Jzy3d Sphere or Disks since they rely on OpenGL primitives.
2) One should "translate" some work done by OpenGL into direct Java2d. For example color and alpha interpolation in a n-point polygon should be handled by java/jfreechart gradients. I don't know if it is possible to define gradients with more than two values to interpolate from?
3) Maybe it is not very important, but we may not garantee there would be a perfect alignement of the raw 3d rendering with the 2d flattened rendering, since for example:
a) the antialiasing algorithm may not be same in OpenGl and in Java2d.
b) the way text are rendered in Jzy3d relies on the OpenGl glutBitmapString method which uses a predefined set of ASCII characters with only few character sizes and fonts provided by GLUT (http://code.google.com/p/jzy3d/source/b ... itmap.java). Maybe a graphic2d.drawText would not render a text exactly the same but is that really important? Maybe not that much. I also implemented an alternative strategy where the bitmap data representing a character are user defined and could be reused for 2d conversion (http://code.google.com/p/jzy3d/source/b ... board.java)
The main issue is point 1, but according to your wish list for JFree (histogram, scatter, and surface), we have no real limitation since all of these chart types can be rendered using points or polygons primitive (jzy's histogram demo uses bars made out of polygons only).
The last difficult point would be to render without displaying on a screen. I'll try to gather informations on that.
Regards,
Martin
-
- Posts: 11
- Joined: Sun Dec 27, 2009 4:18 pm
- antibot: No, of course not.
Re: Proposing 3d lib for extending Jfree capabilities
A short auto-reply 
It seems there is a GLPBuffer for rendering offscreen with JOGL: http://stackoverflow.com/questions/4659 ... -with-jogl
I'll try it when I'll have available time.
Regards,
Martin

It seems there is a GLPBuffer for rendering offscreen with JOGL: http://stackoverflow.com/questions/4659 ... -with-jogl
I'll try it when I'll have available time.
Regards,
Martin
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Proposing 3d lib for extending Jfree capabilities
Hi Martin,
thanks for your efforts!
Concerning the gluProject: Though I haven´t really checked what it covers: the mere translation from 3d to 2d coordinates is already presented in the book that I mentioned above. It already covers elimination of hidden lines and faces.
Your hint concerning the GLPBuffer sounds very promising! This could be the basis of a new Plot class derived from org.jfre.chart.plot.Plot that could use such a buffer as internal rendering engine, and once the draw-method is invoked, simply draw the buffered image onto the supplied Graphics2D. Though the image will be an image and not a vectorized collection of shapes and lines, it would be a huge step towards device-independent rendering.
). IMHO, the possibilities are by far sufficient, at least for a charting application.
I am looking forward to see how this thread develops. My next steps will probably be to take the codes from the book mentioned above, and transform the (solely AWT based) classes to something that can render on any Graphics2D.
David: If you are following this thread: is there any code that you could share?
thanks for your efforts!

Concerning the gluProject: Though I haven´t really checked what it covers: the mere translation from 3d to 2d coordinates is already presented in the book that I mentioned above. It already covers elimination of hidden lines and faces.
Your hint concerning the GLPBuffer sounds very promising! This could be the basis of a new Plot class derived from org.jfre.chart.plot.Plot that could use such a buffer as internal rendering engine, and once the draw-method is invoked, simply draw the buffered image onto the supplied Graphics2D. Though the image will be an image and not a vectorized collection of shapes and lines, it would be a huge step towards device-independent rendering.
I have extended my demo and produced a histogram consisting of "bars" (instances of net.masagroup.jzy3d.plot3d.primitives.Cylinder with a varying number of slices). Though they were of course not real "cylinders" with a round base, a slice number of 12 was sufficient to bring them close enough to cylinders. Cylinders with a slice count of 6 and 8 looked cool (msexcel is not capable of doing that, AFAIKmartin.pernollet wrote: 1) Simple primitives such as points and polygons would be easy to flatten, but I am still wondering how to flatten a Jzy3d Sphere or Disks since they rely on OpenGL primitives.
The main issue is point 1, but according to your wish list for JFree (histogram, scatter, and surface), we have no real limitation since all of these chart types can be rendered using points or polygons primitive (jzy's histogram demo uses bars made out of polygons only).

I am looking forward to see how this thread develops. My next steps will probably be to take the codes from the book mentioned above, and transform the (solely AWT based) classes to something that can render on any Graphics2D.
David: If you are following this thread: is there any code that you could share?
-
- Posts: 11
- Joined: Sun Dec 27, 2009 4:18 pm
- antibot: No, of course not.
Re: Proposing 3d lib for extending Jfree capabilities
Hi!
Among other features (http://groups.google.com/group/jzy3d/br ... 04c1a16567#), I added Chart.screenshot() that returns a BufferedImage for testing an OffscreenCanvas implementation for charts. I have still few problems with the OffscreenCanvas that will maybe require a bit of work.
Once the OffscreenCanvas will be working, it will be indeed possible to use a Chart object as an hidden 3d rendering buffer. There may then be a Graphics2dChartAdapter(Chart) providing a draw(Graphics2d) method which implementation would make Java2d calls necessary to render the scenegraph projected for 2d. One would just have provide the Graphic2d for storing "vectorized" 2d data. Is that the mecanism you woul exepct?
If yes, we may develop a set of DrawableAdapters providing draw(Graphics2d) for each 3d geometry.
Concerning your work on Cylinder, do not forget that you may hide wireframe of your cylinder to enhance its visual smoothness. Did you experienced correct rendering time with lot of bars? In case no, you may use new Chart(Quality.Fastest), which desactivate alpha and color fading.
Since few people are following trunk's infos on the Google Group, I suggest you subscribe to the group to share our discussions with others working on experimental jzy's features.
Regards,
Martin
Among other features (http://groups.google.com/group/jzy3d/br ... 04c1a16567#), I added Chart.screenshot() that returns a BufferedImage for testing an OffscreenCanvas implementation for charts. I have still few problems with the OffscreenCanvas that will maybe require a bit of work.
Once the OffscreenCanvas will be working, it will be indeed possible to use a Chart object as an hidden 3d rendering buffer. There may then be a Graphics2dChartAdapter(Chart) providing a draw(Graphics2d) method which implementation would make Java2d calls necessary to render the scenegraph projected for 2d. One would just have provide the Graphic2d for storing "vectorized" 2d data. Is that the mecanism you woul exepct?
If yes, we may develop a set of DrawableAdapters providing draw(Graphics2d) for each 3d geometry.
Concerning your work on Cylinder, do not forget that you may hide wireframe of your cylinder to enhance its visual smoothness. Did you experienced correct rendering time with lot of bars? In case no, you may use new Chart(Quality.Fastest), which desactivate alpha and color fading.
Since few people are following trunk's infos on the Google Group, I suggest you subscribe to the group to share our discussions with others working on experimental jzy's features.
Regards,
Martin
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Proposing 3d lib for extending Jfree capabilities
Ok, I can follow you here.martin.pernollet wrote: Once the OffscreenCanvas will be working, it will be indeed possible to use a Chart object as an hidden 3d rendering buffer.
Sorry, that was over my top.martin.pernollet wrote: There may then be a Graphics2dChartAdapter(Chart) providing a draw(Graphics2d) method which implementation would make Java2d calls necessary to render the scenegraph projected for 2d. One would just have provide the Graphic2d for storing "vectorized" 2d data. Is that the mecanism you woul exepct?
I just wonder how you can delegate the rendering of entire lines and polygons to a Graphics2D instance. I spent some time to look for someting like a "jogl to Graphics2D" bridge, but didn´t find anything useful.
This weekend, I made some progress concerning the Java2D based 3D engine implementation, based on the Ammeraal/Zhang. Now I have a minimalistic scene graph that is device independent. I created a little histogramm lookalike with real bars (10x10) and rotated that via the keyboard. Overall it felt much less snappier than Davids demo, and I could easily bring the cpu load to > 70 %. Rotating a jzy3d 10x10 histogram with the mouse at almost supersonic speed brought the system to 50 % at best. I now wonder how scalable a Java2D based 3D engine would be.

Well, the last few days have been rich on information and trial-and-error. I will give that a few days to settle, and than probably have a close look at jzy3d.
Good luck with your OffscreenCanvas, and thanks for your hard work. Maybe 2010 is the year of JFreeChart3D, who knows?
-
- Posts: 11
- Joined: Sun Dec 27, 2009 4:18 pm
- antibot: No, of course not.
Re: Proposing 3d lib for extending Jfree capabilities
I have the ability to have 3d coordinates projected to 2d according to the current view point. I have already a prototype of that for making a selection in a scatter plot, which consists in projecting all points to 2d, and checking whether the are in or out the selection 2d rectangle.... how you can delegate the rendering of entire lines and polygons to a Graphics2D instance
For each element of the scene graph I can call Camera.modelToScreen(..., Coord3d) which returns another Coord3d whose x,y coords are screen coord, and z is a value between 0 and 1 indicating a ratio between near and far clipping planes of the Camera.
I think that might be sufficent to render lines and polygons to a Graphics2D, isn't it? I am not sure I really understand your question actually.
Regards,
Martin
-
- Posts: 11
- Joined: Sun Dec 27, 2009 4:18 pm
- antibot: No, of course not.
Re: Proposing 3d lib for extending Jfree capabilities
Hi,
I just did a small proof of concept code that projects a 3d model to 2d and here is the result:

I did not go into color shading or transparency. Well I tried transparency but it was not working
Next time
The projection is about 11ms long (with random pics @ 45ms), and j2d draw is around 15ms long for 2304 polygons.
If you want to try it, I left the code on the trunk in src/trials.
Regards,
Martin
I just did a small proof of concept code that projects a 3d model to 2d and here is the result:

I did not go into color shading or transparency. Well I tried transparency but it was not working


The projection is about 11ms long (with random pics @ 45ms), and j2d draw is around 15ms long for 2304 polygons.
If you want to try it, I left the code on the trunk in src/trials.
Regards,
Martin
-
- Posts: 24
- Joined: Fri Sep 04, 2009 10:28 am
- antibot: No, of course not.
Re: Proposing 3d lib for extending Jfree capabilities
Hi guys,
I am trying to use jzy3d, but I can not get it to work. any time i try to compile the code I get error saying:
I really want to use jzy3d, but cant get it to work any one got idea how to compile the code ?by the way i'll ready checked out the jogl website and how to install it but no luck.
Many Tanx
I am trying to use jzy3d, but I can not get it to work. any time i try to compile the code I get error saying:
Code: Select all
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at com.sun.opengl.impl.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:189)
at com.sun.opengl.impl.NativeLibLoader.access$000(NativeLibLoader.java:49)
at com.sun.opengl.impl.NativeLibLoader$DefaultAction.loadLibrary(NativeLibLoader.java:80)
at com.sun.opengl.impl.NativeLibLoader.loadLibrary(NativeLibLoader.java:103)
at com.sun.opengl.impl.NativeLibLoader.access$200(NativeLibLoader.java:49)
at com.sun.opengl.impl.NativeLibLoader$1.run(NativeLibLoader.java:111)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.opengl.impl.NativeLibLoader.loadCore(NativeLibLoader.java:109)
at com.sun.opengl.impl.windows.WindowsGLDrawableFactory.<clinit>(WindowsGLDrawableFactory.java:60)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at javax.media.opengl.GLDrawableFactory.getFactory(GLDrawableFactory.java:106)
at javax.media.opengl.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:520)
at javax.media.opengl.GLCanvas.<init>(GLCanvas.java:131)
at javax.media.opengl.GLCanvas.<init>(GLCanvas.java:90)
at net.masagroup.jzy3d.plot3d.rendering.canvas.CanvasAWT.<init>(CanvasAWT.java:44)
at net.masagroup.jzy3d.plot3d.rendering.canvas.CanvasAWT.<init>(CanvasAWT.java:39)
at net.masagroup.jzy3d.chart.Chart.initializeCanvas(Chart.java:77)
at net.masagroup.jzy3d.chart.Chart.<init>(Chart.java:68)
at net.masagroup.jzy3d.chart.Chart.<init>(Chart.java:55)
at net.masagroup.jzy3d.demos.surface.delaunay.DelaunaySurfaceDemo$1.<init>(DelaunaySurfaceDemo.java:44)
at net.masagroup.jzy3d.demos.surface.delaunay.DelaunaySurfaceDemo.getChart(DelaunaySurfaceDemo.java:44)
at net.masagroup.jzy3d.demos.Launcher.main(Launcher.java:21)
Java Result: 1
Many Tanx