PDA

View Full Version : QwtPlotMarker are not displayed on the QwtPlot



rambo83
26th February 2010, 09:25
Hello,

I try to display markers above a spectrogram. The spectrogram data is visualized correctly, but I cannot see any markers on it. The code I use for visualization is below. Could you tell me, where the mistake is or why the markers are not visible on the plot? Thank you.

best regards


// this function draws the spectrogram of benchmark function and the constraint curves
void Plot::drawNewData(){

this->detachItems();

d_spectrogram = new QwtPlotSpectrogram();

// load the corresponding struct with optimization problem
//
optProbList = _mf->getOptProblems();
unsigned index= _mf->objFunction;
double (*f)(vector<double> coord) = optProbList[index]->benchmark;
double rangex1[2] = {optProbList[index]->min[_mf->dim_indices[0]], optProbList[index]->max[_mf->dim_indices[0]]};
double rangex2[2] = {optProbList[index]->min[_mf->dim_indices[1]], optProbList[index]->max[_mf->dim_indices[1]]};
QwtDoubleInterval value_interval = optProbList[index]->valuesRange;

// here the data for ploting is set from the function "SpectrogramData()", in which the data is generated
//
d_spectrogram->setData(SpectrogramData((*f), rangex1, rangex2, _mf->dim_indices , _mf->fixed_values, optProbList[index]->dimensions, value_interval));
d_spectrogram->attach(this); // attach the data to the plot widget

// set the colors for intensity values
//
QwtLinearColorMap colorMap(Qt::darkCyan, Qt::red);
colorMap.addColorStop(0.25, Qt::cyan);
colorMap.addColorStop(0.5, Qt::green);
colorMap.addColorStop(0.75, Qt::yellow);
d_spectrogram->setColorMap(colorMap);

// A color bar on the right axis
//
QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight);
rightAxis->setTitle("Intensity");
rightAxis->setColorBarEnabled(true);
rightAxis->setColorMap(d_spectrogram->data().range(), d_spectrogram->colorMap());

// set the scale of color bar
//
setAxisScale(QwtPlot::yRight,
d_spectrogram->data().range().minValue(),
d_spectrogram->data().range().maxValue() );
enableAxis(QwtPlot::yRight);

// define the steps and number of contour lines
//
QwtValueList contourLevels;
double stepsize;
if(value_interval.width()<2){
stepsize = 0.2;
}
if(value_interval.width()>=5 && value_interval.width() < 20){
stepsize = 1;
}
if(value_interval.width()>=20 && value_interval.width() < 50){
stepsize = 5;
}
if (value_interval.width() >= 50 && value_interval.width() < 1000){
stepsize = 50;
}
if ( value_interval.width() >= 1000){
stepsize = 10000;
}
for ( double level = value_interval.minValue(); level < value_interval.maxValue(); level += stepsize )
contourLevels += level;
d_spectrogram->setContourLevels(contourLevels);

plotLayout()->setAlignCanvasToScales(true);

//+++++++++++++++++ plot constraints curves if the option "use constraints" is selected ++++++++++++++++++++++

if(_mf->useConstraints){ // if the user has checked the radio button "use constraints" in initialization...

QVector<int> equality = optProbList[index]->constraint_equality;

if(_mf->allConstraints){ // if use all constraints
int k=0;
for( std::map<QString, double (*)( vector<double> )>::iterator ii = optProbList[index]->constraints.begin(); ii!= optProbList[index]->constraints.end(); ++ii)
{

double step_size = 0.5 ;
for(double x1= optProbList[index]->min[_mf->dim_indices[0]] ; x1 < optProbList[index]->max[_mf->dim_indices[0]] ; x1=x1+ step_size){
for(double x2= optProbList[index]->min[_mf->dim_indices[1]] ; x2 < optProbList[index]->max[_mf->dim_indices[1]] ; x2=x2+ step_size){
vector<double> coords(3,0);
coords = _mf->fixed_values;
coords[_mf->dim_indices[0]] = x1;
coords[_mf->dim_indices[1]] = x2;
double result = (*ii).second(coords); // compute the y value
if(result==1){
// create PlotMarkers to visualize the infeasible area
QwtPlotMarker *mark = new QwtPlotMarker();
QwtSymbol *symb = new QwtSymbol();
symb->setBrush(QBrush(Qt::red, Qt::SolidPattern));
symb->setStyle(QwtSymbol::Ellipse);
symb->setSize(5,5);
mark->setSymbol(*symb);
mark->setXValue(x1); // set the position of marker on the plot
mark->setYValue(x2);
//mark->setZ(101);
mark->attach(this);
}
}
}

k= k+1;
}
}
else{ // if use certain constraint
unsigned t = 0;
for( std::map<QString, double(*)( vector<double> )>::iterator ii = optProbList[index]->constraints.begin(); ii!= optProbList[index]->constraints.end(); ++ii)
{
if(t== _mf->constraint){

double step_size = 0.5 ;
for(double x1= optProbList[index]->min[_mf->dim_indices[0]] ; x1 < optProbList[index]->max[_mf->dim_indices[0]] ; x1=x1+ step_size){
for(double x2= optProbList[index]->min[_mf->dim_indices[1]] ; x2 < optProbList[index]->max[_mf->dim_indices[1]] ; x2=x2+ step_size){
vector<double> coords(3,0);
coords = _mf->fixed_values;
coords[_mf->dim_indices[0]] = x1;
coords[_mf->dim_indices[1]] = x2;
double result = (*ii).second(coords); // compute the y value
if(result==1){
// create PlotMarkers to visualize the infeasible area
QwtPlotMarker *mark = new QwtPlotMarker();
QwtSymbol *symb = new QwtSymbol();
symb->setBrush(QBrush(Qt::red, Qt::SolidPattern));
symb->setStyle(QwtSymbol::Ellipse);
symb->setSize(5,5);
mark->setSymbol(*symb);
mark->setXValue(x1); // set the position of marker on the plot
mark->setYValue(x2);
//mark->setZ(101);
mark->attach(this);
}
}
}
}
t= t+1;
}
}
}
//+++++++++++++++++ end of plot constraints curves if the option "use constraints" is selected ++++++++++++++++++++++
replot();
}

rambo83
26th February 2010, 09:37
Hello,

I have found the reason, why the markers were not visible! Since they were deleted before I could see them due to this command in another function:

d_plot->detachItems(QwtPlotItem::Rtti_PlotMarker, true);

best regards

Astronomy
3rd March 2010, 15:46
Hi rambo,

i create my Markers dynamically and tried to delete them. This was exactly what i needed :)
Although it was the other way round @my problem *gg*

greetz A.