Results 1 to 7 of 7

Thread: Can't figure out how to use Spectrogram with captured data

  1. #1
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Arrow Can't figure out how to use Spectrogram with captured data

    Hi,
    Qwt Spectrogram looks great, but by default is uses double x, y, data as if the routine is supposed to perform some sort of maths on them. What I need to do is plot data from a few QList<double>'s. I have half stolen the code from the spectrogram example but I think my problem is in the value routine where it seems to crash. The data I am trying to plot is held in "QList<double> spectData[180];" Could you provide some pointers as to how to do it correctly?

    Cheers.

    Qt Code:
    1. class SpectrogramData: public QwtRasterData
    2. {
    3. public:
    4. QpnwPhasedArrayPlot * parent;
    5. // Provide pointer to QpnwPhasedArrayPlot so we can access the data
    6. SpectrogramData( QpnwPhasedArrayPlot * theParent ):
    7. QwtRasterData(QwtDoubleRect(-90, 0, 180, 2000)) // Left, bottom, width, height
    8. {
    9. parent = theParent;
    10. }
    11. // Left as example
    12. virtual QwtRasterData *copy() const
    13. {
    14. return new SpectrogramData(0);
    15. }
    16. // Left as example
    17. virtual QwtDoubleInterval range() const
    18. {
    19. return QwtDoubleInterval(0.0, 4096);
    20. }
    21. // Return data. Crashes here.
    22. virtual double value(double x, double y) const
    23. {
    24. QMessageBox::information(0,"","A");
    25. return parent->spectData[(unsigned int) x+90].at( (unsigned int) y );
    26. }
    27.  
    28. };
    29.  
    30.  
    31.  
    32. QpnwPhasedArrayPlot::QpnwPhasedArrayPlot(QwtPlot * thePlot)
    33. {
    34. DEBUG->print(QDateTime::currentDateTime().toString("dd.MM.yy hh:mm:ss.zzz") + ": " + "Initialising Plot");
    35.  
    36. // Create spectrogram
    37. spectrogram = new QwtPlotSpectrogram();
    38.  
    39. // Create some fake data
    40. for( int x = 0; x < 180; x++ )
    41. for( int y = 0; y < 2000; y++ )
    42. spectData[x].append(y);
    43. spectData[90].clear();
    44. for( int x = 0; x < 2000; x++ )
    45. spectData[90].append(x);
    46.  
    47. // Attach the data
    48. spectrogram->setData(SpectrogramData(this));
    49. spectrogram->attach(thePlot);
    50. }
    51. //
    To copy to clipboard, switch view to plain text mode 
    Best Regards,
    Phil Winder
    www.philwinder.com

  2. #2
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Can't figure out how to use Spectrogram with captured data

    Definitely a problem with the value routine. I can stick static values in there and it works ok. So there seems to be a problem accessing its parents data. So I think I need to know a bit more on how it asks for the data. I thought it might just be asking for data that is out of bounds of the array so I put some error checking in, but to no avail.

    Then I tried to return a single value, like:
    Qt Code:
    1. return parent->spectData[90].at(90);
    To copy to clipboard, switch view to plain text mode 
    But that didnt work either. So what else could be causing a crash? Is the parent pointer getting messed up in the copy routine? Or could it be something to do with my multi-dimentional-ness in the data, although it works fine when printf'ing it somewhere.

    My most recent code:
    Qt Code:
    1. class SpectrogramData: public QwtRasterData
    2. {
    3. public:
    4. QpnwPhasedArrayPlot * someParent;
    5. // Provide pointer to QpnwPhasedArrayPlot so we can access the data
    6. SpectrogramData( QpnwPhasedArrayPlot * theParent ):
    7. QwtRasterData(QwtDoubleRect(0.0, 0.0, 180.0, 1999.0)) // Left, bottom, width, height
    8. {
    9. someParent = theParent;
    10. //QMessageBox::information(0,"","Creating Raster");
    11. }
    12. virtual QwtRasterData *copy() const
    13. {
    14. return new SpectrogramData(someParent);
    15. }
    16.  
    17. virtual QwtDoubleInterval range() const
    18. {
    19. return QwtDoubleInterval(0.0, 4096.0);
    20. }
    21.  
    22. virtual double value(double x, double y) const
    23. {
    24. //QMessageBox::information(0,"","Real: " + QString::number(y) + " Round: " + QString::number((unsigned int)y));
    25. if( x < 0 || x > 180 || y < 0.0 || y > 1999.0 )
    26. return 0.0;
    27. else
    28. return someParent->spectData[90].at(90);
    29. }
    30. };
    31.  
    32.  
    33.  
    34. QpnwPhasedArrayPlot::QpnwPhasedArrayPlot(QwtPlot * thePlot)
    35. {
    36. // Create spectrogram
    37. spectrogram = new QwtPlotSpectrogram();
    38. // Create some fake data
    39. for( int x = 0; x < 180; x++ )
    40. for( int y = 0; y < 2000; y++ )
    41. spectData[x].append(y);
    42. // Attach the data
    43. spectrogram->setData(SpectrogramData(this));
    44. spectrogram->attach(thePlot);
    45. }
    To copy to clipboard, switch view to plain text mode 
    Best Regards,
    Phil Winder
    www.philwinder.com

  3. #3
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't figure out how to use Spectrogram with captured data

    Ok,
    Ive managed to half get it working, but not very well. What I have had to do is copy the entire array into the SpectrogramData class, the use the data locally.
    Qt Code:
    1. class SpectrogramData: public QwtRasterData
    2. {
    3. public:
    4. QpnwPhasedArrayPlot * someParent;
    5. QVector< QList<double> > someData;
    6. // Provide pointer to QpnwPhasedArrayPlot so we can access the data
    7. SpectrogramData( QpnwPhasedArrayPlot * theParent ):
    8. QwtRasterData(QwtDoubleRect(0.0, 0.0, 180.0, 2000.0)) // Left, bottom, width, height
    9. {
    10. someParent = theParent;
    11. someData = theParent->spectData;
    12. //QMessageBox::information(0,"","Creating Raster");
    13. }
    14. virtual QwtRasterData *copy() const
    15. {
    16. return new SpectrogramData(someParent);
    17. }
    18.  
    19. virtual QwtDoubleInterval range() const
    20. {
    21. return QwtDoubleInterval(0.0, 4096.0);
    22. }
    23.  
    24. virtual double value(double x, double y) const
    25. {
    26. //QMessageBox::information(0,"","Real: " + QString::number(y) + " Round: " + QString::number((unsigned int)y));
    27. QList<double> temp;
    28. if( x < 0.0 || x > 180.0 || y < 0.0 || y > 2000.0 )
    29. return 0.0;
    30. else
    31. {
    32. return someData.at( (unsigned int)x ).at( (unsigned int)y );
    33. }
    34. //return someParent->spectData.at(1).at(1);
    35. //return 100;
    36. }
    37. };
    To copy to clipboard, switch view to plain text mode 

    I dont know what problems I will have in updating the data, hopefully replot() should take care of it for me, but I'm not sure.
    There is surely a better way of doing this, where the SpectrogramData class can access some external data?
    Best Regards,
    Phil Winder
    www.philwinder.com

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

    Default Re: Can't figure out how to use Spectrogram with captured data

    Havn't checked your code in detail, but I recommend to implement SpectrogramData::rasterHint() too. In your case the resolution of your data is below the screen resolution and you might reduce the number of rendered points a lot.

    Uwe

  5. #5
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't figure out how to use Spectrogram with captured data

    Thanks for the info Uwe, I'll remember that. I still havent arrived at a solution for the data though, I dont really want to be copying whole arrays accross to the SpectrumData class. Maybe I could access the data in the class directly?

    Cheers,
    Phil
    Best Regards,
    Phil Winder
    www.philwinder.com

  6. #6
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't figure out how to use Spectrogram with captured data

    This is fast becoming a nightmare. How am I supposed to use the Raster class. Do I create a new instance of the class every time I want to update the spectrogram plot? How can I access external data? How can I access internal data?
    Are there alternatives to using the Raster class, like a simple setData in the curve class?

    Any hints, tips?
    Sorry to be so broad, I just cant quite see any clear path.
    Best Regards,
    Phil Winder
    www.philwinder.com

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

    Default Re: Can't figure out how to use Spectrogram with captured data

    QwtRasterData is simply an interface for accessing your raster data. You can connect it to any "external" data structure or copy your data in an "internal" member and return the values from there.

    If you change the data behind the back of the spectrogram item you have to call spectrogram->invalidatePaintCache() + plot->replot(). But you can also create a new QwtRasterData object and do spectrogram->setData() + plot->replot().

    Note, that most Qt containers are implicitely shared. So copying QLists is no problem.

    Uwe

Similar Threads

  1. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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.