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

« back to all changes in this revision

Viewing changes to scidavis/src/Filter.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                 : Filter.h
 
3
    Project              : SciDAVis
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2007 by Ion Vasilief
 
6
    Email (use @ for *)  : ion_vasilief*yahoo.fr
 
7
    Description          : Abstract base class for data analysis operations
 
8
 
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
13
 *  This program is free software; you can redistribute it and/or modify   *
 
14
 *  it under the terms of the GNU General Public License as published by   *
 
15
 *  the Free Software Foundation; either version 2 of the License, or      *
 
16
 *  (at your option) any later version.                                    *
 
17
 *                                                                         *
 
18
 *  This program is distributed in the hope that it will be useful,        *
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
21
 *  GNU General Public License for more details.                           *
 
22
 *                                                                         *
 
23
 *   You should have received a copy of the GNU General Public License     *
 
24
 *   along with this program; if not, write to the Free Software           *
 
25
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 
26
 *   Boston, MA  02110-1301  USA                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
29
#ifndef FILTER_H
 
30
#define FILTER_H
 
31
 
 
32
#include <QObject>
 
33
 
 
34
#include "ApplicationWindow.h"
 
35
 
 
36
class QwtPlotCurve;
 
37
class Graph;
 
38
class Table;
 
39
 
 
40
//! Abstract base class for data analysis operations
 
41
class Filter : public QObject
 
42
{
 
43
        Q_OBJECT
 
44
 
 
45
        public:
 
46
        Filter(ApplicationWindow *parent, Table *t = 0, const char * name = 0);
 
47
                Filter(ApplicationWindow *parent, Graph *g = 0, const char * name = 0);
 
48
                ~Filter();
 
49
 
 
50
                //! Actually does the job. Should be reimplemented in derived classes.
 
51
                virtual bool run();
 
52
 
 
53
        virtual void setDataCurve(int curve, double start, double end);
 
54
                bool setDataFromCurve(const QString& curveTitle, Graph *g = 0);
 
55
                bool setDataFromCurve(const QString& curveTitle, double from, double to, Graph *g = 0);
 
56
 
 
57
                //! Changes the data range if the source curve was already assigned. Provided for convenience.
 
58
                void setInterval(double from, double to);
 
59
 
 
60
                //! Sets the tolerance used by the GSL routines
 
61
                void setTolerance(double eps){d_tolerance = eps;};
 
62
 
 
63
                //! Sets the color of the output fit curve.
 
64
                void setColor(int colorId){d_curveColorIndex = colorId;};
 
65
 
 
66
        //! Sets the color of the output fit curve. Provided for convenience. To be used in scripts only!
 
67
        void setColor(const QString& colorName);
 
68
 
 
69
        //! Sets the number of points in the output curve
 
70
        void setOutputPoints(int points){d_points = points;};
 
71
 
 
72
        //! Sets the precision used for the output
 
73
                void setOutputPrecision(int digits){d_prec = digits;};
 
74
 
 
75
                //! Sets the maximum number of iterations to be performed during an iterative session
 
76
                void setMaximumIterations(int iter){d_max_iterations = iter;};
 
77
 
 
78
                //! Adds a new legend to the plot. Calls virtual legendInfo()
 
79
                virtual void showLegend();
 
80
 
 
81
        //! Output string added to the plot as a new legend
 
82
                virtual QString legendInfo(){return QString();};
 
83
 
 
84
                //! Returns the size of the fitted data set
 
85
                int dataSize(){return d_n;};
 
86
 
 
87
        bool error(){return d_init_err;};
 
88
 
 
89
        protected:
 
90
        void init();
 
91
 
 
92
        //! Sets x and y to the curve points between start and end. Memory will be allocated with new double[].
 
93
            //! Returns the number of points within range == size of x and y arrays.
 
94
            virtual int curveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
 
95
        //! Same as curveData, but sorts the points by their x value.
 
96
        virtual int sortedCurveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
 
97
 
 
98
        //! Adds the result curve to the target output plot window. Creates a hidden table and frees the input data from memory.
 
99
        QwtPlotCurve* addResultCurve(double *x, double *y);
 
100
 
 
101
        //! Performs checks and returns the index of the source data curve if OK, -1 otherwise
 
102
        int curveIndex(const QString& curveTitle, Graph *g);
 
103
 
 
104
        //! Output string added to the log pannel of the application
 
105
        virtual QString logInfo(){return QString();};
 
106
 
 
107
                //! Performs the data analysis and takes care of the output
 
108
                virtual void output();
 
109
 
 
110
                //! Calculates the data for the output curve and store it in the X an Y vectors
 
111
                virtual void calculateOutputData(double *X, double *Y) { Q_UNUSED(X) Q_UNUSED(Y) };
 
112
 
 
113
                //! The graph where the result curve should be displayed
 
114
                Graph *d_graph;
 
115
 
 
116
        //! A table source of data
 
117
                Table *d_table;
 
118
 
 
119
                //! Size of the data arrays
 
120
                int d_n;
 
121
 
 
122
                //! x data set to be analysed
 
123
                double *d_x;
 
124
 
 
125
                //! y data set to be analysed
 
126
                double *d_y;
 
127
 
 
128
                //! GSL Tolerance, if ever needed...
 
129
                double d_tolerance;
 
130
 
 
131
                //! Number of result points to de calculated and displayed in the output curve
 
132
                int d_points;
 
133
 
 
134
                //! Color index of the result curve
 
135
                int d_curveColorIndex;
 
136
 
 
137
                //! Maximum number of iterations per fit
 
138
                int d_max_iterations;
 
139
 
 
140
                //! The curve to be analysed
 
141
                QwtPlotCurve *d_curve;
 
142
 
 
143
                //! Precision (number of significant digits) used for the results output
 
144
                int d_prec;
 
145
 
 
146
                //! Error flag telling if something went wrong during the initialization phase.
 
147
                bool d_init_err;
 
148
 
 
149
        //! Data interval
 
150
        double d_from, d_to;
 
151
 
 
152
        //! Specifies if the filter needs sorted data as input
 
153
        bool d_sort_data;
 
154
 
 
155
        //! Minimum number of data points necessary to perform the operation
 
156
        int d_min_points;
 
157
 
 
158
        //! String explaining the operation in the comment of the result table and in the project explorer
 
159
        QString d_explanation;
 
160
};
 
161
 
 
162
#endif