Results 1 to 7 of 7

Thread: Spline interpolation behaves "weird"

  1. #1
    Join Date
    Oct 2019
    Posts
    23
    Qt products
    Qt5
    Platforms
    Windows

    Default Spline interpolation behaves "weird"

    Tested with:
    - qwt 6.2.0 and 6.2.1
    - Qt 5.14.0

    The spline's shape appear to be dependent from the current axes' values (min-max). If the axes' values change, the spline changes its shape.

    Unfortunately I can not upload csv files so I can not provide you with data (my data contains 200 points) but I can show you two screenshots where the problem becomes visible.

    Spline1.jpg
    x axis: 23.7304 / 23.7766
    y axis: -1011.7266 / -875.0032

    Spline2.jpg
    x axis: 23.7335 / 23.7705
    y axis: -1001.1308 / -891.7521

    The data did not change between the two screenshots, only the axes' values were changed slightly.

    I do not know if this is sufficient, if you tell me another way to upload the points data, I will do so.

    Btw, I tried the same data and axes' values with Excel and here the spline does not change its shape.

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

    Default Re: Spline interpolation behaves "weird"

    The spline interpolation is done after the points have been mapped into the paintdevice coordinate system: the motivation is usually to make its representation smoother. This explains, why there is an impact of the current axes.

    If you want to interpolate the data in plot coordinates you would have to use the spline classes manually and pass the result as curve points.
    If you believe that the result of the interpolation is wrong you would have to give more information - f.e which type of spline you are using and - of course - a series of points, that goes wrong.

    HTH,
    Uwe

  3. #3
    Join Date
    Oct 2019
    Posts
    23
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Spline interpolation behaves "weird"

    In my opinion the data as well as the interpolated data (in this case the spline) should not change when I change the sight on the data by changing the axes' values.

    This is the whole code for the curve:

    Qt Code:
    1. auto points = loadPlotData(); // loads the points from the attached file
    2. auto curve1 = new QwtPlotCurve("Curve 1");
    3. curve1->setSamples(points);
    4. curve1->setSymbol(new QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::red), QPen(Qt::darkRed), QSize(8, 8)));
    5. curve1->setPen(QPen(Qt::red));
    6. curve1->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
    7. curve1->setLegendAttribute(QwtPlotCurve::LegendShowSymbol, true);
    8. curve1->setCurveAttribute(QwtPlotCurve::Fitted, true);
    9. curve1->attach(m_plot);
    To copy to clipboard, switch view to plain text mode 
    So there is no special spline that I am using, it is just the curve attribute QwtPlotCurve::Fitted.

    I added the plot points here:
    PlotData.txt

    (At first I tried to upload the data as csv, but that did not work. txt did work however).

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

    Default Re: Spline interpolation behaves "weird"

    The problem should be related to the polygon clipping, that is enabled by default. As the cutting point between curve and canvas replaces the previous point you get a different polynomial.
    If I'm right you should be able to work around this problem by:

    Qt Code:
    1. m_curve->setPaintAttribute( QwtPlotCurve::ClipPolygons, false );
    To copy to clipboard, switch view to plain text mode 
    Could you please modify the code in QwtPlotCurve:: drawLines, so that the fitting is done before the spline interpolation ?

    However a proper fix is not so easy as this reordering results in ( potentially many ) more points that go into both algos and could be a real performance issue for QwtWeedingCurveFitter.

    Uwe

  5. #5
    Join Date
    Oct 2019
    Posts
    23
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Spline interpolation behaves "weird"

    The workaround helped to fix the problem, thank you.

    (I do not know where and how exactly to patch the QwtPlotCurve::drawLines method... it helped to turn polygon clipping off in our code when we switch to spline interpolation.)

    I am well aware that both, the workaround and a proper fix have an impact on the performance, but since a spline interpolation by definition is slower than a linear interpolation I do not consider this a real problem for us (other qwt users may of course object to this option).

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

    Default Re: Spline interpolation behaves "weird"

    I added a bug report with an idea how to "avoid" the problem: https://sourceforge.net/p/qwt/bugs/369/

    Uwe

  7. #7
    Join Date
    Oct 2019
    Posts
    23
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Spline interpolation behaves "weird"

    Sounds good.

Similar Threads

  1. Replies: 1
    Last Post: 20th November 2015, 10:02
  2. Replies: 2
    Last Post: 13th September 2015, 21:48
  3. Replies: 3
    Last Post: 16th March 2015, 07:31
  4. Spline interpolation
    By DomantasB in forum Qt Programming
    Replies: 1
    Last Post: 10th November 2013, 21:53
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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.