Radio Control  Control Software and GUI for the Panoradio SDR, by DC9ST 2016
rasterdata.h
1 #ifndef RASTERDATA_H
2 #define RASTERDATA_H
3 
4 #include <iostream>
5 #include "fstream"
6 
7 using namespace std;
8 
9 static int pixel_cntr_x;
10 static int pixel_cntr_y;
11 
12 
16 class RasterData: public QwtRasterData
17 {
18  double **data_array_;
19 
20  int data_array_xsize_; // size of the data array to be displayed (fixed for one instance)
21  int data_array_ysize_;
22 
23  double data_array_min_; // minimum and maximum data value in the data array
24  double data_array_max_;
25 
26  double xaxis_min_; // upper and lower value for x and y axis (axis scale, not pixels)
27  double yaxis_min_;
28  double xaxis_max_;
29  double yaxis_max_;
30 
31  double axis2index_x_; // number of points on axis for one data point(one array index)
32  double axis2index_y_;
33 
34  double background_value_; // value, that corresponds to the plot background and therefore its color
35 
36 
37 public:
41  RasterData(int data_array_xsize, int data_array_ysize): QwtRasterData()
42  {
43  // set data range and plot axis
44  set_data_range(0, 1);
45  set_axis(0, 0, 10, 10);
46 
47  // allocate array, that contains data to be displayed
48  data_array_xsize_ = data_array_xsize; // size is fixed for one instance!
49  data_array_ysize_ = data_array_ysize;
50 
51  background_value_ = -200; // set a default value for the background
52 
53  data_array_ = NULL;
54  }
55 
56 
57  ~RasterData() {
58  }
59 
60 
61  virtual QwtRasterData *copy() const
62  {
63  RasterData *clone = new RasterData(data_array_xsize_, data_array_ysize_);
64  clone -> set_data_range(data_array_min_, data_array_max_);
65  clone -> set_axis(xaxis_min_, yaxis_min_, xaxis_max_, yaxis_max_);
66  clone -> set_data(data_array_);
67  clone -> set_background_value(background_value_);
68 
69  return clone;
70  }
71 
74  virtual QwtDoubleInterval range() const
75  {
76  return QwtDoubleInterval(data_array_min_, data_array_max_);
77  }
78 
81  virtual double value(double x, double y) const
82  {
83  int x_idx = (int) ( ((x - xaxis_min_) / axis2index_x_ ) + 0.5 );
84  int y_idx = (int) ( (y - yaxis_min_) / axis2index_y_ );
85 
86  double datum = 0;
87 
88  if (x_idx < data_array_xsize_) // this "if" is required. beacuse the Spectrogram in Qwt has some bug: after changing the boundaries "x" goes beyond the boundingRect !?
89  datum = data_array_[y_idx][x_idx]; // x and y exchanged to pivot the plot
90  else
91  datum = background_value_;
92 
93  if ((y - yaxis_min_) <= 1e-6)
94  pixel_cntr_x++;
95 
96  if ((x - xaxis_min_) <= 1e-6)
97  pixel_cntr_y++;
98 
99  return datum;
100  }
101 
102 
103  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
104  // Additional methods
105  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
106 
110  void set_data_range(double data_array_min, double data_array_max) {
111  data_array_min_ = data_array_min;
112  data_array_max_ = data_array_max;
113  }
114 
115 
117  void set_axis(double xaxis_min, double yaxis_min, double xaxis_max, double yaxis_max) {
118  if ((xaxis_min < 0) || (xaxis_max < 0)) cerr << "rasterdata.h: negative Plot Scale does not work! (xaxis_min=" <<xaxis_min << ",xaxis_max= " << xaxis_max << ")" << endl;
119 
120  xaxis_min_ = xaxis_min;
121  yaxis_min_ = yaxis_min;
122  xaxis_max_ = xaxis_max;
123  yaxis_max_ = yaxis_max;
124 
125  setBoundingRect(QwtDoubleRect(xaxis_min_, yaxis_min_, xaxis_max_, yaxis_max_));
126 
127  axis2index_x_ = (xaxis_max_ - xaxis_min_) / (data_array_xsize_-1);
128  axis2index_y_ = (yaxis_max_ - yaxis_min_) / (data_array_ysize_ -1);
129  }
130 
131 
134  void set_data(double **array) {
135  data_array_ = array;
136  }
137 
140  pixel_cntr_x = 0;
141  pixel_cntr_y = 0;
142  }
143 
145  int get_pixels_x() {
146  if (pixel_cntr_x == 0) cerr << "rasterdata.h: ATTENTION: x Pixel counter does not seem to work properly" << endl << endl;
147  return pixel_cntr_x;
148  }
149 
151  int get_pixels_y() {
152  if (pixel_cntr_y == 0) cerr << "rasterdata.h: ATTENTION: y Pixel counter does not seem to work properly" << endl << endl;
153  return pixel_cntr_y;
154  }
155 
157  void set_background_value(double background_value) {background_value_ = background_value;}
158 
160  void read_stuff() {
161  cerr << " #################################" << endl << "rasterdata.h: auslesen_fuck(), Objektadresse: " << this << endl;
162  cerr << "xaxis_max_ " << xaxis_max_ << ", Inhalt : "<< xaxis_max_ << endl;
163  cerr << "xaxis_min_ " << xaxis_min_ <<", Inhalt : "<< xaxis_min_ << endl;
164  cerr << "data_array_xsize_ " << data_array_xsize_ << endl;
165  cerr << "axis2index_x_ " << axis2index_x_ <<", Inhalt : "<< axis2index_x_ << endl;
166  cerr << "data_array_ "<< data_array_ << " &= "<<&data_array_<< endl;
167  cerr << "Adresse der Klasse " << this << endl;
168  cerr << "##################################" << endl << endl;
169  }
170 
171 
172 
173 
174 };
175 
176 #endif // RASTERDATA_H
virtual double value(double x, double y) const
implemented method of abstract QwtRasterData,
Definition: rasterdata.h:81
void read_stuff()
function for debugging, reads class members
Definition: rasterdata.h:160
int get_pixels_y()
reads pixel counter (y) , required to check for the plot size (y) in pixels
Definition: rasterdata.h:151
virtual QwtDoubleInterval range() const
implemented method of abstract QwtRasterData, reads min and max data value
Definition: rasterdata.h:74
void reset_pixel_counter()
resets pixel counter, required to check for the plot size in pixels
Definition: rasterdata.h:139
Implementation of the abstract QwtRasterData Class,.
Definition: rasterdata.h:16
RasterData(int data_array_xsize, int data_array_ysize)
constructor: only sets array size; background value, axis and data range are set to default values an...
Definition: rasterdata.h:41
int get_pixels_x()
reads pixel counter (x) , required to check for the plot size (x) in pixels
Definition: rasterdata.h:145
void set_data(double **array)
sets data array to be displayed @**array pointer to 2d array, call by reference!
Definition: rasterdata.h:134
void set_background_value(double background_value)
sets value for background areas, required to fill rightmost area (bug workaround) ...
Definition: rasterdata.h:157
void set_axis(double xaxis_min, double yaxis_min, double xaxis_max, double yaxis_max)
sets min and max axis values for the painting area (BoundingRect) in axis scale coordinates (not pixe...
Definition: rasterdata.h:117
void set_data_range(double data_array_min, double data_array_max)
sets min and max occuring value in data array
Definition: rasterdata.h:110