iges mesh triangulation issue


I'm new to OpenCascade, so I apologize if my code id not fully correct.

I'm trying to traslate IGES files into our internal format (basically and indexed face set similar to the one used by the VRML) but I'm facing a problem triangulating faces imported from an IGES file.
Some of the faces have correct normals and vertex ordering, while others are reversed.
My code fails even with the provided hammer.iges test file (sse the result in the attached file).

I browsed and searched in the forum, I found some posts but I could not find any working solution fixing my problem.

Hereby I report my code:

this is the method where I adapt a TopoDS_Face to and IndexedFaceSet (a class of mine)

VIndexedFaceSet* converter::IGESConverter::adaptFace(const TopoDS_Face& face)

std::cout // meshing original shape
BRepMesh::Mesh(face, deflection);
// creating ifs structures
VIndexedFaceSet* ifs = new VIndexedFaceSet();

// accessing triangulation
TopLoc_Location loc;
const Handle(Poly_Triangulation)& triangulation = BRep_Tool::Triangulation (face, loc);

TopAbs_Orientation orient = BRepMesh_ShapeTool::Orientation(face);

if (!triangulation.IsNull()){
std::cout NbTriangles() // creating face properties for normal calculation
BRepGProp_Face prop(face);

// Adapting all nodes and realted normals
for(int i=1; iNbNodes(); i++){
gp_Pnt pt = (triangulation -> Nodes())(i).Transformed(loc);
// writing point into ifs
matrix::Vector3 ifsPoint(pt.X(), pt.Y(), pt.Z());
// calculating normal and storing into ifs
gp_Pnt2d uv = (triangulation -> UVNodes()) (i);
gp_Pnt pos;
gp_Vec faceNormal;
matrix::Vector3 ifsNormal(faceNormal.X(), faceNormal.Y(), faceNormal.Z());

// Adapting triangles
for (int j = 1; j NbTriangles(); j++)
Poly_Triangle triangle = (triangulation -> Triangles())(j);
VFace face;
for(int k=1; k VVertex vIfs;
vIfs.vertexIndex = triangle(k)-1;
vIfs.normalIndex = triangle(k)-1;


return ifs;


and this is the code where I load the file:

void converter::IGESConverter::convert(const std::string& igesFile, const std::string& outIfsFile){
// reading file into opencascade structure

IGESControl_Reader Reader;
std::cout Standard_Integer status = Reader.ReadFile(igesFile.c_str());
if(status == IFSelect_ReturnStatus::IFSelect_RetDone){
std::cout }else{
std::cout return;
// end of file reading

// transferring into opencascade shapes
const Standard_Integer roots = Reader.TransferRoots();
std::cout const Standard_Integer shapesNum = Reader.NbShapes();
std::cout // end of data transferring

// adapting shapes to ifs
VTransformGroup* mainGroup = new VTransformGroup();
for(int i=1; i TopoDS_Shape& shape = Reader.Shape(i);
// end of shapes adaptation

// writing ifs out to file
DataWriter writer(outIfsFile.c_str());
write(mainGroup, writer);
// process end


all the rest of the code is my stuff that does not affect the translation process.
Is there anybody that can help me?

Thank you very much in advance.

merve's picture

hi diego,
your code seems to be a time saving work,
thanks for sharing
but could you find a solution?

Ilya Bass's picture

Look at TopoDS_Face.Orientation(). if TopAbs_REVERSED, push vertices in the reversed order. Also flip the normals, I think...

Ilya Bass's picture

No need to flip the normals. Just reversing the vertexes is the right thing to do...