Retrieving a list of "clipped" objects

Being pretty new to OpenGL, I’ve run into a bit of a snag on a project I’m working on. I’m actually using JOGL (Java bindings for OpenGL), since I need to run this as an applet, but the code should look about the same.

What I’ve got is a polyhedral mesh - specifically, it’s a 3D model that’s entirely filled with tetrahedra and octahedra.

What I’d like to be able to do is to paint a 2D cross-section of this model, where the “cutting plane” can be adjusted in realtime. So far, I’ve been able to use a clipping plane to slice the model, but that just gives me a halved 3D model… I realize that I could check each component of the model against the clipping plane, and paint the cross-sections of each component that intersects, but the problem here as that my model has ~10,000 components, and I can’t afford to check them all.

Is there any way, if the components are stored individually in named display lists, to retrieve the indexes of the components that are clipped, so that I can just calculate cross-sections for those components?

Another option I’ve thought of would be to turn off shading in the model, fill the faces in solid colors, and only draw lines along edges that are generated by clipping the model. (So that when you look directly at the cutting-plane, it looks like a 2D cross-section). But I’m not sure how to tell OpenGL to paint those edges but not the other edges of the model, since painting interior edges as well wouldn’t look correct.

Thanks in advance for any ideas or advice! :slight_smile:

For reference, here’s an example of a model I’d use:

Here’s what I’m currently getting with the clipping plane:

And here’s what I’d like to get (albeit this is from a different model, and I’d like to preserve the original coloring)

Is there any way, if the components are stored individually in named display lists, to retrieve the indexes of the components that are clipped, so that I can just calculate cross-sections for those components?

No.

The most you might be able to do is create some kind of vertex or geometry shader that can detect whether clipping will occur and do something based on that.

One thing you can do is render backfacing polygons to the stencil buffer and then draw a big polygon that coincides with the clip plane, but only where the stencil is not zero.

Hi,

If I understood correctly you can:

  1. Using OpenGL: You can use two “very near” clipping planes in opposite direction and use feedback to read only clipped vertices.
  2. Use some tree structure and do fast intersection with the clipping plane.

I would go with 2, it is very simple to implement (many sources online) and may benefit you in other places. In work we have some optimized (static) tree for fast intersection and it take less then 1 ms to calculate the intersection of huge meshes with simple objects (plane,box,sphere…).

Ido

Thank you for the ideas everyone! I’ve had to make some changes the data-structure I’m using to represent the mesh, and based on where things are going, I think I’m going to try the tree structure suggested by Ido.

Since I exclusively need to calculate the intersection of 3,000-300,000 polyhedra with a single plane, where the plane can slide back and forth on a user-specified axis, I’m hoping I can get away with just a binary tree containing all of the polyhedra, sorted by distance along the user-specified axis.

It seems like that should allow intersections to be calculated in real-time without much trouble, even if there are a couple seconds of downtime, re-sorting the tree, when the user asks to put the plane along a new axis.

Thanks again! :slight_smile: