Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Drawing performance issue
Drawing performance issue [message #43147] Mon, 19 May 2014 10:01 Go to next message
crydev is currently offline  crydev
Messages: 151
Registered: October 2012
Location: Netherlands
Experienced Member
Hello,

I am having some trouble with drawing a big amount of lines on a panel. The drawing takes very long. I know this is not strange because the amount of lines is very high, but I was wondering if I could speed it up. Drawing 3 to 12 million lines takes 5 to 20 seconds. The following is the drawing code.

void KochPanel::Paint(Draw& draw)
{
	const Size sz = this->GetSize();
	const int cx = sz.cx;
	const int cy = sz.cy;
	
    draw.DrawRect(0, 0, cx, cy, Black);
    
    if (!kochFractal->IsRunningCalculation())
    {
	    for (int i = 0; i < kochFractal->GetNumberOfEdges(); ++i)
	    {
	        const Edge& e = (*kochFractal)[i];
	        draw.DrawLine((int)e.X1, (int)e.Y1, (int)e.X2, (int)e.Y2, 1, Color::FromRaw(e.Color));
	    }        
    }
}


Thanks in advance!

crydev
Re: Drawing performance issue [message #43148 is a reply to message #43147] Mon, 19 May 2014 11:47 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi crydev,

Here's few tricks that I deployed successfully in past:

- Don't draw anything that is not visible (out of viewport, overlapped by other shapes).

- Don't draw details that can't be visible on screen. Only use high level of detail when you export images or print.

- Use clever algorithms. Sometimes images can be generated much faster going pixel by pixel than using lines and other drawing primitives.

In your particular case with Koch curve, I think the best would be to apply the second optimization. Only use enough iterations so that length of the line is more than one pixel. If you need the data for some subsequent operations, you could also add conditions to only use point when its distance from last drawn point is more than 1 pixel (or 0.5pixel, it might look better).

Best regards,
Honza
Previous Topic: How to create animated GIFs?
Next Topic: Should RGBA have got 4 arguments constructor?
Goto Forum:
  


Current Time: Fri Apr 19 15:24:12 CEST 2024

Total time taken to generate the page: 0.05092 seconds