libkpl  5.0
A Library for Graphical Presentation of Data Sets and Functions
funitem.h
1 /***************************************************************************
2  funitem.h - description
3  -------------------
4 
5  This file is a part of kpl - a program for graphical presentation of
6  data sets and functions.
7 
8  begin : Sun Aug 29 1999
9  copyright : (C) 2017 by Werner Stille
10  email : kpl@werner-stille.de
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #ifndef FUNITEM_H
23 #define FUNITEM_H
24 
25 #include <QVector>
26 #include <QUrl>
27 #include "scaleditem.h"
28 
29 class QLibrary;
30 class QTextStream;
31 class ArrayItem;
32 class LMFit;
33 
39 class Q_DECL_EXPORT FunItem : public ScaledItem
40 {
41 public:
43  static const int NumParMax = 20;
45  enum {
46  Type = UserType + Function
48  };
52  struct DataErrorStruct {
58  ColX,
59  ColY
60  };
62  DataErrorStruct() : errModArg(ColY) {};
67  bool fitErrCol;
71  double parErrMod[NumParMax];
73  QString errModName;
75  QString errModPath;
76  };
83  FunItem(const FunItem& a);
92  FunItem(const KConfigGroup* plo, const QUrl& urlPlo, unsigned color = 0,
93  Symbol symbol = SolidLine, QGraphicsItem* parent = 0);
112  FunItem(const QUrl& url, const QString& name, unsigned color = 0,
113  Symbol symbol = SolidLine, double fx = 1, double fy = 1,
114  QGraphicsItem* parent = 0, double xMin = 0, double xMax = 0,
115  double deltaX = 0, bool visible = true,
116  FillStyle fillStyle = NoBrush, double xOffset = 0,
117  double yOffset = 0, double relSize = 1);
119  virtual ~FunItem();
121  virtual QRectF boundingRect() const;
130  static void calcTable(const double* x, double* values,
131  double (*func)(double, const double*),
132  const double* par, int n);
137  int calcTable() const;
143  int calcTable(bool logX) const;
145  inline double deltaT() const { return m_deltaT; };
152  static bool errorStructChanged(const DataErrorStruct& e1,
153  const DataErrorStruct& e2);
162  void exponent(int& expX, int& expY, double& fx, double& fy, bool logX) const;
170  void exportTable(QTextStream& stream, char separator, char format,
171  int precision) const;
192  static int fit(const QList<const ArrayItem*>* aList, QList<FunItem*>* fList,
193  const bool* bFit, double* par,
194  QVector<double>* resVector = 0, QVector<double>* sigma = 0,
195  FunItem::DataErrorStruct* err = 0, bool nonLin = true,
196  double tol = 1e-14, int itMax = 100, LMFit* lm = 0,
197  double* chiSquare = 0, double* corr = 0, double* parErr = 0,
198  double* avgErr = 0, QObject* parent = 0);
200  double (*funcY)(double, const double*);
202  inline const QLibrary* libY() const { return m_libY; };
211  void limits(double& xMin, double& xMax, double& yMin, double& yMax,
212  bool logX) const;
214  inline QString nameY() const { return m_nameY; };
216  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
217  QWidget* widget = 0);
224  static bool parChanged(const double* p1, const double* p2);
232  static QString parToString(const double* par, char format, int precision);
234  inline double* parY() { return m_parY; };
241  inline void setDeltaT(double deltaT) { m_deltaT = deltaT; };
248  bool setFuncY(const QUrl& url, const QString& name);
255  virtual void setPar(int i, double value, bool yFunc = true);
260  inline void setTMax(double xMax) { m_tMax = xMax; };
265  inline void setTMin(double xMin) { m_tMin = xMin; };
267  virtual QPainterPath shape() const;
273  static void stringToPar(const QString& s, double* par);
275  inline double tMax() const { return m_tMax; };
277  inline double tMin() const { return m_tMin; };
279  const double* tValues() const;
281  virtual int type() const { return Type; };
283  inline const QUrl& urlY() const { return m_urlY; };
292  void writePlo(KConfigGroup* plo, const QUrl& urlPlo, bool absolute,
293  char format, int precision) const;
295  double* yValues() const;
296 
297 protected:
299  void init();
304  void paintCond(QPainter* painter) const;
306  void unload();
307  mutable bool logXo;
308  double m_tMin, m_tMax, m_deltaT;
309  mutable double tMino, tMaxo, deltaTo;
310  mutable double (*funcYo)(double, const double*);
311  double m_parY[NumParMax];
312  mutable double parYo[NumParMax];
313  mutable QVector<double> m_tValues, m_yValues;
314  QString m_nameY;
315  QUrl m_urlY;
316  QLibrary* m_libY;
317 };
318 
319 #endif
Array item class.
Definition: arrayitem.h:37
Function item class.
Definition: funitem.h:40
void limits(double &xMin, double &xMax, double &yMin, double &yMax, bool logX) const
Calculates minimum and maximum values.
virtual QPainterPath shape() const
Returns the shape of the plot item.
void writePlo(KConfigGroup *plo, const QUrl &urlPlo, bool absolute, char format, int precision) const
Writes into plot file.
void init()
Performs initialization.
static QString parToString(const double *par, char format, int precision)
Converts parameter array to string.
int calcTable() const
Calculates function value table.
FunItem(const FunItem &a)
Copy constructor.
double * parY()
Returns y function parameter array pointer.
Definition: funitem.h:234
int calcTable(bool logX) const
Calculates function value table.
static int fit(const QList< const ArrayItem * > *aList, QList< FunItem * > *fList, const bool *bFit, double *par, QVector< double > *resVector=0, QVector< double > *sigma=0, FunItem::DataErrorStruct *err=0, bool nonLin=true, double tol=1e-14, int itMax=100, LMFit *lm=0, double *chiSquare=0, double *corr=0, double *parErr=0, double *avgErr=0, QObject *parent=0)
Performs fit of parameters of a set of functions to a set of arrays.
void exportTable(QTextStream &stream, char separator, char format, int precision) const
Exports function value table to file.
virtual QRectF boundingRect() const
Calculates bounding rectangle.
static void stringToPar(const QString &s, double *par)
Converts string to parameter array values.
double tMax() const
Returns maximum argument value.
Definition: funitem.h:275
double tMin() const
Returns minimum argument value.
Definition: funitem.h:277
void unload()
Unloads y function library.
const QLibrary * libY() const
Returns pointer to library for y function.
Definition: funitem.h:202
const double * tValues() const
Returns pointer to argument value array.
QString nameY() const
Returns y function name.
Definition: funitem.h:214
FunItem()
Constructor.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Paints item.
static bool errorStructChanged(const DataErrorStruct &e1, const DataErrorStruct &e2)
Checks data error structures for differences.
const QUrl & urlY() const
Returns URL of y function library.
Definition: funitem.h:283
double * yValues() const
Returns pointer to y function value array.
void setTMax(double xMax)
Sets maximum argument value.
Definition: funitem.h:260
virtual void setPar(int i, double value, bool yFunc=true)
Sets parameter.
virtual int type() const
Returns specific QGraphicsItem type number.
Definition: funitem.h:281
void setDeltaT(double deltaT)
Sets argument step size.
Definition: funitem.h:241
void setTMin(double xMin)
Sets minimum argument value.
Definition: funitem.h:265
FunItem(const QUrl &url, const QString &name, unsigned color=0, Symbol symbol=SolidLine, double fx=1, double fy=1, QGraphicsItem *parent=0, double xMin=0, double xMax=0, double deltaX=0, bool visible=true, FillStyle fillStyle=NoBrush, double xOffset=0, double yOffset=0, double relSize=1)
Constructor.
void setDashOffset()
Sets offset for dashed lines.
bool setFuncY(const QUrl &url, const QString &name)
Resolves y function address.
static bool parChanged(const double *p1, const double *p2)
Checks parameter arrays for differences.
double deltaT() const
Returns argument step size.
Definition: funitem.h:145
FunItem(const KConfigGroup *plo, const QUrl &urlPlo, unsigned color=0, Symbol symbol=SolidLine, QGraphicsItem *parent=0)
Constructor.
virtual ~FunItem()
Destructor.
static void calcTable(const double *x, double *values, double(*func)(double, const double *), const double *par, int n)
Calculates function value table.
void paintCond(QPainter *painter) const
Paints or calculates bounding area.
void exponent(int &expX, int &expY, double &fx, double &fy, bool logX) const
Calculates normalization factors.
FillStyle
Fill styles.
Definition: kplitem.h:45
Symbol
Symbol types.
Definition: kplitem.h:83
Parameter fit class.
Definition: lmfit.h:42
Scaled item class.
Definition: scaleditem.h:25
Data error structure.
Definition: funitem.h:52
DataErrorStruct()
Initializes structure.
Definition: funitem.h:62
QString errModPath
Path of library containing error model function.
Definition: funitem.h:75
bool fitErrCol
True for using error column of array item instead of error model function.
Definition: funitem.h:62
ErrorModelArgument errModArg
Error model function argument.
Definition: funitem.h:69
ErrorModelArgument
Error model function argument.
Definition: funitem.h:57
@ ColX
x column.
Definition: funitem.h:58
QString errModName
Name of error model function.
Definition: funitem.h:73