Results 1 to 20 of 21

Thread: Newbie : QwtCurveFitter and retrieve curve data

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Gloups...
    fitCurve(points) don't give the exact points that I can see on the plot ....

    I can see on the graph some values always > 0 and in the PolygonF retrieved... I have some negative values...how can I retrieve the exact values of the plot ???

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

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Of course you have to assign the fitted points ( = points2 in your code snippet ) to your curve and disable QwtPlotCurve::Fitted.

    Uwe

  3. #3
    Join Date
    Jun 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    This is my code :
    Qt Code:
    1. Plot::Plot(QWidget *parent):
    2. QwtPlot(parent)
    3. {
    4. tab_x[0] = 0; tab_x[1] = 200; tab_x[2] = 400; tab_x[3] = 600; tab_x[4] = 1600; tab_x[5] = 2000;
    5. tab_x[6] = 2400; tab_x[7] = 2800; tab_x[8] = 3200; tab_x[9] = 3600; tab_x[10] =
    6.  
    7. tab_y[0] = mygamma(tab_x[0],4096,1023,0.5);
    8. tab_y[1] = mygamma(tab_x[1],4096,1023,0.5);
    9. tab_y[2] = mygamma(tab_x[2],4096,1023,0.5);
    10. tab_y[3] = mygamma(tab_x[3],4096,1023,0.5);
    11. tab_y[4] = mygamma(tab_x[4],4096,1023,0.5);
    12. tab_y[5] = mygamma(tab_x[5],4096,1023,0.
    13. tab_y[6] = mygamma(tab_x[6],4096,1023,0.5);
    14. tab_y[7] = mygamma(tab_x[7],4096,1023,0.5);
    15. tab_y[8] = mygamma(tab_x[8],4096,1023,0.5);
    16. tab_y[9] = mygamma(tab_x[9],4096,1023,0.5);
    17. tab_y[10] = mygamma(tab_x[10],4096,1023,0.5);
    18.  
    19. int nb_points = sizeof(tab_x) / sizeof(tab_x[0]);
    20. QPolygonF points,points2;
    21. for ( int i = 0; i < nb_points ; i++ )
    22. {
    23. points += QPointF(tab_x[i], tab_y[i]);
    24. }
    25.  
    26. m_Curve = new QwtPlotCurve();
    27. m_CurveFitter = new QwtSplineCurveFitter();
    28.  
    29. m_Curve->setCurveAttribute(QwtPlotCurve::Fitted, true); // Otherwise I have got Lines and not smooth curve the fitted curve is better for me
    30. m_Curve->setStyle(QwtPlotCurve::Lines);
    31.  
    32. m_CurveFitter->setFitMode(m_CurveFitter->ParametricSpline);
    33. m_CurveFitter->setSplineSize(4096); // from my orignal 10 points I want 4096 points
    34.  
    35. m_Curve->setCurveFitter(m_CurveFitter);
    36. m_Curve->setData(tab_x, tab_y, sizeof(tab_x) / sizeof(tab_x[0]));
    37. m_Curve->attach(this);
    38. }
    39.  
    40.  
    41.  
    42. QPolygonF Plot::getPoints(int nCurve)
    43. {
    44. QPolygonF points,InterpolatedPoints;
    45. m_Curve;
    46. m_CurveFitter
    47.  
    48. for ( int i = 0; i < m_Curve->dataSize(); i++ )
    49. {
    50. points += QPointF(m_Curve->x(i), m_Curve->y(i));
    51. }
    52.  
    53. InterpolatedPoints = curveFitter->fitCurve(points);
    54.  
    55. return InterpolatedPoints;
    56. }
    57.  
    58.  
    59. double mygamma(double in,int nbpoints_in,int nbpoints_out,double gma)
    60. {
    61. double x = in / nbpoints_in;
    62.  
    63. return (pow(x,gma) * nbpoints_out );
    64. }
    To copy to clipboard, switch view to plain text mode 

    So I have to setCurveAttribute(QwtPlotCurve::Fitted, FALSE ); ?? I that case my curve is totally not smooth...
    I don't understand how Qwt can trace a curve, and one cannot access the points of that curve...

    I do understand in my code that the Interpolated points that I retrieve are not the one traced on my graph ..the Fitted parameter should change this ...but I need it.

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

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    You have to interpolate your points first and then assign the interpolated points to to your curve. What's so hard about this ?

    Uwe

  5. #5
    Join Date
    Jun 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Well...sorry to bother you ...how do you assign ? setData ?

    Qt Code:
    1. points2 = m_CurveFitter->fitCurve(points);
    2. m_Curve->setData(points2);
    To copy to clipboard, switch view to plain text mode 

    if I do so : setData...my curve is made of 4096 points... and I cannot move the original points like I used to...

    What I want to "capture" :
    Last edited by sapym; 20th July 2010 at 09:21.

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

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Quote Originally Posted by sapym View Post
    if I do so : setData...my curve is made of 4096 points... and I cannot move the original points like I used to...
    The interpolated points and your 4096 points are different - that's what spline interpolation is about. Of course you have to find a way to re-translate changes of the interpolated points into changes of your original ones.

    Maybe it helps to insert 2 curves: one with your 4096 points with symbols only and a second one with the interpolated points showing the lines but no symbols ?


    Uwe

  7. #7
    Join Date
    Jun 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    I'm starting from 10 points : x_0 = 0 to x_10 = 4095 and y_0 = 0 to y_10 = 1023 y = f(x) with f = gamma function...

    I used the "CanvasPicker" from the event_filter example to be abble to move these points ... the curve is modified at the same time... (setData (tab_x,tab_y,10) with tab_x and tab_y modified )

    And from these 10 pôints ...I want the 4096 interpolated points (I don't see what you mean by "The interpolated points and your 4096 points are different")

  8. #8
    Join Date
    Jun 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    I tried everything... from

    curve->plot()->invTransform(curve->yAxis(), x);
    or curve->plot()->transform(curve->yAxis(), x);
    or curveFitter->spline().value(x);

    Nothing...snif...

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

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Well, without understanding ( what is obvious from your code snippets ) what happens to your points you will fail. But what about the idea of using 2 QwtPlotCurves for your points: the first displaying the symbols only and a second one with a spline interpolated line ?

    Uwe

  10. #10
    Join Date
    Jun 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Yes Uwe... I was a little stubborn and moreover kind of lost... please accept my appologies !
    I know that my code is very far from perfect .. I do my best ... but as I said...a newbie...

    I read this post form the beginning in order to have a fresh view on your advices and #4 is now clear to me...
    Yes I tried yesterday with 2 curves ...
    Qt Code:
    1. for (int ii = 0 ; ii < 2 ; ii ++)
    2. {
    3. m_UniqueCurve[ii] = new QwtPlotCurve();
    4. m_UniqueCurveFitter[ii] = new QwtSplineCurveFitter();
    5. m_UniqueCurveFitter[ii]->setFitMode(m_UniqueCurveFitter[ii]->ParametricSpline);
    6. m_UniqueCurveFitter[ii]->setSplineSize(4096);
    7. m_UniqueCurve[ii]->setCurveFitter(m_UniqueCurveFitter[ii]);
    8. }
    9.  
    10. m_UniqueCurve[0]->setCurveAttribute(QwtPlotCurve::Fitted, true);
    11. m_UniqueCurve[1]->setCurveAttribute(QwtPlotCurve::Fitted, false);
    12. m_UniqueCurve[0]->setStyle(QwtPlotCurve::Lines);
    13. m_UniqueCurve[1]->setStyle(QwtPlotCurve::Dots);
    14.  
    15.  
    16. m_UniqueCurve[0]->setPen(QColor(Qt::transparent));
    17. m_UniqueCurve[0]->setSymbol(QwtSymbol(QwtSymbol::Ellipse,Qt::gray, QColor(Qt::black), QSize(8,8)));
    18.  
    19. m_UniqueCurve[1]->setPen(QColor(Qt::black));
    20.  
    21. QPolygonF OriginalPoints,InterpolatedPoints;
    22. for ( int i = 0; i < TabX.count() ; i++ )
    23. {
    24. OriginalPoints+= QPointF(TabX[i], TabY[i]);
    25. }
    26.  
    27. InterpolatedPoints= m_RedCurveFitter[1]->fitCurve(points);
    28.  
    29. m_UniqueCurve[0]->setData(TabX.data(), TabY.data(),TabX.count());
    30. m_UniqueCurve[1]->setData(InterpolatedPoints);
    To copy to clipboard, switch view to plain text mode 

    And then I had to patch some lines in tne canvaspicker to be abble to select the good curve and move them together...

    So again I'm deeply sorry for hte bad quality of my code and my eyes while reading your posts

    Thanks a lot for your help

    Best regards

    Paul
    Last edited by sapym; 22nd July 2010 at 07:40.

Similar Threads

  1. Replies: 0
    Last Post: 19th September 2009, 07:07
  2. Replies: 0
    Last Post: 14th September 2009, 11:57
  3. Retrieve Curve values
    By nenukino in forum Qwt
    Replies: 2
    Last Post: 26th February 2008, 14:33
  4. Sql Server cannot retrieve data from select
    By Atomino in forum Qt Programming
    Replies: 10
    Last Post: 7th September 2006, 16:37
  5. [QT4 & XP] retrieve data from QTreeView's model
    By incapacitant in forum Newbie
    Replies: 1
    Last Post: 2nd March 2006, 13:02

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
  •  
Qt is a trademark of The Qt Company.