Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Newbie : QwtCurveFitter and retrieve curve data

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

    Default Newbie : QwtCurveFitter and retrieve curve data

    Hello,

    I'm sorry if I'm raising a stupid qusetion but I ran throught the forum and could not find any answer that enables me to solve my problem...

    I'm trying to use Qwt in order to create a widget that will enable me to interpolate a Gamma curve and modify some points...

    So thanks to the event_filter example I was abble to copy the canvaspicker that makes the modification of points possible...

    But now that I have my curve... how can I retrieve all the values ?

    Qt Code:
    1. Plot::Plot(QWidget *parent):
    2. QwtPlot(parent)
    3. {
    4. tab_x[0] = 0; (----) to tab_x[10] = 4096;
    5. tab_y[0] = gamma(Tab_x[0]) = 0 to tab_y[10] = gamma(Tab_x[10]) (= 1024)
    6.  
    7. setAxisScale(QwtPlot::xBottom, 0.0, 4200,100);
    8. setAxisScale(QwtPlot::yLeft, 0.0, 1050.0,100);
    9.  
    10. axisScaleDraw(QwtPlot::xBottom)->setLabelRotation(90);
    11. axisScaleDraw(QwtPlot::xBottom)->setLabelAlignment(Qt::AlignRight);
    12. setAxisFont(QwtPlot::xBottom,QFont("MS Shell Dlg 2",9));
    13.  
    14. curve = new QwtPlotCurve();
    15.  
    16. curve->setStyle(QwtPlotCurve::Lines);
    17. curve->setCurveAttribute(QwtPlotCurve::Fitted, true);
    18. curve->setPen(QColor(Qt::red));
    19. curve->setSymbol(QwtSymbol(QwtSymbol::Cross,Qt::gray,QColor(Qt::red), QSize(8, 8)));
    20.  
    21. curveFitter = new QwtSplineCurveFitter();
    22. curveFitter->setFitMode(curveFitter->ParametricSpline);
    23. curveFitter->setSplineSize(100);
    24. curve->setCurveFitter(curveFitter);
    25.  
    26. curve->setData(tab_x, tab_y, sizeof(tab_x) / sizeof(tab_x[0]));
    27. curve->attach(this);
    28.  
    29. replot();
    30. }
    To copy to clipboard, switch view to plain text mode 

    Thansk a lot for any help....I'm turning crazy ....(and sorry if it is stupid)

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,190
    Thanked 843 Times in 792 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
    But now that I have my curve... how can I retrieve all the values ?
    Which values ?

    Obviously your points can be found in tab_x/tab_y. When painting these points are translated into widget ( canvas ) coordinates and your fitter adds additional points (also in screen coordinates) to smooth your curve. All translated points are temporary only and are recalculated each time the curve is painted.

    Uwe

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

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Thanks for your answer

    Actually yes...I want the 4096 y interpolated values (x is easy indeed ! )
    Is that possible ?

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,190
    Thanked 843 Times in 792 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
    Actually yes...I want the 4096 y interpolated values (x is easy indeed ! )
    These points are temporary because there position depends on the geometry of the plot canvas and the current scales. You could do the same interpolation in your application code, but probably what you want is to interpolate the untranslated curve points.

    So do the interpolation of your points manually ( with a local fitter object ) and pass the interpolated points to a curve without internal fitting.

    Uwe

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

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    I'm sorry... I don't understand...

    Ok...points of the curve are temporary and their position depends of axis scale etc...

    What do you call interpolate manually ? or local fitter object ....

    Sorry if I'm such a noob here...

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

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Qt Code:
    1. QPolygonF points;
    2. for ( int i = 0; i < ...; i++ )
    3. points += QPointF(tab_x[i], tabỵ[i]);
    4.  
    5. points = QwtSplineCurveFitter()::fitCurve(points);
    6.  
    7. // now you have interpolated untranslated points
    8.  
    9. curve = new QwtPlotCurve();
    10. curve->setCurveAttribute(QwtPlotCurve::Fitted, false);
    11. curve->setData(points);
    12. ...
    To copy to clipboard, switch view to plain text mode 

    HTH,
    Uwe

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

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Ok.... that works great...

    Now my only problem is to retrieve the coordonates of the points I moved ...

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,190
    Thanked 843 Times in 792 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    See QwtPlot::canvasMap().

    Uwe

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

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Sorry for my late answer...but... THAKNS a lot for your tips...
    I finally do it this way :

    Qt Code:
    1. void Plot::getPoints()
    2. {
    3. QwtArray<double> xData(curve->dataSize());
    4. QwtArray<double> yData(curve->dataSize());
    5.  
    6. QPolygonF points,points2;
    7.  
    8. for ( int i = 0; i < curve->dataSize(); i++ )
    9. {
    10. points += QPointF(curve->x(i), curve->y(i));
    11. }
    12.  
    13. QwtSplineCurveFitter curvefitter;
    14. curvefitter.setFitMode(curveFitter->ParametricSpline);
    15. curvefitter.setSplineSize(4096);
    16.  
    17. points2 = Toto.fitCurve(points);
    18. }
    To copy to clipboard, switch view to plain text mode 

    Can I raise another last little question ?

    I have my plot...with goes from 0 to 4096 on x and 0 to 1024 on y ....how can I have the same scale on x and y axis ? (1 cm on x = for example 100 = 1 cm on y )

  10. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,190
    Thanked 843 Times in 792 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    See QwtPlotRescaler. In SVN trunk you find the navigation example that shows how to use it.

    Uwe

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

    Default Re: Newbie : QwtCurveFitter and retrieve curve data

    Thanks for all your help !

    I have now another problem...perhas should I start another thread ?

    I have now my plot which I made using the event_filter example : I'm moving points of my curve and I am abble to save them... But I want to have the coordinates of my cursor on the plot...

    So I tried to combine the bode example with QwtPlotZoomer or QwtPlotPicker... but my canvaspicker class (extracted from event_filter example) installs an eventFilter on the canvas ...so no click seems to be linked to the Picker...

  12. #12
    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 ???

  13. #13
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,190
    Thanked 843 Times in 792 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

  14. #14
    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.

  15. #15
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,190
    Thanked 843 Times in 792 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

  16. #16
    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.

  17. #17
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,190
    Thanked 843 Times in 792 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

  18. #18
    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")

  19. #19
    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...

  20. #20
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,190
    Thanked 843 Times in 792 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

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.