Results 1 to 10 of 10

Thread: how to make min and max values of spectrogram dynamical?

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

    Default how to make min and max values of spectrogram dynamical?

    Hello,

    I wonder whether it is possible to get the actual min and max range values of spectrogram and not to set them manually, like I do it now (see the code below). I mean, after the data for spectrogram was calculated, then the max and min values should be known, right? How to get them then? I don't want to set the range manually, but it should be done according to the current data. Help me please.

    best regards,


    Qt Code:
    1. typedef double (*benchFunc)(vector<double>); // definition of function pointer for benchmark function
    2.  
    3. // this class creates the data of objective function
    4.  
    5. class SpectrogramData: public QwtRasterData
    6. {
    7. public:
    8. SpectrogramData(benchFunc b, double rang1[2], double rang2[2], int dims[2], vector<double> fix_vec , unsigned dimens, QwtDoubleInterval interval ):
    9. QwtRasterData(QwtDoubleRect(rang1[0], rang2[0], rang1[1]- rang1[0], rang2[1]- rang2[0]))
    10. {
    11. MybenchFunc = b;
    12. valuesRange = interval; //<<<<<<<<<< here it is set manually
    13. dim_ind[0] = dims[0]; dim_ind[1] = dims[1];
    14. dimensions = dimens;
    15. fix_vals = fix_vec;
    16. }
    17.  
    18. virtual QwtRasterData *copy() const
    19. {
    20. return new SpectrogramData(*this);
    21. }
    22.  
    23. virtual QwtDoubleInterval range() const //<<<<<<<<<<< here the range will be returned
    24. {
    25. return valuesRange;
    26. }
    27.  
    28. virtual double value(double x, double y) const
    29. {
    30. vector<double> coords;
    31. coords = vector<double>(dimensions, 0); // create a vector of size "dimensions" containing zeros
    32. if(dimensions > 2){ // if the benchmark function has more dimensions than 2, then...
    33. for(unsigned i=0 ; i < dimensions ; ++i){
    34. coords[i] = fix_vals[i]; // ... copy first all fixed values into vector and then...
    35. }
    36. coords[dim_ind[0]] = x; // replace the values of dimensions to be visualized
    37. coords[dim_ind[1]] = y;
    38. }
    39. else{
    40. coords[dim_ind[0]] = x;
    41. coords[dim_ind[1]] = y;
    42. }
    43. const double result = MybenchFunc( coords);
    44. return result;
    45. }
    46.  
    47. private:
    48.  
    49. benchFunc MybenchFunc; // function pointer for benchmark function
    50. QwtDoubleInterval valuesRange;
    51. int dim_ind[2];
    52. unsigned dimensions;
    53. vector<double> fix_vals;
    54. };
    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: how to make min and max values of spectrogram dynamical?

    Hello,

    I tried to get it dynamical by manipulating the membver variable, but it is obviously not allowed due to const functions. How can I avoid the error?

    plot.cpp: In member function 'virtual double SpectrogramData::value(double, double) const':
    plot.cpp:75: error: no matching function for call to 'QwtDoubleInterval::setMinValue(double) const'
    /data/home/vanselm/.HRI/Proxy/hri/tree/External/qwt/5.2.0/include/qwt_double_interval.h:171: note: candidates are: void QwtDoubleInterval::setMinValue(double) <near match>
    plot.cpp:78: error: no matching function for call to 'QwtDoubleInterval::setMaxValue(double) const'
    /data/home/vanselm/.HRI/Proxy/hri/tree/External/qwt/5.2.0/include/qwt_double_interval.h:181: note: candidates are: void QwtDoubleInterval::setMaxValue(double) <near match>
    make[1]: *** [../obj/linux-amd64-gcc-lsb31/plot.o] Error 1
    make: *** [obj_qt] Error 2

    here is my current code:

    Qt Code:
    1. typedef double (*benchFunc)(vector<double>); // definition of function pointer for benchmark function
    2.  
    3. // this class creates the data of objective function
    4.  
    5. class SpectrogramData: public QwtRasterData
    6. {
    7. public:
    8. SpectrogramData(benchFunc b, double rang1[2], double rang2[2], int dims[2], vector<double> fix_vec , unsigned dimens, QwtDoubleInterval interval ):
    9. QwtRasterData(QwtDoubleRect(rang1[0], rang2[0], rang1[1]- rang1[0], rang2[1]- rang2[0]))
    10. {
    11. MybenchFunc = b;
    12. //valuesRange = interval;
    13. dim_ind[0] = dims[0]; dim_ind[1] = dims[1];
    14. dimensions = dimens;
    15. fix_vals = fix_vec;
    16. valuesRange.setInterval(0 , 0);
    17. }
    18.  
    19. virtual QwtRasterData *copy() const
    20. {
    21. return new SpectrogramData(*this);
    22. }
    23.  
    24. virtual QwtDoubleInterval range() const
    25. {
    26. return valuesRange;
    27. }
    28.  
    29. virtual double value(double x, double y) const
    30. {
    31. vector<double> coords;
    32. coords = vector<double>(dimensions, 0); // create a vector of size "dimensions" containing zeros
    33. if(dimensions > 2){ // if the benchmark function has more dimensions than 2, then...
    34. for(unsigned i=0 ; i < dimensions ; ++i){
    35. coords[i] = fix_vals[i]; // ... copy first all fixed values into vector and then...
    36. }
    37. coords[dim_ind[0]] = x; // replace the values of dimensions to be visualized
    38. coords[dim_ind[1]] = y;
    39. }
    40. else{
    41. coords[dim_ind[0]] = x;
    42. coords[dim_ind[1]] = y;
    43. }
    44. double result = MybenchFunc( coords);
    45. if(result < valuesRange.minValue()){
    46. valuesRange.setMinValue((double)result);
    47. }
    48. if(result > valuesRange.maxValue()){
    49. valuesRange.setMaxValue((double)result);
    50. }
    51. return result;
    52. }
    53.  
    54. private:
    55.  
    56. benchFunc MybenchFunc; // function pointer for benchmark function
    57. QwtDoubleInterval valuesRange;
    58. int dim_ind[2];
    59. unsigned dimensions;
    60. vector<double> fix_vals;
    61. };
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2009
    Posts
    29
    Thanks
    2
    Thanked 3 Times in 3 Posts

    Default Re: how to make min and max values of spectrogram dynamical?

    what you need is the QValidator Class. More precisely you are going to use QIntValidator and QDoubleValidator.

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

    Default Re: how to make min and max values of spectrogram dynamical?

    I have read the documentation of QValidator class and cannot see any relation to my problem here.

    Actually, I have already the idea how to get the value ranges dynamically (see the code in my second post), where I just check whether the new calculated value is larger than the maxValue of range or smaller than minValue. The only problem, which occurs here is the fact, that I cannot manipulate the member variable "valuesRange" because all member functions are const. It would be nice, if someone could tell me a trick how to achieve it. Thank you.

    best regards,

    Vitali

  5. #5
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to make min and max values of spectrogram dynamical?

    You could use mutable:

    Qt Code:
    1. mutable QwtDoubleInterval valuesRange;
    To copy to clipboard, switch view to plain text mode 

    Then you can modify valuesRange within a const function. This is a dirty solution, but it works.

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

    Default Re: how to make min and max values of spectrogram dynamical?

    Thank you for this hint! After making the member variable "mutable" the code can be compiled without errors, but nothing happen, thus nothing is displayed on the spectrogram. What is wrong then?

  7. #7
    Join Date
    Apr 2008
    Posts
    32
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: how to make min and max values of spectrogram dynamical?

    But range() function of QwtRasterData class is virtual. And Im pretty sure that you have your own derived class, Why don't you just overload range() function to give new max/min values?

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

    Default Re: how to make min and max values of spectrogram dynamical?

    Hello,

    I have figured out the problem, why I cannot calculate the value ranges dynamically.
    The problem is that the function "value", which calculates the values for x1 and x2 coordinates and stores the min and max value range is executed after the function "range", which gives the min and max boundaries of possible values. In other words, the functions are executed in wrong order. For my understanding, if I set data for spectrogram, then the values for all coordinates should be calculated, so that if in the next step I want to get the values range, then they are already calculated correctly. However, if I execute the code below, then first the function "range" and then "value" is called.

    Could you help me please to force the execution in another order?

    Thank you

    Qt Code:
    1. d_spectrogram = new QwtPlotSpectrogram();
    2.  
    3. // load the corresponding struct with optimization problem
    4. //
    5. optProbList = _mf->getOptProblems();
    6. unsigned index= _mf->objFunction;
    7. double (*f)(vector<double> coord) = optProbList[index]->benchmark;
    8. double rangex1[2] = {optProbList[index]->min[_mf->dim_indices[0]], optProbList[index]->max[_mf->dim_indices[0]]};
    9. double rangex2[2] = {optProbList[index]->min[_mf->dim_indices[1]], optProbList[index]->max[_mf->dim_indices[1]]};
    10. QwtDoubleInterval value_interval = optProbList[index]->valuesRange;
    11.  
    12. Model *neuralNet = _mf->getMetaModel();
    13. bool useMet = _mf->isMetaModelUsed();
    14.  
    15. // here the data for ploting is set from the function "SpectrogramData()", in which the data is generated
    16. //
    17. d_spectrogram->setData(SpectrogramData((*f), rangex1, rangex2, _mf->dim_indices , _mf->fixed_values, optProbList[index]->dimensions, value_interval, neuralNet, useMet));
    18. d_spectrogram->attach(this); // attach the data to the plot widget
    19.  
    20. // set the colors for intensity values
    21. //
    22. QwtLinearColorMap colorMap(Qt::darkCyan, Qt::red);
    23. colorMap.addColorStop(0.25, Qt::cyan);
    24. colorMap.addColorStop(0.5, Qt::green);
    25. colorMap.addColorStop(0.75, Qt::yellow);
    26. d_spectrogram->setColorMap(colorMap);
    27.  
    28. // A color bar on the right axis
    29. //
    30. QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight);
    31. rightAxis->setTitle("Intensity");
    32. rightAxis->setColorBarEnabled(true);
    33. rightAxis->setColorMap(d_spectrogram->data().range(), d_spectrogram->colorMap()); //<<< here values range are required, but is not calculated yet
    34.  
    35. // set the scale of color bar
    36. //
    37. setAxisScale(QwtPlot::yRight,
    38. d_spectrogram->data().range().minValue(), //<<< here values range are required, but is not calculated yet
    39. d_spectrogram->data().range().maxValue() ); //<<< here values range are required, but is not calculated yet
    40. enableAxis(QwtPlot::yRight);
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to make min and max values of spectrogram dynamical?

    The range is something, that has to correspond to the color map - but it has nothing to do with the current min/max values of your data set in specific area. But even if you want to have it this way calculating it in QwtRasterData::value is completely the wrong place.

    But your main problem is, that you insist on not trying to understand what you are doing. With this attitude you can't be surprised, that nobody answers to your postings anymore.

    Uwe

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

    Default Re: how to make min and max values of spectrogram dynamical?

    I know that the range corresponds to the colormap. This is exactly the reason why I want it to be dynamical. Otherwise, I have to determine the possible range by plotting the function in Matlab and see what is the global minimum and maximum.

    I could certainly calculate the min and max range by iterating through x1 and x2 space and determine the range in that way, but then I would have to use 2 FOR loops, which would be very time consuming. Therefore, I had the idea to calculate it within the function "value()" because there all values are calculated anyway. Unfortunately, it is not that easy, as I thought.

    @Uwe: How to learn, if nobody answers my questions? ;-)

Similar Threads

  1. How to make layout dynamical?
    By rambo83 in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2010, 15:05
  2. qwt spectrogram example
    By rambo83 in forum Qwt
    Replies: 2
    Last Post: 17th November 2009, 21:13
  3. Dynamical LineEdit and signals
    By martisho in forum Qt Programming
    Replies: 5
    Last Post: 10th November 2009, 15:39
  4. Replies: 8
    Last Post: 8th April 2009, 19:51
  5. Replies: 1
    Last Post: 25th July 2008, 08:38

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
  •  
Qt is a trademark of The Qt Company.