X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FStdMeshers%2FStdMeshers_QuadToTriaAdaptor.cxx;h=95617d10a6979ea00e6ffe0f33946fd4e7fffb80;hb=e15a3a87cc738a5e3da00b3e09e7c8e17d733dc7;hp=47fffaeb2c1244d189d01bfbc65d313e4a94a2f1;hpb=386c76ea033aef391a39dfc3b015ed081ed49fd5;p=modules%2Fsmesh.git diff --git a/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx b/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx index 47fffaeb2..95617d10a 100644 --- a/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx +++ b/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx @@ -33,6 +33,7 @@ #include "SMESH_Mesh.hxx" #include "SMESH_MeshAlgos.hxx" #include "SMESH_MesherHelper.hxx" +#include "SMESH_subMesh.hxx" #include #include @@ -41,6 +42,7 @@ #include #include #include +#include #include #include @@ -172,7 +174,7 @@ namespace PrmJ->GetNodeIndex( otherFaceNode ) >= 0 )) continue; // f is a base quadrangle - // check projections of face direction (baOFN) to triange normals (nI and nJ) + // check projections of face direction (baOFN) to triangle normals (nI and nJ) gp_Vec baOFN( base2, SMESH_TNodeXYZ( otherFaceNode )); if ( nI * baOFN > 0 && nJ * baOFN > 0 && baI* baOFN > 0 && baJ* baOFN > 0 ) // issue 0023212 @@ -257,6 +259,53 @@ namespace } } } + + //================================================================================ + /*! + * \brief Store an error about overlapping faces + */ + //================================================================================ + + bool overlapError( SMESH_Mesh& mesh, + const SMDS_MeshElement* face1, + const SMDS_MeshElement* face2, + const TopoDS_Shape& shape = TopoDS_Shape()) + { + if ( !face1 || !face2 ) return false; + + SMESH_Comment msg; + msg << "face " << face1->GetID() << " overlaps face " << face2->GetID(); + + SMESH_subMesh * sm = 0; + if ( shape.IsNull() ) + { + sm = mesh.GetSubMesh( mesh.GetShapeToMesh() ); + } + else if ( shape.ShapeType() >= TopAbs_SOLID ) + { + sm = mesh.GetSubMesh( shape ); + } + else + { + TopoDS_Iterator it ( shape ); + if ( it.More() ) + sm = mesh.GetSubMesh( it.Value() ); + } + if ( sm ) + { + SMESH_ComputeErrorPtr& err = sm->GetComputeError(); + if ( !err || err->IsOK() ) + { + SMESH_BadInputElements* badElems = + new SMESH_BadInputElements( mesh.GetMeshDS(),COMPERR_BAD_INPUT_MESH, msg, sm->GetAlgo() ); + badElems->add( face1 ); + badElems->add( face2 ); + err.reset( badElems ); + } + } + + return false; // == "algo fails" + } } //================================================================================ @@ -402,17 +451,17 @@ static gp_Pnt FindBestPoint(const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& PC, const gp_Vec& V) { gp_Pnt Pbest = PC; - const double a = P1.Distance(P2); - const double b = P1.Distance(PC); - const double c = P2.Distance(PC); - if( a < (b+c)/2 ) + const double a2 = P1.SquareDistance(P2); + const double b2 = P1.SquareDistance(PC); + const double c2 = P2.SquareDistance(PC); + if ( a2 < ( b2 + Sqrt( 4 * b2 * c2 ) + c2 ) / 4 ) // ( a < (b+c)/2 ) return Pbest; else { // find shift along V in order a to became equal to (b+c)/2 const double Vsize = V.Magnitude(); if ( fabs( Vsize ) > std::numeric_limits::min() ) { - const double shift = sqrt( a*a + (b*b-c*c)*(b*b-c*c)/16/a/a - (b*b+c*c)/2 ); + const double shift = sqrt( a2 + (b2-c2)*(b2-c2)/16/a2 - (b2+c2)/2 ); Pbest.ChangeCoord() += shift * V.XYZ() / Vsize; } } @@ -437,9 +486,6 @@ static bool HasIntersection3(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint, gp_XYZ vert1 = P2.XYZ(); gp_XYZ vert2 = P3.XYZ(); - /* calculate distance from vert0 to ray origin */ - gp_XYZ tvec = orig - vert0; - gp_XYZ edge1 = vert1 - vert0; gp_XYZ edge2 = vert2 - vert0; @@ -449,9 +495,13 @@ static bool HasIntersection3(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint, /* if determinant is near zero, ray lies in plane of triangle */ double det = edge1 * pvec; - if (det > -EPSILON && det < EPSILON) + const double ANGL_EPSILON = 1e-12; + if ( det > -ANGL_EPSILON && det < ANGL_EPSILON ) return false; + /* calculate distance from vert0 to ray origin */ + gp_XYZ tvec = orig - vert0; + /* calculate U parameter and test bounds */ double u = ( tvec * pvec ) / det; //if (u < 0.0 || u > 1.0) @@ -488,15 +538,15 @@ static bool HasIntersection(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint, } else { bool check = false; - if( (aContour(1).Distance(aContour(2)) > 1.e-6) && - (aContour(1).Distance(aContour(3)) > 1.e-6) && - (aContour(2).Distance(aContour(3)) > 1.e-6) ) { + if( (aContour(1).SquareDistance(aContour(2)) > 1.e-12) && + (aContour(1).SquareDistance(aContour(3)) > 1.e-12) && + (aContour(2).SquareDistance(aContour(3)) > 1.e-12) ) { check = HasIntersection3( P, PC, Pint, aContour(1), aContour(2), aContour(3) ); } if(check) return true; - if( (aContour(1).Distance(aContour(4)) > 1.e-6) && - (aContour(1).Distance(aContour(3)) > 1.e-6) && - (aContour(4).Distance(aContour(3)) > 1.e-6) ) { + if( (aContour(1).SquareDistance(aContour(4)) > 1.e-12) && + (aContour(1).SquareDistance(aContour(3)) > 1.e-12) && + (aContour(4).SquareDistance(aContour(3)) > 1.e-12) ) { check = HasIntersection3( P, PC, Pint, aContour(1), aContour(3), aContour(4) ); } if(check) return true; @@ -513,17 +563,19 @@ static bool HasIntersection(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint, * \param PN - four nodes of the quadrangle * \param aMesh - mesh * \param NotCheckedFace - the quadrangle face - * \retval double - pyramid height + * \param Shape - the shape being meshed + * \retval false if mesh invalidity detected */ //================================================================================ -void StdMeshers_QuadToTriaAdaptor::LimitHeight (gp_Pnt& Papex, +bool StdMeshers_QuadToTriaAdaptor::LimitHeight (gp_Pnt& Papex, const gp_Pnt& PC, const TColgp_Array1OfPnt& PN, const vector& FNodes, SMESH_Mesh& aMesh, const SMDS_MeshElement* NotCheckedFace, - const bool UseApexRay) + const bool UseApexRay, + const TopoDS_Shape& Shape) { if ( !myElemSearcher ) myElemSearcher = SMESH_MeshAlgos::GetElementSearcher( *aMesh.GetMeshDS() ); @@ -539,6 +591,9 @@ void StdMeshers_QuadToTriaAdaptor::LimitHeight (gp_Pnt& if ( UseApexRay ) { + double idealHeight = height; + const SMDS_MeshElement* intFace = 0; + // find intersection closest to PC Ptest = PC.XYZ() + line.Direction().XYZ() * height * 3; @@ -554,10 +609,16 @@ void StdMeshers_QuadToTriaAdaptor::LimitHeight (gp_Pnt& if ( HasIntersection( Ptest, PC, Pint, aContour )) { - double dInt = PC.Distance( Pint ); - height = Min( height, dInt / 3. ); + double dInt = PC.Distance( Pint ) / 3.; + if ( dInt < height ) + { + height = dInt; + intFace = face; + } } } + if ( height < 1e-2 * idealHeight && intFace ) + return overlapError( aMesh, NotCheckedFace, intFace, Shape ); } // Find faces intersecting triangular facets of the pyramid (issue 23212) @@ -600,11 +661,13 @@ void StdMeshers_QuadToTriaAdaptor::LimitHeight (gp_Pnt& } Papex = PC.XYZ() + line.Direction().XYZ() * height; + + return true; } //================================================================================ /*! - * \brief Prepare data for the given face + * \brief Retrieve data of the given face * \param PN - coordinates of face nodes * \param VN - cross products of vectors (PC-PN(i)) ^ (PC-PN(i+1)) * \param FNodes - face nodes @@ -643,7 +706,8 @@ int StdMeshers_QuadToTriaAdaptor::Preparation(const SMDS_MeshElement* face int nbp = 4; int j = 0; - for(i=1; i<4; i++) { + for ( i = 1; i < 4; i++ ) + { j = i+1; for(; j<=4; j++) { if( PN(i).Distance(PN(j)) < 1.e-6 ) @@ -651,11 +715,10 @@ int StdMeshers_QuadToTriaAdaptor::Preparation(const SMDS_MeshElement* face } if(j<=4) break; } - //int deg_num = IsDegenarate(PN); - //if(deg_num>0) { + bool hasdeg = false; - if(i<4) { - //cout<<"find degeneration"<X(),N->Y(),N->Z()); if(Pdeg.Distance(Ptmp)<1.e-6) { DegNode = N; - //DegNode = const_cast(N); break; } } @@ -686,6 +748,7 @@ int StdMeshers_QuadToTriaAdaptor::Preparation(const SMDS_MeshElement* face PN.SetValue(nbp+1,PN(1)); FNodes[nbp] = FNodes[0]; + // find normal direction gp_Vec V1(PC,PN(nbp)); gp_Vec V2(PC,PN(1)); @@ -727,7 +790,6 @@ int StdMeshers_QuadToTriaAdaptor::Preparation(const SMDS_MeshElement* face } } - //cout<<" VNorm("<more() ) + { + groupDS = 0; + SMESH_Group * group = groupIt->next(); + if ( !group ) continue; + groupDS = group->GetGroupDS(); + if ( !groupDS || groupDS->IsEmpty() ) { groupDS = 0; - SMESH_Group * group = groupIt->next(); - if ( !group ) continue; - groupDS = group->GetGroupDS(); - if ( !groupDS || groupDS->IsEmpty() ) - { - groupDS = 0; - continue; - } - if (groupDS->GetType() != SMDSAbs_Face) - { - groupDS = 0; - continue; - } - std::string grpName = group->GetName(); - if (grpName == groupName) - { - MESSAGE("group skinFaces provided"); - break; - } - else - groupDS = 0; + continue; + } + if (groupDS->GetType() != SMDSAbs_Face) + { + groupDS = 0; + continue; } + std::string grpName = group->GetName(); + if (grpName == groupName) + { + break; + } + else + groupDS = 0; + } + + const bool toFindVolumes = aMesh.NbVolumes() > 0; vector myPyramids; SMESH_MesherHelper helper(aMesh); @@ -962,13 +1026,16 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh) if ( !myElemSearcher ) myElemSearcher = SMESH_MeshAlgos::GetElementSearcher( *meshDS ); SMESH_ElementSearcher* searcher = const_cast(myElemSearcher); + SMESHUtils::Deleter + volSearcher( SMESH_MeshAlgos::GetElementSearcher( *meshDS )); + vector< const SMDS_MeshElement* > suspectFaces, foundVolumes; TColgp_Array1OfPnt PN(1,5); TColgp_Array1OfVec VN(1,4); vector FNodes(5); TColgp_SequenceOfPnt aContour; - SMDS_FaceIteratorPtr fIt = meshDS->facesIterator(/*idInceasingOrder=*/true); + SMDS_FaceIteratorPtr fIt = meshDS->facesIterator(); while( fIt->more()) { const SMDS_MeshElement* face = fIt->next(); @@ -981,7 +1048,7 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh) if ( what == NOT_QUAD ) continue; if ( volumes[0] && volumes[1] ) - continue; // face is shared by two volumes - no space for a pyramid + continue; // face is shared by two volumes - no room for a pyramid if ( what == DEGEN_QUAD ) { @@ -1082,6 +1149,7 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh) } // Restrict pyramid height by intersection with other faces + gp_Vec tmpDir(PC,PCbest); tmpDir.Normalize(); double tmp = PN(1).Distance(PN(3)) + PN(2).Distance(PN(4)); // far points: in (PC, PCbest) direction and vice-versa @@ -1089,11 +1157,28 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh) PC.XYZ() - tmpDir.XYZ() * tmp * 1.e6 }; // check intersection for farPnt1 and farPnt2 bool intersected[2] = { false, false }; - double dist [2] = { RealLast(), RealLast() }; - gp_Pnt intPnt[2]; + double dist2int [2] = { RealLast(), RealLast() }; + gp_Pnt intPnt [2]; + int intFaceInd [2] = { 0, 0 }; + + if ( toFindVolumes && 0 ) // non-conformal mesh is not suitable for any mesher so far + { + // there are volumes in the mesh, in a non-conformal mesh an neighbor + // volume can be not found yet + for ( int isRev = 0; isRev < 2; ++isRev ) + { + if ( volumes[isRev] ) continue; + gp_Pnt testPnt = PC.XYZ() + tmpDir.XYZ() * height * ( isRev ? -0.1: 0.1 ); + foundVolumes.clear(); + if ( volSearcher->FindElementsByPoint( testPnt, SMDSAbs_Volume, foundVolumes )) + volumes[isRev] = foundVolumes[0]; + } + if ( volumes[0] && volumes[1] ) + continue; // no room for a pyramid + } gp_Ax1 line( PC, tmpDir ); - vector< const SMDS_MeshElement* > suspectFaces; + suspectFaces.clear(); searcher->GetElementsNearLine( line, SMDSAbs_Face, suspectFaces); for ( size_t iF = 0; iF < suspectFaces.size(); ++iF ) @@ -1107,31 +1192,33 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh) gp_Pnt intP; for ( int isRev = 0; isRev < 2; ++isRev ) { - if( !volumes[isRev] && HasIntersection(farPnt[isRev], PC, intP, aContour) ) { - intersected[isRev] = true; + if( !volumes[isRev] && HasIntersection(farPnt[isRev], PC, intP, aContour) ) + { double d = PC.Distance( intP ); - if( d < dist[isRev] ) + if ( d < dist2int[isRev] ) { - intPnt[isRev] = intP; - dist [isRev] = d; + intersected[isRev] = true; + intPnt [isRev] = intP; + dist2int [isRev] = d; + intFaceInd [isRev] = iF; } } } } // if the face belong to the group of skinFaces, do not build a pyramid outside - if (groupDS && groupDS->Contains(face)) + if ( groupDS && groupDS->Contains(face) ) { intersected[0] = false; } else if ( intersected[0] && intersected[1] ) // check if one of pyramids is in a hole { - gp_Pnt P ( PC.XYZ() + tmpDir.XYZ() * 0.5 * PC.Distance( intPnt[0] )); + gp_Pnt P ( PC.XYZ() + tmpDir.XYZ() * 0.5 * dist2int[0] ); if ( searcher->GetPointState( P ) == TopAbs_OUT ) intersected[0] = false; else { - P = ( PC.XYZ() - tmpDir.XYZ() * 0.5 * PC.Distance( intPnt[1] )); + P = ( PC.XYZ() - tmpDir.XYZ() * 0.5 * dist2int[1] ); if ( searcher->GetPointState( P ) == TopAbs_OUT ) intersected[1] = false; } @@ -1141,11 +1228,14 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh) for ( int isRev = 0; isRev < 2; ++isRev ) { - if( !intersected[isRev] ) continue; - double pyramidH = Min( height, PC.Distance(intPnt[isRev])/3.); - gp_Pnt Papex = PC.XYZ() + tmpDir.XYZ() * (isRev ? -pyramidH : pyramidH); - - LimitHeight( Papex, PC, PN, FNodes, aMesh, face, /*UseApexRay=*/false ); + if ( !intersected[isRev] ) continue; + double pyramidH = Min( height, dist2int[isRev]/3. ); + gp_Pnt Papex = PC.XYZ() + tmpDir.XYZ() * (isRev ? -pyramidH : pyramidH); + if ( pyramidH < 1e-2 * height ) + return overlapError( aMesh, face, suspectFaces[ intFaceInd[isRev] ] ); + + if ( !LimitHeight( Papex, PC, PN, FNodes, aMesh, face, /*UseApexRay=*/false )) + return false; // create node for Papex SMDS_MeshNode* NewNode = helper.AddNode( Papex.X(), Papex.Y(), Papex.Z() );