Is there a way to "check out" the object's actual area?

Hi, 

Say I have an irregular raster object like this:

polygon1.png

The app doesn’t know the shape or color of the object before runtime.

So I would like to achieve something like this:

polygon2.png

I.e. cover the entire object with a grid, and mark only the squares that overlap the shape. 

Making the grid etc. is not a problem, but I can’t find a way to detect the overlap. 

A working solution would be to use display.colorSample  and check for alpha>0 but as far as I understand this function can’t analyze objects out of context (will always ‘see’ the background as well). 

Any help on this?

EDIT: Actually , if this is of any help, I think I can use a vector display polygon as the object.

You could try using the shape as a physics object and then check with sensor (physics) squares for collisions maybe.

Yeah but this is kind of inefficient to use physics just for simple overlap, so I would like to avoid it as far as possible.

I’m currently looking into this plugin: https://marketplace.coronalabs.com/plugin/memory-bitmap to see if it could be used for this purpose.

EDIT: Unfortunately this plugin won’t do the job, as from what I gather it can’t access existing images.

What do you want to do with the grid?

I would explore a hacky way to do it. Create a grid of cells, put behind image. Add event listeners to image and grid cells. Trigger events for center / boundaries (?) of each cell. If image event listener catches the event, return true and do nothing. If image does not catch it cell will get the event callback and can remove/disable itself / do whatever.

You will have a boundary problem so you might want to create a more fine-tuned grid or trigger multiple events for each cell. 

This hacky solution might not be good enough performance wise.  

@Yoger Games

This is a very interesting idea. I will try it out. Just one question: what kind of events should I trigger on the boxes/image? The only ones I can think of that work in this kind of vertical manner are “tap” and “touch”. 

As far as the context, this is used for a sort of a pixelation effect on the object. The in-built “filter.pixelate” won’t do the job because of various reasons (e.g. I need control over individual pixels’ alpha) so I ended up iterating through the object area with display.colorSample and drawing bigger squares on top of it. The grid doesn’t actually exist, it’s just a set of locations where the squares (“pixels”) potentially go.

It is not super efficient but it works well. The issue is that I don’t want to pixelate the entire rectangular bounding box but only the general area of the object with only a bit of background “caught”.

Ok, I see. 

Yeah, “tap” and “touch” are the only ones I can think of. I haven’t tried this solution myself, but theoretically it should work. :slight_smile:

suggest you re-post with something like this as your topic, as finding glsl filter help will likely be both easier and more effective.  (because i know a “perfect” solution to your original problem as pictured, from a computational geometry perspective, but it wouldn’t be suitable for your use of continuously resampling a bitmap on repeated frames - that’s what a filter does, and with hardware acceleration)

@davebolinger

Point taken. I’m looking into custom glsl filters. However, I need to process a bit of background around the image so ideally I’d still need a way to determine the shape. As to the “countinuous resampling”, the object is static and needs to be processed only once.

Anyway, could you say more about your solution? Being able to somehow handle object shapes would come in handy for sure.

IFF can treat as a vector rather than raster problem, then “polygon clipping” is your search term, and you’d likely end up here

(otherwise write a filter)

You could try using the shape as a physics object and then check with sensor (physics) squares for collisions maybe.

Yeah but this is kind of inefficient to use physics just for simple overlap, so I would like to avoid it as far as possible.

I’m currently looking into this plugin: https://marketplace.coronalabs.com/plugin/memory-bitmap to see if it could be used for this purpose.

EDIT: Unfortunately this plugin won’t do the job, as from what I gather it can’t access existing images.

What do you want to do with the grid?

I would explore a hacky way to do it. Create a grid of cells, put behind image. Add event listeners to image and grid cells. Trigger events for center / boundaries (?) of each cell. If image event listener catches the event, return true and do nothing. If image does not catch it cell will get the event callback and can remove/disable itself / do whatever.

You will have a boundary problem so you might want to create a more fine-tuned grid or trigger multiple events for each cell. 

This hacky solution might not be good enough performance wise.  

@Yoger Games

This is a very interesting idea. I will try it out. Just one question: what kind of events should I trigger on the boxes/image? The only ones I can think of that work in this kind of vertical manner are “tap” and “touch”. 

As far as the context, this is used for a sort of a pixelation effect on the object. The in-built “filter.pixelate” won’t do the job because of various reasons (e.g. I need control over individual pixels’ alpha) so I ended up iterating through the object area with display.colorSample and drawing bigger squares on top of it. The grid doesn’t actually exist, it’s just a set of locations where the squares (“pixels”) potentially go.

It is not super efficient but it works well. The issue is that I don’t want to pixelate the entire rectangular bounding box but only the general area of the object with only a bit of background “caught”.

Ok, I see. 

Yeah, “tap” and “touch” are the only ones I can think of. I haven’t tried this solution myself, but theoretically it should work. :slight_smile:

suggest you re-post with something like this as your topic, as finding glsl filter help will likely be both easier and more effective.  (because i know a “perfect” solution to your original problem as pictured, from a computational geometry perspective, but it wouldn’t be suitable for your use of continuously resampling a bitmap on repeated frames - that’s what a filter does, and with hardware acceleration)

@davebolinger

Point taken. I’m looking into custom glsl filters. However, I need to process a bit of background around the image so ideally I’d still need a way to determine the shape. As to the “countinuous resampling”, the object is static and needs to be processed only once.

Anyway, could you say more about your solution? Being able to somehow handle object shapes would come in handy for sure.

IFF can treat as a vector rather than raster problem, then “polygon clipping” is your search term, and you’d likely end up here

(otherwise write a filter)