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->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->attach(ui->grid_qwtPlot);
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);
//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);
To copy to clipboard, switch view to plain text mode
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();
}
//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();
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks