IGES import, unexpected results

I am interested in using OCC for the import of IGES data in order to obtain a surface triangulation of the contained root entities. These triangulations are then exported to our own proprietary formats aa a basis for FE mesh generation.
I have an IGES file which displays correctly in the sample Import/Export application. After processing I see the triangulated root entities but not arranged correctly, see fig1.bmp. The pertinant code I am using is shown below taken mainly from the elevant OCC documentation and samples.

// Read file
stat = igesReader.ReadFile(filename);
if (stat == IFSelect_RetDone ) {
myRoots = igesReader.GiveList("iges-visible-transf-roots");
nIgesRoots = myRoots->Length();
readingType = readingIges;
return(nIgesRoots);
} else {
igesReader.PrintCheckLoad(TRUE, IFSelect_ItemsByEntity);
return(0);
} /* if */
.....
// Get root entity
ent = myRoots->Value(index);
// Expand, to get any label
igesEntity = Handle(IGESData_IGESEntity)::DownCast(ent);
if (!igesEntity.IsNull()) {
if (igesEntity->HasShortLabel()) {
Handle(TCollection_HAsciiString) aLabel=igesEntity->ShortLabel();
aName = occ_string(aLabel->ToCString());
} /* if */
} /* if */
// Translate
ok = igesReader.TransferEntity(ent);
if (ok) {
TopoDS_Shape sh;
// Get the shape(s)
sh = igesReader.OneShape();
// and triangulate
BRepMesh::Mesh(sh, 1);
nt = 0;
ntri = 0;
// for each face
for (TopExp_Explorer ex(sh, TopAbs_FACE) ; ex.More(); ex.Next()) {

TopoDS_Face F = TopoDS::Face(ex.Current());
TopLoc_Location L;
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
TColgp_Array1OfPnt tab(1, (facing->NbNodes()));
tab = facing->Nodes();
nt = facing->NbTriangles();
Poly_Array1OfTriangle tri(1, nt);
tri = facing->Triangles();
triangles = (OccTriangle *)realloc(triangles, (nt+ntri)*sizeof(OccTriangle));
// for each triangle
for (i=1; i Poly_Triangle trian = tri.Value(i);
Standard_Integer index1,index2,index3,M,N;
trian.Get(index1,index2,index3);
gp_Pnt p;
Standard_Real x, y, z;
p = tab.Value(index1);
x = p.X(); y = p.Y(); z = p.Z();
triangles[ntri].p1.x = (float)x; triangles[ntri].p1.y = (float)y; triangles[ntri].p1.z = (float)z;
p = tab.Value(index2);
x = p.X(); y = p.Y(); z = p.Z();
triangles[ntri].p2.x = (float)x; triangles[ntri].p2.y = (float)y; triangles[ntri].p2.z = (float)z;
p = tab.Value(index3);
x = p.X(); y = p.Y(); z = p.Z();
triangles[ntri].p3.x = (float)x; triangles[ntri].p3.y = (float)y; triangles[ntri].p3.z = (float)z;
ntri++;
} /* for */
} /* for */
*nTri = ntri;
*tri = triangles;
} else {
igesReader.PrintCheckTransfer(TRUE, IFSelect_ItemsByEntity );
st = 1;
} /* if */
igesReader.PrintCheckTransfer(FALSE, IFSelect_ItemsByEntity );

I should add that the code above has workeed successfully for other IGES files.
Any help on what is going wrong would be greatly appreciated.

Attachments: 
Francois Lauzon's picture

Hello Alan,
you might want to look at the TopLoc_Location of your triangulation, in some case is it the Identity matrix, so you don't have to worry about it, but in some other case there is an actual transformation, so you should transform your Triangulation Node and Normals before assigning them to your own internal triangles data structure.

Good Luck,
Francois.

adavies's picture

Many thanks Francois, that was indeed the problem, locating and using the local transformation matrix for each root shape produced the results I expected.

May I wish you a Happy Christmas and a Peaceful New Year.