Infil

09-18-2008, 02:03 AM

To start off, I want to say that while I have some reasonable openGL experience, I am completely incompetent when it comes to using textures, so please use an appropriate level of detail in any responses. :)

The user will draw a closed curve on the screen (the curve may self-intersect, and the last point is set to equal the first in the list of discrete points drawn), and I want to generate a series of random points that are contained within this curve. The random point generation algorithm is already solved using some other tricks specifically related to my application. However, to do this, I operate in the space defined by the bounding box of the curve, and then I have to apply a second processing step to eliminate those points which are outside the curve.

Currently, I just perform the standard even/odd intersection test, but I do it naively (that is, for each random point, I test its intersection on a horizontal line versus each line segment on the discrete closed curve). When the closed curve has 200 segments and the number of random points gets 20,000 or higher, this obviously is too slow. I had thought about implementing a smarter algorithm for this (BSP-tree related), but perhaps I can use some sort of texturing algorithm to help here?

Is it possible for me to create a texture where everything outside the closed curve is black, and everything inside is transparent (within the curve's bounding box)? Then I could simply render each point with a different color, apply the texture (which will wipe out everything outside the curve, but keep the color info of all points inside), and then use glReadPixels to pick out the non-black, non-white colors? I suppose this may not be all that much faster, because if the point density is high, two points may render to the same pixel and only the last one to be drawn will be recognized. (I suppose this could be solved by simply taking each random point and indexing it into the texture instead of needlessly rendering it and reading it back.) Nonetheless, is my notion of texturing correct here? Is this possible, and it is fast to create such a texture?

Additionally, I want to know the distance from each random point (on the viewing plane) to the closed curve. For this, I will be using a distance transform algorithm, but again, this requires a 2D image with 0 pixels (black) on the boundary of the closed curve (and outside), and 1 pixels (white) in the interior of the closed curve... which is basically what I'm generating by the texture above, so I could potentially speed up TWO algorithms.

Please let me know ways of implementing these ideas using openGL, or if I'm way off base. :)

tl;dr - I would like to get an image (texture?) where all points outside a 2D closed curve (defined by a set of discrete points which define a polyline) are black and all points inside are white.

The user will draw a closed curve on the screen (the curve may self-intersect, and the last point is set to equal the first in the list of discrete points drawn), and I want to generate a series of random points that are contained within this curve. The random point generation algorithm is already solved using some other tricks specifically related to my application. However, to do this, I operate in the space defined by the bounding box of the curve, and then I have to apply a second processing step to eliminate those points which are outside the curve.

Currently, I just perform the standard even/odd intersection test, but I do it naively (that is, for each random point, I test its intersection on a horizontal line versus each line segment on the discrete closed curve). When the closed curve has 200 segments and the number of random points gets 20,000 or higher, this obviously is too slow. I had thought about implementing a smarter algorithm for this (BSP-tree related), but perhaps I can use some sort of texturing algorithm to help here?

Is it possible for me to create a texture where everything outside the closed curve is black, and everything inside is transparent (within the curve's bounding box)? Then I could simply render each point with a different color, apply the texture (which will wipe out everything outside the curve, but keep the color info of all points inside), and then use glReadPixels to pick out the non-black, non-white colors? I suppose this may not be all that much faster, because if the point density is high, two points may render to the same pixel and only the last one to be drawn will be recognized. (I suppose this could be solved by simply taking each random point and indexing it into the texture instead of needlessly rendering it and reading it back.) Nonetheless, is my notion of texturing correct here? Is this possible, and it is fast to create such a texture?

Additionally, I want to know the distance from each random point (on the viewing plane) to the closed curve. For this, I will be using a distance transform algorithm, but again, this requires a 2D image with 0 pixels (black) on the boundary of the closed curve (and outside), and 1 pixels (white) in the interior of the closed curve... which is basically what I'm generating by the texture above, so I could potentially speed up TWO algorithms.

Please let me know ways of implementing these ideas using openGL, or if I'm way off base. :)

tl;dr - I would like to get an image (texture?) where all points outside a 2D closed curve (defined by a set of discrete points which define a polyline) are black and all points inside are white.