+ static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName("SegmentAroundVertex_0D"));
+ if ( const SMESH_Hypothesis * h = theMesh.GetHypothesis( theV, filter, true ))
+ {
+ SMESH_Algo* algo = const_cast< SMESH_Algo* >( static_cast< const SMESH_Algo* > ( h ));
+ const list <const SMESHDS_Hypothesis *> & hypList = algo->GetUsedHypothesis( theMesh, theV, 0 );
+ if ( !hypList.empty() && string("SegmentLengthAroundVertex") == hypList.front()->GetName() )
+ return static_cast<const StdMeshers_SegmentLengthAroundVertex*>( hypList.front() );
+ }
+ return 0;
+}
+
+//================================================================================
+/*!
+ * \brief Tune parameters to fit "SegmentLengthAroundVertex" hypothesis
+ * \param theC3d - wire curve
+ * \param theLength - curve length
+ * \param theParameters - internal nodes parameters to modify
+ * \param theVf - 1st vertex
+ * \param theVl - 2nd vertex
+ */
+//================================================================================
+
+void StdMeshers_Regular_1D::redistributeNearVertices (SMESH_Mesh & theMesh,
+ Adaptor3d_Curve & theC3d,
+ double theLength,
+ std::list< double > & theParameters,
+ const TopoDS_Vertex & theVf,
+ const TopoDS_Vertex & theVl)
+{
+ double f = theC3d.FirstParameter(), l = theC3d.LastParameter();
+ int nPar = theParameters.size();
+ for ( int isEnd1 = 0; isEnd1 < 2; ++isEnd1 )
+ {
+ const TopoDS_Vertex & V = isEnd1 ? theVf : theVl;
+ const StdMeshers_SegmentLengthAroundVertex* hyp = getVertexHyp (theMesh, V );
+ if ( hyp ) {
+ double vertexLength = hyp->GetLength();
+ if ( vertexLength > theLength / 2.0 )
+ continue;
+ if ( isEnd1 ) { // to have a segment of interest at end of theParameters
+ theParameters.reverse();
+ std::swap( f, l );
+ }
+ if ( _hypType == NB_SEGMENTS )
+ {
+ compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
+ }
+ else if ( nPar <= 3 )
+ {
+ if ( !isEnd1 )
+ vertexLength = -vertexLength;
+ double tol = Min( Precision::Confusion(), 0.01 * vertexLength );
+ GCPnts_AbscissaPoint Discret( tol, theC3d, vertexLength, l );
+ if ( Discret.IsDone() ) {
+ if ( nPar == 0 )
+ theParameters.push_back( Discret.Parameter());
+ else {
+ double L = GCPnts_AbscissaPoint::Length( theC3d, theParameters.back(), l);
+ if ( vertexLength < L / 2.0 )
+ theParameters.push_back( Discret.Parameter());
+ else
+ compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
+ }
+ }
+ }
+ else
+ {
+ // recompute params between the last segment and a middle one.
+ // find size of a middle segment
+ int nHalf = ( nPar-1 ) / 2;
+ list< double >::reverse_iterator itU = theParameters.rbegin();
+ std::advance( itU, nHalf );
+ double Um = *itU++;
+ double Lm = GCPnts_AbscissaPoint::Length( theC3d, Um, *itU);
+ double L = GCPnts_AbscissaPoint::Length( theC3d, *itU, l);
+ static StdMeshers_Regular_1D* auxAlgo = 0;
+ if ( !auxAlgo ) {
+ auxAlgo = new StdMeshers_Regular_1D( _gen->GetANewId(), _gen );
+ auxAlgo->_hypType = BEG_END_LENGTH;
+ }
+ auxAlgo->_value[ BEG_LENGTH_IND ] = Lm;
+ auxAlgo->_value[ END_LENGTH_IND ] = vertexLength;
+ double from = *itU, to = l;
+ if ( isEnd1 ) {
+ std::swap( from, to );
+ std::swap( auxAlgo->_value[ BEG_LENGTH_IND ], auxAlgo->_value[ END_LENGTH_IND ]);
+ }
+ list<double> params;
+ if ( auxAlgo->computeInternalParameters( theMesh, theC3d, L, from, to, params, false ))
+ {
+ if ( isEnd1 ) params.reverse();
+ while ( 1 + nHalf-- )
+ theParameters.pop_back();
+ theParameters.splice( theParameters.end(), params );
+ }
+ else
+ {
+ compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
+ }
+ }
+ if ( isEnd1 )
+ theParameters.reverse();
+ }
+ }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh & theMesh,
+ Adaptor3d_Curve& theC3d,
+ double theLength,
+ double theFirstU,
+ double theLastU,
+ list<double> & theParams,
+ const bool theReverse,
+ bool theConsiderPropagation)
+{
+ theParams.clear();
+
+ double f = theFirstU, l = theLastU;
+
+ // Propagation Of Distribution
+ //
+ if ( !_mainEdge.IsNull() && _hypType == DISTRIB_PROPAGATION )
+ {
+ TopoDS_Edge mainEdge = TopoDS::Edge( _mainEdge ); // should not be a reference!
+ _gen->Compute( theMesh, mainEdge, SMESH_Gen::SHAPE_ONLY_UPWARD );
+
+ SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( mainEdge );
+ if ( !smDS )
+ return error("No mesh on the source edge of Propagation Of Distribution");
+ if ( smDS->NbNodes() < 1 )
+ return true; // 1 segment
+
+ map< double, const SMDS_MeshNode* > mainEdgeParamsOfNodes;
+ if ( ! SMESH_Algo::GetSortedNodesOnEdge( theMesh.GetMeshDS(), mainEdge, _quadraticMesh,
+ mainEdgeParamsOfNodes, SMDSAbs_Edge ))
+ return error("Bad node parameters on the source edge of Propagation Of Distribution");
+ vector< double > segLen( mainEdgeParamsOfNodes.size() - 1 );
+ double totalLen = 0;
+ BRepAdaptor_Curve mainEdgeCurve( mainEdge );
+ map< double, const SMDS_MeshNode* >::iterator
+ u_n2 = mainEdgeParamsOfNodes.begin(), u_n1 = u_n2++;
+ for ( size_t i = 1; i < mainEdgeParamsOfNodes.size(); ++i, ++u_n1, ++u_n2 )
+ {
+ segLen[ i-1 ] = GCPnts_AbscissaPoint::Length( mainEdgeCurve,
+ u_n1->first,
+ u_n2->first);
+ totalLen += segLen[ i-1 ];
+ }
+ for ( size_t i = 0; i < segLen.size(); ++i )
+ segLen[ i ] *= theLength / totalLen;
+
+ size_t iSeg = theReverse ? segLen.size()-1 : 0;
+ size_t dSeg = theReverse ? -1 : +1;
+ double param = theFirstU;
+ size_t nbParams = 0;
+ for ( int i = 0, nb = segLen.size()-1; i < nb; ++i, iSeg += dSeg )
+ {
+ double tol = Min( Precision::Confusion(), 0.01 * segLen[ iSeg ]);
+ GCPnts_AbscissaPoint Discret( tol, theC3d, segLen[ iSeg ], param );
+ if ( !Discret.IsDone() ) break;
+ param = Discret.Parameter();
+ theParams.push_back( param );
+ ++nbParams;
+ }
+ if ( nbParams != segLen.size()-1 )
+ return error( SMESH_Comment("Can't divide into ") << segLen.size() << " segments");
+
+ compensateError( segLen[ theReverse ? segLen.size()-1 : 0 ],
+ segLen[ theReverse ? 0 : segLen.size()-1 ],
+ f, l, theLength, theC3d, theParams, true );
+ return true;
+ }
+
+
+ switch( _hypType )
+ {
+ case LOCAL_LENGTH:
+ case MAX_LENGTH:
+ case NB_SEGMENTS:
+ {
+ double eltSize = 1;
+ int nbSegments;
+ if ( _hypType == MAX_LENGTH )
+ {
+ double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
+ if (nbseg <= 0)
+ nbseg = 1; // degenerated edge
+ eltSize = theLength / nbseg * ( 1. - 1e-9 );
+ nbSegments = (int) nbseg;
+ }
+ else if ( _hypType == LOCAL_LENGTH )
+ {
+ // Local Length hypothesis
+ double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
+
+ // NPAL17873:
+ bool isFound = false;
+ if (theConsiderPropagation && !_mainEdge.IsNull()) // propagated from some other edge
+ {
+ // Advanced processing to assure equal number of segments in case of Propagation
+ SMESH_subMesh* sm = theMesh.GetSubMeshContaining(_mainEdge);
+ if (sm) {
+ bool computed = sm->IsMeshComputed();
+ if (!computed) {
+ if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE) {
+ _gen->Compute( theMesh, _mainEdge, /*anUpward=*/true);
+ computed = sm->IsMeshComputed();
+ }
+ }
+ if (computed) {
+ SMESHDS_SubMesh* smds = sm->GetSubMeshDS();
+ int nb_segments = smds->NbElements();
+ if (nbseg - 1 <= nb_segments && nb_segments <= nbseg + 1) {
+ isFound = true;
+ nbseg = nb_segments;
+ }
+ }
+ }
+ }
+ if (!isFound) // not found by meshed edge in the propagation chain, use precision
+ {
+ double aPrecision = _value[ PRECISION_IND ];
+ double nbseg_prec = ceil((theLength / _value[ BEG_LENGTH_IND ]) - aPrecision);
+ if (nbseg_prec == (nbseg - 1)) nbseg--;
+ }
+
+ if (nbseg <= 0)
+ nbseg = 1; // degenerated edge
+ eltSize = theLength / nbseg;
+ nbSegments = (int) nbseg;
+ }
+ else
+ {
+ // Number Of Segments hypothesis
+ nbSegments = _ivalue[ NB_SEGMENTS_IND ];
+ if ( nbSegments < 1 ) return false;
+ if ( nbSegments == 1 ) return true;
+
+ switch (_ivalue[ DISTR_TYPE_IND ])
+ {
+ case StdMeshers_NumberOfSegments::DT_Scale:
+ {
+ double scale = _value[ SCALE_FACTOR_IND ];
+
+ if (fabs(scale - 1.0) < Precision::Confusion()) {
+ // special case to avoid division by zero
+ for (int i = 1; i < nbSegments; i++) {
+ double param = f + (l - f) * i / nbSegments;
+ theParams.push_back( param );
+ }
+ } else {
+ // general case of scale distribution
+ if ( theReverse )
+ scale = 1.0 / scale;
+
+ double alpha = pow(scale, 1.0 / (nbSegments - 1));
+ double factor = (l - f) / (1.0 - pow(alpha, nbSegments));
+
+ for (int i = 1; i < nbSegments; i++) {
+ double param = f + factor * (1.0 - pow(alpha, i));
+ theParams.push_back( param );
+ }
+ }
+ const double lenFactor = theLength/(l-f);
+ const double minSegLen = Min( theParams.front() - f, l - theParams.back() );
+ const double tol = Min( Precision::Confusion(), 0.01 * minSegLen );
+ list<double>::iterator u = theParams.begin(), uEnd = theParams.end();
+ for ( ; u != uEnd; ++u )
+ {
+ GCPnts_AbscissaPoint Discret( tol, theC3d, ((*u)-f) * lenFactor, f );
+ if ( Discret.IsDone() )
+ *u = Discret.Parameter();
+ }
+ return true;
+ }
+ break;
+ case StdMeshers_NumberOfSegments::DT_TabFunc:
+ {
+ FunctionTable func(_vvalue[ TAB_FUNC_IND ], _ivalue[ CONV_MODE_IND ]);
+ return computeParamByFunc(theC3d, f, l, theLength, theReverse,
+ _ivalue[ NB_SEGMENTS_IND ], func,
+ theParams);
+ }
+ break;
+ case StdMeshers_NumberOfSegments::DT_ExprFunc:
+ {
+ FunctionExpr func(_svalue[ EXPR_FUNC_IND ].c_str(), _ivalue[ CONV_MODE_IND ]);
+ return computeParamByFunc(theC3d, f, l, theLength, theReverse,
+ _ivalue[ NB_SEGMENTS_IND ], func,
+ theParams);
+ }
+ break;
+ case StdMeshers_NumberOfSegments::DT_Regular:
+ eltSize = theLength / nbSegments;
+ break;
+ default:
+ return false;
+ }
+ }
+
+ double tol = Min( Precision::Confusion(), 0.01 * eltSize );
+ GCPnts_UniformAbscissa Discret(theC3d, nbSegments + 1, f, l, tol );
+ if ( !Discret.IsDone() )
+ return error( "GCPnts_UniformAbscissa failed");
+ if ( Discret.NbPoints() < nbSegments + 1 )
+ Discret.Initialize(theC3d, nbSegments + 2, f, l, tol );
+
+ int NbPoints = Min( Discret.NbPoints(), nbSegments + 1 );
+ for ( int i = 2; i < NbPoints; i++ ) // skip 1st and last points
+ {
+ double param = Discret.Parameter(i);
+ theParams.push_back( param );
+ }
+ compensateError( eltSize, eltSize, f, l, theLength, theC3d, theParams, true ); // for PAL9899
+ return true;
+ }
+
+
+ case BEG_END_LENGTH: {
+
+ // geometric progression: SUM(n) = ( a1 - an * q ) / ( 1 - q ) = theLength
+
+ double a1 = _value[ BEG_LENGTH_IND ];
+ double an = _value[ END_LENGTH_IND ];
+ double q = ( theLength - a1 ) / ( theLength - an );
+ if ( q < theLength/1e6 || 1.01*theLength < a1 + an)
+ return error ( SMESH_Comment("Invalid segment lengths (")<<a1<<" and "<<an<<") "<<
+ "for an edge of length "<<theLength);
+
+ double U1 = theReverse ? l : f;
+ double Un = theReverse ? f : l;
+ double param = U1;
+ double eltSize = theReverse ? -a1 : a1;
+ double tol = Min( Precision::Confusion(), 0.01 * Min( a1, an ));
+ while ( 1 ) {
+ // computes a point on a curve <theC3d> at the distance <eltSize>
+ // from the point of parameter <param>.
+ GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
+ if ( !Discret.IsDone() ) break;
+ param = Discret.Parameter();
+ if ( f < param && param < l )
+ theParams.push_back( param );
+ else
+ break;
+ eltSize *= q;
+ }
+ compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
+ if (theReverse) theParams.reverse(); // NPAL18025
+ return true;
+ }
+
+ case ARITHMETIC_1D:
+ {
+ // arithmetic progression: SUM(n) = ( an - a1 + q ) * ( a1 + an ) / ( 2 * q ) = theLength
+
+ double a1 = _value[ BEG_LENGTH_IND ];
+ double an = _value[ END_LENGTH_IND ];
+ if ( 1.01*theLength < a1 + an )
+ return error ( SMESH_Comment("Invalid segment lengths (")<<a1<<" and "<<an<<") "<<
+ "for an edge of length "<<theLength);
+
+ double q = ( an - a1 ) / ( 2 *theLength/( a1 + an ) - 1 );
+ int n = int(fabs(q) > numeric_limits<double>::min() ? ( 1+( an-a1 )/q ) : ( 1+theLength/a1 ));
+
+ double U1 = theReverse ? l : f;
+ double Un = theReverse ? f : l;
+ double param = U1;
+ double eltSize = a1;
+ double tol = Min( Precision::Confusion(), 0.01 * Min( a1, an ));
+ if ( theReverse ) {
+ eltSize = -eltSize;
+ q = -q;
+ }
+ while ( n-- > 0 && eltSize * ( Un - U1 ) > 0 ) {
+ // computes a point on a curve <theC3d> at the distance <eltSize>
+ // from the point of parameter <param>.
+ GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
+ if ( !Discret.IsDone() ) break;
+ param = Discret.Parameter();
+ if ( param > f && param < l )
+ theParams.push_back( param );
+ else
+ break;
+ eltSize += q;
+ }
+ compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
+ if ( theReverse ) theParams.reverse(); // NPAL18025
+
+ return true;
+ }
+
+ case GEOMETRIC_1D:
+ {
+ double a1 = _value[ BEG_LENGTH_IND ], an = 0;
+ double q = _value[ END_LENGTH_IND ];
+
+ double U1 = theReverse ? l : f;
+ double Un = theReverse ? f : l;
+ double param = U1;
+ double eltSize = a1;
+ if ( theReverse )
+ eltSize = -eltSize;
+
+ int nbParams = 0;
+ while ( true ) {
+ // computes a point on a curve <theC3d> at the distance <eltSize>
+ // from the point of parameter <param>.
+ double tol = Min( Precision::Confusion(), 0.01 * eltSize );
+ GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
+ if ( !Discret.IsDone() ) break;
+ param = Discret.Parameter();
+ if ( f < param && param < l )
+ theParams.push_back( param );
+ else
+ break;
+ an = eltSize;
+ eltSize *= q;
+ ++nbParams;
+ }
+ if ( nbParams > 1 )
+ {
+ if ( Abs( param - Un ) < 0.2 * Abs( param - theParams.back() ))
+ {
+ compensateError( a1, Abs(eltSize), U1, Un, theLength, theC3d, theParams );
+ }
+ else if ( Abs( Un - theParams.back() ) <
+ 0.2 * Abs( theParams.back() - *(++theParams.rbegin())))
+ {
+ theParams.pop_back();
+ compensateError( a1, Abs(an), U1, Un, theLength, theC3d, theParams );
+ }
+ }
+ if (theReverse) theParams.reverse(); // NPAL18025
+
+ return true;
+ }
+
+ case FIXED_POINTS_1D:
+ {
+ const std::vector<double>& aPnts = _fpHyp->GetPoints();
+ std::vector<int> nbsegs = _fpHyp->GetNbSegments();
+
+ // sort normalized params, taking into account theReverse
+ TColStd_SequenceOfReal Params;
+ double tol = 1e-7 / theLength; // GCPnts_UniformAbscissa allows u2-u1 > 1e-7
+ for ( size_t i = 0; i < aPnts.size(); i++ )
+ {
+ if( aPnts[i] < tol || aPnts[i] > 1 - tol )
+ continue;
+ double u = theReverse ? ( 1 - aPnts[i] ) : aPnts[i];
+ int j = 1;
+ bool IsExist = false;
+ for ( ; j <= Params.Length(); j++ ) {
+ if ( Abs( u - Params.Value(j) ) < tol ) {
+ IsExist = true;
+ break;
+ }
+ if ( u < Params.Value(j) ) break;
+ }
+ if ( !IsExist ) Params.InsertBefore( j, u );
+ }
+
+ // transform normalized Params into real ones
+ std::vector< double > uVec( Params.Length() + 2 );
+ uVec[ 0 ] = theFirstU;
+ double abscissa;
+ for ( int i = 1; i <= Params.Length(); i++ )
+ {
+ abscissa = Params( i ) * theLength;
+ tol = Min( Precision::Confusion(), 0.01 * abscissa );
+ GCPnts_AbscissaPoint APnt( tol, theC3d, abscissa, theFirstU );
+ if ( !APnt.IsDone() )
+ return error( "GCPnts_AbscissaPoint failed");
+ uVec[ i ] = APnt.Parameter();
+ }
+ uVec.back() = theLastU;
+
+ // divide segments
+ if ( theReverse )
+ {
+ if ((int) nbsegs.size() > Params.Length() + 1 )
+ nbsegs.resize( Params.Length() + 1 );
+ std::reverse( nbsegs.begin(), nbsegs.end() );
+ }
+ if ( nbsegs.empty() )
+ {
+ nbsegs.push_back( 1 );
+ }
+ Params.InsertBefore( 1, 0.0 );
+ Params.Append( 1.0 );
+ double eltSize, segmentSize, par1, par2;
+ for ( size_t i = 0; i < uVec.size()-1; i++ )
+ {
+ par1 = uVec[ i ];
+ par2 = uVec[ i+1 ];
+ int nbseg = ( i < nbsegs.size() ) ? nbsegs[i] : nbsegs[0];
+ if ( nbseg == 1 )
+ {
+ theParams.push_back( par2 );
+ }
+ else
+ {
+ segmentSize = ( Params( i+2 ) - Params( i+1 )) * theLength;
+ eltSize = segmentSize / nbseg;
+ tol = Min( Precision::Confusion(), 0.01 * eltSize );
+ GCPnts_UniformAbscissa Discret( theC3d, eltSize, par1, par2, tol );
+ if ( !Discret.IsDone() )
+ return error( "GCPnts_UniformAbscissa failed");
+ if ( Discret.NbPoints() < nbseg + 1 ) {
+ eltSize = segmentSize / ( nbseg + 0.5 );
+ Discret.Initialize( theC3d, eltSize, par1, par2, tol );
+ }
+ int NbPoints = Discret.NbPoints();
+ for ( int i = 2; i <= NbPoints; i++ ) {
+ double param = Discret.Parameter(i);
+ theParams.push_back( param );
+ }
+ }
+ }
+ theParams.pop_back();
+
+ return true;
+ }
+
+ case DEFLECTION:
+ {
+ GCPnts_UniformDeflection Discret( theC3d, _value[ DEFLECTION_IND ], f, l, true );
+ if ( !Discret.IsDone() )
+ return false;
+
+ int NbPoints = Discret.NbPoints();
+ for ( int i = 2; i < NbPoints; i++ )
+ {
+ double param = Discret.Parameter(i);
+ theParams.push_back( param );
+ }
+ return true;
+ }
+
+ default:;
+ }
+
+ return false;