Debug clipping plane not working on some STEP files

Hi,

I am using the clipping plane feature in OCC 7.5.2, and the following code (I'm using python bindings from pyOCCT) works as expected on nearly all STEP files I've loaded.

shape_viewer = ShapeViewerQt(width=512, height=320)
shape_viewer.display_shape(foo, rgb=Quantity_Color(Quantity_NOC_BLUE))
shape_viewer.view.my_view.SetBackgroundColor(Quantity_Color(Quantity_NOC_BLACK))
shape_viewer.view.my_view.SetSize(192)
shape_viewer.view.view_bottom()
shape_viewer.view.my_view.SetLightOff()
shape_viewer.view.my_view.Camera().SetProjectionType(Graphic3d_Camera.Projection_Orthographic)
clip_plane_offset = 1.94
clip_plane.SetEquation(gp_Pln(0.0, 0.0, 1, clip_plane_offset))
shape_viewer.view.my_view.AddClipPlane(clip_plane)
clip_plane.SetCapping(True)
clip_plane.SetOn(True)
clip_plane.SetCappingColor(Quantity_Color(Quantity_NOC_WHITE))
shape_viewer.view.my_view.Update()

But on some STEP files (unfortunately I can't share them and haven't reproduced it on ones I can) the white capping doesn't get displayed. By moving the view around I have confirmed that the shape is in fact being clipped where I expect and that it is just the cap that isn't displaying. I have also tried changing the normal of the clip plane to see if that had an effect, but it did not.

I'm quite new to OCCT and at this point I'm not sure where or how I can continue to debug, can anyone point out an issue/way to make the clipping more robust? Or point me in a direction to find out what could be wrong when displaying these STEPS?

Thanks! Cappie

Kirill Gavrilov's picture

Capping is applied only to closed Solid objects (TopoDS_Solid). If your geometry is not closed - then this behavior is by design, as applying capping to non-closed geometry would lead to visual artifacts.

If your geometry is expected to be closed, but this is not reflected in topology, then either it should be fixed in originating CAD system produced invalid STEP file, or healed after import using OCCT algorithms like sewing. The latter is usually applied to IGES models as this old format just doesn't support preserving information about solidness, while STEP models are expected to be fine.

Cappie Pomeroy's picture

Thank you @Kirill indeed I am able to get better results using the ShapeFix_Shape and ShapeFix_WireFrame classes. I find it a little odd that other CAD programs are able to import these STEPs and section view/capping works. Do you suspect they are also running sewing algorithms after import?

The success of the fix seems to be very susceptible to the precision used i.e. precision of 0.01 doesn't work, 0.001 works as expected, and any precision with more leading zeros also fails to fix the problem. Is there a way I can tune this number programmatically? Perhaps something similar is already implemented in some IGES import source somewhere?

I'm also curious how I can know if a model needs fixed before it is used. Calling Closed() on all of my shapes (both on models which capping works and ones where it doesn't) returns False and their part types are all listed as SOLID. What kind of artifacts would occur when capping a non-closed geometry? Is there a way to force capping so that I'm able to determine if I am alright with such artifacts?

Thanks for all your help!

Kirill Gavrilov's picture

I find it a little odd that other CAD programs are able to import these STEPs and section view/capping works. Do you suspect they are also running sewing algorithms after import?

I don't have experience in this context to comment how other CAD programs implement capping view or how they import a particular STEP model - cannot say what is the key in this particular case. For certain, various CAD engines might read the same STEP file differently - due to bugs / special features in STEP files and in kernels. It might be that OCCT translator fails to import Solid model properly due to some bug, but so far I haven't heard about similar issues before.

Is there a way I can tune this number programmatically?

Shape healing process is a manual process - you cannot use the same number for all models, as for one model it will have no effect (too small value) and for another sewing will explode model into non-usable shape (too large value). Normally, this input is given to the end-user as a parameter to adjust.In specific cases, where you expect to receive models from particular system producing similar artifacts in STEP models, you may conder hard-coding healing operations / their default settings into application.

Kirill Gavrilov's picture

What kind of artifacts would occur when capping a non-closed geometry?

Just try opening mesh models in CAD Assistant. If model is not closed you will see artifacts like that (could look more localized in case if model is almost closed - with some small gaps/holes in a geometry):

Cappie Pomeroy's picture

Wow you're so great! Thanks for all the detail. I have found some models now when exported as a STEP and reimported they import with errors, so likely at least some of the issue is in their exporter.

I have FINALLY, got a test geometry that I can share that exhibits the issue. If you have the time to test with OpenCascade to see if there is an issue there that would awesome! I'll also open a ticket with Onshape to see if they can find a bug in their STEP exporter. It doesn't look like I can attach a STEP to a forum post so here's the Onshape link you'll have to right click on the part, select Export, and then select STEP from the drop down in the dialog.

Onshape's native format is parasolid and I've had enough luck so far with what I'm trying to accomplish that I've reached out about the parasolid import component to see if I can use that to avoid any of these issues as well. Thanks again for all your help!