X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FStdMeshers%2FStdMeshers_FaceSide.cxx;h=1424e4226c40d4b92ffce8f8355cbbc73e6f79c1;hp=07b574a6f35e0e19965ef31feb91ecd4973690cc;hb=096485adbe5e66ace1182bf6c49dc6853f437d9c;hpb=a406fd679300d97b7623d02191f9eaaffff2a019 diff --git a/src/StdMeshers/StdMeshers_FaceSide.cxx b/src/StdMeshers/StdMeshers_FaceSide.cxx index 07b574a6f..1424e4226 100644 --- a/src/StdMeshers/StdMeshers_FaceSide.cxx +++ b/src/StdMeshers/StdMeshers_FaceSide.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -6,7 +6,7 @@ // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -55,12 +56,14 @@ #include "utilities.h" +using namespace std; + //================================================================================ /*! * \brief Constructor of a side of one edge * \param theFace - the face * \param theEdge - the edge - */ + */ //================================================================================ StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace, @@ -68,27 +71,30 @@ StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace, SMESH_Mesh* theMesh, const bool theIsForward, const bool theIgnoreMediumNodes, + SMESH_MesherHelper* theFaceHelper, SMESH_ProxyMesh::Ptr theProxyMesh) { - list edges(1,theEdge); - *this = StdMeshers_FaceSide( theFace, edges, theMesh, theIsForward, - theIgnoreMediumNodes, theProxyMesh ); + std::list edges(1,theEdge); + StdMeshers_FaceSide tmp( theFace, edges, theMesh, theIsForward, + theIgnoreMediumNodes, theFaceHelper, theProxyMesh ); + *this = tmp; + + tmp.myHelper = NULL; } //================================================================================ /*! * \brief Constructor of a side of several edges - * \param theFace - the face - * \param theEdge - the edge */ //================================================================================ -StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace, - list& theEdges, - SMESH_Mesh* theMesh, - const bool theIsForward, - const bool theIgnoreMediumNodes, - SMESH_ProxyMesh::Ptr theProxyMesh) +StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace, + const std::list& theEdges, + SMESH_Mesh* theMesh, + const bool theIsForward, + const bool theIgnoreMediumNodes, + SMESH_MesherHelper* theFaceHelper, + SMESH_ProxyMesh::Ptr theProxyMesh) { int nbEdges = theEdges.size(); myEdge.resize ( nbEdges ); @@ -100,27 +106,33 @@ StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace, myNormPar.resize ( nbEdges ); myEdgeLength.resize( nbEdges ); myIsUniform.resize ( nbEdges, true ); + myFace = theFace; myLength = 0; myNbPonits = myNbSegments = 0; myProxyMesh = theProxyMesh; myMissingVertexNodes = false; myIgnoreMediumNodes = theIgnoreMediumNodes; myDefaultPnt2d = gp_Pnt2d( 1e+100, 1e+100 ); + myHelper = NULL; if ( !myProxyMesh ) myProxyMesh.reset( new SMESH_ProxyMesh( *theMesh )); + if ( theFaceHelper && theFaceHelper->GetSubShape() == myFace ) + { + myHelper = new SMESH_MesherHelper( * myProxyMesh->GetMesh() ); + myHelper->CopySubShapeInfo( *theFaceHelper ); + } if ( nbEdges == 0 ) return; SMESHDS_Mesh* meshDS = myProxyMesh->GetMeshDS(); int nbDegen = 0; - list::iterator edge = theEdges.begin(); - TopoDS_Iterator vExp; + std::list::const_iterator edge = theEdges.begin(); for ( int index = 0; edge != theEdges.end(); ++index, ++edge ) { int i = theIsForward ? index : nbEdges-index-1; myEdgeLength[i] = SMESH_Algo::EdgeLength( *edge ); if ( myEdgeLength[i] < DBL_MIN ) nbDegen++; myLength += myEdgeLength[i]; - myEdge[i] = *edge; + myEdge [i] = *edge; myEdgeID[i] = meshDS->ShapeToIndex( *edge ); if ( !theIsForward ) myEdge[i].Reverse(); @@ -131,58 +143,38 @@ StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace, if ( myEdge[i].Orientation() == TopAbs_REVERSED ) std::swap( myFirst[i], myLast[i] ); - if ( const SMESHDS_SubMesh* sm = myProxyMesh->GetSubMesh( *edge )) { - int nbN = sm->NbNodes(); - if ( theIgnoreMediumNodes ) { - SMDS_ElemIteratorPtr elemIt = sm->GetElements(); - if ( elemIt->more() && elemIt->next()->IsQuadratic() ) - nbN -= sm->NbElements(); - } - myNbPonits += nbN; - myNbSegments += sm->NbElements(); - } - - // TopExp::FirstVertex() and TopExp::LastVertex() return NULL from INTERNAL edge - vExp.Initialize( *edge ); - if ( vExp.Value().Orientation() == TopAbs_REVERSED ) vExp.Next(); - if ( SMESH_Algo::VertexNode( TopoDS::Vertex( vExp.Value()), meshDS )) - myNbPonits += 1; // for the first end - else - myMissingVertexNodes = true; - // check if the edge has a non-uniform parametrization (issue 0020705) - if ( !myC2d[i].IsNull() && myEdgeLength[i] > DBL_MIN) + if ( !myC2d[i].IsNull() ) { - Geom2dAdaptor_Curve A2dC( myC2d[i], - std::min( myFirst[i], myLast[i] ), - std::max( myFirst[i], myLast[i] )); - double p2 = myFirst[i]+(myLast[i]-myFirst[i])/2., p4 = myFirst[i]+(myLast[i]-myFirst[i])/4.; - double d2 = GCPnts_AbscissaPoint::Length( A2dC, myFirst[i], p2 ); - double d4 = GCPnts_AbscissaPoint::Length( A2dC, myFirst[i], p4 ); - //cout<<"len = "<GetSubMesh( myEdge[iE] )) + // Add internal nodes + nodes.clear(); + if ( !GetEdgeNodes( iE, nodes, /*v0=*/false, /*v1=*/false )) + return myPoints; + if ( !nodes.empty() ) { - vector< pair< double, const SMDS_MeshNode*> > u2nodeVec; - u2nodeVec.reserve( sm->NbNodes() ); - SMDS_NodeIteratorPtr nItr = sm->GetNodes(); + u2nodeVec.clear(); double paramSize = myLast[iE] - myFirst[iE]; double r = myNormPar[iE] - prevNormPar; - helper.SetSubShape( myEdge[iE] ); - helper.ToFixNodeParameters( true ); + eHelper.SetSubShape( myEdge[iE] ); + eHelper.ToFixNodeParameters( true ); if ( !myIsUniform[iE] ) - while ( nItr->more() ) + for ( size_t i = 0; i < nodes.size(); ++i ) { - const SMDS_MeshNode* node = nItr->next(); - if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge )) - continue; - double u = helper.GetNodeU( myEdge[iE], node, 0, ¶mOK ); - double aLenU = GCPnts_AbscissaPoint::Length - ( const_cast( myC3dAdaptor[iE]), myFirst[iE], u ); + double u = eHelper.GetNodeU( myEdge[iE], nodes[i], 0, ¶mOK ); + double aLenU = GCPnts_AbscissaPoint::Length( me->myC3dAdaptor[iE], myFirst[iE], u ); if ( myEdgeLength[iE] < aLenU ) // nonregression test "3D_mesh_NETGEN/G6" { u2nodeVec.clear(); break; } - double normPar = prevNormPar + r*aLenU/myEdgeLength[iE]; - u2nodeVec.push_back( make_pair( normPar, node )); + double normPar = prevNormPar + r * aLenU / myEdgeLength[iE]; + u2nodeVec.push_back( make_pair( normPar, nodes[i] )); } - nItr = sm->GetNodes(); if ( u2nodeVec.empty() ) - while ( nItr->more() ) + for ( size_t i = 0; i < nodes.size(); ++i ) { - const SMDS_MeshNode* node = nItr->next(); - if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge )) - continue; - double u = helper.GetNodeU( myEdge[iE], node, 0, ¶mOK ); - + double u = eHelper.GetNodeU( myEdge[iE], nodes[i], 0, ¶mOK ); // paramSize is signed so orientation is taken into account double normPar = prevNormPar + r * ( u - myFirst[iE] ) / paramSize; - u2nodeVec.push_back( make_pair( normPar, node )); + u2nodeVec.push_back( make_pair( normPar, nodes[i] )); } for ( size_t j = 0; j < u2nodeVec.size(); ++j ) u2node.insert( u2node.end(), u2nodeVec[j] ); } + } // loop on myEdge's + + // Add 2nd VERTEX node for a last EDGE + if ( !proxySubMesh.back() ) + { + if ( u2node.empty() ) return myPoints; + + const SMDS_MeshNode* node; + if ( IsClosed() && !proxySubMesh[0] ) + node = u2node.begin()->second; + else + { + node = VertexNode( iE ); + if ( myProxyMesh->GetMesh()->HasModificationsToDiscard() ) + while ( !node && iE > 1 ) // check intermediate VERTEXes + node = VertexNode( --iE ); + } + if ( node ) + { + if ( u2node.rbegin()->second == node && + !fHelper.IsRealSeam ( node->getshapeId() ) && + !fHelper.IsDegenShape( node->getshapeId() )) + u2node.erase( --u2node.end() ); - // Put 2nd vertex node for a last edge - if ( iE+1 == myEdge.size() ) { - node = SMESH_Algo::VertexNode( VV[1], meshDS ); - if ( !node ) { - MESSAGE(" NO NODE on VERTEX" ); - return myPoints; - } u2node.insert( u2node.end(), make_pair( 1., node )); } - } // loop on myEdge's + } - if ( u2node.size() + nbProxyNodes != myNbPonits && - u2node.size() + nbProxyNodes != NbPoints( /*update=*/true )) + if ((int) u2node.size() + nbProxyNodes != myNbPonits && + (int) u2node.size() + nbProxyNodes != NbPoints( /*update=*/true )) + { + return myPoints; + } + if (( u2node.size() > 0 ) && + ( u2node.begin()->first < 0 || u2node.rbegin()->first > 1 )) { - MESSAGE("Wrong node parameters on edges, u2node.size():" - <( myPoints ); + UVPtStructVec& points = me->myPoints; points.resize( myNbPonits ); int iPt = 0; @@ -445,25 +493,39 @@ const vector& StdMeshers_FaceSide::GetUVPtStruct(bool isXConst, if ( proxySubMesh[ iE ] ) // copy data from a proxy sub-mesh { const UVPtStructVec& edgeUVPtStruct = proxySubMesh[iE]->GetUVPtStructVec(); - std::copy( edgeUVPtStruct.begin(), edgeUVPtStruct.end(), & points[iPt] ); + UVPtStruct* pointsPtr = & points[iPt]; + std::copy( edgeUVPtStruct.begin(), edgeUVPtStruct.end(), pointsPtr ); // check orientation double du1 = edgeUVPtStruct.back().param - edgeUVPtStruct[0].param; double du2 = myLast[iE] - myFirst[iE]; if ( du1 * du2 < 0 ) { - std::reverse( & points[iPt], & points[iPt + edgeUVPtStruct.size()]); + std::reverse( pointsPtr, pointsPtr + edgeUVPtStruct.size()); for ( size_t i = 0; i < edgeUVPtStruct.size(); ++i ) - points[iPt+i].normParam = 1. - points[iPt+i].normParam; + pointsPtr[i].normParam = 1. - pointsPtr[i].normParam; } // update normalized params if ( myEdge.size() > 1 ) { - for ( size_t i = 0; i < edgeUVPtStruct.size(); ++i, ++iPt ) + for ( size_t i = 0; i < edgeUVPtStruct.size(); ++i ) { - UVPtStruct & uvPt = points[iPt]; + UVPtStruct & uvPt = pointsPtr[i]; uvPt.normParam = prevNormPar + uvPt.normParam * paramSize; uvPt.x = uvPt.y = uvPt.normParam; } - --iPt; // to point to the 1st VERTEX of the next EDGE + iPt += edgeUVPtStruct.size() - 1; // to point to the 1st VERTEX of the next EDGE + } + // update UV on a seam EDGE + if ( fHelper.IsRealSeam( myEdgeID[ iE ])) + { + // check if points lye on the EDGE + const UVPtStruct& pm = edgeUVPtStruct[ edgeUVPtStruct.size()/2 ]; + gp_Pnt pNode = SMESH_TNodeXYZ( pm.node ); + gp_Pnt pCurv = myC3dAdaptor[ iE ].Value( pm.param ); + double tol = BRep_Tool::Tolerance( myEdge[ iE ]) * 10; + bool isPointOnEdge = ( pNode.SquareDistance( pCurv ) < tol * tol ); + if ( isPointOnEdge ) + for ( size_t i = 0; i < edgeUVPtStruct.size(); ++i ) + pointsPtr[i].SetUV( myC2d[ iE ]->Value( pointsPtr[i].param ).XY() ); } } else @@ -471,7 +533,7 @@ const vector& StdMeshers_FaceSide::GetUVPtStruct(bool isXConst, for ( ; u_node != u2node.end(); ++u_node, ++iPt ) { if ( myNormPar[ iE ]-eps < u_node->first ) - break; // u_node is at VERTEX of the next EDGE + break; // u_node is at VERTEX of the next EDGE UVPtStruct & uvPt = points[iPt]; uvPt.node = u_node->second; @@ -481,7 +543,7 @@ const vector& StdMeshers_FaceSide::GetUVPtStruct(bool isXConst, // -- U ---------------------------------------------- const SMDS_EdgePosition* epos = dynamic_cast(uvPt.node->GetPosition()); - if ( epos ) { + if ( epos && uvPt.node->getshapeId() == myEdgeID[iE] ) { uvPt.param = epos->GetUParameter(); } else { @@ -509,9 +571,9 @@ const vector& StdMeshers_FaceSide::GetUVPtStruct(bool isXConst, // set if ( isXConst ) - for ( iPt = 0; iPt < points.size(); ++iPt ) points[ iPt ].x = constValue; + for ( iPt = 0; iPt < (int)points.size(); ++iPt ) points[ iPt ].x = constValue; else - for ( iPt = 0; iPt < points.size(); ++iPt ) points[ iPt ].y = constValue; + for ( iPt = 0; iPt < (int)points.size(); ++iPt ) points[ iPt ].y = constValue; } // if ( myPoints.empty()) @@ -530,8 +592,8 @@ const vector& StdMeshers_FaceSide::SimulateUVPtStruct(int nbSeg, bool isXConst, double constValue) const { - if ( myFalsePoints.empty() ) { - + if ( myFalsePoints.empty() ) + { if ( NbEdges() == 0 ) return myFalsePoints; vector* points = const_cast*>( &myFalsePoints ); @@ -539,28 +601,29 @@ const vector& StdMeshers_FaceSide::SimulateUVPtStruct(int nbSeg, int EdgeIndex = 0; double prevNormPar = 0, paramSize = myNormPar[ EdgeIndex ]; - for (int i = 0 ; i < myFalsePoints.size(); ++i ) { + gp_Pnt2d p; + for ( size_t i = 0 ; i < myFalsePoints.size(); ++i ) + { double normPar = double(i) / double(nbSeg); UVPtStruct & uvPt = (*points)[i]; uvPt.node = 0; uvPt.x = uvPt.y = uvPt.param = uvPt.normParam = normPar; if ( isXConst ) uvPt.x = constValue; else uvPt.y = constValue; - if ( myNormPar[ EdgeIndex ] < normPar ) { + if ( myNormPar[ EdgeIndex ] < normPar ) + { prevNormPar = myNormPar[ EdgeIndex ]; ++EdgeIndex; paramSize = myNormPar[ EdgeIndex ] - prevNormPar; } double r = ( normPar - prevNormPar )/ paramSize; uvPt.param = myFirst[EdgeIndex] * ( 1 - r ) + myLast[EdgeIndex] * r; - if ( !myC2d[ EdgeIndex ].IsNull() ) { - gp_Pnt2d p = myC2d[ EdgeIndex ]->Value( uvPt.param ); - uvPt.u = p.X(); - uvPt.v = p.Y(); - } - else { - uvPt.u = uvPt.v = 1e+100; - } + if ( !myC2d[ EdgeIndex ].IsNull() ) + p = myC2d[ EdgeIndex ]->Value( uvPt.param ); + else + p = Value2d( normPar ); + uvPt.u = p.X(); + uvPt.v = p.Y(); } } return myFalsePoints; @@ -571,76 +634,121 @@ const vector& StdMeshers_FaceSide::SimulateUVPtStruct(int nbSeg, //purpose : Return nodes in the order they encounter while walking along the side //======================================================================= -std::vector StdMeshers_FaceSide::GetOrderedNodes() const +std::vector StdMeshers_FaceSide::GetOrderedNodes(int theEdgeInd) const { vector resultNodes; - if ( myPoints.empty() ) + if ( myPoints.empty() || ( theEdgeInd >= 0 && NbEdges() > 0 )) { if ( NbEdges() == 0 ) return resultNodes; - SMESHDS_Mesh* meshDS = myProxyMesh->GetMeshDS(); - SMESH_MesherHelper helper(*myProxyMesh->GetMesh()); - bool paramOK; + //SMESHDS_Mesh* meshDS = myProxyMesh->GetMeshDS(); + SMESH_MesherHelper eHelper( *myProxyMesh->GetMesh() ); + SMESH_MesherHelper& fHelper = * FaceHelper(); + bool paramOK = true; // Sort nodes of all edges putting them into a map map< double, const SMDS_MeshNode*> u2node; - for ( int i = 0; i < myEdge.size(); ++i ) + vector nodes; + set vertexNodes; + int iE = 0, iEnd = myEdge.size(); + if ( theEdgeInd >= 0 ) { - // Put 1st vertex node of a current edge - TopoDS_Vertex VV[2]; // TopExp::FirstVertex() returns NULL for INTERNAL edge - VV[0] = SMESH_MesherHelper::IthVertex( 0, myEdge[i]); - VV[1] = SMESH_MesherHelper::IthVertex( 1, myEdge[i]); - const SMDS_MeshNode* node = SMESH_Algo::VertexNode( VV[0], meshDS ); - double prevNormPar = ( i == 0 ? 0 : myNormPar[ i-1 ]); // normalized param + iE = theEdgeInd % NbEdges(); + iEnd = iE + 1; + } + for ( iE = 0; iE < iEnd; ++iE ) + { + double prevNormPar = ( iE == 0 ? 0 : myNormPar[ iE-1 ]); // normalized param + + const SMESH_ProxyMesh::SubMesh* proxySM = myProxyMesh->GetProxySubMesh( myEdge[iE] ); + if ( proxySM ) + { + const UVPtStructVec& points = proxySM->GetUVPtStructVec(); + for ( size_t i = 0; i < points.size(); ++i ) + u2node.insert( make_pair( prevNormPar + points[i].normParam, points[i].node )); + continue; + } + + // Add 1st vertex node of a current EDGE + const SMDS_MeshNode* node = VertexNode( iE ); if ( node ) { // nodes on internal vertices may be missing - u2node.insert( make_pair( prevNormPar, node )); + if ( vertexNodes.insert( node ).second || + fHelper.IsRealSeam ( node->getshapeId() ) || + fHelper.IsDegenShape( node->getshapeId() )) + u2node.insert( make_pair( prevNormPar, node )); } - else if ( i == 0 ) { - MESSAGE(" NO NODE on VERTEX" ); - return resultNodes; + else if ( iE == 0 ) + { + if ( nodes.empty() ) { + for ( ++iE; iE < iEnd; ++iE ) + if (( node = VertexNode( iE ))) { + u2node.insert( make_pair( prevNormPar, node )); + break; + } + --iE; + } + if ( !node ) + return resultNodes; + vertexNodes.insert( node ); } - // Put internal nodes - if ( SMESHDS_SubMesh* sm = meshDS->MeshElements( myEdge[i] )) + // Add internal nodes + nodes.clear(); + if ( !GetEdgeNodes( iE, nodes, /*v0=*/false, /*v1=*/false )) + return resultNodes; + if ( !nodes.empty() ) { - SMDS_NodeIteratorPtr nItr = sm->GetNodes(); - double paramSize = myLast[i] - myFirst[i]; - double r = myNormPar[i] - prevNormPar; - helper.SetSubShape( myEdge[i] ); - helper.ToFixNodeParameters( true ); - while ( nItr->more() ) + double paramSize = myLast[iE] - myFirst[iE]; + double r = myNormPar[iE] - prevNormPar; + eHelper.SetSubShape( myEdge[iE] ); + eHelper.ToFixNodeParameters( true ); + for ( size_t i = 0; i < nodes.size(); ++i ) { - const SMDS_MeshNode* node = nItr->next(); - if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge )) - continue; - double u = helper.GetNodeU( myEdge[i], node, 0, ¶mOK ); - + double u = eHelper.GetNodeU( myEdge[iE], nodes[i], 0, ¶mOK ); // paramSize is signed so orientation is taken into account - double normPar = prevNormPar + r * ( u - myFirst[i] ) / paramSize; - u2node.insert( u2node.end(), make_pair( normPar, node )); + double normPar = prevNormPar + r * ( u - myFirst[iE] ) / paramSize; + u2node.insert( u2node.end(), make_pair( normPar, nodes[i] )); } } - // Put 2nd vertex node for a last edge - if ( i+1 == myEdge.size() ) { - node = SMESH_Algo::VertexNode( VV[1], meshDS ); - if ( !node ) { + } // loop on myEdges + + if ( u2node.empty() ) return resultNodes; + + // Add 2nd vertex node for a last EDGE + { + const SMDS_MeshNode* node; + if ( IsClosed() && theEdgeInd < 0 ) + node = u2node.begin()->second; + else + { + node = VertexNode( iE ); + while ( !node && iE > 0 ) + node = VertexNode( --iE ); + if ( !node ) return resultNodes; - } - u2node.insert( u2node.end(), make_pair( 1., node )); } + if ( u2node.rbegin()->second == node && + !fHelper.IsRealSeam ( node->getshapeId() ) && + !fHelper.IsDegenShape( node->getshapeId() )) + u2node.erase( --u2node.end() ); + + u2node.insert( u2node.end(), make_pair( 1., node )); } // Fill the result vector - if ( u2node.size() == myNbPonits ) + if ( theEdgeInd < 0 && + (int) u2node.size() != myNbPonits && + (int) u2node.size() != NbPoints( /*update=*/true )) { - resultNodes.reserve( u2node.size() ); - map< double, const SMDS_MeshNode*>::iterator u2n = u2node.begin(); - for ( ; u2n != u2node.end(); ++u2n ) - resultNodes.push_back( u2n->second ); + u2node.clear(); } + resultNodes.reserve( u2node.size() ); + map< double, const SMDS_MeshNode*>::iterator u2n = u2node.begin(); + for ( ; u2n != u2node.end(); ++u2n ) + resultNodes.push_back( u2n->second ); } else { @@ -652,6 +760,133 @@ std::vector StdMeshers_FaceSide::GetOrderedNodes() const return resultNodes; } +//================================================================================ +/*! + * \brief Return (unsorted) nodes of the i-th EDGE. + * Nodes moved to other geometry by MergeNodes() are also returned. + * \retval bool - is OK + */ +//================================================================================ + +bool StdMeshers_FaceSide::GetEdgeNodes(size_t i, + vector& nodes, + bool inlude1stVertex, + bool inludeLastVertex) const +{ + if ( i >= myEdge.size() ) + return false; + + SMESH_Mesh* mesh = myProxyMesh->GetMesh(); + SMESHDS_Mesh* meshDS = mesh->GetMeshDS(); + SMESHDS_SubMesh* sm = meshDS->MeshElements( myEdge[i] ); + + if ( inlude1stVertex ) + { + if ( const SMDS_MeshNode* n0 = VertexNode( i )) + nodes.push_back( n0 ); + } + + if ( sm && ( sm->NbElements() > 0 || sm->NbNodes() > 0 )) + { + if ( mesh->HasModificationsToDiscard() ) // check nb of nodes on the EDGE sub-mesh + { + int iQuad = sm->NbElements() ? sm->GetElements()->next()->IsQuadratic() : 0; + int nbExpect = sm->NbElements() - 1 + iQuad * sm->NbElements(); + if ( nbExpect != sm->NbNodes() ) // some nodes are moved from the EDGE by MergeNodes() + { + // add nodes of all segments + typedef set< const SMDS_MeshNode* > TNodeSet; + TNodeSet sharedNodes; + SMDS_ElemIteratorPtr segIt = sm->GetElements(); + while ( segIt->more() ) + { + const SMDS_MeshElement* seg = segIt->next(); + if ( seg->GetType() != SMDSAbs_Edge ) + continue; + for ( int i = 0; i < 3-myIgnoreMediumNodes; ++i ) + { + const SMDS_MeshNode* n = seg->GetNode( i ); + if ( i == 2 ) // medium node + { + nodes.push_back( n ); + } + else + { + pair it2new = sharedNodes.insert( n ); + if ( !it2new.second ) // n encounters twice == it's on EDGE, not on VERTEX + { + nodes.push_back( n ); + sharedNodes.erase( it2new.first ); + } + } + } + } + } + } + if ( nodes.size() < 2 ) // add nodes assigned to the EDGE + { + SMDS_NodeIteratorPtr nItr = sm->GetNodes(); + while ( nItr->more() ) + { + const SMDS_MeshNode* n = nItr->next(); + if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( n, SMDSAbs_Edge )) + continue; + nodes.push_back( n ); + } + } + } // if ( sm && sm->NbElements() > 0 ) + + if ( inludeLastVertex ) + { + if ( const SMDS_MeshNode* n1 = VertexNode( i+1 )) + nodes.push_back( n1 ); + } + return true; +} + +//================================================================================ +/*! + * \brief Return a node from the i-th VERTEX (count starts from zero) + * Nodes moved to other geometry by MergeNodes() are also returned. + * \param [in] i - the VERTEX index + * \param [out] isMoved - returns \c true if the found node is moved by MergeNodes() + * \return const SMDS_MeshNode* - the found node + */ +//================================================================================ + +const SMDS_MeshNode* StdMeshers_FaceSide::VertexNode(std::size_t i, bool* isMoved) const +{ + TopoDS_Vertex V = ( i >= myEdge.size() ) ? LastVertex() : FirstVertex(i); + + const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, myProxyMesh->GetMeshDS() ); + + if ( !n && !myEdge.empty() && myProxyMesh->GetMesh()->HasModificationsToDiscard() ) + { + size_t iE = ( i < myEdge.size() ) ? i : myEdge.size()-1; + SMESHDS_SubMesh* sm = myProxyMesh->GetMeshDS()->MeshElements( myEdgeID[ iE ]); + + n = SMESH_Algo::VertexNode( V, sm, myProxyMesh->GetMesh(), /*checkV=*/false ); + + if (( !n ) && + (( i > 0 && (int) i < NbEdges() ) || IsClosed() )) + { + iE = SMESH_MesherHelper::WrapIndex( int(i)-1, NbEdges() ); + sm = myProxyMesh->GetMeshDS()->MeshElements( myEdgeID[ iE ]); + n = SMESH_Algo::VertexNode( V, sm, myProxyMesh->GetMesh(), /*checkV=*/false ); + } + + if ( n && n->GetPosition()->GetDim() == 1 ) // check that n does not lie on an EDGE of myFace + { + TopoDS_Shape S = SMESH_MesherHelper::GetSubShapeByNode( n, myProxyMesh->GetMeshDS() ); + if ( SMESH_MesherHelper::IsSubShape( S, myFace )) + n = 0; // VERTEX ignored by e.g. Composite Wire Discretization algo + } + if ( isMoved ) + *isMoved = n; + } + return n; +} + //================================================================================ /*! * \brief reverse order of vector elements @@ -661,8 +896,7 @@ std::vector StdMeshers_FaceSide::GetOrderedNodes() const template void reverse(vector & vec) { - for ( int f=0, r=vec.size()-1; f < r; ++f, --r ) - std::swap( vec[f], vec[r] ); + std::reverse( vec.begin(), vec.end() ); } //================================================================================ @@ -782,30 +1016,47 @@ int StdMeshers_FaceSide::NbPoints(const bool update) const me->myNbSegments = 0; me->myMissingVertexNodes = false; + vector nodes; for ( int i = 0; i < NbEdges(); ++i ) { - TopoDS_Vertex v1 = SMESH_MesherHelper::IthVertex( 0, myEdge[i] ); - if ( SMESH_Algo::VertexNode( v1, myProxyMesh->GetMeshDS() )) - me->myNbPonits += 1; // for the first end - else - me->myMissingVertexNodes = true; - - if ( const SMESHDS_SubMesh* sm = myProxyMesh->GetSubMesh( Edge(i) )) { - int nbN = sm->NbNodes(); - if ( myIgnoreMediumNodes ) { - SMDS_ElemIteratorPtr elemIt = sm->GetElements(); - if ( elemIt->more() && elemIt->next()->IsQuadratic() ) - nbN -= sm->NbElements(); + if ( const SMESHDS_SubMesh* sm = myProxyMesh->GetSubMesh( Edge(i) )) + { + if ( sm->NbNodes() == sm->NbElements()-1 || sm->NbElements() == 0 ) + { + me->myNbPonits += sm->NbNodes(); + if ( myIgnoreMediumNodes && sm->IsQuadratic() ) + me->myNbPonits -= sm->NbElements(); + } + else // nodes can be moved to other shapes by MergeNodes() + { + nodes.clear(); + GetEdgeNodes( i, nodes, /*v1=*/false, /*v2=*/false ); + me->myNbPonits += nodes.size(); } - me->myNbPonits += nbN; me->myNbSegments += sm->NbElements(); } } - TopoDS_Vertex v1 = SMESH_MesherHelper::IthVertex( 1, Edge( NbEdges()-1 )); - if ( SMESH_Algo::VertexNode( v1, myProxyMesh->GetMeshDS() )) - me->myNbPonits++; // for the last end - else - me->myMissingVertexNodes = true; + + SMESH_MesherHelper* helper = FaceHelper(); + + std::set< const SMDS_MeshNode* > vNodes; + const int nbV = NbEdges() + !IsClosed(); + for ( int i = 0; i < nbV; ++i ) + if ( const SMDS_MeshNode* n = VertexNode( i )) + { + if ( !vNodes.insert( n ).second && + ( helper->IsRealSeam ( n->getshapeId() ) || + helper->IsDegenShape( n->getshapeId() ))) + me->myNbPonits++; + } + else + { + me->myMissingVertexNodes = true; + } + me->myNbPonits += vNodes.size(); + + if ( IsClosed() ) + me->myNbPonits++; // closing node is repeated } return myNbPonits; } @@ -857,7 +1108,7 @@ void StdMeshers_FaceSide::dump(const char* msg) const if (msg) MESSAGE ( std::endl << msg ); MESSAGE_BEGIN ("NB EDGES: "<< myEdge.size() ); MESSAGE_ADD ( "nbPoints: "<()<() - << " V2: " << TopExp::LastVertex( myEdge[i], 1).TShape().operator->() ); + << " V2: " << TopExp::LastVertex( myEdge[i], 1).TShape().operator->() ); } MESSAGE_ADD ( "\tC2d: "); - + if (myC2d[i].IsNull()) { MESSAGE_ADD ( "NULL" ); } else { MESSAGE_ADD ( myC2d[i].operator->() ); } - + MESSAGE_ADD ( "\tF: "< 0 && myPoints[ i ].normParam > U ) --i; - while ( i+1 < myPoints.size() && myPoints[ i+1 ].normParam < U ) + while ( i+1 < (int)myPoints.size() && myPoints[ i+1 ].normParam < U ) ++i; double r = (( U - myPoints[ i ].normParam ) / ( myPoints[ i+1 ].normParam - myPoints[ i ].normParam )); @@ -988,7 +1239,7 @@ gp_Pnt StdMeshers_FaceSide::Value3d(double U) const double r = ( U - prevU )/ ( myNormPar[ i ] - prevU ); double par = myFirst[i] * ( 1 - r ) + myLast[i] * r; - + // check parametrization of curve if( !myIsUniform[i] ) { @@ -1012,8 +1263,14 @@ TSideVector StdMeshers_FaceSide::GetFaceWires(const TopoDS_Face& theFace, SMESH_Mesh & theMesh, const bool theIgnoreMediumNodes, TError & theError, - SMESH_ProxyMesh::Ptr theProxyMesh) + SMESH_MesherHelper* theFaceHelper, + SMESH_ProxyMesh::Ptr theProxyMesh, + const bool theCheckVertexNodes) { + SMESH_MesherHelper helper( theMesh ); + if ( theFaceHelper && theFaceHelper->GetSubShape() == theFace ) + helper.CopySubShapeInfo( *theFaceHelper ); + list< TopoDS_Edge > edges, internalEdges; list< int > nbEdgesInWires; int nbWires = SMESH_Block::GetOrderedEdges (theFace, edges, nbEdgesInWires); @@ -1037,17 +1294,18 @@ TSideVector StdMeshers_FaceSide::GetFaceWires(const TopoDS_Face& theFace, // as StdMeshers_FaceSide::GetUVPtStruct() requires if ( wireEdges.front().Orientation() != TopAbs_INTERNAL ) // Issue 0020676 { - while ( !SMESH_Algo::VertexNode( TopExp::FirstVertex( wireEdges.front(), true), - theMesh.GetMeshDS())) - { - wireEdges.splice(wireEdges.end(), wireEdges, - wireEdges.begin(), ++wireEdges.begin()); - if ( from->IsSame( wireEdges.front() )) { - theError = TError - ( new SMESH_ComputeError(COMPERR_BAD_INPUT_MESH,"No nodes on vertices")); - return TSideVector(0); + if ( theCheckVertexNodes ) + while ( !SMESH_Algo::VertexNode( TopExp::FirstVertex( wireEdges.front(), true), + theMesh.GetMeshDS())) + { + wireEdges.splice(wireEdges.end(), wireEdges, + wireEdges.begin(), ++wireEdges.begin()); + if ( from->IsSame( wireEdges.front() )) { + theError = TError + ( new SMESH_ComputeError(COMPERR_BAD_INPUT_MESH,"No nodes on vertices")); + return TSideVector(0); + } } - } } else if ( *nbE > 1 ) // Issue 0020676 (Face_pb_netgen.brep) - several internal edges in a wire { @@ -1056,7 +1314,7 @@ TSideVector StdMeshers_FaceSide::GetFaceWires(const TopoDS_Face& theFace, StdMeshers_FaceSide* wire = new StdMeshers_FaceSide( theFace, wireEdges, &theMesh, /*isForward=*/true, theIgnoreMediumNodes, - theProxyMesh ); + &helper, theProxyMesh ); wires[ iW ] = StdMeshers_FaceSidePtr( wire ); from = to; } @@ -1064,7 +1322,7 @@ TSideVector StdMeshers_FaceSide::GetFaceWires(const TopoDS_Face& theFace, { StdMeshers_FaceSide* wire = new StdMeshers_FaceSide( theFace, internalEdges.back(), &theMesh, /*isForward=*/true, theIgnoreMediumNodes, - theProxyMesh ); + &helper, theProxyMesh ); wires.push_back( StdMeshers_FaceSidePtr( wire )); internalEdges.pop_back(); } @@ -1110,3 +1368,30 @@ TopoDS_Vertex StdMeshers_FaceSide::LastVertex(int i) const return v; } +//================================================================================ +/*! + * \brief Return \c true if the chain of EDGEs is closed + */ +//================================================================================ + +bool StdMeshers_FaceSide::IsClosed() const +{ + return myEdge.empty() ? false : FirstVertex().IsSame( LastVertex() ); +} + +//================================================================================ +/*! + * \brief Return a helper initialized with the FACE + */ +//================================================================================ + +SMESH_MesherHelper* StdMeshers_FaceSide::FaceHelper() const +{ + StdMeshers_FaceSide* me = const_cast< StdMeshers_FaceSide* >( this ); + if ( !myHelper && myProxyMesh ) + { + me->myHelper = new SMESH_MesherHelper( *myProxyMesh->GetMesh() ); + me->myHelper->SetSubShape( myFace ); + } + return me->myHelper; +}