:doh:
I have a project, which requires to intersect anatomical mesh objects along specified axis (e.g. from head to foot) into a series of 2D gray-level slices. I used OpenGL stencil buffer with defined clipping plane to generate 2D slices.
For most of mesh objects, I can obtain good 2D intersected slices. But some mesh objects, like heart and trachea, with more tubes not-enclosed (airways, arteries, veins), this clipping algorithm did not work well. After stacking 2D slices to a volume, it looks to be extended along the end of tube to the bottom. Fig. 1 is the mesh object with texturing, Fig.2 shows each slice and Fig. 3 the stacked volume.

Please help find possible reasons for this issue, and any helpful suggestions are welcome.
2455 2456 2457

saveStencilBufferToExtraMemory(…, …); // using "glReadPixels()" to read the stencil buffer and save to memory and then to a file

glDisable(GL_DEPTH_TEST);

glDisable(GL_STENCIL_TEST);
glClear(GL_STENCIL_BUFFER_BIT);

john_connor

08-16-2017, 04:04 PM

i'd try to use a 3D texture to store the "slices", or an 2D array texture, but that would require to program your own pipeline (without legacy GL functions).

for example, you disable depth testing / culling / stencil test etc, and attach a 3D texture to an framebuffe object, then use a simple vertex + fragment shader to render the meshes as usual, but in the fragment shader you use the fragments depth value to determine the final 3D texture texel in which to write the resulting color.

when you want to visualize an arbitrary "slice", render a simple textured quad (use the generated 3D texture), depending on the orientation of your quad you can look into arbitrary positions on the mesh.

GClements

08-17-2017, 04:53 AM

For most of mesh objects, I can obtain good 2D intersected slices. But some mesh objects, like heart and trachea, with more tubes not-enclosed (airways, arteries, veins), this clipping algorithm did not work well.
Is the presence of uncapped tubes the only feature of the problematic meshes? Are they 2-manifold surfaces otherwise? Is face winding consistent (i.e. are front/back faces identified correctly)? Does it make any difference if you use a single pass (both front and back faces) with GL_INVERT?

I can't think of any explanation for the vertical "smear" in the third attachment. It shouldn't be possible to modify the stencil value of any pixel which isn't covered by at least one surface.

i'd try to use a 3D texture to store the "slices"
He isn't rendering voxel data. He's rendering meshes, using stencilling to detect regions which are made "open" by clipping.

michael_ca

08-17-2017, 09:17 AM

Thank very much you guys.
GClements' hints are enlightening me. I am now checking my meshes and capping code.

My mesh rendering looks good. I have intersected bones, lungs, kidneys, colon, and 2D capping looks very well. Only the capping for trachea, heart, stomach did not work well. Especially the result of intersecting for human heart mesh is so bad, because it has more uncapped tubes.

In these objects, definition for the position of some meshes is mirrored(scale value is negative). Before capping, I changed the face winding direction (from GL_CCW to GL_CW). Only these meshes with uncapped tubes can not work.

I also tried to use more passing processing. But till now, I did not get good results yet.

Is the presence of uncapped tubes the only feature of the problematic meshes? Are they 2-manifold surfaces otherwise? Is face winding consistent (i.e. are front/back faces identified correctly)? Does it make any difference if you use a single pass (both front and back faces) with GL_INVERT?

I can't think of any explanation for the vertical "smear" in the third attachment. It shouldn't be possible to modify the stencil value of any pixel which isn't covered by at least one surface.

He isn't rendering voxel data. He's rendering meshes, using stencilling to detect regions which are made "open" by clipping.

michael_ca

11-02-2017, 12:58 PM

Hello everybody,

Finally I got very perfect volumes. GClements' suggestion is very helpful.

I first tried my static model, and found the problem's core is hole issue. I used meshlab to close hole and run my code, it worked.

Because my major interest is on dynamic data. I applied my needed vcglib (that meshlab uses) functions to my code, keeping the original vertices of mesh, no change was made.