PDA

View Full Version : How to "fill" a solid?



varieux
09-24-2009, 07:10 PM
Hi all,

I have a large number of triangles that depict the surface of an object. I currently am able to show a cross-section, i.e. a narrow slice of the triangles that make up the surface.

However the request has come in that I make the cross-section solid.

The cross-section currently looks a little thin -- due to the triangles themselves being thin and often perpendicular to the cross section.

Does OpenGL have any facility for creating a solid cross section?
I believe I can guarantee that the surface is closed.

Thanks.

todayman
09-24-2009, 07:24 PM
There's nothing that will create more geometry for you (unless you count geometry shaders, which really you do yourself). If you need to draw more triangles, then you need to tell OpenGL to draw more triangles.

Here's how I'm picturing what you're saying: You have some object, say a ball. You slice the ball and you can see the interior volume of the ball, but really you want a hemisphere? Do you want to fill in the gaps created by slicing away the front? In this case, you would have to create the covering yourself.

I'm not entirely sure what you're getting at here...

charliejay
09-25-2009, 04:08 AM
If you're trying to do as todayman suggests, and turn a spherical shell into a hemisphere (for instance), then you can use the stencil buffer to identify the "inside" area of your shape, and then fill that with a full screen quad.

The red book has a section on doing something like this, I think, along the lines of: Set up one or more clipping planes, to cut away the sections of the model that you don't want to see. Draw the front faces of the model, doing nothing to the stencil buffer (but clipping to the clipping planes). Draw the back faces of the model, setting the stencil buffer to 1 where the depth test passes (ie, where you've drawn a back face that wasn't covered by a front face).

This leaves you with a 2D region in the stencil buffer, defining the "inside" of your solid, which you can then fill in by drawing a full screen quad, with the stencil test set up to discard any fragments for which the stencil is not 1.

I think this approach can also be used (with modifications) to work with clipping polygons, rather than clipping planes.

If, on the other hand, you are just showing a connected line loop, like a single slice of a CAT (or MRI?) scan, then it looks like you will need to generate geometry. The red book also has a section on drawing concave polygons using the stencil buffer, a technique that I think could be used for this scenario. Not sure from memory how well it deals with intersecting polygon line segments, though.