Results 1 to 6 of 6

Thread: How to avoid linking both ends of a Curve Plot

  1. #1
    Join Date
    May 2015
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default How to avoid linking both ends of a Curve Plot

    Hello, I'm trying to implement a continuous plot application that has two main guidelines:
    1. when the plot reaches the end it must start to refresh the existing data from the start
    2. there must be a gap between the new data being fed to the plot and the data that gets erased


    I managed to successfully maintain the gap between the new data and the old data using something like this:
    Qt Code:
    1. m_mainData->takeFirst();
    2. m_mainData->append(yValue);
    To copy to clipboard, switch view to plain text mode 

    the first time I reach the end of the screen I just delete some extra data from the start of the array and with it I guarantee that I'll always have that gap.

    now ... the problem I'm facing is when the plot reaches the end and starts over, the plot interpolates the last point with the first one and visually I see a horizontal line that appears at different locations in relation to the last data point. My first idea was to try to plot the last and first data points off-screen so that the lines is not visible, but I don't see it as a clean approach and I may also have some cases where the line manages to appear since it depends on the data.

    Any ideas on how I can manage to separate the last data point on screen with the first one painted? I'm using a left to right sweep for plotting, the signal type is the same as a medical electrocardiograph parameter for reference.

    Thanks in advance

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,236
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to avoid linking both ends of a Curve Plot

    I'd try using two curves. First time through, add data to curve 1. When curve 1 reaches the end, start adding data to curve 2. At the same time, remove points from curve 1 to create the gap, then for each new point you add to curve 2, take one from the start of curve 1 to maintain the gap. When curve 1 has no more points, you have reached the end and now you start the process again by flipping curves.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2015
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: How to avoid linking both ends of a Curve Plot

    Quote Originally Posted by d_stranz View Post
    I'd try using two curves. First time through, add data to curve 1. When curve 1 reaches the end, start adding data to curve 2. At the same time, remove points from curve 1 to create the gap, then for each new point you add to curve 2, take one from the start of curve 1 to maintain the gap. When curve 1 has no more points, you have reached the end and now you start the process again by flipping curves.
    thanks for the answer, that was my initial approach too, the application I'm developing uses 6 chart objects on screen and I felt having 12 charts at one point could be optimized. I started noticing some issues in performance when the application was running for 1 or 2 days non stop, but I could give it another go and see.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,236
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to avoid linking both ends of a Curve Plot

    I started noticing some issues in performance when the application was running for 1 or 2 days non stop
    Then I'd suggest you start looking for a memory leak. It could also be that even if you don't have a leak, the constant modification of the curve data (and array length) is causing memory fragmentation. In that case, I would look at using fixed-length arrays where instead of adding or removing points, you simply give a different starting position and number of points by manipulating the pointers you send to the curve plot.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    May 2015
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: How to avoid linking both ends of a Curve Plot

    Quote Originally Posted by d_stranz View Post
    Then I'd suggest you start looking for a memory leak. It could also be that even if you don't have a leak, the constant modification of the curve data (and array length) is causing memory fragmentation. In that case, I would look at using fixed-length arrays where instead of adding or removing points, you simply give a different starting position and number of points by manipulating the pointers you send to the curve plot.
    okay, I'll keep it in mind, I'll test again first removing and adding points and if I notice something odd I'll fallback to using a pointer, thanks !!!

  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: How to avoid linking both ends of a Curve Plot

    You could inherit from QwtSeriesData. Inside you would have an array of points and a start index. When a new point arrives you simply replace the point at the index and increment the index.
    Then all you have to do is to reimplement the sample method in a way, that the start index is taken into count.

    Or something similar along this idea

    HTH,
    Uwe

  7. The following user says thank you to Uwe for this useful post:

    d_stranz (6th October 2021)

Similar Threads

  1. Replies: 1
    Last Post: 5th May 2014, 07:49
  2. Replies: 6
    Last Post: 7th January 2013, 16:30
  3. Plot x^2 curve
    By qt_developer in forum Qwt
    Replies: 4
    Last Post: 14th June 2012, 08:17
  4. How to plot tan(x) curve?
    By Name in forum Qwt
    Replies: 1
    Last Post: 17th September 2010, 13:20
  5. Replies: 4
    Last Post: 7th September 2010, 11:52

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.