PDA

View Full Version : QwtPlotSpectrogram and QwtRasterData



jesse_mark
30th January 2013, 21:04
Hello,

I have a vector that has a structure (x,y,z and value). looking into the spectrogram example, i could not know how to make the x,y in the virtual value method match my x and y.

also does the raster data has to go through all the x,y in the plot ?? I want it to only go through my x and y and not all the x and y's for the whole plot.

sorry if i am asking in a stupid way, i just don't know exactly how to do it, and why i can not just give the rasterData my x,y and value immediately, and all the other x,y takes as a default No value. ??

I would really highly appreciate if some one can provide an example of how i can do this, which is how can i give the raster my x,y's and their values.

Thank you so much.

Uwe
30th January 2013, 21:14
Use QwtMatrixRasterData - have a look at the rasterview example.

Uwe

jesse_mark
30th January 2013, 22:40
I was looking at rasterview example, and we can assigne the the values, but not a long with the x,y position.

we gave the number of columns, which as I understand , it should be the number of different X's i have. but what if my points are not in order ?? how can it know which x,y that
should take this value ??

sorry but i am a bit confused.
also, we set the intervalY , intervalY to bound the area where i want to spectrogram to be drawn. but what is i have nonRect shape or a Rect but has rotation.

I hope my questions are clear.

Thanks so much

Uwe
31st January 2013, 06:37
I hope my questions are clear.
No, I have absolutely no idea what you need to know.

Uwe

jesse_mark
31st January 2013, 15:04
ok
my first question was, how do I assign x,y a value. in the rasterview example you used :


QVector<double> values;
for ( uint i = 0; i < sizeof( matrix ) / sizeof( double ); i++ )
values += matrix[i];

const int numColumns = 4;
setValueMatrix( values, numColumns );

but how do we know which x,y assigned which value?? and what is the affect of NumColumns ??
as well is there a way to control

my second question was:
the area of the spectrogram. in the example you used intervals:


setInterval( Qt::XAxis,
QwtInterval( 0.5, 3.5, QwtInterval::ExcludeMaximum ) );
setInterval( Qt::YAxis,
QwtInterval( 0.5, 3.5, QwtInterval::ExcludeMaximum ) );
setInterval( Qt::ZAxis, QwtInterval( 1.0, 6.0 ) );

this way made the spectrogram a rectangle, but what if its a poly shap or a rectangle that is rotated?? in other way how do i control the area in which i want the map "spectrogram" to be drawn.

Uwe
31st January 2013, 18:50
Let's do it the other way round: what type of values do you have an how do you want to display them on the plot ?

Uwe

jesse_mark
31st January 2013, 20:39
8661

see the attachment:

I have a map (x ,y and value) for the colored rectangle.
Let’s assume the origin point of the colored rectangle is (5000, 2000). The map will be for points only
inside the colored rectangle, with fixed distance between each point.
Map will be:
X
Y
Value
// for all points in the colored rectangle.
If (value = -1) that means NO value assigned.

Uwe
1st February 2013, 06:50
O.k. then you have to use QwtRasterData like in the spectrogram example.

The X/Y intervals have to be from the bounding rectangle of your rotated rect. In the implementation of YourRasterData::value() you have to translate/rotate x/y so that it finds the value from your value matrix.

For the positions inside of the bounding rectangle but outside of your rotated rectangle do the same as for other positions, where you don't have values: return -1.

Then use a color map that maps values <0 to qRgba( 0, 0, 0, 0 ).

Uwe

PS: be careful with your implementation of YourRasterData::value() as it will be called very often. So try to avoid doing heavy calculations there. Maybe it is better to build a rotated matrix ( probably with a different - higher - resolution ) in advance.

jesse_mark
1st February 2013, 15:53
The X/Y intervals have to be from the bounding rectangle of your rotated rect

ok let us assume my bounding rect :

for X-interval (0,40,000)
for Y-interval (0,35,000)
the values (Z-interval) (0-5000)
Also lets say that i have

QVector<QPoint> postions
QVector<double> val; // the value of postions->at(i) is val->at(i)


as I understood from the spectrogram example:

now the
virtual double value( double x, double y ) method will be called for every pixel in the bounding rect (the x/y intervals).


have to translate/rotate x/y so that it finds the value from your value matrix.

how can i do this ??
is it like


virtual double value( double x, double y )
{
QPoint tp;
tp.setX(x);
tp.setY(y);

int p = postions->indexOf(tp)
if (p!=-1)
{
return val->at(p);
}
else
return p;

}


Thank you so much for your patience and helping me to understand

Uwe
1st February 2013, 21:32
x/y are values from the scales. How your values are related to the scale coordinates is something I can't tell you.

The implementation of "value()" you have posted will be way to slow. It will be called for each pixel of the canvas ( when there is no pixelHint() ). You can't have an operation like indexOf() there.

Also indexOf() will fail for almost all values as the position of the pixels usually never meet the position, where you have a value. So you usually have a to do something called resampling. Mostly it is a nearest neighbor algorithm, but you might use some sort of interpolation as well.

F.e. QwtMatrixRasterData offers nearest neighbor and bilinear interpolation.

Uwe

PS: If all you want to do is to map values at a specific position to a colored dot QwtPlotSpectroCurve might be what you are looking for.

jesse_mark
5th February 2013, 14:59
QwtPlotSpectroCurve was close to what I want to do, but as I have too many points QwtPlotSpectroCurve is a bit slow when zooming or when dropping it after panning.

about QwtMatrixRasterData, so to use it we just assign a matrix of values to it.
how does it assign these values to the points ???
what is the affect of number of columns ??
other thing is as a I have -1 means no color, I tried the addColorStop(-1,qRgba(0,0,0,0)) but the colors still show even with QwtPlotSpectroCurve.


Thanks