Fastest way to do 2D line drawing?

Hi, I’m currently writing some geophysical software which takes in a set of data based on seismic layers, and does ray tracing. I have the optimal algorithms for the math involved, but I am being slowed down by my current drawing algorithm in java.

I am currently using a Graphics2D object with .drawLine() to draw my lines on screen. The problem is that there may be up to 4 million lines which need to be drawn to a single image. This is resulting in literally minutes to refresh the screen. With up to 10 seconds just to draw a few thousand lines.

My question is this… for the problem of drawing a lot of lines to the screen, what is the fastest way possible to do this using the standard java api? With no other packages such as jogl, etc?

If you can speed this up somehow i’d be very greatful!

Oh, I just noticed I didnt have opengl support for 2d rendering turned on. But I cant get the command line syntax to work. Under linux I typed

% java -Dsun.java2d.opengl=true

But this is just giving me the java options splash screen, what am i typing wrong?

Uh… you didn’t give it any Java class or Jar to run.

Oh, I thought this would set the flag permanently. My bad!

Nope, this isnt my problem. Whenever I resize the window, it still takes 7 seconds to redraw around 2000 lines. Moving the window around however is fine. So the displaying of the lines isnt a problem (NVidia quadro card), its the drawing and redisplaying of the image that is taking all the time.

Any suggestions?

with millions of line you just NEED hardware acceleration.

As we recently learned that the OpenGL pipeline of J2D rougly performs the speed of immediate-mode in JOGL/LWJGL there is a LOT of room for improvement by doing it yourself. Yes, this means working with JOGL, and yes, it might be kinda complex at first sight, but once you made the effort, you won’t regret it. The GPU might render these millions of lines at over 100fps when you use vertex-arrays.

If you really don’t want to learn a few lines of OpenGL, you’re pretty much stuck at your current performance levels.

I didnt say I didnt want to learn OpenGL… I’ve been using opengl for almost 5 years now (in c)

I was just wondering if there was a way to do it almost as fast with the standard API, so i wouldnt have to install Jogl on any computer I need to demo this on :confused:

Try -Dsun.java2d.opengl=True with uppercase T, then it’ll tell you whether it succeeds or fails.

:-[

I start this reply off with this face… because I was able to speed up my performance about a million fold…

… by turning off antialiasing…

I forgot that in my original drawing algorithm I needed to make it pretty for a screenshot we had to do for a paper, and did not turn this off. Now instead of a 7 second refresh, im getting about 10fps.

Exactly, and since all supported Java2D (screen-)backends provide hardware accaleration for non-AA lines when rendering to native surfaces this is a no-brainer.

churchill:
Just because of interest, how fast is your example running with AA turned on and using the OpenGL pipeline?
Would be really interesting if you could try that out :slight_smile:

Thank you in advance, lg Clemens