Inspecting pixels used on a facet

This is more of a math question than a scripting question (unless there is a builtin method to do this) but I don't seem to know enough about the topic to create a useful search query...

I would like to inspect a facet to determine if the relevant portion of an image map applied to it is all black (0, 0, 0).

I can find the corner pixels on the image, but I'm not sure how to generate a list of all pixels contained within the polygon from that.

Is it necessary to go the other direction, and check each pixel between (min x, min y) and (max x, max y) to see if it is within the polygon?

 

Can anyone point me in the right direction?

Comments

  • Seven193Seven193 Posts: 1,080
    edited February 2022

    If you just need to inspect a point on a polygon, just calculate the barycentric coordinates for the triangle.  This will give you weights, which will let you pick out any interpolated point within that triangle.  Scanning a polygon, pixel by pixel, is what you would do if you wanted to render a polygon.

    Post edited by Seven193 on
  • OmnifluxOmniflux Posts: 377

    You've lost me, and I suspect it is because of my poor phrasing of the problem, but it could also be because I don't understand barycentric coordinates.

    My reference to polygon was not polygon == facet, but the polygon defined on the image map by the uv points from the facet.

    For the forward facing facet on this cube with the texture image on the right applied to it, I want to check if all pixels in the texture image in the red square (the pixels that will be used on the facet when rendering) are black.

    I can calculate the coordinates for the corners (red square) on the texture image.

    From this point, how do I know which pixels on the texture image I need to check? This is simple in the case of the red rectangle, but a facet could also map to the yellow triangle.

     

    Is there a way to enumerate the pixels used inside the yellow triangle or do I need to loop through all the pixels in a rectangle bounding the triangle and check if each pixel falls inside the triangle?

     

    Or, when you say you don't think I want to scan a polygon pixel by pixel, do you mean there is another way to check if the portion of the image applied to the facet is completely black?

     

     

     

     

     

    Untitled.png
    513 x 315 - 94K
  • Seven193Seven193 Posts: 1,080
    edited February 2022

    Ok, You've had the right idea.

    Post edited by Seven193 on
  • Seven193Seven193 Posts: 1,080
    edited February 2022

    post

    Post edited by Seven193 on
Sign In or Register to comment.