Holes while importing from iges

Hi all,

I'm loading an iges file with IGESControl_Reader, meshing each face in the shape with StlTransfer::BuildIncrementalMesh and triangulating with BRep_Tool::Triangulation; visualization is done in my own app.

It seems to work quite good, but with a problem; vertex of triangles do not match along surfaces contact borders and holes appears. see images below:

This is probably due to the fact that I'm triangulating each surface indipendently, but no idea how to do it in a different way.

Any ideas? Hints?
Any help appreciated, thanks!


Rob Bachrach's picture

Instead of meshing the faces individually, mesh the entire shape (shell or solid) as a single object. Then, loop through the faces to query the triangulation.

By the way, unless you are using the StlMesh returned from StlTransfer::BuildIncrementalMesh, you can get the mesh faster and maintain better control with BRepMesh_Discret and BRepMesh_IncrementalMesh.


josef.grunig's picture

Hi Rob,

I'm sorry, but I'm quite new to OpenCascade and I'm not sure to have understand correctly.

Now I'm computing the mesh on the whole shape
StlTransfer::BuildIncrementalMesh (Shape, theDeflection, Mesh);

and looping through the faces
for (TopExp_Explorer itf(Shape,TopAbs_FACE); itf.More(); itf.Next())

and triangulating with
TopoDS_Face face = TopoDS::Face(itf.Current());
Handle(Poly_Triangulation) theTriangulation = BRep_Tool::Triangulation(face, Loc);

but still get holes on contact borders. Am I missing something?
It's ok for me to use BRepMesh_Discret and BRepMesh_IncrementalMesh, but no idea where to start from. Can you point me to some sample?

Thankyou for your help and time,

Josef Grunig

Fotis Sioutis's picture

Hello Josef

Usually IGES files suffer from precision problems (when transfering from one CAD system to another...).It might be the case that faces are not sewed properly, or do not have the right precision, and so the tesselator does not treat them like "sewed", and you have the results you mention.

Try to apply a Shape Fix on the shape, using the ShapeHealing package.There is a big chance that you will solve your problem.



josef.grunig's picture

Hi Fotis,

I've tried healing right after loading shape

BRepOffsetAPI_Sewing face_sewer (0.001);
TopExp_Explorer explorer (Shape1, TopAbs_FACE);
while (explorer.More ())
face_sewer.Add (explorer.Current ());
explorer.Next ();
face_sewer.Perform ();
TopoDS_Shape Shape = face_sewer.SewedShape ();
// build mesh...
StlTransfer::BuildIncrementalMesh (Shape, theDeflection, Mesh);

with two surfaces it works quite good, but with a bigger model of 71 surfaces it does not sew every border. Do you suggest other Healing methods?

Loading with IGESControl_Reader in debug, I have this output for each face:
Warning: IGESToBRep_IGESBoundary: Deviation = 7.76636
Warning: IGESToBRep_IGESBoundary: 3D and 2D curves are inconsistent; 3D is ignored
Does it mean something?


Fotis Sioutis's picture

I have two suggestions for your case.

1)BRepOffsetAPI_Sewing with a smaller tollerance value.The tollerance value is the distance between faces in order to be sewed.

2)Use of the generic ShapeFix_Shape class might work also !.Try to read the Shape Healing user guide pdf in the package in order to see how to use this class !

I really do not have a clue on what the message about the inconsistent curves mean.I will try to dig the IGESToBRep_IGESBoundary code a bit and i will post my findings.


Fotis Sioutis

Bearloga's picture

I think sewing should be done with a larger tolerance, to sew larger gaps between faces. Warning in iges reader probably tells that 2d curve and 3d curve of some edge do not correspond to each other, i.e. there is a distance between 3d curve and restored in 3d space 2d curve. In such case the code removes 3d curve. After that two adjacent faces will have two different 3d curves for their common boundary, and a gap will occur.

P G's picture

Can u share the IGES file ?
I need to test it in my environment where I have used OCC

thanks in advance
- PG

josef.grunig's picture

Here is the model simplified down to 2 surfaces:


let me know...


LIU's picture

I have the same problem. I have tried to use the class ShapeFix_Shape , but it doesn't work, Perhaps I haven't used it in right way.

If you have resolved it , Please tell me your methode?

Thanks in advance!


Matthias Teich's picture

This is what I do to obtain a correct IGES-shape:
ShapeFix_Shape fixer(shape);
BRepBuilderAPI_Sewing sew;
shape = sew.SewedShape();

Maybe it helps.

LIU's picture

Hi Matthias,
It works, thanks a lot!

now there is anthoer problem of sewing when the IGES file has many top-level shapes(read file by XDE). There is the holes between some top-level shapes. I have tried to sew all top-level together , so I have added all top-level shapes in a compound, then sew this compound, My code is fowlling :
BRep_Builder l_Builder;
TopoDS_Compound l_Compound;

Handle (XCAFDoc_ShapeTool) l_ShapeTool = XCAFDoc_DocumentTool::ShapeTool (m_Document->Main());

for ( i =1; i <= TopLevelShape_Labels.Length(); i++)
TopoDS_Shape l_Shape = ShapeTool->GetShape(TopLevelShape_Labels.Value(i));
l_Builder.Add(l_Compound, l_Shape);

ShapeFix_Shape Fixer(l_Compound);
BRepBuilderAPI_Sewing Sew;
l_Compound = Sew.SewedShape();
// here is the problem , it can'tconvert
//TopoDS_Shape to TopoDS_Compound;

I will use again all top-level shapes sewed, That is why I tried to sew them together. Can anyone kown how to sew all top-level shapes together? any help will be appreciated.

Thanks in advance