Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Pumpkin Software
AGK Developer
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location: uk
Posted: 5th Mar 2014 18:59
Hi,
Can anyone help with some floodfill agk code that works on irregular shapes. I have spent the last 2 weeks looking at many online examples and coding but can't get anything too work with 100% fill coverage.
Thanks
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 5th Mar 2014 20:21
No doubt you have seen this bit here goes anyhow:

http://lodev.org/cgtutor/floodfill.html

Seems 'followable'?

www.bitmanip.com
All the juicy you could ever dream of!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Mar 2014 22:53 Edited at: 5th Mar 2014 22:56
hmm, my idea is try to find outside/border/inside in a single line and useing flags.
nearly...
for x from left to right. if no border than outside,
if border than nothing, if no border and last was border than inside
if inside and border and next no border than outside=1 (inside=0).
means you get a flag paint or not.
the same for each line at y.
it is not a floodfill, it is more a fill one shape only.

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Pumpkin Software
AGK Developer
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location: uk
Posted: 6th Mar 2014 10:44
Hi the daddy & markus,

I understand the principal off a floodfill and can get it too work to some degree, but just having problems with a full fill in some smaller areas for some reason. I will leave it for a couple of weeks and get on with something else, and then come back to it with fresh eyes.

Thanks Guys
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 6th Mar 2014 14:13
I guess in some shapes, there are areas where the fill is believing it is done when there are still 'pixels' that are not filled.

A work around be to fill from several places in your shapes. Finding the extreme areas of the shape is no easy task, assuming that these shapes are created dynamically, otherwise this can be pre-calculated!

Maybe get the bounding box of the shape, then starting at top left of bounding box fire a ray to the right 'across' the shape...where the ray collides with the shape you have the shape boundary. If you do this from the right, firing left you will know on any vertical pixels position of where the shape starts and finishes on this horizontal line, then in the correct colour draw a line or fill pixels between start and end points....with a little but of work this is viable?

www.bitmanip.com
All the juicy you could ever dream of!
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 6th Mar 2014 14:13
How are you drawing your shapes? Sprites, lines etc?

www.bitmanip.com
All the juicy you could ever dream of!
Pumpkin Software
AGK Developer
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location: uk
Posted: 6th Mar 2014 15:12 Edited at: 6th Mar 2014 15:14
Hi,
I am using small 4 pixel size sprites as the border, I am using a basic map[x,y] = border when laying them down on the screen. I can then draw like the old etch a sketch, when the drawing line (border) touches another part of itself, it then fills. Everything works well except for full fills. The border can be zig-zaging all over the screen, but you may only have the last small area that joins, and only this part that needs filling. We will only know the end x,y (touching point) of the border, but the rest of the border drawn will be irrelevant. This makes it difficult to know the area high & low x,y, or area size to fill.
Thanks
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 7th Mar 2014 09:07
Based on it being Etch-a-sketch can you draw curves or is it limited to angles?

If it is angles, you could, at each change of angle, store the point position in an array, this way when the shape is complete you could draw a polygon and then you would have the bounding box and the ray casting would work?

www.bitmanip.com
All the juicy you could ever dream of!
Pumpkin Software
AGK Developer
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location: uk
Posted: 7th Mar 2014 10:41
Hi,
There are no curves, just l,r,u,d drawing 4x4 pixel individual sprite boxes. I did at one point think about storing the x,y position on a direction change but abandoned it in favour of trying to get the mapping to work. Not dealt much with bounding boxes and ray casting before, I will have to look into it to see if I can manage to figure it all out at some point when I get back to this project.

Thanks for all your advice.
peterJBE
16
Years of Service
User Offline
Joined: 11th Mar 2008
Location: Belgium
Posted: 7th Mar 2014 17:09 Edited at: 7th Mar 2014 18:02
@Pumpkin Software
I a have a floodfill routine that works for my purposes. It handles (at least some) irregular shapes. I use it to fill jigsaw pieces drawn using bezier curves.
There are some isues: see code.
There is a crash if you start filling outside a closed shape!!!
This means it will also crash if there are holes(leaks) in your shape.


Can you tell me if it works with your shapes?
peterJBE
16
Years of Service
User Offline
Joined: 11th Mar 2008
Location: Belgium
Posted: 7th Mar 2014 17:40 Edited at: 7th Mar 2014 18:02
A version that checks for the global boundaries of the image.

Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 8th Mar 2014 01:41 Edited at: 8th Mar 2014 01:42
Sounds like there might be a stack overflow. What's the size of the image ? Even if it's only say 640x*480y that's 307,200 unique pixels. So it's entirely possible the 100K stack array (dim stack[100000] as point) can overflow in such situations.

peterJBE
16
Years of Service
User Offline
Joined: 11th Mar 2008
Location: Belgium
Posted: 8th Mar 2014 09:06 Edited at: 8th Mar 2014 09:12
@Kevin Picone


You are right. I had to enhance the stack to 1000000 for this attached 549x455 image.
I am sure their more memory efficient algoritms but it works for me.
One thing that could be done easily: encode a point in one (long)integer.
Do you get a stack overflow with image drawn with the createimage2 function in my code snippet?

My project has 480x480 resolution in setup.agc

Attachments

Login to view attachments
Pumpkin Software
AGK Developer
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location: uk
Posted: 8th Mar 2014 10:30
Thanks for all the advice guys, will have a proper look when back on this project, I also have a few other fill ideas I'm going to try.
Cheers

Login to post a reply

Server time is: 2024-05-05 21:47:06
Your offset time is: 2024-05-05 21:47:06