Results 1 to 4 of 4

Thread: Curve Fitting Not Always Applied

  1. #1
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Curve Fitting Not Always Applied

    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:

    Qt Code:
    1. void BytesProcessed(int size, double * xArray, double * yArray, double yMax, int BtNo, bool bResetScale);
    2.  
    3. emit BytesProcessed( ( scDPPtr->dQVPressure.data()[scDPPtr->GetCount()-1].size()-1),
    4. scDPPtr->dQVTime.data(),
    5. scDPPtr->dQVPressure.data()[scDPPtr->GetCount()-1].data(),
    6. scDPPtr->dPeakRawPressure.data()[scDPPtr->GetBreathCount()-1],
    7. scDPPtr->GetBreathCount()-1,bNew);
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. QVector < QVector <double> > dQVPressure;
    2. QVector <double> dQVTime;
    3. QVector <double> dPeakRawPressure;
    To copy to clipboard, switch view to plain text mode 

    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.

    Qt Code:
    1. fitter[i]->setSplineSize(1000);
    To copy to clipboard, switch view to plain text mode 




    Qt Code:
    1. Plot::Plot(QWidget *parent, QString pTitle, QString pAxisX, QString pAxisY ) :
    2. plotTitle(pTitle), plotAxisX(pAxisX), plotAxisY(pAxisY){
    3. setTitle(plotTitle);
    4. dyMaxMax = 0.0; dxMaxMax = 0.0;
    5. BtIndex = 0;
    6. bRefresh = true;
    7. xBlank[0]=0.0;
    8. yBlank[0]=0.0;
    9. xBlank[1]=0.0;
    10. yBlank[1]=0.0;
    11. graphAxes = (graphType)0;
    12. setAxisTitle(xBottom, plotAxisX + " (Bt " + QString::number(BtIndex) +")" );
    13. setAxisScale(xBottom, 0.0, 0.001);
    14. setAxisTitle(yLeft, plotAxisY);
    15. setAxisScale(yLeft, 0.0, 0.001);
    16. static const QColor qCol(255,255,255);
    17. static const QColor qColA[50];
    18. for (int i=0; i<50; i++){ qColArray[i]=(255,i*5,i*5) ; }
    19. this->setCanvasBackground(qCol);
    20.  
    21. for (int i=0; i<50; i++) {
    22. d_curve[i] = new QwtPlotCurve("Data Moving Right");
    23. d_curveLin[i] = new QwtPlotCurve("Linear");
    24. }
    25.  
    26. int colcount = 0;
    27. for (int i=0; i<4; i++) {
    28. for (int j=0; j<4; j++) {
    29. for (int k=0; k<4; k++) {
    30. if (colcount <50) {
    31. d_Color[colcount] = new QColor(((3-i)*(140/3)),(j*(140/3)),(k*(140/3)));
    32. d_Pen[colcount] = new QPen( *d_Color[colcount], 0, Qt::SolidLine ) ;
    33. d_curve[colcount]->setPen(*d_Pen[colcount] ) ;
    34. colcount++;
    35. }else{ i=4; j=4; k=4; }
    36. }
    37. }
    38. }
    39. d_Pen[54] = new QPen( *d_Color[49], 0, Qt::DotLine) ;
    40. for (int i=0; i<50; i++) { d_curveLin[i]->setPen(*d_Pen[54] ) ; }
    41.  
    42. for (int i=0; i<50; i++) {
    43. fitter[i] = new QwtSplineCurveFitter();
    44. fitter[i]->setSplineSize(1000);
    45. d_curve[i]->setCurveAttribute(QwtPlotCurve::Fitted,true);
    46. fitter[i]->setFitMode(QwtSplineCurveFitter::Spline);
    47. d_curve[i]->setCurveFitter(fitter[i]);
    48. bSmoothed[i]=true;
    49. d_curveLin[i]->setCurveAttribute(QwtPlotCurve::Fitted,false);
    50.  
    51. d_curve[i]->setRenderHint(QwtPlotItem::RenderAntialiased);
    52. d_curve[i]->setPaintAttribute( QwtPlotCurve::ClipPolygons, true );
    53. d_curve[i]->attach(this);
    54. d_curveLin[i]->setRenderHint(QwtPlotItem::RenderAntialiased);
    55. d_curveLin[i]->setPaintAttribute( QwtPlotCurve::ClipPolygons, true );
    56. d_curveLin[i]->attach(this);
    57. }
    58. }
    59.  
    60. void Plot::UpdatePlotTest(int firstIndex, int lastIndex, double dyMax, double * dxarray, double * dyarray, int BtNo, bool bResetScale){
    61. if (BtIndex!= BtNo ) {
    62. BtIndex = BtNo;
    63. setAxisTitle(xBottom, plotAxisX + " (Bt " + QString::number(BtIndex+1) + ")" ); }
    64. if (this->bRefresh){ dyMaxMax = 0.001; dxMaxMax = 0.001; }
    65. if (dyMaxMax < dyMax) { dyMaxMax = dyMax; setAxisScale(yLeft, 0, (dyMaxMax*1.05) ); }
    66. if (dxMaxMax < dxarray[lastIndex]) {
    67. dxMaxMax = dxarray[lastIndex];
    68. setAxisScale(xBottom, dxarray[firstIndex], dxMaxMax); }
    69. d_Pen[BtNo]->setWidth(4);
    70. d_Pen[BtNo]->setColor(d_Color[0]->rgb());
    71. d_curve[BtNo]->setCurveAttribute(QwtPlotCurve::Fitted,false);
    72. fitter[BtNo]=NULL;
    73. d_curve[BtNo]->setCurveFitter(NULL);
    74. d_curve[BtNo]->setPen(*d_Pen[BtNo] ) ;
    75. bSmoothed[BtNo] = false;
    76. if (BtNo>0){
    77. for (int jj = 0; jj<=49; jj++){
    78. if (jj!=BtNo){
    79. if (bSmoothed[jj] == false){
    80. d_Pen[jj]->setWidth(0);
    81. d_Pen[jj]->setColor(d_Color[jj]->rgb());
    82. fitter[jj] = new QwtSplineCurveFitter();
    83. fitter[jj]->setSplineSize(1000);
    84. d_curve[jj]->setCurveAttribute(QwtPlotCurve::Fitted,true);
    85. fitter[jj]->setFitMode(QwtSplineCurveFitter::Spline);
    86. d_curve[jj]->setCurveFitter(fitter[jj]);
    87. d_curve[jj]->setPen(*d_Pen[jj] ) ;
    88. bSmoothed[jj]= true;
    89. }
    90. }
    91. }
    92. }
    93. d_curve[BtNo]->setRawSamples(dxarray,dyarray,((lastIndex-firstIndex)+1) );
    94. d_curveLin[BtNo]->setRawSamples(dxarray,dyarray,((lastIndex-firstIndex)+1) );
    95. if (bResetScale == true){
    96. for (int jj = 0; jj<=BtNo; jj++){
    97. if (bSmoothed[jj] == false){
    98. d_Pen[jj]->setWidth(0);
    99. d_Pen[jj]->setColor(d_Color[jj]->rgb());
    100. fitter[jj] = new QwtSplineCurveFitter();
    101. fitter[jj]->setSplineSize(1000);
    102. d_curve[jj]->setCurveAttribute(QwtPlotCurve::Fitted,true);
    103. fitter[jj]->setFitMode(QwtSplineCurveFitter::Spline);
    104. d_curve[jj]->setCurveFitter(fitter[jj]);
    105. d_curve[jj]->setPen(*d_Pen[jj] ) ;
    106. bSmoothed[jj]= true;
    107. }
    108. }
    109. this->replot();
    110. this->repaint();
    111. }
    112. this->bRefresh = false;
    113. }
    114.  
    115. void Plot::RePlot(){this->replot();}
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by Mannion; 10th March 2011 at 16:58. Reason: Adding attached image and installation information

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Curve Fitting Not Always Applied

    Sometimes the curve fitting does not seem to occur?
    When you isolate the problem to a small demo application I will have a look at it.

    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.
    Well most optimizations have to do with introducing the characteristics of your specific data/plot into the algorithms. Without knowing them it is hard to tell you something useful.

    In general spline interpolation is an expensive operation and in your application it is done every time the curve is repainted for the translated points in pixel coordinates. Maybe it is possible to interpolate the points in plot coordinates before you pass them to the curve.

    Often the key for improving performance is to reduce the number of points, that need to be painted. In Qwt 6.0 you find an implementation of the Douglas Peucker algorithm ( QwtWeedingCurveFitter ) that might be useful.

    Uwe

  3. #3
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Curve Fitting Not Always Applied

    Hi Mannion...
    While using QwtSplineCurveFitter in qwt6 i found out that it works beautifully for integers but has problems with doubles. Why don't you check by making the x and y var. integers(like multiply em by 1000).. c if it works...

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Curve Fitting Not Always Applied

    Or use some version from SVN, where this issue has been resolved.

    Uwe

  5. The following user says thank you to Uwe for this useful post:

    pkj (16th March 2011)

Similar Threads

  1. Fitting QWebView to content
    By Sölve in forum Newbie
    Replies: 0
    Last Post: 7th September 2010, 00:25
  2. Replies: 4
    Last Post: 29th April 2010, 06:11
  3. Moving QGraphicsItems and Fitting QGraphicsView
    By aladagemre in forum Qt Programming
    Replies: 0
    Last Post: 30th January 2010, 18:21
  4. Replies: 1
    Last Post: 22nd January 2010, 14:34
  5. KDE 3 style applied to Qt 4 programs
    By alecs1 in forum KDE Forum
    Replies: 4
    Last Post: 4th December 2008, 21:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.