+
+ //================================================================================
+ /*!
+ * \brief Find association of nodes existing on the sinuous sides of a ring
+ *
+ * TMAPar2NPoints filled here is used in setQuadSides() only if theSinuFace.IsRing()
+ * to find most distant nodes of the inner and the outer wires
+ */
+ //================================================================================
+
+ void assocNodes( SMESH_MesherHelper& theHelper,
+ SinuousFace& theSinuFace,
+ const SMESH_MAT2d::MedialAxis& theMA,
+ TMAPar2NPoints & thePointsOnE )
+ {
+ SMESH_Mesh* mesh = theHelper.GetMesh();
+ SMESHDS_Mesh* meshDS = theHelper.GetMeshDS();
+
+ list< TopoDS_Edge > ee1( theSinuFace._sinuSide [0].begin(), theSinuFace._sinuSide [0].end() );
+ list< TopoDS_Edge > ee2( theSinuFace._sinuSide [1].begin(), theSinuFace._sinuSide [1].end() );
+ StdMeshers_FaceSide sideOut( theSinuFace.Face(), ee1, mesh, true, true, &theHelper );
+ StdMeshers_FaceSide sideIn ( theSinuFace.Face(), ee2, mesh, true, true, &theHelper );
+ const UVPtStructVec& uvsOut = sideOut.GetUVPtStruct();
+ const UVPtStructVec& uvsIn = sideIn.GetUVPtStruct();
+ // if ( uvs1.size() != uvs2.size() )
+ // return;
+
+ const SMESH_MAT2d::Branch& branch = *theMA.getBranch(0);
+ SMESH_MAT2d::BoundaryPoint bp[2];
+ SMESH_MAT2d::BranchPoint brp;
+
+ map< double, const SMDS_MeshNode* > nodeParams; // params of existing nodes
+ map< double, const SMDS_MeshNode* >::iterator u2n;
+
+ // find a node of sideOut most distant from sideIn
+
+ vector< BRepAdaptor_Curve > curvesIn( theSinuFace._sinuSide[1].size() );
+ for ( size_t iE = 0; iE < theSinuFace._sinuSide[1].size(); ++iE )
+ curvesIn[ iE ].Initialize( theSinuFace._sinuSide[1][iE] );
+
+ double maxDist = 0;
+ SMESH_MAT2d::BoundaryPoint bpIn; // closest IN point
+ const SMDS_MeshNode* nOut = 0;
+ const size_t nbEOut = theSinuFace._sinuSide[0].size();
+ for ( size_t iE = 0; iE < nbEOut; ++iE )
+ {
+ const TopoDS_Edge& E = theSinuFace._sinuSide[0][iE];
+
+ if ( !SMESH_Algo::GetSortedNodesOnEdge( meshDS, E, /*skipMedium=*/true, nodeParams ))
+ return;
+ for ( u2n = nodeParams.begin(); u2n != nodeParams.end(); ++u2n )
+ {
+ // point on EDGE (u2n) --> MA point (brp)
+ if ( !theMA.getBoundary().getBranchPoint( iE, u2n->first, brp ) ||
+ !branch.getBoundaryPoints( brp, bp[0], bp[1] ))
+ return;
+ gp_Pnt pOut = SMESH_TNodeXYZ( u2n->second );
+ gp_Pnt pIn = curvesIn[ bp[1]._edgeIndex - nbEOut ].Value( bp[1]._param );
+ double dist = pOut.SquareDistance( pIn );
+ if ( dist > maxDist )
+ {
+ maxDist = dist;
+ nOut = u2n->second;
+ bpIn = bp[1];
+ }
+ }
+ }
+ const SMDS_MeshNode* nIn = 0;
+ if ( !SMESH_Algo::GetSortedNodesOnEdge( meshDS,
+ theSinuFace._sinuEdges[ bpIn._edgeIndex ],
+ /*skipMedium=*/true,
+ nodeParams ))
+ return;
+ u2n = nodeParams.lower_bound( bpIn._param );
+ if ( u2n == nodeParams.end() )
+ nIn = nodeParams.rbegin()->second;
+ else
+ nIn = u2n->second;
+
+ // find position of distant nodes in uvsOut and uvsIn
+ size_t iDistOut, iDistIn;
+ for ( iDistOut = 0; iDistOut < uvsOut.size(); ++iDistOut )
+ {
+ if ( uvsOut[iDistOut].node == nOut )
+ break;
+ }
+ for ( iDistIn = 0; iDistIn < uvsIn.size(); ++iDistIn )
+ {
+ if ( uvsIn[iDistIn].node == nIn )
+ break;
+ }
+ if ( iDistOut == uvsOut.size() || iDistIn == uvsIn.size() )
+ return;
+
+ // store opposite nodes in thePointsOnE (param and EDGE have no sense)
+ pair< NodePoint, NodePoint > oppNodes( NodePoint( nOut, 0, 0 ), NodePoint( nIn, 0, 0));
+ thePointsOnE.insert( make_pair( uvsOut[ iDistOut ].normParam, oppNodes ));
+ int iOut = iDistOut, iIn = iDistIn;
+ int i, nbNodes = std::min( uvsOut.size(), uvsIn.size() );
+ if ( nbNodes > 5 ) nbNodes = 5;
+ for ( i = 0, ++iOut, --iIn; i < nbNodes; ++iOut, --iIn, ++i )
+ {
+ iOut = theHelper.WrapIndex( iOut, uvsOut.size() );
+ iIn = theHelper.WrapIndex( iIn, uvsIn.size() );
+ oppNodes.first._node = uvsOut[ iOut ].node;
+ oppNodes.second._node = uvsIn[ iIn ].node;
+ thePointsOnE.insert( make_pair( uvsOut[ iOut ].normParam, oppNodes ));
+ }
+
+ return;
+ } // assocNodes()
+