+ 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();
+ if ( theReverse )
+ std::reverse( nbsegs.begin(), nbsegs.end() );
+
+ // 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
+ 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;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & theShape)