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