QtiPlot  0.9.8.2
Filter.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : Filter.h
3  Project : QtiPlot
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 MultiLayer;
37 class QwtPlotCurve;
38 class Graph;
39 class Table;
40 class Matrix;
41 
43 class Filter : public QObject
44 {
45  Q_OBJECT
46 
47  public:
48  Filter(ApplicationWindow *parent, Table *t = 0, const QString& name = QString());
49  Filter(ApplicationWindow *parent, Graph *g = 0, const QString& name = QString());
50  Filter(ApplicationWindow *parent, Matrix *m, const QString& name = QString());
51  Filter(ApplicationWindow *parent, QwtPlotCurve *c);
52  ~Filter();
53 
55  virtual bool run();
56 
57  virtual void setDataCurve(QwtPlotCurve *curve, double start, double end);
58  bool setDataFromCurve(QwtPlotCurve *c);
59  bool setDataFromCurve(QwtPlotCurve *c, double from, double to);
60  bool setDataFromCurve(const QString& curveTitle, Graph *g = 0);
61  bool setDataFromCurve(const QString& curveTitle, double from, double to, Graph *g = 0);
62 
63  virtual bool setDataFromTable(Table *, const QString&, const QString&, int = 1, int = -1, bool = false);
64 
66  void setInterval(double from, double to);
67 
69  void setTolerance(double eps){d_tolerance = eps;};
70 
72  void setColor(int colorId);
74  void setColor(const QColor& color){d_curveColor = color;};
76  void setColor(const QString& colorName);
77 
79  void setOutputPoints(int points){d_points = points;};
80 
82  void setOutputPrecision(int digits){d_prec = digits;};
83 
85  void setMaximumIterations(int iter){d_max_iterations = iter;};
86 
87  void setSortData(bool on = true){d_sort_data = on;}
88 
90  virtual void showLegend();
91 
93  virtual QString legendInfo(){return QString();};
94 
96  int dataSize(){return d_n;};
98  double* x(){return d_x;};
100  double* y(){return d_y;};
106  QwtPlotCurve *resultCurve(){return d_result_curve;};
107 
108  bool error(){return d_init_err;};
109  void setError(bool on = true){d_init_err = on;};
110 
111  virtual void enableGraphicsDisplay(bool on = true, Graph *g = 0);
112 
113  void setUpdateOutputGraph(bool update = true) {d_update_output_graph = update;};
114 
115  protected:
116  void init();
117  void memoryErrorMessage();
119  virtual void freeMemory();
120 
123  virtual int curveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
125  virtual int sortedCurveData(QwtPlotCurve *c, double start, double end, double **x, double **y);
126 
127  int curveRange(QwtPlotCurve *c, double start, double end, int *iStart, int *iEnd);
128 
130  QwtPlotCurve* addResultCurve(double *x, double *y);
131 
133  int curveIndex(const QString& curveTitle, Graph *g);
134 
136  virtual QString logInfo(){return QString();};
137 
139  virtual void output();
140 
142  virtual void calculateOutputData(double *X, double *Y) { Q_UNUSED(X) Q_UNUSED(Y) };
143 
145 
148 
151 
154 
157 
159  int d_n;
160 
162  double *d_x;
163 
165  double *d_y;
166 
168  double d_tolerance;
169 
171  int d_points;
172 
174  QColor d_curveColor;
175 
178 
180  QwtPlotCurve *d_curve;
181 
183  QwtPlotCurve *d_result_curve;
184 
186  int d_prec;
187 
190 
192  double d_from, d_to;
193 
196 
199 
201  QString d_explanation;
202 
205 
208 
209  QString d_y_col_name;
211 };
212 
213 #endif
double * d_x
x data set to be analysed
Definition: Filter.h:162
void setColor(const QColor &color)
Sets the color of the output fit curve.
Definition: Filter.h:74
QwtPlotCurve * d_curve
The curve to be analysed.
Definition: Filter.h:180
An MDI window (MdiSubWindow) managing one or more Graph objects.
Definition: MultiLayer.h:64
bool d_init_err
Error flag telling if something went wrong during the initialization phase.
Definition: Filter.h:189
int d_prec
Precision (number of significant digits) used for the results output.
Definition: Filter.h:186
~Filter()
Definition: Filter.cpp:628
double * d_y
y data set to be analysed
Definition: Filter.h:165
Matrix * d_matrix
Definition: Filter.h:210
int d_min_points
Minimum number of data points necessary to perform the operation.
Definition: Filter.h:198
MultiLayer * createOutputGraph()
Definition: Filter.cpp:501
int dataSize()
Returns the size of the input data set.
Definition: Filter.h:96
QString d_y_col_name
Definition: Filter.h:209
A 2D-plotting widget.
Definition: Graph.h:123
void setColor(int colorId)
Obsolete: sets the color of the output fit curve.
Definition: Filter.cpp:227
Filter(ApplicationWindow *parent, Table *t=0, const QString &name=QString())
Definition: Filter.cpp:63
void setInterval(double from, double to)
Changes the data range if the source curve was already assigned. Provided for convenience.
Definition: Filter.cpp:103
int curveIndex(const QString &curveTitle, Graph *g)
Performs checks and returns the index of the source data curve if OK, -1 otherwise.
Definition: Filter.cpp:144
virtual void showLegend()
Adds a new legend to the plot. Calls virtual legendInfo()
Definition: Filter.cpp:251
virtual void calculateOutputData(double *X, double *Y)
Calculates the data for the output curve and store it in the X an Y vectors.
Definition: Filter.h:142
Abstract base class for data analysis operations.
Definition: Filter.h:43
virtual QString logInfo()
Output string added to the log pannel of the application.
Definition: Filter.h:136
double d_from
Data interval.
Definition: Filter.h:192
bool d_update_output_graph
Specifies if the filter should update the output graph.
Definition: Filter.h:207
int curveRange(QwtPlotCurve *c, double start, double end, int *iStart, int *iEnd)
Definition: Filter.cpp:403
bool error()
Definition: Filter.h:108
virtual void setDataCurve(QwtPlotCurve *curve, double start, double end)
Definition: Filter.cpp:113
bool d_sort_data
Specifies if the filter needs sorted data as input.
Definition: Filter.h:195
void setOutputPoints(int points)
Sets the number of points in the output curve.
Definition: Filter.h:79
Table * resultTable()
Returns a pointer to the table created to display the results.
Definition: Filter.h:102
virtual bool setDataFromTable(Table *, const QString &, const QString &, int=1, int=-1, bool=false)
Definition: Filter.cpp:514
Table * d_table
A table source of data.
Definition: Filter.h:153
virtual void output()
Performs the data analysis and takes care of the output.
Definition: Filter.cpp:295
double d_to
Definition: Filter.h:192
void init()
Definition: Filter.cpp:79
int d_n
Size of the data arrays.
Definition: Filter.h:159
virtual void freeMemory()
Frees the memory allocated for the X and Y data sets.
Definition: Filter.cpp:616
int d_points
Number of result points to de calculated and displayed in the output curve.
Definition: Filter.h:171
Graph * d_graph
The source graph with the curve to be analyzed.
Definition: Filter.h:147
QtiPlot&#39;s main window.
Definition: ApplicationWindow.h:133
double d_tolerance
GSL Tolerance, if ever needed...
Definition: Filter.h:168
QwtPlotCurve * d_result_curve
The resulting curve.
Definition: Filter.h:183
int d_max_iterations
Maximum number of iterations per fit.
Definition: Filter.h:177
void setUpdateOutputGraph(bool update=true)
Definition: Filter.h:113
Matrix worksheet class.
Definition: Matrix.h:57
void setSortData(bool on=true)
Definition: Filter.h:87
void memoryErrorMessage()
Definition: Filter.cpp:605
bool d_graphics_display
Specifies if the filter should display a result curve.
Definition: Filter.h:204
bool setDataFromCurve(QwtPlotCurve *c)
Definition: Filter.cpp:166
Table * d_result_table
The table displaying the results of the filtering operation (not alvays valid!)
Definition: Filter.h:156
virtual int curveData(QwtPlotCurve *c, double start, double end, double **x, double **y)
Definition: Filter.cpp:367
virtual bool run()
Actually does the job. Should be reimplemented in derived classes.
Definition: Filter.cpp:270
virtual void enableGraphicsDisplay(bool on=true, Graph *g=0)
Definition: Filter.cpp:490
void setTolerance(double eps)
Sets the tolerance used by the GSL routines.
Definition: Filter.h:69
void setOutputPrecision(int digits)
Sets the precision used for the output.
Definition: Filter.h:82
QwtPlotCurve * addResultCurve(double *x, double *y)
Adds the result curve to the target output plot window. Creates a hidden table and frees the input da...
Definition: Filter.cpp:445
Graph * d_output_graph
The graph where the result curve should be displayed.
Definition: Filter.h:150
double * x()
Returns the x values of the input data set.
Definition: Filter.h:98
double * y()
Returns the y values of the input data set.
Definition: Filter.h:100
QString d_explanation
String explaining the operation in the comment of the result table and in the project explorer...
Definition: Filter.h:201
MDI window providing a spreadsheet table with column logic.
Definition: Table.h:57
virtual int sortedCurveData(QwtPlotCurve *c, double start, double end, double **x, double **y)
Same as curveData, but sorts the points by their x value.
Definition: Filter.cpp:316
virtual QString legendInfo()
Output string added to the plot as a new legend.
Definition: Filter.h:93
void setMaximumIterations(int iter)
Sets the maximum number of iterations to be performed during an iterative session.
Definition: Filter.h:85
QColor d_curveColor
Color index of the result curve.
Definition: Filter.h:174
Graph * outputGraph()
Returns a pointer to the graph where the result curve should be displayed.
Definition: Filter.h:104
QwtPlotCurve * resultCurve()
Returns a pointer to the plot curve created to display the results.
Definition: Filter.h:106
void setError(bool on=true)
Definition: Filter.h:109