+
+//=======================================================================
+//function : GetOrderedNodes
+//purpose : Return nodes in the order they encounter while walking along the side
+//=======================================================================
+
+std::vector<const SMDS_MeshNode*> StdMeshers_FaceSide::GetOrderedNodes(int theEdgeInd) const
+{
+ vector<const SMDS_MeshNode*> resultNodes;
+ if ( myPoints.empty() || ( theEdgeInd >= 0 && NbEdges() > 0 ))
+ {
+ if ( NbEdges() == 0 ) return resultNodes;
+
+ SMESHDS_Mesh* meshDS = myProxyMesh->GetMeshDS();
+ SMESH_MesherHelper eHelper( *myProxyMesh->GetMesh() );
+ SMESH_MesherHelper fHelper( *myProxyMesh->GetMesh() );
+ fHelper.SetSubShape( myFace );
+ bool paramOK = true;
+
+ // Sort nodes of all edges putting them into a map
+
+ map< double, const SMDS_MeshNode*> u2node;
+ vector<const SMDS_MeshNode*> nodes;
+ set<const SMDS_MeshNode*> vertexNodes;
+ int iE = 0, iEnd = myEdge.size();
+ if ( theEdgeInd >= 0 )
+ {
+ 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
+ if ( vertexNodes.insert( node ).second ||
+ fHelper.IsRealSeam ( node->getshapeId() ) ||
+ fHelper.IsDegenShape( node->getshapeId() ))
+ u2node.insert( make_pair( prevNormPar, node ));
+ }
+ 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 );
+ }
+
+ // Add internal nodes
+ nodes.clear();
+ if ( !GetEdgeNodes( iE, nodes, /*v0=*/false, /*v1=*/false ))
+ return resultNodes;
+ if ( !nodes.empty() )
+ {
+ 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 )
+ {
+ 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;
+ u2node.insert( u2node.end(), make_pair( normPar, nodes[i] ));
+ }
+ }
+
+ } // 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;
+ }
+ 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 ( theEdgeInd < 0 &&
+ u2node.size() != myNbPonits &&
+ u2node.size() != NbPoints( /*update=*/true ))
+ {
+ 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
+ {
+ resultNodes.resize( myPoints.size() );
+ for ( size_t i = 0; i < myPoints.size(); ++i )
+ resultNodes[i] = myPoints[i].node;
+ }
+
+ 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<const SMDS_MeshNode*>& 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<TNodeSet::iterator, bool> 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 && 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;
+}