+//================================================================================
+/*!
+ * \brief Return nb triangles in a decomposed mesh face
+ * \retval int - number of triangles
+ */
+//================================================================================
+
+static int getNbTriangles( const SMDS_MeshElement* face)
+{
+ // WARNING: counting triangles must be coherent with getTriangles()
+ switch ( face->GetEntityType() )
+ {
+ case SMDSEntity_BiQuad_Triangle:
+ case SMDSEntity_BiQuad_Quadrangle:
+ return face->NbNodes() - 1;
+ // case SMDSEntity_Triangle:
+ // case SMDSEntity_Quad_Triangle:
+ // case SMDSEntity_Quadrangle:
+ // case SMDSEntity_Quad_Quadrangle:
+ // case SMDSEntity_Polygon:
+ // case SMDSEntity_Quad_Polygon:
+ default:
+ return face->NbNodes() - 2;
+ }
+ return 0;
+}
+
+//================================================================================
+/*!
+ * \brief Decompose a mesh face into triangles
+ * \retval int - number of triangles
+ */
+//================================================================================
+
+static int getTriangles( const SMDS_MeshElement* face,
+ const SMDS_MeshNode** nodes)
+{
+ // WARNING: decomposing into triangles must be coherent with getNbTriangles()
+ int nbTria, i = 0;
+ SMDS_NodeIteratorPtr nIt = face->interlacedNodesIterator();
+ nodes[ i++ ] = nIt->next();
+ nodes[ i++ ] = nIt->next();
+
+ const SMDSAbs_EntityType type = face->GetEntityType();
+ switch ( type )
+ {
+ case SMDSEntity_BiQuad_Triangle:
+ case SMDSEntity_BiQuad_Quadrangle:
+ nbTria = ( type == SMDSEntity_BiQuad_Triangle ) ? 6 : 8;
+ nodes[ i++ ] = face->GetNode( nbTria );
+ while ( i < 3*(nbTria-1) )
+ {
+ nodes[ i++ ] = nodes[ i-2 ];
+ nodes[ i++ ] = nIt->next();
+ nodes[ i++ ] = nodes[ 2 ];
+ }
+ nodes[ i++ ] = nodes[ i-2 ];
+ nodes[ i++ ] = nodes[ 0 ];
+ nodes[ i++ ] = nodes[ 2 ];
+ break;
+ default:
+ // case SMDSEntity_Triangle:
+ // case SMDSEntity_Quad_Triangle:
+ // case SMDSEntity_Quadrangle:
+ // case SMDSEntity_Quad_Quadrangle:
+ // case SMDSEntity_Polygon:
+ // case SMDSEntity_Quad_Polygon:
+ nbTria = face->NbNodes() - 2;
+ nodes[ i++ ] = nIt->next();
+ while ( i < 3*nbTria )
+ {
+ nodes[ i++ ] = nodes[ 0 ];
+ nodes[ i++ ] = nodes[ i-2 ];
+ nodes[ i++ ] = nIt->next();
+ }
+ break;
+ }
+ return nbTria;
+}
+