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 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,309
    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
    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,309
    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
    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,309
    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

    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,309
    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

    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,309
    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

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

Similar Threads

  1. Replies: 0
    Last Post: 19th September 2009, 08:07
  2. Replies: 0
    Last Post: 14th September 2009, 12:57
  3. Retrieve Curve values
    By nenukino in forum Qwt
    Replies: 2
    Last Post: 26th February 2008, 15:33
  4. Sql Server cannot retrieve data from select
    By Atomino in forum Qt Programming
    Replies: 10
    Last Post: 7th September 2006, 17:37
  5. [QT4 & XP] retrieve data from QTreeView's model
    By incapacitant in forum Newbie
    Replies: 1
    Last Post: 2nd March 2006, 14: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.