- TopExp_Explorer expface( theMesh->ShapeToMesh(), TopAbs_FACE );
- for ( int i = 0; expface.More(); expface.Next(), i++ ) {
- tabID[i] = 0;
- aShape = expface.Current();
- shapeID = theMesh->ShapeToIndex( aShape );
- idFound = false;
- for ( int j=0; j<=i; j++) {
- if ( shapeID == tabID[j] ) {
- idFound = true;
- break;
- }
- }
- if ( ! idFound ) {
- tabID[i] = shapeID;
- tabShape[i] = aShape;
- theSubMesh = theMesh->MeshElements( aShape );
- if ( theSubMesh )
- nbFaces += theSubMesh->NbElements();
+ TopTools_IndexedMapOfShape facesMap;
+ TopExp::MapShapes( theShape, TopAbs_FACE, facesMap );
+
+ // 2 adaptors for each face in facesMap, as a face can belong to 2 solids
+ typedef vector< StdMeshers_QuadToTriaAdaptor* > TwoAdaptors;
+ vector< TwoAdaptors > qttaByFace;
+ if ( theQuad2Trias.empty() )
+ {
+ // case w/o quadrangles
+ for ( int i = 1; i <= facesMap.Extent(); ++i )
+ if (( theSubMesh = theMesh->MeshElements( facesMap(i))))
+ nbTriangles += theSubMesh->NbElements();
+ }
+ else
+ {
+ // case with quadrangles
+ qttaByFace.resize( facesMap.Extent() );
+ for ( unsigned i = 0; i < theQuad2Trias.size(); ++i )
+ {
+ TopoDS_Shape solid = theQuad2Trias[i].GetShape();
+ TopExp_Explorer expface( solid, TopAbs_FACE );
+ for ( ; expface.More(); expface.Next() )
+ if (( theSubMesh = theMesh->MeshElements( expface.Current()) ))
+ {
+ const int faceIndex = facesMap.Add( expface.Current() );
+ TwoAdaptors& aTwoAdaptors = qttaByFace[ faceIndex-1 ];
+ const bool newFaceEncounters = aTwoAdaptors.empty();
+ aTwoAdaptors.push_back( & theQuad2Trias[i] );
+
+ // on a shared face encountered for the second time
+ // we count only triangles of pyramids
+ const int countTrias = int( newFaceEncounters );
+ itOnSubMesh = theSubMesh->GetElements();
+ while ( itOnSubMesh->more() )
+ {
+ aFace = itOnSubMesh->next();
+ if ( aFace->NbCornerNodes() != 4 )
+ nbTriangles += countTrias;
+ else if ( TTriaList* trias = theQuad2Trias[i].GetTriangles( aFace ))
+ nbTriangles += trias->size();
+ else
+ nbTriangles += countTrias;
+ }
+ }