Iteration through my vector of pixels.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 4
Reputation: ixuz is an unknown quantity at this point 
Solved Threads: 0
ixuz ixuz is offline Offline
Newbie Poster

Iteration through my vector of pixels.

 
0
  #1
Apr 1st, 2009
Hello there!

I'm having problem with my drawing graphics programming, let's say I want to draw a circle.

This circle is made out of smaller pieces called pixels.

Okay I got a pixelclass containing three values x, y and color.
My circle contains a vector which contains all the pixels that the circle is made of.

If I make a circle with a radius of 100, I get to draw 31417 pixels. If I draw all these ones as often as my program allows, my program only max out ~97fps.

I wonder is it supposed to be this slow to loop 31 thousand times and drawing one pixel each time? Am I storing these pixels the wrong way? Is vector a bad choice, what other type of storing structure would I use instead?

Thanks for any help.
// ixuz
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Iteration through my vector of pixels.

 
0
  #2
Apr 1st, 2009
Oy! Please don't use a vector (or any other STL container) to hold individual pixel data -- Just draw directly to the target surface.

Also, you needn't directly calculate every pixel in the circle. One quarter of them is sufficient. (That is, calculate 1/4 of the circle, and draw four pixels each step.)

Good luck!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 4
Reputation: ixuz is an unknown quantity at this point 
Solved Threads: 0
ixuz ixuz is offline Offline
Newbie Poster

Re: Iteration through my vector of pixels.

 
0
  #3
Apr 1st, 2009
Okay thanks alot, I removed this vector holding pixels thing and I understand what you mean by doing more than one pixel each loop, the thought that came to my mind when you told me this was:

When I'm going to draw a line of pixels, shouldn't I use a for loop? Or is it faster by just repeating the drawPixel function 4 times in the source code?

thanks!
// ixuz

Edit: As soon as I started to program I realized what you ment by draw 4 pixels at the same time. I'm using pythagoras algorithm to calculate the distance to each pixel of the circle, to see if it's inside or outside the circles radius.

I'm drawing one circle with a radius of 150 using the graphic library SDL.
Your tips actually boosted up my drawing speed from 82circles per second to 119 circles per second thanks alot!

Is pythagoras a good or bad choice of algorithm? Is there any algorithms that are faster? Tips and tricks are welcome aswell!

Thanks in advance.
// ixuz
Last edited by ixuz; Apr 1st, 2009 at 7:42 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Iteration through my vector of pixels.

 
0
  #4
Apr 2nd, 2009
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,753
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 283
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Iteration through my vector of pixels.

 
0
  #5
Apr 2nd, 2009
Nice link! Any other recommendations per chance?
Klatu Barada Nikto
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Iteration through my vector of pixels.

 
1
  #6
Apr 3rd, 2009
Alas, I just googled it.

Try searching for things like "bresenham line circle ellipse algorithm".

Speed comes from doing the least to draw individual pixels. Hence, a lot of optimization comes from low-level accesses. In modern GUI architectures, often the case is for pixel access to occur in memory (in-memory bitmaps/pixmaps and the like), and then have the WM/OS/whatever copy the image to the graphics hardware. When you move to more direct accesses (like DirectX, etc.) then you must minimize accesses to the hardware yourself -- since it is slower than normal memory accesses.

Hope this helps.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC