PDA

View Full Version : QwtSpectrogram example program



cgifford
1st July 2008, 04:27
Greetings,

I need functionality similar to Matlab's "imagesc" function, but in Qt. I will be filling a 2D matrix with values, where the x and y represent a point and the value represents a magnitude that needs to be displayed as a color based on its value within a range/colormap. This matrix will get filled pretty often (every half second or so), and need to be replotted after it gets filled each time.

I noticed that QwtSpectrogram may do this for me, but I don't want the contours. I can't get it working at all, however. Is this the class I should be using to plot such a thing, or is there something better or more suiting in the qwt library?

If someone would be so kind, could a standalone example program be put together that merely fills a 2D array with values and plots it as a spectrogram properly (with a default colormap, but no contours)? An accompanying screenshot would be fantastic as well!

This would be a great help, and may prove very useful for others searching the forum for such a thing. I can't thank you enough for your help.

Chris

Uwe
1st July 2008, 06:18
I will be filling a 2D matrix with values, where the x and y represent a point and the value represents a magnitude that needs to be displayed as a color based on its value within a range/colormap.
This is exactly, what QwtPlotSpectrogram is intended for.


I noticed that QwtSpectrogram may do this for me, but I don't want the contours.
You can display your raster data as image and/or as contour mode - the default is as image only. So if you don't explicitely turn on the contour you don't get one.

If someone would be so kind, could a standalone example program be put together that merely fills a 2D array with values and plots it as a spectrogram properly (with a default colormap, but no contours)? An accompanying screenshot would be fantastic as well!
Look at the spectrogram example of Qwt or at the screenshots on the Qwt homepage.

All you need to do is to derive your own type of QwtRasterData and connect the range and value methods with your 2D array. Note that you need to do some resampling ( in most cases simply a next neighbour ) of your array, because the value method requests values for a raster, that comes from the pixel positions - not from your raster. Also don't forget to implement the copy method, but don't copy your array - only the interface. The easiest way to do so is to use a Qt container ( f.e a QVector ), that implicitely shares your values.

Uwe

cgifford
1st July 2008, 22:24
Thank you for your quick response, Uwe.

I currently have a large Qt application that does not use anything from the Qwt library. We would like to add a spectrogram plot to this existing application. An obvious first step is to put the Qwt spectrogram example into the existing Qt code (which cannot easily be changed).

Can this be done easily? Is there a way to do the exact same thing as QwtPlotSpectrogram without having to include Qwt? Sorry for the naive questions, I am still trying to wrap my head around how this can be done within my existing codebase.

Thanks again for all of your help.

Chris

Uwe
2nd July 2008, 06:46
I currently have a large Qt application that does not use anything from the Qwt library. We would like to add a spectrogram plot to this existing application. An obvious first step is to put the Qwt spectrogram example into the existing Qt code (which cannot easily be changed).
All Qwt widgets are Qt widgets and adding a QwtPlot widget to a Qt application is as easy/difficult as adding a QLabel ( or any other Qt widget ).


Can this be done easily? Is there a way to do the exact same thing as QwtPlotSpectrogram without having to include Qwt? Sorry for the naive questions, I am still trying to wrap my head around how this can be done within my existing codebase.
Of course you can implement your own plot widget from scratch. But in the end you have to add it to your application too, what is exactly the same work you have to do with a derived QwtPlot widget.

Uwe