libkpl  5.0
A Library for Graphical Presentation of Data Sets and Functions
splineitem.h
1 /***************************************************************************
2  splineitem.h - description
3  -------------------
4  begin : Wed Feb 27 2002
5  copyright : (C) 2017 by Werner Stille
6  email : kpl@werner-stille.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef SPLINEITEM_H
19 #define SPLINEITEM_H
20 
21 #include "funitem.h"
22 
28 class Q_DECL_EXPORT SplineItem : public ScaledItem
29 {
30 public:
32  enum {
33  Type = UserType + Spline
38  };
58  SplineItem(int degree = 3, int derivOrder = 0, double xLow = 0,
59  unsigned color = 0, Symbol symbol = SolidLine, double fx = 1,
60  double fy = 1, QGraphicsItem* parent = 0, double xMin = 0,
61  double xMax = 0, double deltaX = 0, bool visible = true,
62  FillStyle fillStyle = NoBrush, double xOffset = 0,
63  double yOffset = 0, double relSize = 1);
65  SplineItem(const SplineItem& a);
73  SplineItem(const KConfigGroup* plo, unsigned color = 0,
74  Symbol symbol = SolidLine, QGraphicsItem* parent = 0);
76  virtual ~SplineItem();
78  virtual QRectF boundingRect() const;
84  int calcTable(bool logX) const;
94  int calcTable(const double* x, double* values, int n = 1, int derivOrder = 0,
95  double xLow = 0) const;
100  void copySpline(const SplineItem* a);
102  inline int degree() const { return m_degree; };
104  inline double deltaX() const { return m_deltaX; };
106  inline int derivOrder() const { return m_derivOrder; };
115  void exponent(int& expX, int& expY, double& fx, double& fy, bool logX) const;
123  void exportTable(QTextStream& stream, char separator, char format,
124  int precision) const;
137  int fit(const ArrayItem* ai, double xMin, double xMax, double* chiSquare = 0,
138  int* numKnots = 0, double smooth = 0,
139  FunItem::DataErrorStruct* err = 0, double* avgErr = 0);
155  int fit(const double* x, const double* y, const double* errors, int n,
156  double xMin, double xMax, double* chiSquare = 0, int* numKnots = 0,
157  double smooth = 0, FunItem::DataErrorStruct* err = 0,
158  double* avgErr = 0);
168  int interpolation(const double* x, const double *y, int n, double xMin,
169  double xMax);
178  void limits(double& xMin, double& xMax, double& yMin, double& yMax,
179  bool logX) const;
181  inline int numKnots() const { return m_numKnots; };
183  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
184  QWidget* widget = 0);
192  int roots(QVector<double>& zero, int derivOrder = 0,
193  double offset = 0) const;
195  void setDashOffset();
200  inline void setDegree(int degree) { m_degree = degree; };
205  inline void setDeltaX(double deltaX) { m_deltaX = deltaX; };
210  inline void setDerivOrder(int derivOrder) { m_derivOrder = derivOrder; };
215  inline void setXLow(double xLow) { m_xLow = xLow; };
220  inline void setXMax(double xMax) { m_xMax = xMax; };
225  inline void setXMin(double xMin) { m_xMin = xMin; };
227  virtual QPainterPath shape() const;
240  static int sortArrays(const double* x0, const double* y0,
241  const double* errors0, int& n,
242  FunItem::DataErrorStruct* err, double* x, double* y,
243  double* errors);
245  virtual int type() const { return Type; };
252  void writePlo(KConfigGroup* plo, char format, int precision) const;
254  inline double xLow() const { return m_xLow; };
256  inline double xMax() const { return m_xMax; };
258  inline double xMin() const { return m_xMin; };
260  double* xValues() const;
262  double* yValues() const;
263 
264 protected:
269  void paintCond(QPainter* painter) const;
270  mutable bool logXo;
271  int m_degree, m_numKnots, m_derivOrder;
272  mutable int degreeo, numKnotso, derivOrdero;
273  double m_xMin, m_xMax, m_deltaX, m_xLow;
274  mutable double xMino, xMaxo, deltaXo, xLowo;
275  mutable QVector<double> m_xValues, m_yValues, t, c;
276 };
277 
278 #endif
double deltaX() const
Returns argument step size.
Definition: splineitem.h:104
int numKnots() const
Returns number of knots.
Definition: splineitem.h:181
FillStyle
Fill styles.
Definition: kplitem.h:45
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)=0
Symbol
Symbol types.
Definition: kplitem.h:83
double xLow() const
Returns lower x limit for spline integral.
Definition: splineitem.h:254
void setXMax(double xMax)
Sets maximum argument value.
Definition: splineitem.h:220
static bool limits(double &xMin, double &xMax, const double *values, int n)
Calculates minimum and maximum values of an array.
double xMax() const
Returns maximum argument value.
Definition: splineitem.h:256
void setXMin(double xMin)
Sets minimum argument value.
Definition: splineitem.h:225
int degree() const
Returns degree of spline.
Definition: splineitem.h:102
static void exponent(double a, int &iExp, double &f)
Calculates normalization factor.
void setDegree(int degree)
Sets degree of spline.
Definition: splineitem.h:200
void setDerivOrder(int derivOrder)
Sets order of derivative.
Definition: splineitem.h:210
int derivOrder() const
Returns order of derivative.
Definition: splineitem.h:106
Data error structure.
Definition: funitem.h:52
virtual QRectF boundingRect() const =0
Spline item class.
Definition: splineitem.h:28
virtual QPainterPath shape() const
void writePlo(KConfigGroup *plo, bool visible) const
Writes into plot file.
Scaled item class.
Definition: scaleditem.h:24
double xMin() const
Returns minimum argument value.
Definition: splineitem.h:258
virtual int type() const
Returns specific QGraphicsItem type number.
Definition: splineitem.h:245
void setXLow(double xLow)
Sets lower x limit for spline integral.
Definition: splineitem.h:215
void setDeltaX(double deltaX)
Sets argument step size.
Definition: splineitem.h:205
Array item class.
Definition: arrayitem.h:36