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

Qt Code:
  1. // this function draws the spectrogram of benchmark function and the constraint curves
  2. void Plot::drawNewData(){
  3.  
  4. this->detachItems();
  5.  
  6. d_spectrogram = new QwtPlotSpectrogram();
  7.  
  8. // load the corresponding struct with optimization problem
  9. //
  10. optProbList = _mf->getOptProblems();
  11. unsigned index= _mf->objFunction;
  12. double (*f)(vector<double> coord) = optProbList[index]->benchmark;
  13. double rangex1[2] = {optProbList[index]->min[_mf->dim_indices[0]], optProbList[index]->max[_mf->dim_indices[0]]};
  14. double rangex2[2] = {optProbList[index]->min[_mf->dim_indices[1]], optProbList[index]->max[_mf->dim_indices[1]]};
  15. QwtDoubleInterval value_interval = optProbList[index]->valuesRange;
  16.  
  17. // here the data for ploting is set from the function "SpectrogramData()", in which the data is generated
  18. //
  19. d_spectrogram->setData(SpectrogramData((*f), rangex1, rangex2, _mf->dim_indices , _mf->fixed_values, optProbList[index]->dimensions, value_interval));
  20. d_spectrogram->attach(this); // attach the data to the plot widget
  21.  
  22. // set the colors for intensity values
  23. //
  24. QwtLinearColorMap colorMap(Qt::darkCyan, Qt::red);
  25. colorMap.addColorStop(0.25, Qt::cyan);
  26. colorMap.addColorStop(0.5, Qt::green);
  27. colorMap.addColorStop(0.75, Qt::yellow);
  28. d_spectrogram->setColorMap(colorMap);
  29.  
  30. // A color bar on the right axis
  31. //
  32. QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight);
  33. rightAxis->setTitle("Intensity");
  34. rightAxis->setColorBarEnabled(true);
  35. rightAxis->setColorMap(d_spectrogram->data().range(), d_spectrogram->colorMap());
  36.  
  37. // set the scale of color bar
  38. //
  39. setAxisScale(QwtPlot::yRight,
  40. d_spectrogram->data().range().minValue(),
  41. d_spectrogram->data().range().maxValue() );
  42. enableAxis(QwtPlot::yRight);
  43.  
  44. // define the steps and number of contour lines
  45. //
  46. QwtValueList contourLevels;
  47. double stepsize;
  48. if(value_interval.width()<2){
  49. stepsize = 0.2;
  50. }
  51. if(value_interval.width()>=5 && value_interval.width() < 20){
  52. stepsize = 1;
  53. }
  54. if(value_interval.width()>=20 && value_interval.width() < 50){
  55. stepsize = 5;
  56. }
  57. if (value_interval.width() >= 50 && value_interval.width() < 1000){
  58. stepsize = 50;
  59. }
  60. if ( value_interval.width() >= 1000){
  61. stepsize = 10000;
  62. }
  63. for ( double level = value_interval.minValue(); level < value_interval.maxValue(); level += stepsize )
  64. contourLevels += level;
  65. d_spectrogram->setContourLevels(contourLevels);
  66.  
  67. plotLayout()->setAlignCanvasToScales(true);
  68.  
  69. //+++++++++++++++++ plot constraints curves if the option "use constraints" is selected ++++++++++++++++++++++
  70.  
  71. if(_mf->useConstraints){ // if the user has checked the radio button "use constraints" in initialization...
  72.  
  73. QVector<int> equality = optProbList[index]->constraint_equality;
  74.  
  75. if(_mf->allConstraints){ // if use all constraints
  76. int k=0;
  77. for( std::map<QString, double (*)( vector<double> )>::iterator ii = optProbList[index]->constraints.begin(); ii!= optProbList[index]->constraints.end(); ++ii)
  78. {
  79.  
  80. double step_size = 0.5 ;
  81. for(double x1= optProbList[index]->min[_mf->dim_indices[0]] ; x1 < optProbList[index]->max[_mf->dim_indices[0]] ; x1=x1+ step_size){
  82. for(double x2= optProbList[index]->min[_mf->dim_indices[1]] ; x2 < optProbList[index]->max[_mf->dim_indices[1]] ; x2=x2+ step_size){
  83. vector<double> coords(3,0);
  84. coords = _mf->fixed_values;
  85. coords[_mf->dim_indices[0]] = x1;
  86. coords[_mf->dim_indices[1]] = x2;
  87. double result = (*ii).second(coords); // compute the y value
  88. if(result==1){
  89. // create PlotMarkers to visualize the infeasible area
  90. QwtSymbol *symb = new QwtSymbol();
  91. symb->setBrush(QBrush(Qt::red, Qt::SolidPattern));
  92. symb->setStyle(QwtSymbol::Ellipse);
  93. symb->setSize(5,5);
  94. mark->setSymbol(*symb);
  95. mark->setXValue(x1); // set the position of marker on the plot
  96. mark->setYValue(x2);
  97. //mark->setZ(101);
  98. mark->attach(this);
  99. }
  100. }
  101. }
  102.  
  103. k= k+1;
  104. }
  105. }
  106. else{ // if use certain constraint
  107. unsigned t = 0;
  108. for( std::map<QString, double(*)( vector<double> )>::iterator ii = optProbList[index]->constraints.begin(); ii!= optProbList[index]->constraints.end(); ++ii)
  109. {
  110. if(t== _mf->constraint){
  111.  
  112. double step_size = 0.5 ;
  113. for(double x1= optProbList[index]->min[_mf->dim_indices[0]] ; x1 < optProbList[index]->max[_mf->dim_indices[0]] ; x1=x1+ step_size){
  114. for(double x2= optProbList[index]->min[_mf->dim_indices[1]] ; x2 < optProbList[index]->max[_mf->dim_indices[1]] ; x2=x2+ step_size){
  115. vector<double> coords(3,0);
  116. coords = _mf->fixed_values;
  117. coords[_mf->dim_indices[0]] = x1;
  118. coords[_mf->dim_indices[1]] = x2;
  119. double result = (*ii).second(coords); // compute the y value
  120. if(result==1){
  121. // create PlotMarkers to visualize the infeasible area
  122. QwtSymbol *symb = new QwtSymbol();
  123. symb->setBrush(QBrush(Qt::red, Qt::SolidPattern));
  124. symb->setStyle(QwtSymbol::Ellipse);
  125. symb->setSize(5,5);
  126. mark->setSymbol(*symb);
  127. mark->setXValue(x1); // set the position of marker on the plot
  128. mark->setYValue(x2);
  129. //mark->setZ(101);
  130. mark->attach(this);
  131. }
  132. }
  133. }
  134. }
  135. t= t+1;
  136. }
  137. }
  138. }
  139. //+++++++++++++++++ end of plot constraints curves if the option "use constraints" is selected ++++++++++++++++++++++
  140. replot();
  141. }
To copy to clipboard, switch view to plain text mode