Results 1 to 4 of 4

Thread: Curve Fitting Not Always Applied

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

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.