PDA

View Full Version : Problem with QwtPlotSpectrogram: completely gray output



prubbens
2nd September 2013, 16:39
Dear all,

I have the following problem. I would like to visualize a two-dimensional grid in which agents move. They all have a certain value which I like to visualize using colours, that is why I like to use QwtPlotSpectrogram. However, after reading various examples and implementing code, my grid stays gray, and none of the colours are displayed.

This is my code:

In the constructor of mainwindow.cpp:



//Colormap
colormap = new QwtLinearColorMap(Qt::darkCyan, Qt::red);
colormap->addColorStop(0.1, Qt::cyan);
colormap->addColorStop(0.6, Qt::green);
colormap->addColorStop(0.95, Qt::yellow); //empty paradigm different color from all other paradigms

//Grid
grid_qwtSpectPLot = new QwtPlotSpectrogram;
grid_qwtSpectPLot->attach(ui->grid_qwtPlot);
grid_qwtSpectPLot->setDisplayMode(QwtPlotSpectrogram::ImageMode, true);
grid_qwtSpectPLot->setColorMap(colormap);
grid_qwtSpectPLot->setRenderThreadCount(0);

//Matrix
matrixdata = new QwtMatrixRasterData;
matrixdata->setInterval(Qt::XAxis,QwtInterval(0,99,QwtInterval ::IncludeBorders));
matrixdata->setInterval(Qt::YAxis,QwtInterval(0,99,QwtInterval ::IncludeBorders));

grid_qwtSpectPLot->attach(ui->grid_qwtPlot);
ui->grid_qwtPlot->setTitle(QString("Grid"));
ui->grid_qwtPlot->plotLayout()->setAlignCanvasToScales(true);

And two methods which are called during the simulation. Nigel_DeJong is the object which represents the agents on a grid and maxvalue makes sure the values are between 0 and 1. grid is a QVector consisting out of doubles.


//Get the data to display the grid
void MainWindow::getDataGrid()
{
int l=0;
for(int j=0; j<L; j++){
for(int k=0; k<L; k++){
grid.append(float(Nigel_DeJong->get_value)/maxvalue);
l++;
}
}
}

//Update the grid
void MainWindow::viewGrid()
{
getDataGrid();
matrixdata->setValueMatrix(grid,L);
grid_qwtSpectPLot->setData(matrixdata);
ui->grid_qwtPlot->replot();
grid.clear();
}

I checked the values in the matrix, and it is filled with doubles between 0 and 1. Does anyone see what results in a completely grey grid?

Much thanks in advance.

Uwe
2nd September 2013, 17:49
At least one thing that is missing in your code is setting a valid range:


matrixdata->setInterval( Qt::ZAxis, QwtInterval(min, max ) );
min corresponds with 0.0 in the color map, max with 1.0.

Uwe

prubbens
3rd September 2013, 11:26
Thanks, this solved my problem.