I need some help with the Shape Healing functions

I need some help with the Shape Healing functions of OpenCascade, please.

I am loading in shapes from STEP files. Most of them are OK, but some of them need a little fixing - getting rid of tiny faces, ensuring that wires are closed, that sort of thing.
I need to do this at a Shape level (rather on each face in isolation ), as I need to get the face/edge adjacency information when I'm done.

I have looked at the notes here:
And tried several approaches, with partial success, but i'm not getting quite the results I want.

I have one particular STEP file, that has the two problems I want to fix:   
1) There is a tiny triangular face that I want to merge with a large face that it is co-planar with.
See the attached screenshot

2) Several of that faces have wires that don't quite join up, 
eg the first point of the first edge and the last point of the last edge are very close, but not quite the same.
What is the best way to fix these problems? 

To fix 1), I have done the following:
The trianlge has a max dimension of approx 0.4

    TopoDS_Shape inputShape;// This is loaded in from the step file
    ShapeFix_FixSmallFace aFixSmallFaces;            
    TopoDS_Shape aResShape = aFixSmallFaces.FixShape();

This works in that it merges the small face with the larger, but this new  face has 2 wires;
one edge with the new perimeter (good!) and another that edge has no Geom_Curve associated with it (bad!)
I was expecting just the first wire. 
Is it even valid to have an edge without an associated curve?
Is there any way to remove this edge from the shape?

To fix 2) I have done the following:
    ShapeFix_Wireframe fix_tool(aResShape);
    fix_tool.ModeDropSmallEdges() = Standard_True;                                
    fix_tool.SetPrecision(0.05); //yes!                
    TopoDS_Shape new_shape = fix_tool.Shape();

This usually works, but sometimes does not close the wire, even when the gap is less than SetPrecision().

Is there a standard approach to fixing shapes loaded files?
Are there any good examples? (I can't find any!)

Should I be using  ShapeFix_Shape, ShapeFix_Face ShapeFix_Wire?
Something like:
        Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape();
        Handle(ShapeFix_Face)  sff = sfs->FixFaceTool();
        Handle(ShapeFix_Wire)  sfw = sfs->FixWireTool();
        sfs->FixSolidMode() = 1;
        //parameters for ShapeFix_Face
        sff->FixWireMode() = 1;
        //parameters for ShapeFix_Wire
        sfw->ModifyTopologyMode() = Standard_True; 
        TopoDS_Shape resShape = sfs->Shape();

If so, which of the many parameters should I be using?
What is the relationship (if any) between the classes ShapeFix_FixSmallFace and ShapeFix_Shape ?
Is ShapeFix_FixSmallFace contained anywhere in ShapeFix_Shape?
Sorry, that's a lot of questions - help with any of them appreciated! 
Merry Xmas!

qa qa's picture

ShapeFix_Shape is entry point for shape fix classes. Internally it uses corresponding classes like ShapeFix_Face, ShapeFix_Edge and so on. Of course, you can use particular fixing classes but this process requires some experience.

Jim Williams's picture

Thank you.

How do I access ShapeFix_FixSmallFace from ShapeFix_Shape?

Is this possible?


Qr Qr's picture

Hi Jim,

Can you share some dirty STEP file here, so we can experiment on it? Do you use Draw? There is "fixshape" command in it with a number of options.

It is probably worth pointing out that shape healing is sometimes something more than ShapeFix package offers. E.g for face maximization and stitching there are dedicated components in OpenCascade: sewing and "unify same domain" tools.

Anyway, it will just more instructive if you share a model.

qa qa's picture

Hi Jim,

If you want to tune healing parameters in ShapeFix_Shape you should use FixFaceTool() method (and similar ones) to get underlying fixing utility. After that you can set particular instructions related to the healing process. It can be done by usage of the FixSmallAreaWireMode() method and other ones.

Giovanni Bettega's picture

Hi Jim, you should have a look at the file OCCgeometry.cpp within the Netgen srcs

​Regards G

Giovanni Bettega's picture

Hi Jim, you should have a look at the file OCCgeometry.cpp within the Netgen srcs

​Regards G

Giovanni Bettega's picture

Hi Jim, you should have a look at the file OCCgeometry.cpp within the Netgen srcs

​Regards G

Jim Williams's picture

Thank you, I'll take a look there.

Jim Williams's picture

For reference, the URLs to download NetGen are:



And the file referred to is occgeom.cpp

The function of most relevance seems to be: 

void OCCGeometry :: HealGeometry ()