+namespace
+{
+
+ //================================================================================
+ /*!
+ * \brief Checks structure of a quadrangular mesh at the common VERTEX of two EDGEs.
+ * Returns true if there are two quadrangles near the VERTEX.
+ */
+ //================================================================================
+
+ bool isContinuousMesh(TopoDS_Edge E1,
+ TopoDS_Edge E2,
+ const TopoDS_Face& F,
+ const SMESH_ProxyMesh& mesh)
+ {
+ if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
+ E1.Orientation( TopAbs_FORWARD );
+ if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
+ E2.Orientation( TopAbs_FORWARD );
+
+ TopoDS_Vertex V;
+ if ( !TopExp::CommonVertex( E1, E2, V )) return false;
+
+ const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
+ if ( !n ) return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
+
+ n = mesh.GetProxyNode( n );
+
+ const SMESHDS_SubMesh* sm = mesh.GetSubMesh( F );
+ if ( !sm ) return false;
+
+ int nbQuads = 0;
+ SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
+ if ( !fIt->more() )
+ return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
+ while ( fIt->more() )
+ {
+ const SMDS_MeshElement* f = fIt->next();
+ if ( !sm->Contains( f )) continue;
+
+ if ( f->NbCornerNodes() == 4 )
+ ++nbQuads;
+ else
+ return false;
+ }
+ return nbQuads == 2;
+ }
+
+ //================================================================================
+ /*!
+ * \brief Return true if a vertex holds a node and this node is used by some quadrangle
+ */
+ //================================================================================
+
+ // bool isMeshedVertex( TopoDS_Vertex& V,
+ // const SMESH_Mesh& mesh )
+ // {
+ // const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
+ // if ( !n ) return false;
+
+ // SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
+ // while ( fIt->more() )
+ // {
+ // const SMDS_MeshElement* f = fIt->next();
+ // if ( f->NbCornerNodes() == 4 )
+ // return true;
+ // }
+ // return false;
+ // }
+
+ //================================================================================
+ /*!
+ * \brief Finds VERTEXes located at block corners
+ */
+ //================================================================================
+
+ void getBlockCorners( SMESH_ProxyMesh& mesh,
+ const TopoDS_Shape& shape,
+ TopTools_MapOfShape& cornerVV)
+ {
+ std::set<int> faceIDs; // ids of FACEs in the shape
+ TopExp_Explorer exp;
+ for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next() )
+ faceIDs.insert( mesh.GetMeshDS()->ShapeToIndex( exp.Current() ));
+
+ TopTools_MapOfShape checkedVV;
+ for ( exp.Init( shape, TopAbs_VERTEX ); exp.More(); exp.Next() )
+ {
+ TopoDS_Vertex V = TopoDS::Vertex( exp.Current() );
+ if ( !checkedVV.Add( V )) continue;
+
+ const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
+ if ( !n ) continue;
+
+ const SMDS_MeshNode* nProxy = mesh.GetProxyNode( n );
+ bool isProxy = ( nProxy != n );
+ n = nProxy;
+
+ int nbQuads = 0;
+ SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
+ while ( fIt->more() )
+ {
+ const SMDS_MeshElement* f = fIt->next();
+ if ( !faceIDs.count( f->getshapeId() )) continue;
+
+ if ( isProxy && !mesh.GetSubMesh( f->getshapeId() )->Contains( f ))
+ continue;
+
+ if ( f->NbCornerNodes() == 4 )
+ ++nbQuads;
+ else
+ nbQuads = 100;
+ }
+ if ( nbQuads == 3 )
+ cornerVV.Add( V );
+ }
+ }
+
+ //================================================================================
+ /*!
+ * \brief Return EDGEs dividing one box side
+ */
+ //================================================================================
+
+ bool getInternalEdges( SMESH_Mesh& mesh,
+ const TopoDS_Shape& shape,
+ const TopTools_MapOfShape& cornerVV,
+ TopTools_MapOfShape& internEE)
+ {
+ TopTools_IndexedMapOfShape subEE, subFF;
+ TopExp::MapShapes( shape, TopAbs_EDGE, subEE );
+ TopExp::MapShapes( shape, TopAbs_FACE, subFF );
+
+ TopoDS_Vertex VV[2];
+ TopTools_MapOfShape subChecked, ridgeEE;
+ TopTools_MapIteratorOfMapOfShape vIt( cornerVV );
+ for ( ; vIt.More(); vIt.Next() )
+ {
+ TopoDS_Shape V0 = vIt.Key();
+ // walk from one corner VERTEX to another along ridge EDGEs
+ PShapeIteratorPtr riIt = SMESH_MesherHelper::GetAncestors( V0, mesh, TopAbs_EDGE );
+ while ( const TopoDS_Shape* riE = riIt->next() )
+ {
+ if ( !subEE.Contains( *riE ) || !subChecked.Add( *riE ))
+ continue;
+ TopoDS_Edge ridgeE = TopoDS::Edge( *riE );
+ while ( !ridgeE.IsNull() )
+ {
+ if ( !ridgeEE.Add( ridgeE ))
+ break;
+ TopExp::Vertices( ridgeE, VV[0], VV[1] );
+ TopoDS_Shape V1 = VV[ V0.IsSame( VV[0] )];
+ if ( cornerVV.Contains( V1 ) )
+ break; // ridgeE reached a corner VERTEX
+
+ // detect internal EDGEs among those sharing V1. There can be 2, 3 or 4 EDGEs and
+ // number of internal EDGEs is N-2
+ TopoDS_Shape nextRidgeE;
+ PShapeIteratorPtr eIt = SMESH_MesherHelper::GetAncestors( V1, mesh, TopAbs_EDGE );
+ while ( const TopoDS_Shape* E = eIt->next() )
+ {
+ if ( E->IsSame( ridgeE ) || !subEE.Contains( *E ) || !subChecked.Add( *E ))
+ continue;
+ // look for FACEs sharing both E and ridgeE
+ PShapeIteratorPtr fIt = SMESH_MesherHelper::GetAncestors( *E, mesh, TopAbs_FACE );
+ while ( const TopoDS_Shape* F = fIt->next() )
+ {
+ if ( !SMESH_MesherHelper::IsSubShape( ridgeE, *F ))
+ continue;
+ if ( !subFF.Contains( *F ))
+ continue;
+ if ( isContinuousMesh( ridgeE, TopoDS::Edge( *E ), TopoDS::Face( *F ), mesh ))
+ {
+ nextRidgeE = *E;
+ }
+ else
+ {
+ internEE.Add( *E );
+ }
+ break;
+ }
+ }
+ // look for the next ridge EDGE ending at V1
+ if ( nextRidgeE.IsNull() )
+ {
+ eIt = SMESH_MesherHelper::GetAncestors( V1, mesh, TopAbs_EDGE );
+ while ( const TopoDS_Shape* E = eIt->next() )
+ if ( !ridgeE.IsSame( *E ) && !internEE.Contains( *E ) && subEE.Contains( *E ))
+ {
+ nextRidgeE = *E;
+ break;
+ }
+ }
+ ridgeE = TopoDS::Edge( nextRidgeE );
+ V0 = V1;
+
+ if ( ridgeE.IsNull() )
+ return false;
+ } // check EDGEs around the last VERTEX of ridgeE
+ } // loop on ridge EDGEs around a corner VERTEX
+ } // loop on on corner VERTEXes
+
+ if ( subEE.Extent() > ridgeEE.Extent() + internEE.Extent() ) // PAL23269
+ for ( int i = 1; i < subEE.Extent(); ++i )
+ if ( !ridgeEE.Contains( subEE(i) ))
+ internEE.Add( subEE(i) );
+
+ return true;
+ } // getInternalEdges()
+
+ //================================================================================
+ /*!
+ * \brief Find a face including two given nodes
+ */
+ //================================================================================
+
+ const SMDS_MeshElement* FindFaceByNodes( const SMDS_MeshNode* n1,
+ const SMDS_MeshNode* n2,
+ TIDSortedElemSet avoidSet,
+ SMESH_ProxyMesh& mesh)
+ {
+ SMDS_ElemIteratorPtr faceIt = mesh.GetInverseElementIterator( n1, SMDSAbs_Face );
+ while ( faceIt->more() )
+ {
+ const SMDS_MeshElement* f = faceIt->next();
+ if ( !avoidSet.count( f ) && f->GetNodeIndex( n2 ) >= 0 )
+ return f;
+ }
+ return 0;
+ }
+
+ //================================================================================
+ /*!
+ * \brief Check that a segment bounds a face belonging to smOfFaces
+ */
+ //================================================================================
+
+ bool IsSegmentOnSubMeshBoundary( const SMDS_MeshNode* n1,
+ const SMDS_MeshNode* n2,
+ const SMESHDS_SubMesh* smOfFaces,
+ SMESH_ProxyMesh& mesh)
+ {
+ TIDSortedElemSet avoidSet;
+ bool faceFound = false;
+
+ while ( const SMDS_MeshElement* f = FindFaceByNodes( n1, n2, avoidSet, mesh ))
+ {
+ if (( faceFound = smOfFaces->Contains( f )))
+ break;
+ avoidSet.insert( f );
+ }
+ return faceFound;
+ }
+
+} // namespace
+