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     virtual QwtDoubleRect boundingRect() const;
00074 
00075 protected:
00077     Matrix *d_matrix;
00078 
00080     int color_axis;
00081 
00083     ColorMapPolicy color_map_policy;
00084 
00085     QwtLinearColorMap color_map;
00086 };
00087 
00088 
00089 class MatrixData: public QwtRasterData
00090 {
00091 public:
00092     MatrixData(Matrix *m):
00093         QwtRasterData(m->boundingRect()),
00094         d_matrix(m)
00095     {
00096     n_rows = d_matrix->numRows();
00097     n_cols = d_matrix->numCols();
00098 
00099     d_m = new double* [n_rows];
00100     for ( int l = 0; l < n_rows; ++l)
00101         d_m[l] = new double [n_cols];
00102 
00103     for (int i = 0; i < n_rows; i++)
00104          for (int j = 0; j < n_cols; j++)
00105            d_m[i][j] = d_matrix->cell(i, j);
00106 
00107     m->range(&min_z, &max_z);
00108 
00109     x_start = d_matrix->xStart();
00110     dx = d_matrix->dx();
00111     y_start = d_matrix->yStart();
00112     dy = d_matrix->dy();
00113     }
00114 
00115     ~MatrixData()
00116     {
00117     for (int i = 0; i < n_rows; i++)
00118         delete [] d_m[i];
00119 
00120     delete [] d_m;
00121     };
00122 
00123     virtual QwtRasterData *copy() const
00124     {
00125         return new MatrixData(d_matrix);
00126     }
00127 
00128     virtual QwtDoubleInterval range() const
00129     {
00130         return QwtDoubleInterval(min_z, max_z);
00131     }
00132 
00133     virtual QSize rasterHint (const QwtDoubleRect &) const
00134     {
00135         return QSize(n_cols, n_rows);
00136     }
00137 
00138     virtual double value(double x, double y) const;
00139 
00140 private:
00142     Matrix *d_matrix;
00143 
00145     double** d_m;
00146 
00148     int n_rows, n_cols;
00149 
00151     double min_z, max_z;
00152 
00154     double dx, dy;
00155 
00157     double x_start;
00158 
00160     double y_start;
00161 };
00162 
00163 #endif

Generated on Thu Feb 7 13:59:27 2008 for QtiPlot by  doxygen 1.5.4