X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH%2FSMESH_MesherHelper.cxx;h=0d4173c28db7da996bdd311c049c1b25ca2cfdc8;hp=e89a75f56125776d276a982470c10bd040461d6d;hb=b905bf1432be723426745721b4afde568d54d459;hpb=e16f6412dbdda05bd8b9800d5d15e046c521a529 diff --git a/src/SMESH/SMESH_MesherHelper.cxx b/src/SMESH/SMESH_MesherHelper.cxx index e89a75f56..0d4173c28 100644 --- a/src/SMESH/SMESH_MesherHelper.cxx +++ b/src/SMESH/SMESH_MesherHelper.cxx @@ -242,40 +242,68 @@ void SMESH_MesherHelper::SetSubShape(const TopoDS_Shape& aSh) for ( TopExp_Explorer eF( aSh, TopAbs_FACE ); eF.More(); eF.Next() ) { const TopoDS_Face& face = TopoDS::Face( eF.Current() ); + BRepAdaptor_Surface surf( face, false ); + if ( surf.IsUPeriodic() || surf.IsUClosed() ) { + myParIndex |= U_periodic; + myPar1[0] = surf.FirstUParameter(); + myPar2[0] = surf.LastUParameter(); + } + if ( surf.IsVPeriodic() || surf.IsVClosed() ) { + myParIndex |= V_periodic; + myPar1[1] = surf.FirstVParameter(); + myPar2[1] = surf.LastVParameter(); + } - // if ( surface->IsUPeriodic() || surface->IsVPeriodic() || - // surface->IsUClosed() || surface->IsVClosed() ) + gp_Pnt2d uv1, uv2; + for (TopExp_Explorer exp( face, TopAbs_EDGE ); exp.More(); exp.Next()) { - //while ( surface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface ))) - //surface = Handle(Geom_RectangularTrimmedSurface)::DownCast( surface )->BasisSurface(); - - for (TopExp_Explorer exp( face, TopAbs_EDGE ); exp.More(); exp.Next()) + // look for a "seam" edge, a real seam or an edge on period boundary + TopoDS_Edge edge = TopoDS::Edge( exp.Current() ); + if ( myParIndex ) { - // look for a seam edge - TopoDS_Edge edge = TopoDS::Edge( exp.Current() ); - if ( BRep_Tool::IsClosed( edge, face )) { - // initialize myPar1, myPar2 and myParIndex - gp_Pnt2d uv1, uv2; - BRep_Tool::UVPoints( edge, face, uv1, uv2 ); - if ( Abs( uv1.Coord(1) - uv2.Coord(1) ) < Abs( uv1.Coord(2) - uv2.Coord(2) )) + BRep_Tool::UVPoints( edge, face, uv1, uv2 ); + const double du = Abs( uv1.Coord(1) - uv2.Coord(1) ); + const double dv = Abs( uv1.Coord(2) - uv2.Coord(2) ); + + bool isSeam = BRep_Tool::IsClosed( edge, face ); + if ( isSeam ) // real seam - having two pcurves on face + { + // pcurve can lie not on pediod boundary (22582, mesh_Quadratic_01/C9) + if ( du < dv ) { double u1 = uv1.Coord(1); edge.Reverse(); BRep_Tool::UVPoints( edge, face, uv1, uv2 ); double u2 = uv1.Coord(1); - myParIndex |= U_periodic; myPar1[0] = Min( u1, u2 ); myPar2[0] = Max( u1, u2 ); } - else { + else + { double v1 = uv1.Coord(2); edge.Reverse(); BRep_Tool::UVPoints( edge, face, uv1, uv2 ); double v2 = uv1.Coord(2); - myParIndex |= V_periodic; myPar1[1] = Min( v1, v2 ); myPar2[1] = Max( v1, v2 ); } + } + else //if ( !isSeam ) + { + // one pcurve but on period boundary (22772, mesh_Quadratic_01/D1) + if (( myParIndex & U_periodic ) && du < Precision::PConfusion() ) + { + isSeam = ( Abs( uv1.Coord(1) - myPar1[0] ) < Precision::PConfusion() || + Abs( uv1.Coord(1) - myPar2[0] ) < Precision::PConfusion() ); + } + else if (( myParIndex & V_periodic ) && dv < Precision::PConfusion() ) + { + isSeam = ( Abs( uv1.Coord(2) - myPar1[1] ) < Precision::PConfusion() || + Abs( uv1.Coord(2) - myPar2[1] ) < Precision::PConfusion() ); + } + } + if ( isSeam ) + { // store seam shape indices, negative if shape encounters twice int edgeID = meshDS->ShapeToIndex( edge ); mySeamShapeIds.insert( IsSeamShape( edgeID ) ? -edgeID : edgeID ); @@ -284,27 +312,12 @@ void SMESH_MesherHelper::SetSubShape(const TopoDS_Shape& aSh) mySeamShapeIds.insert( IsSeamShape( vertexID ) ? -vertexID : vertexID ); } } - - // look for a degenerated edge - if ( SMESH_Algo::isDegenerated( edge )) { - myDegenShapeIds.insert( meshDS->ShapeToIndex( edge )); - for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() ) - myDegenShapeIds.insert( meshDS->ShapeToIndex( v.Current() )); - } } - if ( !myDegenShapeIds.empty() && !myParIndex ) - { - BRepAdaptor_Surface surf( face, false ); - if ( surf.IsUPeriodic() || surf.IsUClosed() ) { - myParIndex |= U_periodic; - myPar1[0] = surf.FirstUParameter(); - myPar2[0] = surf.LastUParameter(); - } - else if ( surf.IsVPeriodic() || surf.IsVClosed() ) { - myParIndex |= V_periodic; - myPar1[1] = surf.FirstVParameter(); - myPar2[1] = surf.LastVParameter(); - } + // look for a degenerated edge + if ( SMESH_Algo::isDegenerated( edge )) { + myDegenShapeIds.insert( meshDS->ShapeToIndex( edge )); + for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() ) + myDegenShapeIds.insert( meshDS->ShapeToIndex( v.Current() )); } } } @@ -2541,6 +2554,77 @@ bool SMESH_MesherHelper::IsStructured( SMESH_subMesh* faceSM ) return true; } +//======================================================================= +//function : IsDistorted2D +//purpose : Return true if 2D mesh on FACE is ditorted +//======================================================================= + +bool SMESH_MesherHelper::IsDistorted2D( SMESH_subMesh* faceSM ) +{ + if ( !faceSM || faceSM->GetSubShape().ShapeType() != TopAbs_FACE ) + return false; + + bool haveBadFaces = false; + + SMESH_MesherHelper helper( *faceSM->GetFather() ); + helper.SetSubShape( faceSM->GetSubShape() ); + + const TopoDS_Face& F = TopoDS::Face( faceSM->GetSubShape() ); + SMESHDS_SubMesh* smDS = helper.GetMeshDS()->MeshElements( F ); + if ( !smDS || smDS->NbElements() == 0 ) return false; + + SMDS_ElemIteratorPtr faceIt = smDS->GetElements(); + double prevArea2D = 0; + vector< const SMDS_MeshNode* > nodes; + vector< gp_XY > uv; + while ( faceIt->more() && !haveBadFaces ) + { + const SMDS_MeshElement* face = faceIt->next(); + + // get nodes + nodes.resize( face->NbCornerNodes() ); + SMDS_MeshElement::iterator n = face->begin_nodes(); + for ( size_t i = 0; i < nodes.size(); ++n, ++i ) + nodes[ i ] = *n; + + // avoid elems on degenarate shapes as UV on them can be wrong + if ( helper.HasDegeneratedEdges() ) + { + bool isOnDegen = false; + for ( size_t i = 0; ( i < nodes.size() && !isOnDegen ); ++i ) + isOnDegen = helper.IsDegenShape( nodes[ i ]->getshapeId() ); + if ( isOnDegen ) + continue; + } + // prepare to getting UVs + const SMDS_MeshNode* inFaceNode = 0; + if ( helper.HasSeam() ) { + for ( size_t i = 0; ( i < nodes.size() && !inFaceNode ); ++i ) + if ( !helper.IsSeamShape( nodes[ i ]->getshapeId() )) + inFaceNode = nodes[ i ]; + if ( !inFaceNode ) + continue; + } + // get UVs + uv.resize( nodes.size() ); + for ( size_t i = 0; i < nodes.size(); ++i ) + uv[ i ] = helper.GetNodeUV( F, nodes[ i ], inFaceNode ); + + // compare orientation of triangles + for ( int iT = 0, nbT = nodes.size()-2; iT < nbT; ++iT ) + { + gp_XY v1 = uv[ iT+1 ] - uv[ 0 ]; + gp_XY v2 = uv[ iT+2 ] - uv[ 0 ]; + double area2D = v2 ^ v1; + if (( haveBadFaces = ( area2D * prevArea2D < 0 ))) + break; + prevArea2D = area2D; + } + } + + return haveBadFaces; +} + //================================================================================ /*! * \brief Find out elements orientation on a geometrical face @@ -2720,6 +2804,28 @@ bool SMESH_MesherHelper::IsSubShape( const TopoDS_Shape& shape, SMESH_Mesh* aMes (shape.ShapeType() == TopAbs_COMPOUND && aMesh->GetMeshDS()->IsGroupOfSubShapes( shape )); } +//======================================================================= +//function : IsBlock +//purpose : +//======================================================================= + +bool SMESH_MesherHelper::IsBlock( const TopoDS_Shape& shape ) +{ + if ( shape.IsNull() ) + return false; + + TopoDS_Shell shell; + TopExp_Explorer exp( shape, TopAbs_SHELL ); + if ( !exp.More() ) return false; + shell = TopoDS::Shell( exp.Current() ); + if ( exp.Next(), exp.More() ) return false; + + TopoDS_Vertex v; + TopTools_IndexedMapOfOrientedShape map; + return SMESH_Block::FindBlockShapes( shell, v, v, map ); +} + + //================================================================================ /*! * \brief Return maximal tolerance of shape