1
/***************************************************************************
4
--------------------------------------------------------------------
5
Copyright : (C) 2006 by Ion Vasilief
6
Email (use @ for *) : ion_vasilief*yahoo.fr
7
Description : SciDAVis's Spectrogram Class
8
***************************************************************************/
10
/***************************************************************************
12
* This program is free software; you can redistribute it and/or modify *
13
* it under the terms of the GNU General Public License as published by *
14
* the Free Software Foundation; either version 2 of the License, or *
15
* (at your option) any later version. *
17
* This program is distributed in the hope that it will be useful, *
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20
* GNU General Public License for more details. *
22
* You should have received a copy of the GNU General Public License *
23
* along with this program; if not, write to the Free Software *
24
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
25
* Boston, MA 02110-1301 USA *
27
***************************************************************************/
33
#include <qwt_raster_data.h>
35
#include <qwt_plot_spectrogram.h>
36
#include <qwt_color_map.h>
40
class Spectrogram: public QwtPlotSpectrogram
44
Spectrogram(Matrix *m);
46
enum ColorMapPolicy{GrayScale, Default, Custom};
49
Matrix * matrix(){return d_matrix;};
51
int levels(){return (int)contourLevels().size() + 1;};
52
void setLevelsNumber(int levels);
55
int colorScaleAxis(){return color_axis;};
56
void showColorScale(int axis, bool on = true);
59
void setColorBarWidth(int width);
62
void setDefaultColorMap();
63
static QwtLinearColorMap defaultColorMap();
65
void setCustomColorMap(const QwtLinearColorMap& map);
66
void updateData(Matrix *m);
68
//! Used when saving a project file
69
QString saveToString();
71
ColorMapPolicy colorMapPolicy(){return color_map_policy;};
74
//! Pointer to the source data matrix
77
//! Axis used to display the color scale
81
ColorMapPolicy color_map_policy;
83
QwtLinearColorMap color_map;
87
class MatrixData: public QwtRasterData
90
MatrixData(Matrix *m):
91
QwtRasterData(m->boundingRect()),
94
n_rows = d_matrix->numRows();
95
n_cols = d_matrix->numCols();
97
d_m = new double* [n_rows];
98
for ( int l = 0; l < n_rows; ++l)
99
d_m[l] = new double [n_cols];
101
for (int i = 0; i < n_rows; i++)
102
for (int j = 0; j < n_cols; j++)
103
d_m[i][j] = d_matrix->cell(i, j);
105
m->range(&min_z, &max_z);
107
x_start = d_matrix->xStart();
108
dx = (d_matrix->xEnd() - x_start)/(double)n_cols;
110
y_start = d_matrix->yStart();
111
dy = (d_matrix->yEnd() - y_start)/(double)n_rows;
116
for (int i = 0; i < n_rows; i++)
122
virtual QwtRasterData *copy() const
124
return new MatrixData(d_matrix);
127
virtual QwtDoubleInterval range() const
129
return QwtDoubleInterval(min_z, max_z);
132
virtual QSize rasterHint (const QwtDoubleRect &) const
134
return QSize(n_cols, n_rows);
137
virtual double value(double x, double y) const;
140
//! Pointer to the source data matrix
143
//! Vector used to store in memory the data from the source matrix window
149
//! Min and max values in the source data matrix
152
//! Data resolution in x(columns) and y(rows)
155
//! X axis left value in the data matrix
158
//! Y axis bottom value in the data matrix