From 54d60d76150c81d6e611942623d436f40e68edb2 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 20 Feb 2007 07:14:12 +0000 Subject: [PATCH] PAL13615 (EDF PAL 315/31 GEOM SMESH : meshing of a "5 edges quadrangle") implementation --- src/StdMeshers/StdMeshers_MEFISTO_2D.cxx | 602 +++++------ src/StdMeshers/StdMeshers_MEFISTO_2D.hxx | 41 +- src/StdMeshers/StdMeshers_Quadrangle_2D.cxx | 1000 ++++--------------- src/StdMeshers/StdMeshers_Quadrangle_2D.hxx | 53 +- 4 files changed, 448 insertions(+), 1248 deletions(-) diff --git a/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx b/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx index 8ee44579b..fcaefa535 100644 --- a/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx +++ b/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx @@ -27,12 +27,15 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_MEFISTO_2D.hxx" + #include "SMESH_Gen.hxx" #include "SMESH_Mesh.hxx" #include "SMESH_subMesh.hxx" +#include "SMESH_Block.hxx" +#include "SMESH_MesherHelper.hxx" +#include "StdMeshers_FaceSide.hxx" #include "StdMeshers_MaxElementArea.hxx" #include "StdMeshers_LengthFromEdges.hxx" @@ -48,19 +51,16 @@ using namespace std; #include #include -#include #include -#include #include #include #include #include -#include -#include -#include -#include #include #include +#include + +using namespace std; //============================================================================= /*! @@ -68,8 +68,8 @@ using namespace std; */ //============================================================================= -StdMeshers_MEFISTO_2D::StdMeshers_MEFISTO_2D(int hypId, int studyId, - SMESH_Gen * gen):SMESH_2D_Algo(hypId, studyId, gen) +StdMeshers_MEFISTO_2D::StdMeshers_MEFISTO_2D(int hypId, int studyId, SMESH_Gen * gen): + SMESH_2D_Algo(hypId, studyId, gen) { MESSAGE("StdMeshers_MEFISTO_2D::StdMeshers_MEFISTO_2D"); _name = "MEFISTO_2D"; @@ -102,75 +102,69 @@ StdMeshers_MEFISTO_2D::~StdMeshers_MEFISTO_2D() //============================================================================= bool StdMeshers_MEFISTO_2D::CheckHypothesis - (SMESH_Mesh& aMesh, - const TopoDS_Shape& aShape, + (SMESH_Mesh& aMesh, + const TopoDS_Shape& aShape, SMESH_Hypothesis::Hypothesis_Status& aStatus) { - //MESSAGE("StdMeshers_MEFISTO_2D::CheckHypothesis"); + _hypMaxElementArea = NULL; + _hypLengthFromEdges = NULL; - _hypMaxElementArea = NULL; - _hypLengthFromEdges = NULL; + list ::const_iterator itl; + const SMESHDS_Hypothesis *theHyp; - list ::const_iterator itl; - const SMESHDS_Hypothesis *theHyp; + const list &hyps = GetUsedHypothesis(aMesh, aShape); + int nbHyp = hyps.size(); + if (!nbHyp) + { + aStatus = SMESH_Hypothesis::HYP_MISSING; + return false; // can't work with no hypothesis + } - const list &hyps = GetUsedHypothesis(aMesh, aShape); - int nbHyp = hyps.size(); - if (!nbHyp) - { - aStatus = SMESH_Hypothesis::HYP_MISSING; - return false; // can't work with no hypothesis - } + itl = hyps.begin(); + theHyp = (*itl); // use only the first hypothesis + + string hypName = theHyp->GetName(); + + bool isOk = false; + + if (hypName == "MaxElementArea") + { + _hypMaxElementArea = static_cast(theHyp); + ASSERT(_hypMaxElementArea); + _maxElementArea = _hypMaxElementArea->GetMaxArea(); + _edgeLength = 0; + isOk = true; + aStatus = SMESH_Hypothesis::HYP_OK; + } + + else if (hypName == "LengthFromEdges") + { + _hypLengthFromEdges = static_cast(theHyp); + ASSERT(_hypLengthFromEdges); + _edgeLength = 0; + _maxElementArea = 0; + isOk = true; + aStatus = SMESH_Hypothesis::HYP_OK; + } + else + aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE; - itl = hyps.begin(); - theHyp = (*itl); // use only the first hypothesis - - string hypName = theHyp->GetName(); - //int hypId = theHyp->GetID(); - //SCRUTE(hypName); - - bool isOk = false; - - if (hypName == "MaxElementArea") - { - _hypMaxElementArea = static_cast(theHyp); - ASSERT(_hypMaxElementArea); - _maxElementArea = _hypMaxElementArea->GetMaxArea(); - _edgeLength = 0; - isOk = true; - aStatus = SMESH_Hypothesis::HYP_OK; - } - - else if (hypName == "LengthFromEdges") - { - _hypLengthFromEdges = static_cast(theHyp); - ASSERT(_hypLengthFromEdges); - _edgeLength = 0; - _maxElementArea = 0; - isOk = true; - aStatus = SMESH_Hypothesis::HYP_OK; - } - else - aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE; - - if (isOk) - { - isOk = false; - if (_maxElementArea > 0) - { -// _edgeLength = 2 * sqrt(_maxElementArea); // triangles : minorant - _edgeLength = sqrt(2. * _maxElementArea/sqrt(3.0)); - isOk = true; - } - else - isOk = (_hypLengthFromEdges != NULL); // **** check mode - if (!isOk) - aStatus = SMESH_Hypothesis::HYP_BAD_PARAMETER; - } - - //SCRUTE(_edgeLength); - //SCRUTE(_maxElementArea); - return isOk; + if (isOk) + { + isOk = false; + if (_maxElementArea > 0) + { + //_edgeLength = 2 * sqrt(_maxElementArea); // triangles : minorant + _edgeLength = sqrt(2. * _maxElementArea/sqrt(3.0)); + isOk = true; + } + else + isOk = (_hypLengthFromEdges != NULL); // **** check mode + if (!isOk) + aStatus = SMESH_Hypothesis::HYP_BAD_PARAMETER; + } + + return isOk; } //============================================================================= @@ -183,21 +177,58 @@ bool StdMeshers_MEFISTO_2D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aSh { MESSAGE("StdMeshers_MEFISTO_2D::Compute"); - if (_hypLengthFromEdges) - _edgeLength = ComputeEdgeElementLength(aMesh, aShape); - - bool isOk = false; - //const SMESHDS_Mesh * meshDS = aMesh.GetMeshDS(); - //SMESH_subMesh *theSubMesh = aMesh.GetSubMesh(aShape); + TopoDS_Face F = TopoDS::Face(aShape.Oriented(TopAbs_FORWARD)); + + // get all edges of a face + TopoDS_Vertex V1; + list< TopoDS_Edge > edges; + list< int > nbEdgesInWires; + int nbWires = SMESH_Block::GetOrderedEdges (F, V1, edges, nbEdgesInWires); + + if (_hypLengthFromEdges) _edgeLength = 0; + + // split list of all edges into separate wires + TWireVector wires ( nbWires ); + list< int >::iterator nbE = nbEdgesInWires.begin(); + list< TopoDS_Edge >::iterator from, to; + from = to = edges.begin(); + for ( int iW = 0; iW < nbWires; ++iW ) + { + std::advance( to, *nbE++ ); + list< TopoDS_Edge > wireEdges( from, to ); + // assure that there is a node on the first vertex + // as StdMeshers_FaceSide::GetUVPtStruct() requires + while ( !VertexNode( TopExp::FirstVertex( wireEdges.front(), true), + aMesh.GetMeshDS())) + { + wireEdges.splice(wireEdges.end(), wireEdges, + wireEdges.begin(), ++wireEdges.begin()); + if ( from->IsSame( wireEdges.front() )) { + MESSAGE( "No nodes on vertices on wire " << iW+1); + return false; + } + } + StdMeshers_FaceSide* wire = new StdMeshers_FaceSide( F, wireEdges, &aMesh, true ); + wires[ iW ] = StdMeshers_FaceSidePtr( wire ); + if (_hypLengthFromEdges && wire->NbSegments() ) + _edgeLength += wire->Length() / wire->NbSegments(); + from = to; + } + if ( wires[0]->NbSegments() < 3 ) // ex: a circle with 2 segments + return false; - const TopoDS_Face & FF = TopoDS::Face(aShape); - bool faceIsForward = (FF.Orientation() == TopAbs_FORWARD); - TopoDS_Face F = TopoDS::Face(FF.Oriented(TopAbs_FORWARD)); + if (_hypLengthFromEdges && _edgeLength < DBL_MIN ) + _edgeLength = 100; - Z nblf; //nombre de lignes fermees (enveloppe en tete) - Z *nudslf = NULL; //numero du dernier sommet de chaque ligne fermee - R2 *uvslf = NULL; - Z nbpti = 0; //nombre points internes futurs sommets de la triangulation + // helper builds a quadratic mesh if necessary + myTool = new SMESH_MesherHelper(aMesh); + auto_ptr helperDeleter( myTool ); + _quadraticMesh = myTool->IsQuadraticSubMesh(aShape); + + Z nblf; //nombre de lignes fermees (enveloppe en tete) + Z *nudslf = NULL; //numero du dernier sommet de chaque ligne fermee + R2 *uvslf = NULL; + Z nbpti = 0; //nombre points internes futurs sommets de la triangulation R2 *uvpti = NULL; Z nbst; @@ -206,97 +237,55 @@ bool StdMeshers_MEFISTO_2D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aSh Z *nust = NULL; Z ierr = 0; - Z nutysu = 1; // 1: il existe un fonction areteideale_() - // Z nutysu=0; // 0: on utilise aretmx - R aretmx = _edgeLength; // longueur max aretes future triangulation + Z nutysu = 1; // 1: il existe un fonction areteideale_() + // Z nutysu=0; // 0: on utilise aretmx + R aretmx = _edgeLength; // longueur max aretes future triangulation - nblf = NumberOfWires(F); + nblf = nbWires; nudslf = new Z[1 + nblf]; nudslf[0] = 0; int iw = 1; int nbpnt = 0; - myTool = new SMESH_MesherHelper(aMesh); - _quadraticMesh = myTool->IsQuadraticSubMesh(aShape); - - if ( _quadraticMesh && _hypLengthFromEdges ) - aretmx *= 2.; - - myOuterWire = BRepTools::OuterWire(F); - nbpnt += NumberOfPoints(aMesh, myOuterWire); - if ( nbpnt < 3 ) { // ex: a circle with 2 segments - delete myTool; myTool = 0; - return false; - } - nudslf[iw++] = nbpnt; - - for (TopExp_Explorer exp(F, TopAbs_WIRE); exp.More(); exp.Next()) { - const TopoDS_Wire & W = TopoDS::Wire(exp.Current()); - if (!myOuterWire.IsSame(W)) { - nbpnt += NumberOfPoints(aMesh, W); - nudslf[iw++] = nbpnt; - } + // count nb of input points + for ( int iW = 0; iW < nbWires; ++iW ) + { + nbpnt += wires[iW]->NbSegments(); + nudslf[iw++] = nbpnt; } - // avoid passing same uv points for a vertex common to 2 wires - TopTools_IndexedDataMapOfShapeListOfShape VWMap; - if ( iw - 1 > 1 ) // nbofWires > 1 - TopExp::MapShapesAndAncestors( F , TopAbs_VERTEX, TopAbs_WIRE, VWMap ); - uvslf = new R2[nudslf[nblf]]; - int m = 0; double scalex, scaley; ComputeScaleOnFace(aMesh, F, scalex, scaley); - map mefistoToDS; // correspondence mefisto index--> points IDNodes - if ( !LoadPoints(aMesh, F, myOuterWire, uvslf, m, - mefistoToDS, scalex, scaley, VWMap) ) { - delete myTool; myTool = 0; - return false; - } + // correspondence mefisto index --> Nodes + vector< const SMDS_MeshNode*> mefistoToDS(nbpnt, (const SMDS_MeshNode*)0); - for (TopExp_Explorer exp(F, TopAbs_WIRE); exp.More(); exp.Next()) - { - const TopoDS_Wire & W = TopoDS::Wire(exp.Current()); - if (!myOuterWire.IsSame(W)) - { - if (! LoadPoints(aMesh, F, W, uvslf, m, - mefistoToDS, scalex, scaley, VWMap )) { - delete myTool; myTool = 0; - return false; - } - } - } + // fill input points UV + LoadPoints(wires, uvslf, mefistoToDS, scalex, scaley); - uvst = NULL; - nust = NULL; + // Compute aptrte(nutysu, aretmx, nblf, nudslf, uvslf, nbpti, uvpti, nbst, uvst, nbt, nust, ierr); + bool isOk = false; if (ierr == 0) { MESSAGE("... End Triangulation Generated Triangle Number " << nbt); MESSAGE(" Node Number " << nbst); - StoreResult(aMesh, nbst, uvst, nbt, nust, F, - faceIsForward, mefistoToDS, scalex, scaley); + StoreResult(nbst, uvst, nbt, nust, mefistoToDS, scalex, scaley); isOk = true; } else { MESSAGE("Error in Triangulation"); - isOk = false; } - if (nudslf != NULL) - delete[]nudslf; - if (uvslf != NULL) - delete[]uvslf; - if (uvst != NULL) - delete[]uvst; - if (nust != NULL) - delete[]nust; - delete myTool; myTool = 0; + if (nudslf != NULL) delete[]nudslf; + if (uvslf != NULL) delete[]uvslf; + if (uvst != NULL) delete[]uvst; + if (nust != NULL) delete[]nust; return isOk; } @@ -357,25 +346,30 @@ static bool fixOverlappedLinkUV( R2& uv0, const R2& uv1, const R2& uv2 ) //purpose : //======================================================================= -static bool fixCommonVertexUV (gp_Pnt2d & theUV, +static bool fixCommonVertexUV (R2 & theUV, const TopoDS_Vertex& theV, - const TopoDS_Wire& theW, - const TopoDS_Wire& theOW, const TopoDS_Face& theF, const TopTools_IndexedDataMapOfShapeListOfShape & theVWMap, SMESH_Mesh & theMesh, - bool CreateQuadratic) + const double theScaleX, + const double theScaleY, + const bool theCreateQuadratic) { - if( theW.IsSame( theOW ) || - !theVWMap.Contains( theV )) return false; + if( !theVWMap.Contains( theV )) return false; // check if there is another wire sharing theV const TopTools_ListOfShape& WList = theVWMap.FindFromKey( theV ); TopTools_ListIteratorOfListOfShape aWIt; + TopTools_MapOfShape aWires; for ( aWIt.Initialize( WList ); aWIt.More(); aWIt.Next() ) - if ( !theW.IsSame( aWIt.Value() )) - break; - if ( !aWIt.More() ) return false; + aWires.Add( aWIt.Value() ); + if ( aWires.Extent() < 2 ) return false; + + TopoDS_Shape anOuterWire = BRepTools::OuterWire(theF); + TopoDS_Shape anInnerWire; + for ( aWIt.Initialize( WList ); aWIt.More() && anInnerWire.IsNull(); aWIt.Next() ) + if ( !anOuterWire.IsSame( aWIt.Value() )) + anInnerWire = aWIt.Value(); TopTools_ListOfShape EList; list< double > UList; @@ -383,7 +377,7 @@ static bool fixCommonVertexUV (gp_Pnt2d & theUV, // find edges of theW sharing theV // and find 2d normal to them at theV gp_Vec2d N(0.,0.); - TopoDS_Iterator itE( theW ); + TopoDS_Iterator itE( anInnerWire ); for ( ; itE.More(); itE.Next() ) { const TopoDS_Edge& E = TopoDS::Edge( itE.Value() ); @@ -401,7 +395,7 @@ static bool fixCommonVertexUV (gp_Pnt2d & theUV, gp_Vec2d d1; gp_Pnt2d p; C2d->D1( u, p, d1 ); - gp_Vec2d n( d1.Y(), -d1.X() ); + gp_Vec2d n( d1.Y() * theScaleX, -d1.X() * theScaleY); if ( E.Orientation() == TopAbs_REVERSED ) n.Reverse(); N += n.Normalized(); @@ -411,6 +405,7 @@ static bool fixCommonVertexUV (gp_Pnt2d & theUV, // define step size by which to move theUV gp_Pnt2d nextUV; // uv of next node on edge, most distant of the four + gp_Pnt2d thisUV( theUV.x, theUV.y ); double maxDist = -DBL_MAX; TopTools_ListIteratorOfListOfShape aEIt (EList); list< double >::iterator aUIt = UList.begin(); @@ -431,7 +426,7 @@ static bool fixCommonVertexUV (gp_Pnt2d & theUV, while ( nIt->more() ) { const SMDS_MeshNode* node = nIt->next(); // check if node is medium - if ( CreateQuadratic && SMESH_MesherHelper::IsMedium( node, SMDSAbs_Edge )) + if ( theCreateQuadratic && SMESH_MesherHelper::IsMedium( node, SMDSAbs_Edge )) continue; const SMDS_EdgePosition* epos = static_cast(node->GetPosition().get()); @@ -444,29 +439,33 @@ static bool fixCommonVertexUV (gp_Pnt2d & theUV, } bool isFirstCommon = ( *aUIt == f ); gp_Pnt2d uv = C2d->Value( isFirstCommon ? umin : umax ); - double dist = theUV.SquareDistance( uv ); + double dist = thisUV.SquareDistance( uv ); if ( dist > maxDist ) { maxDist = dist; nextUV = uv; } } R2 uv0, uv1, uv2; - uv0.x = theUV.X(); uv0.y = theUV.Y(); + uv0.x = thisUV.X(); uv0.y = thisUV.Y(); uv1.x = nextUV.X(); uv1.y = nextUV.Y(); - uv2.x = uv0.x; uv2.y = uv0.y; + uv2.x = thisUV.X(); uv2.y = thisUV.Y(); + + uv1.x *= theScaleX; uv1.y *= theScaleY; + if ( fixOverlappedLinkUV( uv0, uv1, uv2 )) { - double step = theUV.Distance( gp_Pnt2d( uv0.x, uv0.y )); + double step = thisUV.Distance( gp_Pnt2d( uv0.x, uv0.y )); // move theUV along the normal by the step N *= step; - MESSAGE("--fixCommonVertexUV move(" << theUV.X() << " " << theUV.Y() + MESSAGE("--fixCommonVertexUV move(" << theUV.x << " " << theUV.x << ") by (" << N.X() << " " << N.Y() << ")" << endl << "--- MAX DIST " << maxDist); - theUV.SetXY( theUV.XY() + N.XY() ); + theUV.x += N.X(); + theUV.y += N.Y(); return true; } @@ -479,111 +478,71 @@ static bool fixCommonVertexUV (gp_Pnt2d & theUV, */ //============================================================================= -bool StdMeshers_MEFISTO_2D::LoadPoints(SMESH_Mesh & aMesh, - const TopoDS_Face & FF, - const TopoDS_Wire & WW, - R2 * uvslf, - int & m, - map&mefistoToDS, - double scalex, - double scaley, - const TopTools_IndexedDataMapOfShapeListOfShape& VWMap) +bool StdMeshers_MEFISTO_2D::LoadPoints(TWireVector & wires, + R2 * uvslf, + vector& mefistoToDS, + double scalex, + double scaley) { - // MESSAGE("StdMeshers_MEFISTO_2D::LoadPoints"); + // to avoid passing same uv points for a vertex common to 2 wires + TopoDS_Face F; + TopTools_IndexedDataMapOfShapeListOfShape VWMap; + if ( wires.size() > 1 ) + { + F = TopoDS::Face( myTool->GetSubShape() ); + TopExp::MapShapesAndAncestors( F, TopAbs_VERTEX, TopAbs_WIRE, VWMap ); + int nbVertices = 0; + for ( int iW = 0; iW < wires.size(); ++iW ) + nbVertices += wires[ iW ]->NbSegments(); + if ( nbVertices == VWMap.Extent() ) + VWMap.Clear(); // wires have no common vertices + } - TopoDS_Face F = TopoDS::Face(FF.Oriented(TopAbs_FORWARD)); + const bool isXConst = false; // meaningles here + const double constValue = 0; // meaningles here + int m = 0; list< int > mOnVertex; - gp_XY scale( scalex, scaley ); - - TopoDS_Wire W = TopoDS::Wire(WW.Oriented(TopAbs_FORWARD)); - BRepTools_WireExplorer wexp(W, F); - for ( wexp.Init(W, F); wexp.More(); wexp.Next() ) + for ( int iW = 0; iW < wires.size(); ++iW ) { - const TopoDS_Edge & E = wexp.Current(); - bool isForward = (E.Orientation() == TopAbs_FORWARD); - - // --- IDNodes of first and last Vertex + const vector& uvPtVec = wires[ iW ]->GetUVPtStruct(isXConst,constValue); - TopoDS_Vertex VFirst, VLast, V; - TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l - V = isForward ? VFirst : VLast; - - ASSERT(!V.IsNull()); - SMDS_NodeIteratorPtr lid= aMesh.GetSubMesh(V)->GetSubMeshDS()->GetNodes(); - if ( !lid->more() ) { - MESSAGE (" NO NODE BUILT ON VERTEX "); - return false; - } - const SMDS_MeshNode* idFirst = lid->next(); - - // --- edge internal IDNodes (relies on good order storage, not checked) - - map params; - const SMDS_MeshNode * node; - - SMDS_NodeIteratorPtr nodeIt= aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes(); - while ( nodeIt->more() ) + vector::const_iterator uvPt = uvPtVec.begin(); + for ( ++uvPt; uvPt != uvPtVec.end(); ++uvPt ) { - node = nodeIt->next(); - if ( _quadraticMesh && SMESH_MesherHelper::IsMedium( node, SMDSAbs_Edge )) - continue; - const SMDS_EdgePosition* epos = - static_cast(node->GetPosition().get()); - double param = epos->GetUParameter(); - if ( !isForward ) param = -param; - if ( !params.insert( make_pair( param, node )).second ) - { - MESSAGE( "BAD NODE ON EDGE POSITIONS" ); - return false; - } + // bind mefisto ID to node + mefistoToDS[m] = uvPt->node; + // set UV + uvslf[m].x = uvPt->u * scalex; + uvslf[m].y = uvPt->v * scaley; + if ( uvPt->node->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX ) + mOnVertex.push_back( m ); + m++; } - // --- load 2D values into MEFISTO structure, - // add IDNodes in mefistoToDS map - - double f, l, uFirst, u; - Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l); - uFirst = isForward ? f : l; - - // vertex node - gp_Pnt2d p = C2d->Value( uFirst ).XY().Multiplied( scale ); - if ( fixCommonVertexUV( p, V, W, myOuterWire, F, VWMap, aMesh, _quadraticMesh )) - myNodesOnCommonV.push_back( idFirst ); - mOnVertex.push_back( m ); - uvslf[m].x = p.X(); - uvslf[m].y = p.Y(); - mefistoToDS[m + 1] = idFirst; - //MESSAGE(" "<::iterator u_n = params.begin(); - for ( int i = 0; u_n != params.end(); ++u_n, ++i ) + int mFirst = mOnVertex.front(), mLast = m - 1; + list< int >::iterator mIt = mOnVertex.begin(); + for ( ; mIt != mOnVertex.end(); ++mIt) { - u = isForward ? u_n->first : - u_n->first; - gp_Pnt2d p = C2d->Value( u ).XY().Multiplied( scale ); - uvslf[m].x = p.X(); - uvslf[m].y = p.Y(); - mefistoToDS[m + 1] = u_n->second; - //MESSAGE(" "<GetPosition()->GetShapeId(); + TopoDS_Vertex V = TopoDS::Vertex( myTool->GetMeshDS()->IndexToShape( vID )); + if ( fixCommonVertexUV( uvslf[m], V, F, VWMap, *myTool->GetMesh(), + scalex, scaley, _quadraticMesh )) { + myNodesOnCommonV.push_back( mefistoToDS[m] ); + continue; + } + } + // prevent failure on overlapped adjacent links, + // check only links ending in vertex nodes + int mB = m - 1, mA = m + 1; // indices Before and After + if ( mB < mFirst ) mB = mLast; + if ( mA > mLast ) mA = mFirst; + fixOverlappedLinkUV (uvslf[ mB ], uvslf[ m ], uvslf[ mA ]); } - } // for wexp - - // prevent failure on overlapped adjacent links, - // check only links ending in vertex nodes - int mFirst = mOnVertex.front(), mLast = m - 1; - list< int >::iterator mIt = mOnVertex.begin(); - for ( ; mIt != mOnVertex.end(); ++mIt ) { - int i = *mIt; - int iB = i - 1, iA = i + 1; // indices Before and After - if ( iB < mFirst ) iB = mLast; - if ( iA > mLast ) iA = mFirst; - fixOverlappedLinkUV (uvslf[ iB ], uvslf[ i ], uvslf[ iA ]); } return true; @@ -595,12 +554,12 @@ bool StdMeshers_MEFISTO_2D::LoadPoints(SMESH_Mesh & aMesh, */ //============================================================================= -void StdMeshers_MEFISTO_2D::ComputeScaleOnFace(SMESH_Mesh & aMesh, - const TopoDS_Face & aFace, double &scalex, double &scaley) +void StdMeshers_MEFISTO_2D::ComputeScaleOnFace(SMESH_Mesh & aMesh, + const TopoDS_Face & aFace, + double & scalex, + double & scaley) { - //MESSAGE("StdMeshers_MEFISTO_2D::ComputeScaleOnFace"); - TopoDS_Face F = TopoDS::Face(aFace.Oriented(TopAbs_FORWARD)); - TopoDS_Wire W = BRepTools::OuterWire(F); + TopoDS_Wire W = BRepTools::OuterWire(aFace); double xmin = 1.e300; // min & max of face 2D parametric coord. double xmax = -1.e300; @@ -615,7 +574,7 @@ void StdMeshers_MEFISTO_2D::ComputeScaleOnFace(SMESH_Mesh & aMesh, { const TopoDS_Edge & E = TopoDS::Edge( wexp.Current() ); double f, l; - Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l); + Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, aFace, f, l); if ( C2d.IsNull() ) continue; double du = (l - f) / double (nbp); for (int i = 0; i <= nbp; i++) @@ -642,7 +601,8 @@ void StdMeshers_MEFISTO_2D::ComputeScaleOnFace(SMESH_Mesh & aMesh, double xsize = xmax - xmin; double ysize = ymax - ymin; - Handle(Geom_Surface) S = BRep_Tool::Surface(F); // 3D surface + TopLoc_Location L; + Handle(Geom_Surface) S = BRep_Tool::Surface(aFace,L); // 3D surface double length_x = 0; double length_y = 0; @@ -688,21 +648,21 @@ void StdMeshers_MEFISTO_2D::ComputeScaleOnFace(SMESH_Mesh & aMesh, */ //============================================================================= -void StdMeshers_MEFISTO_2D::StoreResult(SMESH_Mesh & aMesh, - Z nbst, R2 * uvst, Z nbt, Z * nust, - const TopoDS_Face & F, bool faceIsForward, - map&mefistoToDS, +void StdMeshers_MEFISTO_2D::StoreResult(Z nbst, R2 * uvst, Z nbt, Z * nust, + vector< const SMDS_MeshNode*>&mefistoToDS, double scalex, double scaley) { - SMESHDS_Mesh * meshDS = aMesh.GetMeshDS(); - int faceID = meshDS->ShapeToIndex( F ); + SMESHDS_Mesh * meshDS = myTool->GetMeshDS(); + int faceID = myTool->GetSubShapeID(); - Z n, m; - Handle(Geom_Surface) S = BRep_Tool::Surface(F); + TopoDS_Face F = TopoDS::Face( myTool->GetSubShape() ); + Handle(Geom_Surface) S = BRep_Tool::Surface( F ); - for (n = 0; n < nbst; n++) + Z n = mefistoToDS.size(); // nb input points + mefistoToDS.resize( nbst ); + for ( ; n < nbst; n++) { - if (mefistoToDS.find(n + 1) == mefistoToDS.end()) + if (!mefistoToDS[n]) { double u = uvst[n][0] / scalex; double v = uvst[n][1] / scaley; @@ -712,30 +672,28 @@ void StdMeshers_MEFISTO_2D::StoreResult(SMESH_Mesh & aMesh, meshDS->SetNodeOnFace(node, faceID, u, v); //MESSAGE(P.X()<<" "<AddFace(n1, n2, n3); elt = myTool->AddFace(n1, n2, n3); else - //elt = meshDS->AddFace(n1, n3, n2); elt = myTool->AddFace(n1, n3, n2); meshDS->SetMeshElementOnShape(elt, faceID); @@ -763,82 +721,4 @@ void StdMeshers_MEFISTO_2D::StoreResult(SMESH_Mesh & aMesh, } } } - -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -double StdMeshers_MEFISTO_2D::ComputeEdgeElementLength(SMESH_Mesh & aMesh, - const TopoDS_Shape & aShape) -{ - //MESSAGE("StdMeshers_MEFISTO_2D::ComputeEdgeElementLength"); - // **** a mettre dans SMESH_2D_Algo ? - - //const TopoDS_Face & FF = TopoDS::Face(aShape); - //bool faceIsForward = (FF.Orientation() == TopAbs_FORWARD); - //TopoDS_Face F = TopoDS::Face(FF.Oriented(TopAbs_FORWARD)); - - double meanElementLength = 100; - double wireLength = 0; - int wireElementsNumber = 0; - for (TopExp_Explorer expe(aShape, TopAbs_EDGE); expe.More(); expe.Next()) - { - const TopoDS_Edge & E = TopoDS::Edge(expe.Current()); - int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); - double length = EdgeLength(E); - wireLength += length; - wireElementsNumber += nb; - } - if (wireElementsNumber) - meanElementLength = wireLength / wireElementsNumber; - //SCRUTE(meanElementLength); - return meanElementLength; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -ostream & StdMeshers_MEFISTO_2D::SaveTo(ostream & save) -{ - return save; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -istream & StdMeshers_MEFISTO_2D::LoadFrom(istream & load) -{ - return load; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -ostream & operator <<(ostream & save, StdMeshers_MEFISTO_2D & hyp) -{ - return hyp.SaveTo( save ); -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -istream & operator >>(istream & load, StdMeshers_MEFISTO_2D & hyp) -{ - return hyp.LoadFrom( load ); } diff --git a/src/StdMeshers/StdMeshers_MEFISTO_2D.hxx b/src/StdMeshers/StdMeshers_MEFISTO_2D.hxx index 5b27addcc..08536fcd6 100644 --- a/src/StdMeshers/StdMeshers_MEFISTO_2D.hxx +++ b/src/StdMeshers/StdMeshers_MEFISTO_2D.hxx @@ -31,24 +31,19 @@ #define _StdMeshers_MEFISTO_2D_HXX_ #include "SMESH_2D_Algo.hxx" -#include -#include "SMESH_MesherHelper.hxx" - -class SMDS_MeshNode; -class TopTools_IndexedDataMapOfShapeListOfShape; class TopoDS_Face; -class TopoDS_WIre; class StdMeshers_MaxElementArea; class StdMeshers_LengthFromEdges; class SMDS_MeshNode; +class SMESH_MesherHelper; +class StdMeshers_FaceSide; +#include #include -#include #include "Rn.h" -class StdMeshers_MEFISTO_2D: - public SMESH_2D_Algo +class StdMeshers_MEFISTO_2D: public SMESH_2D_Algo { public: StdMeshers_MEFISTO_2D(int hypId, int studyId, SMESH_Gen* gen); @@ -61,41 +56,29 @@ public: virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); - double ComputeEdgeElementLength(SMESH_Mesh& aMesh, - const TopoDS_Shape& aShape); + typedef boost::shared_ptr< StdMeshers_FaceSide> StdMeshers_FaceSidePtr; + typedef std::vector< StdMeshers_FaceSidePtr > TWireVector; - bool LoadPoints(SMESH_Mesh& aMesh, - const TopoDS_Face& F, - const TopoDS_Wire& W, - R2* uvslf, - int& m, - map& mefistoToDS, - double scalex, double scaley, - const TopTools_IndexedDataMapOfShapeListOfShape& VWMap); + bool LoadPoints(TWireVector & wires, + R2* uvslf, + std::vector< const SMDS_MeshNode*>& mefistoToDS, + double scalex, double scaley); void ComputeScaleOnFace(SMESH_Mesh& aMesh, const TopoDS_Face& aFace, double& scalex, double& scaley); - void StoreResult (SMESH_Mesh& aMesh, - Z nbst, R2* uvst, Z nbt, Z* nust, - const TopoDS_Face& F, bool faceIsForward, - map& mefistoToDS, + void StoreResult (Z nbst, R2* uvst, Z nbt, Z* nust, + std::vector< const SMDS_MeshNode*>& mefistoToDS, double scalex, double scaley); - ostream & SaveTo(ostream & save); - istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_MEFISTO_2D & hyp); - friend istream & operator >> (istream & load, StdMeshers_MEFISTO_2D & hyp); - protected: double _edgeLength; double _maxElementArea; const StdMeshers_MaxElementArea* _hypMaxElementArea; const StdMeshers_LengthFromEdges* _hypLengthFromEdges; - TopoDS_Wire myOuterWire; std::list myNodesOnCommonV; SMESH_MesherHelper* myTool; // toll for working with quadratic elements diff --git a/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx b/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx index fb24bf950..3cb243f8a 100644 --- a/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx +++ b/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx @@ -27,33 +27,38 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_Quadrangle_2D.hxx" + +#include "StdMeshers_FaceSide.hxx" + #include "SMESH_Gen.hxx" #include "SMESH_Mesh.hxx" #include "SMESH_subMesh.hxx" +#include "SMESH_MesherHelper.hxx" +#include "SMESH_Block.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" #include "SMDS_EdgePosition.hxx" #include "SMDS_FacePosition.hxx" +#include #include +#include #include #include - #include #include #include #include #include #include - #include #include #include #include #include +#include #include "utilities.h" #include "Utils_ExceptHandlers.hxx" @@ -61,12 +66,14 @@ using namespace std; #ifndef StdMeshers_Array2OfNode_HeaderFile #define StdMeshers_Array2OfNode_HeaderFile typedef const SMDS_MeshNode* SMDS_MeshNodePtr; -#include DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr) DEFINE_ARRAY2(StdMeshers_Array2OfNode, StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr) #endif +using namespace std; + +typedef gp_XY gp_UV; //============================================================================= /*! @@ -93,8 +100,6 @@ StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId, SMES StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D() { MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D"); - if ( myTool ) - delete myTool; } //============================================================================= @@ -128,52 +133,47 @@ bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) throw (SALOME_Exception) { Unexpect aCatch(SalomeException); - //MESSAGE("StdMeshers_Quadrangle_2D::Compute"); + SMESHDS_Mesh * meshDS = aMesh.GetMeshDS(); aMesh.GetSubMesh(aShape); - if ( !myTool ) - myTool = new SMESH_MesherHelper(aMesh); - _quadraticMesh = myTool->IsQuadraticSubMesh(aShape); + myTool = new SMESH_MesherHelper(aMesh); + std::auto_ptr helperDeleter( myTool );// to delete helper at exit from Compute() - //FaceQuadStruct *quad = CheckAnd2Dcompute(aMesh, aShape); - FaceQuadStruct* quad = CheckNbEdges(aMesh, aShape); + _quadraticMesh = myTool->IsQuadraticSubMesh(aShape); - if (!quad) { - delete myTool; myTool = 0; + FaceQuadStruct *quad = CheckNbEdges( aMesh, aShape ); + std::auto_ptr quadDeleter( quad ); // to delete quad at exit from Compute() + if (!quad) return false; - } if(myQuadranglePreference) { - int n1 = quad->nbPts[0]; - int n2 = quad->nbPts[1]; - int n3 = quad->nbPts[2]; - int n4 = quad->nbPts[3]; + int n1 = quad->side[0]->NbPoints(); + int n2 = quad->side[1]->NbPoints(); + int n3 = quad->side[2]->NbPoints(); + int n4 = quad->side[3]->NbPoints(); int nfull = n1+n2+n3+n4; int ntmp = nfull/2; ntmp = ntmp*2; if( nfull==ntmp && ( (n1!=n3) || (n2!=n4) ) ) { // special path for using only quandrangle faces bool ok = ComputeQuadPref(aMesh, aShape, quad); - delete myTool; myTool = 0; return ok; } } // set normalized grid on unit square in parametric domain - SetNormalizedGrid(aMesh, aShape, quad); - if (!quad) { - delete myTool; myTool = 0; + + if (!SetNormalizedGrid(aMesh, aShape, quad)) return false; - } // --- compute 3D values on points, store points & quadrangles - int nbdown = quad->nbPts[0]; - int nbup = quad->nbPts[2]; + int nbdown = quad->side[0]->NbPoints(); + int nbup = quad->side[2]->NbPoints(); - int nbright = quad->nbPts[1]; - int nbleft = quad->nbPts[3]; + int nbright = quad->side[1]->NbPoints(); + int nbleft = quad->side[3]->NbPoints(); int nbhoriz = Min(nbdown, nbup); int nbvertic = Min(nbright, nbleft); @@ -226,16 +226,15 @@ bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh, b = quad->uv_grid[j * nbhoriz + i + 1].node; c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node; d = quad->uv_grid[(j + 1) * nbhoriz + i].node; - //SMDS_MeshFace * face = meshDS->AddFace(a, b, c, d); SMDS_MeshFace* face = myTool->AddFace(a, b, c, d); meshDS->SetMeshElementOnShape(face, geomFaceID); } } - - UVPtStruct *uv_e0 = quad->uv_edges[0]; - UVPtStruct *uv_e1 = quad->uv_edges[1]; - UVPtStruct *uv_e2 = quad->uv_edges[2]; - UVPtStruct *uv_e3 = quad->uv_edges[3]; + + const vector& uv_e0 = quad->side[0]->GetUVPtStruct(true,0 ); + const vector& uv_e1 = quad->side[1]->GetUVPtStruct(false,1); + const vector& uv_e2 = quad->side[2]->GetUVPtStruct(true,1 ); + const vector& uv_e3 = quad->side[3]->GetUVPtStruct(false,0); double eps = Precision::Confusion(); @@ -549,21 +548,17 @@ bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh, } } - QuadDelete(quad); - delete myTool; myTool = 0; - bool isOk = true; return isOk; } - //============================================================================= /*! * */ //============================================================================= -FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh, +FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) throw(SALOME_Exception) { @@ -572,40 +567,43 @@ FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh, const TopoDS_Face & F = TopoDS::Face(aShape); // verify 1 wire only, with 4 edges - - if (NumberOfWires(F) != 1) { + TopoDS_Vertex V; + list< TopoDS_Edge > edges; + list< int > nbEdgesInWire; + int nbWire = SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire); + if (nbWire != 1) { INFOS("only 1 wire by face (quadrangles)"); return 0; } - const TopoDS_Wire& W = BRepTools::OuterWire(F); - BRepTools_WireExplorer wexp (W, F); - FaceQuadStruct* quad = new FaceQuadStruct; - for (int i = 0; i < 4; i++) - quad->uv_edges[i] = 0; quad->uv_grid = 0; - int nbEdges = 0; - for (wexp.Init(W, F); wexp.More(); wexp.Next()) { - const TopoDS_Edge& E = wexp.Current(); - int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); - if (nbEdges < 4) { - quad->edge[nbEdges] = E; - if(!_quadraticMesh) { - quad->nbPts[nbEdges] = nb + 2; // internal points + 2 extrema - } - else { - int tmp = nb/2; - quad->nbPts[nbEdges] = tmp + 2; // internal not medium points + 2 extrema + int nbSides = 0; + list< TopoDS_Edge >::iterator edgeIt = edges.begin(); + if ( nbEdgesInWire.front() == 4 ) { + for ( ; edgeIt != edges.end(); ++edgeIt, nbSides++ ) + quad->side[nbSides] = new StdMeshers_FaceSide(F,*edgeIt,&aMesh,nbSides sideEdges; + while ( edgeIt != edges.end()) { + sideEdges.clear(); + sideEdges.push_back( *edgeIt++ ); + bool sameSide = true; + while ( edgeIt != edges.end() && sameSide ) { + GeomAbs_Shape cont = SMESH_Algo::Continuity( sideEdges.back(), *edgeIt ); + sameSide = ( cont >= GeomAbs_C1 ); + if ( sameSide ) + sideEdges.push_back( *edgeIt++ ); } + quad->side[nbSides] = new StdMeshers_FaceSide(F,sideEdges,&aMesh,nbSides& GetUVPtStructIn(FaceQuadStruct* quad, int i, int nbSeg) { - for (int i = 0; i < 4; i++) - { - if (quad->uv_edges[i]) - delete [] quad->uv_edges[i]; - quad->edge[i].Nullify(); - } - if (quad->uv_grid) - delete [] quad->uv_grid; - delete quad; + bool isXConst = ( i == BOTTOM_SIDE || i == TOP_SIDE ); + double constValue = ( i == BOTTOM_SIDE || i == LEFT_SIDE ) ? 0 : 1; + return + quad->isEdgeOut[i] ? + quad->side[i]->SimulateUVPtStruct(nbSeg,isXConst,constValue) : + quad->side[i]->GetUVPtStruct(isXConst,constValue); } } @@ -665,7 +667,7 @@ void StdMeshers_Quadrangle_2D::QuadDelete (FaceQuadStruct * quad) */ //============================================================================= -void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh, +bool StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh, const TopoDS_Shape& aShape, FaceQuadStruct* & quad) throw (SALOME_Exception) { @@ -676,7 +678,7 @@ void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh, // transport - projection sur le carré unité // MESSAGE("StdMeshers_Quadrangle_2D::SetNormalizedGrid"); - const TopoDS_Face& F = TopoDS::Face(aShape); +// const TopoDS_Face& F = TopoDS::Face(aShape); // 1 --- find orientation of the 4 edges, by test on extrema @@ -692,88 +694,27 @@ void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh, // =down // - Handle(Geom2d_Curve) c2d[4]; - gp_Pnt2d pf[4]; - gp_Pnt2d pl[4]; - for (int i = 0; i < 4; i++) - { - c2d[i] = BRep_Tool::CurveOnSurface(quad->edge[i], F, - quad->first[i], quad->last[i]); - pf[i] = c2d[i]->Value(quad->first[i]); - pl[i] = c2d[i]->Value(quad->last[i]); - quad->isEdgeForward[i] = false; - } + // 3 --- 2D normalized values on unit square [0..1][0..1] - double l0f1 = pl[0].SquareDistance(pf[1]); - double l0l1 = pl[0].SquareDistance(pl[1]); - double f0f1 = pf[0].SquareDistance(pf[1]); - double f0l1 = pf[0].SquareDistance(pl[1]); - if ( Min( l0f1, l0l1 ) < Min ( f0f1, f0l1 )) - { - quad->isEdgeForward[0] = true; - } else { - double tmp = quad->first[0]; - quad->first[0] = quad->last[0]; - quad->last[0] = tmp; - pf[0] = c2d[0]->Value(quad->first[0]); - pl[0] = c2d[0]->Value(quad->last[0]); - } - for (int i = 1; i < 4; i++) - { - l0l1 = pl[i - 1].SquareDistance(pl[i]); - l0f1 = pl[i - 1].SquareDistance(pf[i]); - quad->isEdgeForward[i] = ( l0f1 < l0l1 ); - if (!quad->isEdgeForward[i]) - { - double tmp = quad->first[i]; - quad->first[i] = quad->last[i]; - quad->last[i] = tmp; - pf[i] = c2d[i]->Value(quad->first[i]); - pl[i] = c2d[i]->Value(quad->last[i]); - } - } + int nbhoriz = Min(quad->side[0]->NbPoints(), quad->side[2]->NbPoints()); + int nbvertic = Min(quad->side[1]->NbPoints(), quad->side[3]->NbPoints()); - // 2 --- load 2d edge points (u,v) with orientation and value on unit square + quad->isEdgeOut[0] = (quad->side[0]->NbPoints() > quad->side[2]->NbPoints()); + quad->isEdgeOut[1] = (quad->side[1]->NbPoints() > quad->side[3]->NbPoints()); + quad->isEdgeOut[2] = (quad->side[2]->NbPoints() > quad->side[0]->NbPoints()); + quad->isEdgeOut[3] = (quad->side[3]->NbPoints() > quad->side[1]->NbPoints()); - bool loadOk = true; - for (int i = 0; i < 2; i++) - { - quad->uv_edges[i] = LoadEdgePoints(aMesh, F, quad->edge[i], - quad->first[i], quad->last[i]); - if (!quad->uv_edges[i]) loadOk = false; - } + UVPtStruct *uv_grid = quad->uv_grid = new UVPtStruct[nbvertic * nbhoriz]; - for (int i = 2; i < 4; i++) - { - quad->uv_edges[i] = LoadEdgePoints(aMesh, F, quad->edge[i], - quad->last[i], quad->first[i]); - if (!quad->uv_edges[i]) loadOk = false; - } + const vector& uv_e0 = GetUVPtStructIn( quad, 0, nbhoriz - 1 ); + const vector& uv_e1 = GetUVPtStructIn( quad, 1, nbvertic - 1 ); + const vector& uv_e2 = GetUVPtStructIn( quad, 2, nbhoriz - 1 ); + const vector& uv_e3 = GetUVPtStructIn( quad, 3, nbvertic - 1 ); - if (!loadOk) - { - INFOS("StdMeshers_Quadrangle_2D::SetNormalizedGrid - LoadEdgePoints failed"); - QuadDelete( quad ); - quad = 0; - return; + if ( uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty() ) { + MESSAGE("Nodes from edges not loaded"); + return false; } - // 3 --- 2D normalized values on unit square [0..1][0..1] - - int nbhoriz = Min(quad->nbPts[0], quad->nbPts[2]); - int nbvertic = Min(quad->nbPts[1], quad->nbPts[3]); - - quad->isEdgeOut[0] = (quad->nbPts[0] > quad->nbPts[2]); - quad->isEdgeOut[1] = (quad->nbPts[1] > quad->nbPts[3]); - quad->isEdgeOut[2] = (quad->nbPts[2] > quad->nbPts[0]); - quad->isEdgeOut[3] = (quad->nbPts[3] > quad->nbPts[1]); - - quad->uv_grid = new UVPtStruct[nbvertic * nbhoriz]; - - UVPtStruct *uv_grid = quad->uv_grid; - UVPtStruct *uv_e0 = quad->uv_edges[0]; - UVPtStruct *uv_e1 = quad->uv_edges[1]; - UVPtStruct *uv_e2 = quad->uv_edges[2]; - UVPtStruct *uv_e3 = quad->uv_edges[3]; // nodes Id on "in" edges if (! quad->isEdgeOut[0]) { @@ -805,21 +746,6 @@ void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh, } } - // falsificate "out" edges - if (quad->isEdgeOut[0]) // down - uv_e0 = MakeEdgePoints - (aMesh, F, quad->edge[0], quad->first[0], quad->last[0], nbhoriz - 1); - else if (quad->isEdgeOut[2]) // up - uv_e2 = MakeEdgePoints - (aMesh, F, quad->edge[2], quad->last[2], quad->first[2], nbhoriz - 1); - - if (quad->isEdgeOut[1]) // right - uv_e1 = MakeEdgePoints - (aMesh, F, quad->edge[1], quad->first[1], quad->last[1], nbvertic - 1); - else if (quad->isEdgeOut[3]) // left - uv_e3 = MakeEdgePoints - (aMesh, F, quad->edge[3], quad->last[3], quad->first[3], nbvertic - 1); - // normalized 2d values on grid for (int i = 0; i < nbhoriz; i++) { @@ -843,10 +769,10 @@ void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh, } // 4 --- projection on 2d domain (u,v) - gp_Pnt2d a0 = pf[0]; - gp_Pnt2d a1 = pf[1]; - gp_Pnt2d a2 = pf[2]; - gp_Pnt2d a3 = pf[3]; + gp_UV a0( uv_e0.front().u, uv_e0.front().v ); + gp_UV a1( uv_e0.back().u, uv_e0.back().v ); + gp_UV a2( uv_e2.back().u, uv_e2.back().v ); + gp_UV a3( uv_e2.front().u, uv_e2.front().v ); for (int i = 0; i < nbhoriz; i++) { @@ -855,157 +781,85 @@ void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh, int ij = j * nbhoriz + i; double x = uv_grid[ij].x; double y = uv_grid[ij].y; - double param_0 = uv_e0[0].param + x * (uv_e0[nbhoriz - 1].param - uv_e0[0].param); // sud - double param_2 = uv_e2[0].param + x * (uv_e2[nbhoriz - 1].param - uv_e2[0].param); // nord - double param_1 = uv_e1[0].param + y * (uv_e1[nbvertic - 1].param - uv_e1[0].param); // est - double param_3 = uv_e3[0].param + y * (uv_e3[nbvertic - 1].param - uv_e3[0].param); // ouest + double param_0 = uv_e0[0].normParam + x * (uv_e0.back().normParam - uv_e0[0].normParam); // sud + double param_2 = uv_e2[0].normParam + x * (uv_e2.back().normParam - uv_e2[0].normParam); // nord + double param_1 = uv_e1[0].normParam + y * (uv_e1.back().normParam - uv_e1[0].normParam); // est + double param_3 = uv_e3[0].normParam + y * (uv_e3.back().normParam - uv_e3[0].normParam); // ouest //MESSAGE("params "<Value(param_0); - gp_Pnt2d p1 = c2d[1]->Value(param_1); - gp_Pnt2d p2 = c2d[2]->Value(param_2); - gp_Pnt2d p3 = c2d[3]->Value(param_3); + gp_UV p0 = quad->side[0]->Value2d(param_0).XY(); + gp_UV p1 = quad->side[1]->Value2d(param_1).XY(); + gp_UV p2 = quad->side[2]->Value2d(param_2).XY(); + gp_UV p3 = quad->side[3]->Value2d(param_3).XY(); - double u = (1 - y) * p0.X() + x * p1.X() + y * p2.X() + (1 - x) * p3.X(); - double v = (1 - y) * p0.Y() + x * p1.Y() + y * p2.Y() + (1 - x) * p3.Y(); + gp_UV uv = (1 - y) * p0 + x * p1 + y * p2 + (1 - x) * p3; + uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3; - u -= (1 - x) * (1 - y) * a0.X() + x * (1 - y) * a1.X() + - x * y * a2.X() + (1 - x) * y * a3.X(); - v -= (1 - x) * (1 - y) * a0.Y() + x * (1 - y) * a1.Y() + - x * y * a2.Y() + (1 - x) * y * a3.Y(); - - uv_grid[ij].u = u; - uv_grid[ij].v = v; + uv_grid[ij].u = uv.X(); + uv_grid[ij].v = uv.Y(); } } + return true; } - //======================================================================= //function : ShiftQuad //purpose : auxilary function for ComputeQuadPref //======================================================================= -static void ShiftQuad(FaceQuadStruct* quad, const int num, bool WisF) + +static void ShiftQuad(FaceQuadStruct* quad, const int num, bool) { - if(num>3) return; - int i; - for(i=1; i<=num; i++) { - int nbPts3 = quad->nbPts[0]; - quad->nbPts[0] = quad->nbPts[1]; - quad->nbPts[1] = quad->nbPts[2]; - quad->nbPts[2] = quad->nbPts[3]; - quad->nbPts[3] = nbPts3; - TopoDS_Edge edge3 = quad->edge[0]; - quad->edge[0] = quad->edge[1]; - quad->edge[1] = quad->edge[2]; - quad->edge[2] = quad->edge[3]; - quad->edge[3] = edge3; - double first3 = quad->first[0]; - quad->first[0] = quad->first[1]; - quad->first[1] = quad->first[2]; - quad->first[2] = quad->first[3]; - quad->first[3] = first3; - double last3 = quad->last[0]; - quad->last[0] = quad->last[1]; - quad->last[1] = quad->last[2]; - quad->last[2] = quad->last[3]; - quad->last[3] = last3; - bool isEdgeForward3 = quad->isEdgeForward[0]; - quad->isEdgeForward[0] = quad->isEdgeForward[1]; - quad->isEdgeForward[1] = quad->isEdgeForward[2]; - quad->isEdgeForward[2] = quad->isEdgeForward[3]; - quad->isEdgeForward[3] = isEdgeForward3; - bool isEdgeOut3 = quad->isEdgeOut[0]; - quad->isEdgeOut[0] = quad->isEdgeOut[1]; - quad->isEdgeOut[1] = quad->isEdgeOut[2]; - quad->isEdgeOut[2] = quad->isEdgeOut[3]; - quad->isEdgeOut[3] = isEdgeOut3; - UVPtStruct* uv_edges3 = quad->uv_edges[0]; - quad->uv_edges[0] = quad->uv_edges[1]; - quad->uv_edges[1] = quad->uv_edges[2]; - quad->uv_edges[2] = quad->uv_edges[3]; - quad->uv_edges[3] = uv_edges3; - } - if(!WisF) { - // replacement left and right edges - int nbPts3 = quad->nbPts[1]; - quad->nbPts[1] = quad->nbPts[3]; - quad->nbPts[3] = nbPts3; - TopoDS_Edge edge3 = quad->edge[1]; - quad->edge[1] = quad->edge[3]; - quad->edge[3] = edge3; - double first3 = quad->first[1]; - quad->first[1] = quad->first[3]; - quad->first[3] = first3; - double last3 = quad->last[1]; - quad->last[1] = quad->last[2]; - quad->last[3] = last3; - bool isEdgeForward3 = quad->isEdgeForward[1]; - quad->isEdgeForward[1] = quad->isEdgeForward[3]; - quad->isEdgeForward[3] = isEdgeForward3; - bool isEdgeOut3 = quad->isEdgeOut[1]; - quad->isEdgeOut[1] = quad->isEdgeOut[3]; - quad->isEdgeOut[3] = isEdgeOut3; - UVPtStruct* uv_edges3 = quad->uv_edges[1]; - quad->uv_edges[1] = quad->uv_edges[3]; - quad->uv_edges[3] = uv_edges3; + StdMeshers_FaceSide* side[4] = { quad->side[0], quad->side[1], quad->side[2], quad->side[3] }; + for (int i = BOTTOM_SIDE; i < NB_SIDES; ++i ) { + int id = ( i + num ) % NB_SIDES; + bool wasForward = ( i < TOP_SIDE ); + bool newForward = ( id < TOP_SIDE ); + if ( wasForward != newForward ) + side[ i ]->Reverse(); + quad->side[ id ] = side[ i ]; } } - //======================================================================= //function : CalcUV //purpose : auxilary function for ComputeQuadPref //======================================================================= -static gp_XY CalcUV(double x0, double x1, double y0, double y1, + +static gp_UV CalcUV(double x0, double x1, double y0, double y1, FaceQuadStruct* quad, - const gp_Pnt2d& a0, const gp_Pnt2d& a1, - const gp_Pnt2d& a2, const gp_Pnt2d& a3, - const Handle(Geom2d_Curve)& c2db, - const Handle(Geom2d_Curve)& c2dr, - const Handle(Geom2d_Curve)& c2dt, - const Handle(Geom2d_Curve)& c2dl) + const gp_UV& a0, const gp_UV& a1, + const gp_UV& a2, const gp_UV& a3) { - int nb = quad->nbPts[0]; - int nr = quad->nbPts[1]; - int nt = quad->nbPts[2]; - int nl = quad->nbPts[3]; - - UVPtStruct* uv_eb = quad->uv_edges[0]; - UVPtStruct* uv_er = quad->uv_edges[1]; - UVPtStruct* uv_et = quad->uv_edges[2]; - UVPtStruct* uv_el = quad->uv_edges[3]; + const vector& uv_eb = quad->side[0]->GetUVPtStruct(true,0 ); + const vector& uv_er = quad->side[1]->GetUVPtStruct(false,1); + const vector& uv_et = quad->side[2]->GetUVPtStruct(true,1 ); + const vector& uv_el = quad->side[3]->GetUVPtStruct(false,0); double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0)); double y = y0 + x * (y1 - y0); - double param_b = uv_eb[0].param + x * (uv_eb[nb-1].param - uv_eb[0].param); - double param_t = uv_et[0].param + x * (uv_et[nt-1].param - uv_et[0].param); - double param_r = uv_er[0].param + y * (uv_er[nr-1].param - uv_er[0].param); - double param_l = uv_el[0].param + y * (uv_el[nl-1].param - uv_el[0].param); + double param_b = uv_eb[0].normParam + x * (uv_eb.back().normParam - uv_eb[0].normParam); + double param_t = uv_et[0].normParam + x * (uv_et.back().normParam - uv_et[0].normParam); + double param_r = uv_er[0].normParam + y * (uv_er.back().normParam - uv_er[0].normParam); + double param_l = uv_el[0].normParam + y * (uv_el.back().normParam - uv_el[0].normParam); - gp_Pnt2d p0 = c2db->Value(param_b); - gp_Pnt2d p1 = c2dr->Value(param_r); - gp_Pnt2d p2 = c2dt->Value(param_t); - gp_Pnt2d p3 = c2dl->Value(param_l); + gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(param_b).XY(); + gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(param_r).XY(); + gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(param_t).XY(); + gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(param_l).XY(); - double u = (1 - y) * p0.X() + x * p1.X() + y * p2.X() + (1 - x) * p3.X(); - double v = (1 - y) * p0.Y() + x * p1.Y() + y * p2.Y() + (1 - x) * p3.Y(); + gp_UV uv = p0 * (1 - y) + p1 * x + p2 * y + p3 * (1 - x); - u -= (1 - x) * (1 - y) * a0.X() + x * (1 - y) * a1.X() + - x * y * a2.X() + (1 - x) * y * a3.X(); - v -= (1 - x) * (1 - y) * a0.Y() + x * (1 - y) * a1.Y() + - x * y * a2.Y() + (1 - x) * y * a3.Y(); + uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3; //cout<<"x0="<uv_edges[0]; - UVPtStruct* uv_er = quad->uv_edges[1]; - UVPtStruct* uv_et = quad->uv_edges[2]; - UVPtStruct* uv_el = quad->uv_edges[3]; + const vector& uv_eb = quad->side[0]->GetUVPtStruct(true,0 ); + const vector& uv_er = quad->side[1]->GetUVPtStruct(false,1); + const vector& uv_et = quad->side[2]->GetUVPtStruct(true,1 ); + const vector& uv_el = quad->side[3]->GetUVPtStruct(false,0); // arrays for normalized params //cout<<"Dump B:"<X()<<","<Y()<<","<Z()<<")"<D0(uv_eb[0].param,a[0]); - c2d[0]->D0(uv_eb[nb-1].param,a[1]); - c2d[2]->D0(uv_et[nt-1].param,a[2]); - c2d[2]->D0(uv_et[0].param,a[3]); - //cout<<" a[0]("<0) { // add top nodes @@ -1192,8 +1022,7 @@ bool StdMeshers_Quadrangle_2D::ComputeQuadPref // diagonal node double y0 = npl.Value(i+1); double y1 = npr.Value(i+1); - gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3], - c2d[0], c2d[1], c2d[2], c2d[3]); + gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3); gp_Pnt P = S->Value(UV.X(),UV.Y()); SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z()); meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); @@ -1203,8 +1032,7 @@ bool StdMeshers_Quadrangle_2D::ComputeQuadPref for(j=2; jValue(UV.X(),UV.Y()); SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); @@ -1244,9 +1072,7 @@ bool StdMeshers_Quadrangle_2D::ComputeQuadPref else { // fill UVL using c2d for(i=1; iD0(uv_el[i].param,p2d); - UVL.Append(p2d.XY()); + UVL.Append( gp_UV ( uv_el[i].u, uv_el[i].v )); } } @@ -1267,8 +1093,7 @@ bool StdMeshers_Quadrangle_2D::ComputeQuadPref // diagonal node double y0 = npl.Value(i+1); double y1 = npr.Value(i+1); - gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3], - c2d[0], c2d[1], c2d[2], c2d[3]); + gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3); gp_Pnt P = S->Value(UV.X(),UV.Y()); SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z()); meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); @@ -1278,8 +1103,7 @@ bool StdMeshers_Quadrangle_2D::ComputeQuadPref for(j=2; jValue(UV.X(),UV.Y()); SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); @@ -1311,9 +1135,7 @@ bool StdMeshers_Quadrangle_2D::ComputeQuadPref else { // fill UVR using c2d for(i=1; iD0(uv_er[i].param,p2d); - UVR.Append(p2d.XY()); + UVR.Append( gp_UV( uv_er[i].u, uv_er[i].v )); } } @@ -1333,11 +1155,9 @@ bool StdMeshers_Quadrangle_2D::ComputeQuadPref for(i=dl+2; iD0(uv_eb[i-1].param,p2d); - } + // create and add needed nodes // add linear layers for(i=2; iValue(UV.X(),UV.Y()); SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); @@ -1391,470 +1210,7 @@ bool StdMeshers_Quadrangle_2D::ComputeQuadPref } } - QuadDelete(quad); bool isOk = true; return isOk; } - -//============================================================================= -/*! - * LoadEdgePoints2 - */ -//============================================================================= -UVPtStruct* StdMeshers_Quadrangle_2D::LoadEdgePoints2 (SMESH_Mesh & aMesh, - const TopoDS_Face& F, - const TopoDS_Edge& E, - bool IsReverse) -{ - //MESSAGE("StdMeshers_Quadrangle_2D::LoadEdgePoints"); - // --- IDNodes of first and last Vertex - TopoDS_Vertex VFirst, VLast; - TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l - - ASSERT(!VFirst.IsNull()); - SMDS_NodeIteratorPtr lid = aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes(); - if (!lid->more()) { - MESSAGE ( "NO NODE BUILT ON VERTEX" ); - return 0; - } - const SMDS_MeshNode* idFirst = lid->next(); - - ASSERT(!VLast.IsNull()); - lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes(); - if (!lid->more()) { - MESSAGE ( "NO NODE BUILT ON VERTEX" ); - return 0; - } - const SMDS_MeshNode* idLast = lid->next(); - - // --- edge internal IDNodes (relies on good order storage, not checked) - - map params; - SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes(); - int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); - - if(!_quadraticMesh) { - while(ite->more()) { - const SMDS_MeshNode* node = ite->next(); - const SMDS_EdgePosition* epos = - static_cast(node->GetPosition().get()); - double param = epos->GetUParameter(); - params[param] = node; - } - } - else { - vector nodes(nbPoints+2); - nodes[0] = idFirst; - nodes[nbPoints+1] = idLast; - nbPoints = nbPoints/2; - int nn = 1; - while(ite->more()) { - const SMDS_MeshNode* node = ite->next(); - nodes[nn++] = node; - // check if node is medium - bool IsMedium = false; - SMDS_ElemIteratorPtr itn = node->GetInverseElementIterator(); - while (itn->more()) { - const SMDS_MeshElement* elem = itn->next(); - if ( elem->GetType() != SMDSAbs_Edge ) - continue; - if(elem->IsMediumNode(node)) { - IsMedium = true; - break; - } - } - if(IsMedium) - continue; - const SMDS_EdgePosition* epos = - static_cast(node->GetPosition().get()); - double param = epos->GetUParameter(); - params[param] = node; - } - } - - if (nbPoints != params.size()) { - MESSAGE( "BAD NODE ON EDGE POSITIONS" ); - return 0; - } - UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2]; - - double f, l; - Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l); - - const TopoDS_Wire& W = BRepTools::OuterWire(F); - bool FisF = (F.Orientation()==TopAbs_FORWARD); - bool WisF = (W.Orientation()==TopAbs_FORWARD); - bool isForward = (E.Orientation()==TopAbs_FORWARD); - //if(isForward) cout<<"E is FORWARD"<Value(f); // first point = Vertex Forward - uvslf[0].x = p.X(); - uvslf[0].y = p.Y(); - uvslf[0].param = f; - uvslf[0].node = idFirst; - //MESSAGE("__ f "<::iterator itp = params.begin(); - for (int i = 1; i <= nbPoints; i++) { // nbPoints internal - double param = (*itp).first; - gp_Pnt2d p = C2d->Value(param); - uvslf[i].x = p.X(); - uvslf[i].y = p.Y(); - uvslf[i].param = param; - uvslf[i].node = (*itp).second; - //MESSAGE("__ "<Value(l); // last point = Vertex Reversed - uvslf[nbPoints + 1].x = p.X(); - uvslf[nbPoints + 1].y = p.Y(); - uvslf[nbPoints + 1].param = l; - uvslf[nbPoints + 1].node = idLast; - //MESSAGE("__ l "<Value(l); // first point = Vertex Reversed - uvslf[0].x = p.X(); - uvslf[0].y = p.Y(); - uvslf[0].param = l; - uvslf[0].node = idLast; - //MESSAGE("__ l "<::reverse_iterator itp = params.rbegin(); - for (int j = nbPoints; j >= 1; j--) { // nbPoints internal - double param = (*itp).first; - int i = nbPoints + 1 - j; - gp_Pnt2d p = C2d->Value(param); - uvslf[i].x = p.X(); - uvslf[i].y = p.Y(); - uvslf[i].param = param; - uvslf[i].node = (*itp).second; - //MESSAGE("__ "<Value(f); // last point = Vertex Forward - uvslf[nbPoints + 1].x = p.X(); - uvslf[nbPoints + 1].y = p.Y(); - uvslf[nbPoints + 1].param = f; - uvslf[nbPoints + 1].node = idFirst; - //MESSAGE("__ f "<GetSubMeshDS()->GetNodes(); - if (!lid->more()) - { - MESSAGE ( "NO NODE BUILT ON VERTEX" ); - return 0; - } - const SMDS_MeshNode* idFirst = lid->next(); - - ASSERT(!VLast.IsNull()); - lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes(); - if (!lid->more()) - { - MESSAGE ( "NO NODE BUILT ON VERTEX" ); - return 0; - } - const SMDS_MeshNode* idLast = lid->next(); - - // --- edge internal IDNodes (relies on good order storage, not checked) - -// if(_quadraticMesh) { - // fill myNLinkNodeMap -// SMDS_ElemIteratorPtr iter = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetElements(); -// while(iter->more()) { -// const SMDS_MeshElement* elem = iter->next(); -// SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator(); -// const SMDS_MeshNode* n1 = static_cast( nodeIt->next() ); -// const SMDS_MeshNode* n2 = static_cast( nodeIt->next() ); -// const SMDS_MeshNode* n3 = static_cast( nodeIt->next() ); -// NLink link(( n1 < n2 ? n1 : n2 ), ( n1 < n2 ? n2 : n1 )); -// myNLinkNodeMap.insert(NLinkNodeMap::value_type(link,n3)); -// myNLinkNodeMap[link] = n3; -// } -// } - - map params; - SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes(); - int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); - - if(!_quadraticMesh) { - while(ite->more()) { - const SMDS_MeshNode* node = ite->next(); - const SMDS_EdgePosition* epos = - static_cast(node->GetPosition().get()); - double param = epos->GetUParameter(); - params[param] = node; - } - } - else { - nbPoints = nbPoints/2; - while(ite->more()) { - const SMDS_MeshNode* node = ite->next(); - // check if node is medium - bool IsMedium = false; - SMDS_ElemIteratorPtr itn = node->GetInverseElementIterator(); - while (itn->more()) { - const SMDS_MeshElement* elem = itn->next(); - if ( elem->GetType() != SMDSAbs_Edge ) - continue; - if(elem->IsMediumNode(node)) { - IsMedium = true; - break; - } - } - if(IsMedium) - continue; - const SMDS_EdgePosition* epos = - static_cast(node->GetPosition().get()); - double param = epos->GetUParameter(); - params[param] = node; - } - } - - if (nbPoints != params.size()) { - MESSAGE( "BAD NODE ON EDGE POSITIONS" ); - return 0; - } - UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2]; - - double f, l; - Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l); - - bool isForward = (((l - f) * (last - first)) > 0); - double paramin = 0; - double paramax = 0; - if (isForward) - { - paramin = f; - paramax = l; - gp_Pnt2d p = C2d->Value(f); // first point = Vertex Forward - uvslf[0].x = p.X(); - uvslf[0].y = p.Y(); - uvslf[0].param = f; - uvslf[0].node = idFirst; - //MESSAGE("__ f "<::iterator itp = params.begin(); - for (int i = 1; i <= nbPoints; i++) // nbPoints internal - { - double param = (*itp).first; - gp_Pnt2d p = C2d->Value(param); - uvslf[i].x = p.X(); - uvslf[i].y = p.Y(); - uvslf[i].param = param; - uvslf[i].node = (*itp).second; - //MESSAGE("__ "<Value(l); // last point = Vertex Reversed - uvslf[nbPoints + 1].x = p.X(); - uvslf[nbPoints + 1].y = p.Y(); - uvslf[nbPoints + 1].param = l; - uvslf[nbPoints + 1].node = idLast; - //MESSAGE("__ l "<Value(l); // first point = Vertex Reversed - uvslf[0].x = p.X(); - uvslf[0].y = p.Y(); - uvslf[0].param = l; - uvslf[0].node = idLast; - //MESSAGE("__ l "<::reverse_iterator itp = params.rbegin(); - - for (int j = nbPoints; j >= 1; j--) // nbPoints internal - { - double param = (*itp).first; - int i = nbPoints + 1 - j; - gp_Pnt2d p = C2d->Value(param); - uvslf[i].x = p.X(); - uvslf[i].y = p.Y(); - uvslf[i].param = param; - uvslf[i].node = (*itp).second; - //MESSAGE("__ "<Value(f); // last point = Vertex Forward - uvslf[nbPoints + 1].x = p.X(); - uvslf[nbPoints + 1].y = p.Y(); - uvslf[nbPoints + 1].param = f; - uvslf[nbPoints + 1].node = idFirst; - //MESSAGE("__ f "< params; - - // --- edge internal points - double fi, li; - Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, fi, li); - if (!Curve.IsNull()) { - try { - GeomAdaptor_Curve C3d (Curve); - double length = EdgeLength(E); - double eltSize = length / nb_segm; - GCPnts_UniformAbscissa Discret (C3d, eltSize, fi, li); - if (!Discret.IsDone()) return false; - int NbPoints = Discret.NbPoints(); - for (int i = 1; i <= NbPoints; i++) { - double param = Discret.Parameter(i); - params.push_back(param); - } - } - catch (Standard_Failure) { - return 0; - } - } - else - { - // Edge is a degenerated Edge - BRep_Tool::Range(E, fi, li); - double du = (li - fi) / nb_segm; - for (int i = 1; i <= nb_segm + 1; i++) - { - double param = fi + (i - 1) * du; - params.push_back(param); - } - } - - double f, l; - Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l); - ASSERT(f != l); - - bool isForward = (((l - f) * (last - first)) > 0); - if (isForward) { - list::iterator itU = params.begin(); - for (int i = 0; i <= nb_segm; i++) // nbPoints internal - { - double param = *itU; - gp_Pnt2d p = C2d->Value(param); - uvslf[i].x = p.X(); - uvslf[i].y = p.Y(); - uvslf[i].param = param; - uvslf[i].normParam = (param - f) / (l - f); - itU++; - } - } else { - list::reverse_iterator itU = params.rbegin(); - for (int j = nb_segm; j >= 0; j--) // nbPoints internal - { - double param = *itU; - int i = nb_segm - j; - gp_Pnt2d p = C2d->Value(param); - uvslf[i].x = p.X(); - uvslf[i].y = p.Y(); - uvslf[i].param = param; - uvslf[i].normParam = (param - l) / (f - l); - itU++; - } - } - - return uvslf; -} - - -//============================================================================= -/*! - * - */ -//============================================================================= - -ostream & StdMeshers_Quadrangle_2D::SaveTo(ostream & save) -{ - return save; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -istream & StdMeshers_Quadrangle_2D::LoadFrom(istream & load) -{ - return load; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -ostream & operator <<(ostream & save, StdMeshers_Quadrangle_2D & hyp) -{ - return hyp.SaveTo( save ); -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -istream & operator >>(istream & load, StdMeshers_Quadrangle_2D & hyp) -{ - return hyp.LoadFrom( load ); -} diff --git a/src/StdMeshers/StdMeshers_Quadrangle_2D.hxx b/src/StdMeshers/StdMeshers_Quadrangle_2D.hxx index 769ed12f3..1bc272a5c 100644 --- a/src/StdMeshers/StdMeshers_Quadrangle_2D.hxx +++ b/src/StdMeshers/StdMeshers_Quadrangle_2D.hxx @@ -31,40 +31,33 @@ #define _SMESH_QUADRANGLE_2D_HXX_ #include "SMESH_2D_Algo.hxx" -#include "SMESH_Mesh.hxx" #include "Utils_SALOME_Exception.hxx" -#include "gp_XY.hxx" - -#include "SMESH_MesherHelper.hxx" +class SMESH_Mesh; +class SMESH_MesherHelper; +class StdMeshers_FaceSide; +struct uvPtStruct; //class SMDS_MeshNode; -typedef struct uvPtStruct -{ - double param; - double normParam; - double u; // original 2d parameter - double v; - double x; // 2d parameter, normalized [0,1] - double y; - const SMDS_MeshNode * node; -} UVPtStruct; +enum TSideID { BOTTOM_SIDE=0, RIGHT_SIDE, TOP_SIDE, LEFT_SIDE, NB_SIDES }; +typedef uvPtStruct UVPtStruct; typedef struct faceQuadStruct { - int nbPts[4]; - TopoDS_Edge edge[4]; - double first[4]; - double last[4]; - bool isEdgeForward[4]; + //int nbPts[4]; + //TopoDS_Edge edge[4]; + StdMeshers_FaceSide* side[4]; + //double first[4]; + //double last[4]; + //bool isEdgeForward[4]; bool isEdgeOut[4]; // true, if an edge has more nodes, than the opposite - UVPtStruct* uv_edges[4]; + //UVPtStruct* uv_edges[4]; UVPtStruct* uv_grid; + ~faceQuadStruct(); } FaceQuadStruct; -class StdMeshers_Quadrangle_2D: - public SMESH_2D_Algo +class StdMeshers_Quadrangle_2D: public SMESH_2D_Algo { public: StdMeshers_Quadrangle_2D(int hypId, int studyId, SMESH_Gen* gen); @@ -83,25 +76,13 @@ public: const bool CreateQuadratic) throw (SALOME_Exception); - static void QuadDelete(FaceQuadStruct* quad); - - /** - * Returns NLinkNodeMap from myTool - */ - const NLinkNodeMap& GetNLinkNodeMap() { return myTool->GetNLinkNodeMap(); } - - ostream & SaveTo(ostream & save); - istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_Quadrangle_2D & hyp); - friend istream & operator >> (istream & load, StdMeshers_Quadrangle_2D & hyp); - protected: FaceQuadStruct* CheckNbEdges(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) throw (SALOME_Exception); - void SetNormalizedGrid(SMESH_Mesh& aMesh, + bool SetNormalizedGrid(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, FaceQuadStruct*& quad) throw (SALOME_Exception); @@ -131,7 +112,7 @@ protected: // is not the same in the case where the global number of nodes on edges is even bool myQuadranglePreference; - SMESH_MesherHelper* myTool; // toll for working with quadratic elements + SMESH_MesherHelper* myTool; // tool for working with quadratic elements }; #endif -- 2.39.2