Jump to content
  • Advertisement
Sign in to follow this  
RegularKid

Algorithm To Detect Selection Area?

This topic is 3568 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm trying to figure out the best to way determine which pixels in a bitmap are inside a selection area I've created. The selection area is defined by a list of vertices that create a line loop ( picture using the mouse to draw a circle around an object within a bitmap...each point on your hand-drawn circle is represented by an (x,y) coordinate ). After I have my "selection area" I'd like to go through the bitmap and determine which pixels are within this region and which aren't. Thought, ideas, suggestions ( I tried doing a search here in the forums and in google, but don't think I know the words or terms to describe this correctly :) ) Any help would be great!

Share this post


Link to post
Share on other sites
Advertisement
Well, my first thought is to find the mid-point, or mid-point approximation, and turn the area into a triangle fan. Finding which pixels are in these triangles should be an easier task...

But I am pulling this out of my ass, because I haven't tackled such a problem. You should probably listen to someone smarter than me.

Share this post


Link to post
Share on other sites
Scanline fill. Google for more and various implementations.

It was one way to draw filled polygons manually. Usually it involves doing Bresenham algorithm over bounding polygon.

Share this post


Link to post
Share on other sites
I think the best way is to just rasterize the selection polygon into a seperate bitmap, of the same size as your bitmap, and use that as a "mask".

I don't know if you are using any drawing toolkit, like GDI, but if so, most of them do have a polygon drawing function.

If not, you'll have to write your own rasterizer algorithm (in which case you could omit the second buffer, and use the coordinates you would draw to directly as coordinates of the pixels that are selected), which is going to be a bit harder, but a google search should help you there.

Share this post


Link to post
Share on other sites
Interesting, I hadn't thought of just rendering the triangle fan and using it as a mask on a seperate bitmap. I think that will work!

Thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by RegularKid
Interesting, I hadn't thought of just rendering the triangle fan and using it as a mask on a seperate bitmap. I think that will work!
It might work, but it might not work in some cases. Although it should work with convex and partly concave shapes, it probably isn't going to work for more concave shapes such as the outline of the letter 'C', where the centre is outside of the shape, and shapes that cross over themselves.

But if as you say the hand-drawn shape is always circle-like then it should be okay.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!