I am trying to use OpenCascade to build a mesh (OpenMesh) from an IGES-file.
My first try was to mesh the imported shape with BRepMesh_IncrementalMesh or BRepMesh_Discret.
In both triangulations there were wrong normals.
I dont see any errors in OpenCascade, but when I export the mesh to OpenMesh, it sais there are complex edges.
This means there are edges that have 3 neighbouring faces.
In my second attempt I wrote an STL-File with StlAPI_Writer and imported the stlfile to OpenMesh with the included stl-reader.
The effect was the same. I guess StlAPI_Writer uses the triangulation created by BRepMesh.
I dont really know what is wrong here.
Searching this forum I noticed there are many problems with normals in triangulations from IGES files, so I guess this is the problem.
Does anyone know how to fix the wrong normals?
I forgot to mention that I already use shapehealing to sew faces.
Everything seems to be fine when I use STEP files instead.
Oh, fine was exaggerated. Lets say its better :(
check the Face Orientation. If the Orientation is different between different faces then also the normals of the mesh you generate will point to the wrong side.
I did quite a lot of mesh stuff with OCC and this was the way I used to solve that problems.
thanks for your answer.
Can you elaborate a bit on this?
and then I check its orientation with
if(F.Orientation() = TopAbs_REVERSED )
//add vertices counterclockwise to the Openmesh Datastructure
//add vertices clockwise
Then Openmesh calculates the normal by itself.
Do you mean I should set the orientation of each face to either Reversed or Forward?
I just tried it, the normals are also messed up when all TopoDS_faces have the same orientation :(
You can invert them to a specific direction if a certain treshold value is reached. For example if 60% of the normals show in one direction you can use this direction as the "guiding" direction and invert all the other triangle normals as well.
Before we do it like that we check the orientation agains 0,0,1 and then decide to which direction we invert the normals.
I played a bit with the triangulation of OpenCascade and I came to the conclusion that the normals are not the problem.
I am not sure if this is your problem, but you are not accounting for the face location in your triangulation. It is possible that 2 faces share the same triangulation but one is a transformed version of the other. Your points need to be transformed as well: