Spectrogram.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : Spectrogram.h
00003     Project              : QtiPlot
00004 --------------------------------------------------------------------
00005     Copyright            : (C) 2006 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : QtiPlot's Spectrogram Class
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *  This program is free software; you can redistribute it and/or modify   *
00013  *  it under the terms of the GNU General Public License as published by   *
00014  *  the Free Software Foundation; either version 2 of the License, or      *
00015  *  (at your option) any later version.                                    *
00016  *                                                                         *
00017  *  This program is distributed in the hope that it will be useful,        *
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00020  *  GNU General Public License for more details.                           *
00021  *                                                                         *
00022  *   You should have received a copy of the GNU General Public License     *
00023  *   along with this program; if not, write to the Free Software           *
00024  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00025  *   Boston, MA  02110-1301  USA                                           *
00026  *                                                                         *
00027  ***************************************************************************/
00028 
00029 #ifndef SPECTROGRAM_H
00030 #define SPECTROGRAM_H
00031 
00032 #include "Matrix.h"
00033 #include <qwt_raster_data.h>
00034 #include <qwt_plot.h>
00035 #include <qwt_plot_spectrogram.h>
00036 #include <qwt_color_map.h>
00037 
00038 class MatrixData;
00039 
00040 class Spectrogram: public QwtPlotSpectrogram
00041 {
00042 public:
00043     Spectrogram();
00044     Spectrogram(Matrix *m);
00045 
00046     enum ColorMapPolicy{GrayScale, Default, Custom};
00047 
00048     Spectrogram* copy();
00049     Matrix * matrix(){return d_matrix;};
00050 
00051     int levels(){return (int)contourLevels().size() + 1;};
00052     void setLevelsNumber(int levels);
00053 
00054     bool hasColorScale();
00055     int colorScaleAxis(){return color_axis;};
00056     void showColorScale(int axis, bool on = true);
00057 
00058     int colorBarWidth();
00059     void setColorBarWidth(int width);
00060 
00061     void setGrayScale();
00062     void setDefaultColorMap();
00063     static QwtLinearColorMap defaultColorMap();
00064 
00065     void setCustomColorMap(const QwtLinearColorMap& map);
00066     void updateData(Matrix *m);
00067 
00069     QString saveToString();
00070 
00071     ColorMapPolicy colorMapPolicy(){return color_map_policy;};
00072 
00073 protected:
00075     Matrix *d_matrix;
00076 
00078     int color_axis;
00079 
00081     ColorMapPolicy color_map_policy;
00082 
00083     QwtLinearColorMap color_map;
00084 };
00085 
00086 
00087 class MatrixData: public QwtRasterData
00088 {
00089 public:
00090     MatrixData(Matrix *m):
00091         QwtRasterData(m->boundingRect()),
00092         d_matrix(m)
00093     {
00094     n_rows = d_matrix->numRows();
00095     n_cols = d_matrix->numCols();
00096 
00097     d_m = new double* [n_rows];
00098     for ( int l = 0; l < n_rows; ++l)
00099         d_m[l] = new double [n_cols];
00100 
00101     for (int i = 0; i < n_rows; i++)
00102          for (int j = 0; j < n_cols; j++)
00103            d_m[i][j] = d_matrix->cell(i, j);
00104 
00105     m->range(&min_z, &max_z);
00106 
00107     x_start = d_matrix->xStart();
00108     dx = (d_matrix->xEnd() - x_start)/(double)n_cols;
00109 
00110     y_start = d_matrix->yStart();
00111     dy = (d_matrix->yEnd() - y_start)/(double)n_rows;
00112     }
00113 
00114     ~MatrixData()
00115     {
00116     for (int i = 0; i < n_rows; i++)
00117         delete [] d_m[i];
00118 
00119     delete [] d_m;
00120     };
00121 
00122     virtual QwtRasterData *copy() const
00123     {
00124         return new MatrixData(d_matrix);
00125     }
00126 
00127     virtual QwtDoubleInterval range() const
00128     {
00129         return QwtDoubleInterval(min_z, max_z);
00130     }
00131 
00132     virtual QSize rasterHint (const QwtDoubleRect &) const
00133     {
00134         return QSize(n_cols, n_rows);
00135     }
00136 
00137     virtual double value(double x, double y) const;
00138 
00139 private:
00141     Matrix *d_matrix;
00142 
00144     double** d_m;
00145 
00147     int n_rows, n_cols;
00148 
00150     double min_z, max_z;
00151 
00153     double dx, dy;
00154 
00156     double x_start;
00157 
00159     double y_start;
00160 };
00161 
00162 #endif

Generated on Mon Oct 15 06:11:42 2007 for QtiPlot by  doxygen 1.5.3