PDA

View Full Version : qwtspectrogram axis adjustment for area not pixels



habbas33
20th September 2014, 08:40
Hi I am using qwtspectrogram to plot my array data but the problem i am having is scaling.. the qwt scales are distributed over the intervals x and y and the axis are dependent on the pixels. for example if I have a data set of (500×500) and i want to plot for 500mm x500mm its perfect because it is translated over the pixels but if i want to plot 500×500 number of points for 300mmx300mm it is a mess and it shows in the plot 500×500 i know i have to manage the x and y axis but I have no idea how to do that. I manage to play a little and display 500×500 for 250mmx250mm area but can not do for others.
my code is as shown below


class mydata: public QwtRasterData
{
char filepath[35];
QFile myfile;
QVector<qint16> fileBuf;
int pixel =500; // it represents the number of pixels in one row or column
int dial =1000;
public:

mydata()
{
setInterval( Qt::XAxis, QwtInterval( 0, (pixel)-1 ) );
setInterval( Qt::YAxis, QwtInterval( 0, (pixel)-1 ) );
setInterval( Qt::ZAxis, QwtInterval( -dial, dial ) );

{
sprintf_s(filepath, "c:\\myfile.bin");

myfile.setFileName(filepath);
if(!myfile.open(QIODevice::ReadOnly)) return;

QDataStream data(&myfile);
data.setByteOrder(QDataStream::LittleEndian);

while(!data.atEnd()) {
qint16 x;
data >> x;
fileBuf.append(x);
}

myfile.close();
}
}

virtual double value( double x, double y ) const
{
int x_pos = static_cast<int>(x);
int y_pos = static_cast<int>(y);
double c = (fileBuf[ ((x_pos)+((pixel-(y_pos))*pixel))]);
return c;
}
}
in short i have same number of pixels for different areas but i have same representation of axis in plot.

habbas33
21st September 2014, 08:32
here is a class that converts double value of scale into string and display instead


class MyScaleDraw: public QwtScaleDraw
{
public:
MyScaleDraw()
{
setTickLength( QwtScaleDiv::MajorTick, 10 );
setTickLength( QwtScaleDiv::MinorTick, 2 );
setTickLength( QwtScaleDiv::MediumTick, 0 );

setLabelRotation( 0 );
setLabelAlignment( Qt::AlignLeft | Qt::AlignVCenter );

setSpacing( 10 );
}

virtual QwtText label( double value ) const
{
QwtText h=QwtText(QString::number(value*0.75); //use any scaling factor you want
return h;
}
};

include the following below code after creating a plot



d_plot->setAxisScaleDraw( QwtPlot::xBottom, new MyScaleDraw() );
d_plot->setAxisScaleDraw( QwtPlot::yLeft, new MyScaleDraw() );

this solved my problem

Uwe
22nd September 2014, 07:40
I'm not 100% sure if I understand your initial mail exactly, but it looks like all you want to is to display a 500x500 matrix of values inside an area of a different size ( f.e 100x200 ) in plot coordinates :


rasterdata->setInterval( Qt::XAxis, QwtInterval( 0.0, 100 ) );
rasterdata->setInterval( Qt::YAxis, QwtInterval( 0.0, 200 ) );

If you are using QwtMatrixRaterData this would be all, otherwise it might be a good idea to implement YourRasterData::pixelHint() returning the size of one data pixel.

With using your label transformation you are faking a different coordinate system to the user, than the one that is used by the plot. You will have effects, that the ticks are not aligned to your faked coordinate system, labels at other places ( picker/zoom ) might be wrong etc.

Uwe