Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Curve Fitting Not Always Applied
QtWS25 Last Chance

Curve Fitting Not Always Applied

Scheduled Pinned Locked Moved 3rd Party Software
3 Posts 1 Posters 3.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mannion
    wrote on 10 Mar 2011, 17:23 last edited by
    #1

    Hi

    Installation Information:
    Qt Creator 2.0.1
    Based on Qt 4.7.0 (32 bit)
    Built on Aug 24 2010 at 11:00:55
    From revision 97d831e3de

    First of all thanks for Qwt. It has proved to be a very useful library for my Qt work.

    I am currently having an intermittent problem with the QwtSplineCurveFitter class.
    Sometimes the curve fitting does not seem to occur?

    See attached example image. I have also attached my plot class constructor and my update plot slot.
    The connected signal call is as follows:

    @void BytesProcessed(int size, double * xArray, double * yArray, double yMax, int BtNo, bool bResetScale);

    emit BytesProcessed( ( scDPPtr->dQVPressure.data()[scDPPtr->GetCount()-1].size()-1),
    scDPPtr->dQVTime.data(),
    scDPPtr->dQVPressure.data()[scDPPtr->GetCount()-1].data(),
    scDPPtr->dPeakRawPressure.data()[scDPPtr->GetBreathCount()-1],
    scDPPtr->GetBreathCount()-1,bNew);@

    The arrays used in the signal are referenced from the following QVectors:

    @QVector < QVector <double> > dQVPressure;
    QVector <double> dQVTime;
    QVector <double> dPeakRawPressure;@

    My plots seem to perform fairly well in almost real time but if you have any advice on optimising my code it would be appreciated greatly.

    Is there a limit to the number of splines or spline points that can be created? I am plotting up to 4 plots of 50 curves that are each curve fitted.

    Is my Spline Size a problem? It seems to give better results than lower settings but does begin to inhibit performance with larger numbers of plots e.g. 4 X 20+ curves.

    @fitter[i]->setSplineSize(1000);@

    http://img46.imageshack.us/i/noncurvefitting.jpg/

    @Plot::Plot(QWidget parent, QString pTitle, QString pAxisX, QString pAxisY ) :
    plotTitle(pTitle), plotAxisX(pAxisX), plotAxisY(pAxisY){
    setTitle(plotTitle);
    dyMaxMax = 0.0; dxMaxMax = 0.0;
    BtIndex = 0;
    bRefresh = true;
    xBlank[0]=0.0;
    yBlank[0]=0.0;
    xBlank[1]=0.0;
    yBlank[1]=0.0;
    graphAxes = (graphType)0;
    setAxisTitle(xBottom, plotAxisX + " (Bt " + QString::number(BtIndex) +")" );
    setAxisScale(xBottom, 0.0, 0.001);
    setAxisTitle(yLeft, plotAxisY);
    setAxisScale(yLeft, 0.0, 0.001);
    static const QColor qCol(255,255,255);
    static const QColor qColA[50];
    for (int i=0; i<50; i++){ qColArray[i]=(255,i
    5,i*5) ; }
    this->setCanvasBackground(qCol);

    for (int i=0; i<50; i++) {
        d_curve[i] = new QwtPlotCurve("Data Moving Right");
        d_curveLin[i] = new QwtPlotCurve("Linear");
    }
    
    int colcount = 0;
    for (int i=0; i<4; i++) {
        for (int j=0; j<4; j++) {
            for (int k=0; k<4; k++) {
                if (colcount <50) {
                    d_Color[colcount] = new QColor(((3-i)*(140/3)),(j*(140/3)),(k*(140/3)));
                    d_Pen[colcount] = new QPen(    *d_Color[colcount], 0, Qt::SolidLine ) ;
                    d_curve[colcount]->setPen(*d_Pen[colcount] ) ;
                    colcount++;
                }else{   i=4;   j=4;   k=4;   }
            }
        }
    }
    d_Pen[54] = new QPen(    *d_Color[49], 0, Qt::DotLine) ;
    for (int i=0; i<50; i++) {   d_curveLin[i]->setPen(*d_Pen[54] ) ;  }
    
    for (int i=0; i<50; i++) {
        fitter[i] = new QwtSplineCurveFitter();
        fitter[i]->setSplineSize(1000);
        d_curve[i]->setCurveAttribute(QwtPlotCurve::Fitted,true);
        fitter[i]->setFitMode(QwtSplineCurveFitter::Spline);
        d_curve[i]->setCurveFitter(fitter[i]);
        bSmoothed[i]=true;
        d_curveLin[i]->setCurveAttribute(QwtPlotCurve::Fitted,false);
        
        d_curve[i]->setRenderHint(QwtPlotItem::RenderAntialiased);
        d_curve[i]->setPaintAttribute( QwtPlotCurve::ClipPolygons, true );
        d_curve[i]->attach(this);
        d_curveLin[i]->setRenderHint(QwtPlotItem::RenderAntialiased);
        d_curveLin[i]->setPaintAttribute( QwtPlotCurve::ClipPolygons, true );
        d_curveLin[i]->attach(this);
    }
    

    }@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mannion
      wrote on 10 Mar 2011, 17:23 last edited by
      #2

      @void Plot::UpdatePlotTest(int firstIndex, int lastIndex, double dyMax, double * dxarray, double * dyarray, int BtNo, bool bResetScale){
      if (BtIndex!= BtNo ) {
      BtIndex = BtNo;
      setAxisTitle(xBottom, plotAxisX + " (Bt " + QString::number(BtIndex+1) + ")" ); }
      if (this->bRefresh){ dyMaxMax = 0.001; dxMaxMax = 0.001; }
      if (dyMaxMax < dyMax) { dyMaxMax = dyMax; setAxisScale(yLeft, 0, (dyMaxMax*1.05) ); }
      if (dxMaxMax < dxarray[lastIndex]) {
      dxMaxMax = dxarray[lastIndex];
      setAxisScale(xBottom, dxarray[firstIndex], dxMaxMax); }
      d_Pen[BtNo]->setWidth(4);
      d_Pen[BtNo]->setColor(d_Color[0]->rgb());
      d_curve[BtNo]->setCurveAttribute(QwtPlotCurve::Fitted,false);
      fitter[BtNo]=NULL;
      d_curve[BtNo]->setCurveFitter(NULL);
      d_curve[BtNo]->setPen(*d_Pen[BtNo] ) ;
      bSmoothed[BtNo] = false;
      if (BtNo>0){
      for (int jj = 0; jj<=49; jj++){
      if (jj!=BtNo){
      if (bSmoothed[jj] == false){
      d_Pen[jj]->setWidth(0);
      d_Pen[jj]->setColor(d_Color[jj]->rgb());
      fitter[jj] = new QwtSplineCurveFitter();
      fitter[jj]->setSplineSize(1000);
      d_curve[jj]->setCurveAttribute(QwtPlotCurve::Fitted,true);
      fitter[jj]->setFitMode(QwtSplineCurveFitter::Spline);
      d_curve[jj]->setCurveFitter(fitter[jj]);
      d_curve[jj]->setPen(*d_Pen[jj] ) ;
      bSmoothed[jj]= true;
      }
      }
      }
      }
      d_curve[BtNo]->setRawSamples(dxarray,dyarray,((lastIndex-firstIndex)+1) );
      d_curveLin[BtNo]->setRawSamples(dxarray,dyarray,((lastIndex-firstIndex)+1) );
      if (bResetScale == true){
      for (int jj = 0; jj<=BtNo; jj++){
      if (bSmoothed[jj] == false){
      d_Pen[jj]->setWidth(0);
      d_Pen[jj]->setColor(d_Color[jj]->rgb());
      fitter[jj] = new QwtSplineCurveFitter();
      fitter[jj]->setSplineSize(1000);
      d_curve[jj]->setCurveAttribute(QwtPlotCurve::Fitted,true);
      fitter[jj]->setFitMode(QwtSplineCurveFitter::Spline);
      d_curve[jj]->setCurveFitter(fitter[jj]);
      d_curve[jj]->setPen(*d_Pen[jj] ) ;
      bSmoothed[jj]= true;
      }
      }
      this->replot();
      this->repaint();
      }
      this->bRefresh = false;
      }

      void Plot::RePlot(){this->replot();}@

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mannion
        wrote on 13 Mar 2011, 03:54 last edited by
        #3

        Uwe has kindly begun to help me on

        "http://www.qtcentre.org/threads/39533-Cu…ght=#post181435":http://www.qtcentre.org/threads/39533-Cu…ght=#post181435

        I will follow this up there as I don't want to waste experts tiem with multiple posts.

        1 Reply Last reply
        0

        1/3

        10 Mar 2011, 17:23

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved