Results 1 to 3 of 3

Thread: QwtPlotMarker are not displayed on the QwtPlot

  1. #1
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QwtPlotMarker are not displayed on the QwtPlot

    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 

  2. #2
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlotMarker are not displayed on the QwtPlot

    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:
    Qt Code:
    1. d_plot->detachItems(QwtPlotItem::Rtti_PlotMarker, true);
    To copy to clipboard, switch view to plain text mode 

    best regards

  3. The following user says thank you to rambo83 for this useful post:

    Astronomy (3rd March 2010)

  4. #3
    Join Date
    May 2009
    Location
    Vienna
    Posts
    91
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Cool Re: QwtPlotMarker are not displayed on the QwtPlot

    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.

Similar Threads

  1. Replies: 5
    Last Post: 25th November 2009, 13:55
  2. Implement draggable QWtplotmarker
    By shud in forum Qwt
    Replies: 3
    Last Post: 13th August 2009, 07:25
  3. Replies: 6
    Last Post: 14th May 2009, 13:02
  4. QwtPlotMarker segfault
    By viridis in forum Qwt
    Replies: 4
    Last Post: 17th September 2008, 14:22
  5. QwtPlotMarker confusion
    By baray98 in forum Qwt
    Replies: 3
    Last Post: 20th July 2008, 10:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.