DiscussionsIssue archiveData Exchange and Application Framework

Archived discussion

Fix faces with error orientation

Data Exchange and Application FrameworkTue, 08/04/2020 - 04:558 replies

Browse this forum
QuestionAuthor

I have a .iges file, which contains faces with error orientation. That is, some faces point inside, while others point outside.

I convert it to obj and get 001.png.

I sew faces and get 002.png.

I sew faces and then combine shells to a solid and get 003.png, which is still not correct.

What shoud I do to fix those faces?

 

 

Discussion

8 archived replies

Posts are displayed in their archived order.

01Commenter-1

Sharing a model (input IGES, sewed results and created Solid in .BREP format) would be useful to make any comment.

02Author

This is another .igs file which has similar problems.

Actually, I found that many .igs models have faces with error orientation.

Like 004.png and 005.png. Maybe this is an common issue for igs files.

Here is my code:

// import iges file
IGESControl_Reader igesReader = IGESControl_Reader();
Standard_Integer status = igesReader.ReadFile(file);
igesReader.TransferRoots();
// get shape
TopoDS_Shape igesTopoShape = igesReader.OneShape();
// sewing the shape
BRepBuilderAPI_Sewing sewing = BRepBuilderAPI_Sewing();
sewing.Add(igesTopoShape);
sewing.Perform();
TopoDS_Shape sewedShape = sewing.SewedShape();

// try make solid with shells
BRepBuilderAPI_MakeSolid makeSolid;
for (TopExp_Explorer anExp(sewedShape, TopAbs_SHELL); anExp.More(); anExp.Next())
{
    TopoDS_Shell shell = TopoDS::Shell(anExp.Current());
    makeSolid.Add(shell);
}
makeSolid.Build();
TopoDS_Solid solid = makeSolid.Solid();

// add left faces
TopoDS_Compound allShapes;
BRep_Builder aBuilder;
aBuilder.MakeCompound(allShapes);
aBuilder.Add(allShapes, solid); // add solid
for (TopExp_Explorer anExp(sewedShape, TopAbs_FACE); anExp.More(); anExp.Next())
{
    TopoDS_Face face = TopoDS::Face(anExp.Current());
    bool faceInSolid = false;
    // check if face is in solid
    for (TopExp_Explorer anExp2(solid, TopAbs_FACE); anExp2.More(); anExp2.Next())
    {
        TopoDS_Face face2 = TopoDS::Face(anExp2.Current());
        if (face == face2)
        {
            faceInSolid = true;
            break;
        }
    }
    if (!faceInSolid)
    {
        // face not in solid: add to allShapes
        // not to add face twice
        aBuilder.Add(allShapes, face);
    }
}


03Commenter-2

I haven't had any orientation problems with the .igs files before, to be honest

04Commenter-1

Sewing does work for me on a given shape with a reasonable tolerance - wholes between triangulated Faces do not appear and normals are oriented consistently.
Probably you should check the tolerance - algorithm does not sew any faces, only close enough, and geometry tolerance within IGES model might be larger than you expect.

Archived image: external image

pload XDE MODELING VISUALIZATION
vclear
vclose *
# import IGES file
testreadiges 8878777_0.igs i
nbshapes i
# display original shape with oriented normals
incmesh i 1
vinit v1/v1
vnormals i on -length 3 -useMesh -oriented 1
vsetdispmode i 1
vfit
vsetcolor i ORANGE4
# export original shape into i.obj file
wavefront i i

# perform sewing with tolerance=1.0
sewing s 1.0 i
nbshapes s
# display sewed shape with oriented normals
incmesh s 1
vinit v2/v1
vnormals s on -length 3 -useMesh -oriented 1
vfit
vsetdispmode s 1
vsetcolor s GREEN4
# export sewed shape into s.obj file
wavefront s s

Original shape:

Draw[5]> nbshapes i
Number of shapes in i
 VERTEX    : 72
 EDGE      : 74
 WIRE      : 6
 FACE      : 4
 SHELL     : 0
 SOLID     : 0
 COMPSOLID : 0
 COMPOUND  : 1
 SHAPE     : 157

Result shape (SHELL appeared and several EDGES merged):

Draw[13]> nbshapes s
Number of shapes in s
 VERTEX    : 64
 EDGE      : 66
 WIRE      : 6
 FACE      : 4
 SHELL     : 1
 SOLID     : 0
 COMPSOLID : 0
 COMPOUND  : 0
 SHAPE     : 141
05Commenter-1

Actually, I found that many .igs models have faces with error orientation.

IGES format does not support a proper Solid definition, so that surfaces orientations might be arbitrary and edges between faces duplicated.
This is expected for IGES files, considering limitations of this old format.

STEP format is much more advanced in this aspect and allows preserving correct Solid definition (if it existed in originating CAD software) .
Hence, this format is preferable for data exchange, when possible.

06Author

THANKS SO MUCH. This really solve my problem. The sewing fixes face orientation problems well if I use a proper tolerance.

BRepBuilderAPI_Sewing sewing = BRepBuilderAPI_Sewing(1.0);
sewing.Add(igesTopoShape);
sewing.Perform();
TopoDS_Shape sewedShape= sewing.SewedShape();
07Commenter-1

Note, that 1.0 is just an arbitrary number. Tolerance should be defined based on some other information (like a user input / knowledge of typical models / something else).

08Commenter-2

Thank you for the detailed explanation, Kirill, as always very informative.