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
28class Q_DECL_EXPORT SplineItem : public ScaledItem
29{
30public:
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);
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;
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
264protected:
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
Array item class.
Definition: arrayitem.h:37
FillStyle
Fill styles.
Definition: kplitem.h:45
Symbol
Symbol types.
Definition: kplitem.h:83
Scaled item class.
Definition: scaleditem.h:25
Spline item class.
Definition: splineitem.h:29
SplineItem(const KConfigGroup *plo, unsigned color=0, Symbol symbol=SolidLine, QGraphicsItem *parent=0)
Constructor.
double * yValues() const
Returns pointer to y function value array.
double xMax() const
Returns maximum argument value.
Definition: splineitem.h:256
int degree() const
Returns degree of spline.
Definition: splineitem.h:102
double * xValues() const
Returns pointer to x function value array.
int numKnots() const
Returns number of knots.
Definition: splineitem.h:181
int fit(const ArrayItem *ai, double xMin, double xMax, double *chiSquare=0, int *numKnots=0, double smooth=0, FunItem::DataErrorStruct *err=0, double *avgErr=0)
Performs smoothing spline fit.
void copySpline(const SplineItem *a)
Copies spline data.
void setXMax(double xMax)
Sets maximum argument value.
Definition: splineitem.h:220
virtual QPainterPath shape() const
Returns the shape of the plot item.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Paints item.
int interpolation(const double *x, const double *y, int n, double xMin, double xMax)
Performs interpolating (non-smoothing) spline fit.
double xLow() const
Returns lower x limit for spline integral.
Definition: splineitem.h:254
double deltaX() const
Returns argument step size.
Definition: splineitem.h:104
double xMin() const
Returns minimum argument value.
Definition: splineitem.h:258
virtual QRectF boundingRect() const
Calculates bounding rectangle.
static int sortArrays(const double *x0, const double *y0, const double *errors0, int &n, FunItem::DataErrorStruct *err, double *x, double *y, double *errors)
Sorts arrays and calculates error column.
void setXMin(double xMin)
Sets minimum argument value.
Definition: splineitem.h:225
SplineItem(const SplineItem &a)
Copy constructor.
virtual ~SplineItem()
Destructor.
void exportTable(QTextStream &stream, char separator, char format, int precision) const
Exports spline value table to file.
void setDerivOrder(int derivOrder)
Sets order of derivative.
Definition: splineitem.h:210
void writePlo(KConfigGroup *plo, char format, int precision) const
Writes into plot file.
int fit(const double *x, const double *y, const double *errors, int n, double xMin, double xMax, double *chiSquare=0, int *numKnots=0, double smooth=0, FunItem::DataErrorStruct *err=0, double *avgErr=0)
Performs smoothing spline fit.
void exponent(int &expX, int &expY, double &fx, double &fy, bool logX) const
Calculates normalization factors.
void paintCond(QPainter *painter) const
Paints or calculates bounding area.
int derivOrder() const
Returns order of derivative.
Definition: splineitem.h:106
void setDegree(int degree)
Sets degree of spline.
Definition: splineitem.h:200
void setDashOffset()
Sets offset for dashed lines.
void setDeltaX(double deltaX)
Sets argument step size.
Definition: splineitem.h:205
int roots(QVector< double > &zero, int derivOrder=0, double offset=0) const
Finds roots of a cubic spline or its derivatives.
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
int calcTable(const double *x, double *values, int n=1, int derivOrder=0, double xLow=0) const
Calculates spline value table.
SplineItem(int degree=3, int derivOrder=0, double xLow=0, 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.
int calcTable(bool logX) const
Calculates spline value table.
void limits(double &xMin, double &xMax, double &yMin, double &yMax, bool logX) const
Calculates minimum and maximum values.
Data error structure.
Definition: funitem.h:52