Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (512)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Speeding up line drawing  (Read 1925 times)
0 Members and 1 Guest are viewing this topic.
Offline CapKrugers

Junior Newbie




Java games rock!


« Posted 2004-08-30 18:43:44 »

I'm programming a parallel coordinates visualization tool (sure, it's not a game by most people's standards, but it is interactive and colorful), and I'm experiencing speed problems with large datasets (i.e., drawing many, many lines). Handling the data and doing calculations is not the bottleneck; the drawing is. An example of a parallel coordinates visualization in Java can be found here: http://home.subnet.at/flo/mv/parvis/ if you have never heard of "parallel coordinates".

Of course, the poor performance is to be expected, because for each record in the dataset I am analyzing I need to check whether the user has highlighted the record, then for each record draw a line between each column on the visualization. Basically, with a dataset with about 2000 records, each with 7 dimensions,  I'll be drawing 6 * 2000 or 12,000 lines (if they are all selected). At times, the tool performs sluggishly, making it sometimes difficult for the user to be precise with selections. The tool has to be cross-platform, and I haven't tested OpenGL acceleration since I only have onboard video on my machine. I have already optimized for() loops, etc., so is there any faster way to draw lines in Java than using drawLine onto BufferedImage objects?
Offline Hansdampf

Senior Duke


Projects: 3


too offending?


« Reply #1 - Posted 2004-08-30 19:45:02 »

if you are not afraid of the effort, you can convert an image to an int[] array and use the Bresenham algorithm to draw the lines.
That should be much faster if you draw 10000+ lines, but its slower when drawing only a few lines (with java api) because of the *converting* overhead


lots of sillystupid games: http://www.emaggame.com
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #2 - Posted 2004-08-30 23:04:48 »

Hm... someone mentioned that he got a nice speed increase by combining several lines in one Area and drawing that instead. Unfortunately I can't remember the details nor find the thread. However, I do remember that he (who?) said that there was a sweet spot with somewhat like 30-50 lines in one Area object.

You might just give that a try... it's rather easy to implement and you can easily find out the sweet spot by trial'n'error.

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CapKrugers

Junior Newbie




Java games rock!


« Reply #3 - Posted 2004-08-31 12:24:17 »

Quote
Hm... someone mentioned that he got a nice speed increase by combining several lines in one Area and drawing that instead. Unfortunately I can't remember the details nor find the thread. However, I do remember that he (who?) said that there was a sweet spot with somewhat like 30-50 lines in one Area object.

You might just give that a try... it's rather easy to implement and you can easily find out the sweet spot by trial'n'error.

What do you mean by "combining several lines in one Area"? Do you mean drawing the lines to the Area and then drawing the area on the BufferedImage? I'm a Java2D n00b...is there a method for drawing lines to an Area object?
Offline abies

Senior Duke





« Reply #4 - Posted 2004-08-31 12:29:14 »

Quote
Hm... someone mentioned that he got a nice speed increase by combining several lines in one Area and drawing that instead. Unfortunately I can't remember the details nor find the thread. However, I do remember that he (who?) said that there was a sweet spot with somewhat like 30-50 lines in one Area object.


GeneralPath, not Area.

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=2D;action=display;num=1081955210

Artur Biesiadowski
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #5 - Posted 2004-08-31 13:14:16 »

Oops Embarrassed

Well, I've never used that stuff Wink

弾幕 ☆ @mahonnaiseblog
Offline nonnus29

Senior Duke




Giving Java a second chance after ludumdare fiasco


« Reply #6 - Posted 2004-09-01 01:30:30 »

I really don't see drawing 12,000 lines being a problem, (edit I'm sure the profiler doesn't lie, but do you need to draw all the lines all the time?);

1. load the dataset, draw the lines
2. mouse hovers over a line, redraw in hilite color
3. mouse hovers a different line || mouse leaves line pane then redraw previous line dark && 2.

or

1. load the dataset, draw the lines
2. mouse hovers over a datapoint, redraw all connected lines in hilite color
3. mouse hovers a different datapoint || mouse leaves line pane then redraw previous lines dark && 2.

Should be a fraction of 12,000 lines connected to a node?

I'm probably way off though, I usually am....
Offline pepe

Junior Duke




Nothing unreal exists


« Reply #7 - Posted 2004-09-01 11:42:43 »

Quote

1. load the dataset, draw the lines
2. mouse hovers over a line, redraw in hilite color
3. mouse hovers a different line || mouse leaves line pane then redraw previous line dark && 2.

Slight detail. screenshots show that he is using antialiased lines, thus the overwriting would give crappy results.
Nevertheless, he can still draw an ORed line for the good result.

Home page: http://frederic.barachant.com
------------------------------------------------------
GoSub: java2D gamechmark http://frederic.barachant.com/GoSub/GoSub.jnlp
Offline Mark Thornton

Senior Duke





« Reply #8 - Posted 2004-09-01 14:29:35 »

The best way top speed this up is to not draw so many lines each time! Create an extra BufferedImage and draw everything in to it in the unselected state. Now to paint with a line selected, first copy this image to the output surface and the draw any selected lines on top.
Now each refresh only does bitmap copy plus drawing just the selected lines. Provided the number of lines selected is much less than the total, the code will be much faster.
I do something like this with road maps containing 10s (or even 100s) of thousands of antialiased 'wide' lines. I cache the background map images and just draw interesting (highlighted) routes on top.
Offline rreyelts

Junior Duke




There is nothing Nu under the sun


« Reply #9 - Posted 2004-09-08 16:54:05 »

Quote
I do something like this with road maps containing 10s (or even 100s) of thousands of antialiased 'wide' lines. I cache the background map images and just draw interesting (highlighted) routes on top.

Lol. I do the same thing. I suppose there aren't too many different ways to go about it, is there? Smiley

God bless,
-Toby Reyelts

About me: http://jroller.com/page/rreyelts
Jace - Easier JNI: http://jace.reyelts.com/jace
Retroweaver - Compile on JDK1.5, and deploy on 1.4: http://retroweaver.sf.net.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (39 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (35 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!