const QwtArray<QwtDoublePoint> &points) const #else QPolygonF QwtSplineCurveFitter::fitSpline( const QPolygonF &points) const #endif { d_data->spline.setPoints(points); if ( !d_data->spline.isValid() ) return points; #if QT_VERSION < 0x040000 QwtArray<QwtDoublePoint> fittedPoints(d_data->splineSize); #else QPolygonF fittedPoints(d_data->splineSize); #endif const double x1 = points[0].x(); const double x2 = points[int(points.size() - 1)].x(); const double dx = x2 - x1; const double delta = dx / (d_data->splineSize - 1); for (int i = 0; i < d_data->splineSize; i++) { QwtDoublePoint &p = fittedPoints[i]; const double v = x1 + i * delta; const double sv = d_data->spline.value(v); p.setX(qRound(v)); p.setY(qRound(sv)); } d_data->spline.reset(); return fittedPoints; }
QPolygonF QwtSplineCurveFitter::fitSpline( const QPolygonF &points ) const { d_data->spline.setPoints( points ); if ( !d_data->spline.isValid() ) return points; QPolygonF fittedPoints( d_data->splineSize ); const double x1 = points[0].x(); const double x2 = points[int( points.size() - 1 )].x(); const double dx = x2 - x1; const double delta = dx / ( d_data->splineSize - 1 ); for ( int i = 0; i < d_data->splineSize; i++ ) { QPointF &p = fittedPoints[i]; const double v = x1 + i * delta; const double sv = d_data->spline.value( v ); p.setX( qRound( v ) ); p.setY( qRound( sv ) ); } d_data->spline.reset(); return fittedPoints; }
QPolygonF QwtSplineCurveFitter::fitParametric( const QPolygonF &points ) const { int i; const int size = points.size(); QPolygonF fittedPoints( d_data->splineSize ); QPolygonF splinePointsX( size ); QPolygonF splinePointsY( size ); const QPointF *p = points.data(); QPointF *spX = splinePointsX.data(); QPointF *spY = splinePointsY.data(); double param = 0.0; for ( i = 0; i < size; i++ ) { const double x = p[i].x(); const double y = p[i].y(); if ( i > 0 ) { const double delta = qSqrt( qwtSqr( x - spX[i-1].y() ) + qwtSqr( y - spY[i-1].y() ) ); param += qMax( delta, 1.0 ); } spX[i].setX( param ); spX[i].setY( x ); spY[i].setX( param ); spY[i].setY( y ); } d_data->spline.setPoints( splinePointsX ); if ( !d_data->spline.isValid() ) return points; const double deltaX = splinePointsX[size - 1].x() / ( d_data->splineSize - 1 ); for ( i = 0; i < d_data->splineSize; i++ ) { const double dtmp = i * deltaX; fittedPoints[i].setX( qRound( d_data->spline.value( dtmp ) ) ); } d_data->spline.setPoints( splinePointsY ); if ( !d_data->spline.isValid() ) return points; const double deltaY = splinePointsY[size - 1].x() / ( d_data->splineSize - 1 ); for ( i = 0; i < d_data->splineSize; i++ ) { const double dtmp = i * deltaY; fittedPoints[i].setY( qRound( d_data->spline.value( dtmp ) ) ); } return fittedPoints; }