# Decomposing geometry into triangles

Hi guys,

I'm writing an IGES to X3D converter using SALOME's python TUI. My algorithm works as follows:

1. Import IGES geometry using SALOME's geom

2. Extract all faces from geometry

3. Extract all vertices from each face

4. Get vertices coordinates

5. Write all faces and its vertices using the X3D format

My problem is that vertices are exported on a random order (they do not follow the right hand rule), so this means that the geometry in X3D does not display correctly. So, what am I doing wrong?

PS: I know I can check the vertex list and organize it using the right hand rule, but for this I need to know the face's normal and also this seems like an unnecessary extra step.

My code:

http://pastebin.com/xFMhqnJV

Thanks!

Hi

Switch off sorting when you extract vertices:

geom.ExtractShapes(face, geom.ShapeType["VERTEX"], **isSorted = False**)

St.Michael

Thanks for the reply Saint Michael.

I got better results, but some faces are still not showing. Here is my updated code:

http://pastebin.com/NJdE0kkW

I also checked the coordinates by hand, just to make sure that this was not the problem with the X3D viewer and it seems that my first guess was correct: points are out of order.

On a simple rectangular face with 4 vertices. The vertices are extracted on this order:

3--------4

| |

1--------2

It seems that there is no a GEOM function to get ordered vertices from a face. As a workaround I can propose generating a mesh on your geometry and get nodes from mesh faces. This way you get ordered nodes.

The code to make the mesh and retrieve ordered nodes follows.

mesh = smesh.Mesh( root_shape )

mesh.Segment().NumberOfSegments( 1 )

mesh.Polygon()

mesh.Compute()

for node in mesh.GetNodesId():

x,y,z = mesh.GetNodeXYZ( node )

for face in mesh.GetElementsByType( SMESH.FACE ):

nodes = mesh.GetElemNodes( face )

St.Michael