~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/Spectrogram.h

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
        File                 : Spectrogram.h
 
3
        Project              : SciDAVis
 
4
--------------------------------------------------------------------
 
5
        Copyright            : (C) 2006 by Ion Vasilief
 
6
        Email (use @ for *)  : ion_vasilief*yahoo.fr
 
7
        Description          : SciDAVis's Spectrogram Class
 
8
 ***************************************************************************/
 
9
 
 
10
/***************************************************************************
 
11
 *                                                                         *
 
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.                                    *
 
16
 *                                                                         *
 
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.                           *
 
21
 *                                                                         *
 
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                                           *
 
26
 *                                                                         *
 
27
 ***************************************************************************/
 
28
 
 
29
#ifndef SPECTROGRAM_H
 
30
#define SPECTROGRAM_H
 
31
 
 
32
#include "Matrix.h"
 
33
#include <qwt_raster_data.h>
 
34
#include <qwt_plot.h>
 
35
#include <qwt_plot_spectrogram.h>
 
36
#include <qwt_color_map.h>
 
37
 
 
38
class MatrixData;
 
39
 
 
40
class Spectrogram: public QwtPlotSpectrogram
 
41
{
 
42
public:
 
43
        Spectrogram();
 
44
    Spectrogram(Matrix *m);
 
45
 
 
46
        enum ColorMapPolicy{GrayScale, Default, Custom};
 
47
 
 
48
        Spectrogram* copy();
 
49
        Matrix * matrix(){return d_matrix;};
 
50
 
 
51
        int levels(){return (int)contourLevels().size() + 1;};
 
52
        void setLevelsNumber(int levels);
 
53
 
 
54
        bool hasColorScale();
 
55
        int colorScaleAxis(){return color_axis;};
 
56
        void showColorScale(int axis, bool on = true);
 
57
 
 
58
        int colorBarWidth();
 
59
        void setColorBarWidth(int width);
 
60
 
 
61
        void setGrayScale();
 
62
        void setDefaultColorMap();
 
63
        static QwtLinearColorMap defaultColorMap();
 
64
 
 
65
        void setCustomColorMap(const QwtLinearColorMap& map);
 
66
        void updateData(Matrix *m);
 
67
 
 
68
        //! Used when saving a project file
 
69
        QString saveToString();
 
70
 
 
71
        ColorMapPolicy colorMapPolicy(){return color_map_policy;};
 
72
 
 
73
protected:
 
74
        //! Pointer to the source data matrix
 
75
        Matrix *d_matrix;
 
76
 
 
77
        //! Axis used to display the color scale
 
78
        int color_axis;
 
79
 
 
80
        //! Flags
 
81
        ColorMapPolicy color_map_policy;
 
82
 
 
83
        QwtLinearColorMap color_map;
 
84
};
 
85
 
 
86
 
 
87
class MatrixData: public QwtRasterData
 
88
{
 
89
public:
 
90
    MatrixData(Matrix *m):
 
91
        QwtRasterData(m->boundingRect()),
 
92
                d_matrix(m)
 
93
    {
 
94
        n_rows = d_matrix->numRows();
 
95
        n_cols = d_matrix->numCols();
 
96
 
 
97
        d_m = new double* [n_rows];
 
98
        for ( int l = 0; l < n_rows; ++l)
 
99
                d_m[l] = new double [n_cols];
 
100
 
 
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);
 
104
 
 
105
        m->range(&min_z, &max_z);
 
106
 
 
107
        x_start = d_matrix->xStart();
 
108
        dx = (d_matrix->xEnd() - x_start)/(double)n_cols;
 
109
 
 
110
        y_start = d_matrix->yStart();
 
111
        dy = (d_matrix->yEnd() - y_start)/(double)n_rows;
 
112
    }
 
113
 
 
114
        ~MatrixData()
 
115
        {
 
116
        for (int i = 0; i < n_rows; i++)
 
117
                delete [] d_m[i];
 
118
 
 
119
        delete [] d_m;
 
120
        };
 
121
 
 
122
    virtual QwtRasterData *copy() const
 
123
    {
 
124
        return new MatrixData(d_matrix);
 
125
    }
 
126
 
 
127
    virtual QwtDoubleInterval range() const
 
128
    {
 
129
        return QwtDoubleInterval(min_z, max_z);
 
130
    }
 
131
 
 
132
        virtual QSize rasterHint (const QwtDoubleRect &) const
 
133
        {
 
134
                return QSize(n_cols, n_rows);
 
135
        }
 
136
 
 
137
    virtual double value(double x, double y) const;
 
138
 
 
139
private:
 
140
        //! Pointer to the source data matrix
 
141
        Matrix *d_matrix;
 
142
 
 
143
        //! Vector used to store in memory the data from the source matrix window
 
144
        double** d_m;
 
145
 
 
146
        //! Data size
 
147
        int n_rows, n_cols;
 
148
 
 
149
        //! Min and max values in the source data matrix
 
150
        double min_z, max_z;
 
151
 
 
152
        //! Data resolution in x(columns) and y(rows)
 
153
        double dx, dy;
 
154
 
 
155
        //! X axis left value in the data matrix
 
156
        double x_start;
 
157
 
 
158
        //! Y axis bottom value in the data matrix
 
159
        double y_start;
 
160
};
 
161
 
 
162
#endif