# 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.

## 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 on other sites
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 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 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 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 on other sites
Quote:
 Original post by RegularKidInteresting, 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.

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632999
• Total Posts
3009812
• ### Who's Online (See full list)

There are no registered users currently online

×