JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtpevaluatedparametriccurve.h
1/*
2 Copyright (c) 2020-2022 Jan W. Krieger (<jan@jkrieger.de>)
3
4
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License (LGPL) as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License (LGPL) for more details.
15
16 You should have received a copy of the GNU Lesser General Public License (LGPL)
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21#ifndef jkqtpevaluatedparametriccurve_H
22#define jkqtpevaluatedparametriccurve_H
23
24
25#include <QString>
26#include <QPainter>
27#include <QPair>
28#include "jkqtplotter/graphs/jkqtpscatter.h"
29#include "jkqtplotter/jkqtpgraphsbasestylingmixins.h"
30#include "jkqtplotter/jkqtplotter_imexport.h"
31#include "jkqtcommon/jkqtpgeometrytools.h"
32#include "jkqtplotter/graphs/jkqtpevaluatedfunctionbase.h"
33#include <functional>
34
35
36/** \brief Base class for line plots where the data is taken from a user supplied function \f$ [x,y]=f(t) \f$
37 * The function is evaluated on a user-specified range \f$ t \in \left[t_\text{min}, t_\text{max}\right] \f$
38 * \ingroup jkqtplotter_functiongraphs
39 *
40 * This class uses the intelligent plotting algorithm for functions, implemented in JKQTPAdaptiveFunctionGraphEvaluator.
41 * It starts by sampling the function at minSamples positions. Then each function interval is bisected recursively if
42 * necessary. To do so the function is evaluated at the mid point and the slopes \f$ \alpha_{\mbox{left}} \f$
43 * and \f$ \alpha_{\mbox{right}} \f$ of the two linear segments are compared. the midpoint is added
44 * to the graph if \f[ \left|\alpha_{\mbox{right}}-\alpha_{\mbox{left}}\right|>\mbox{slopeTolerance} \f]
45 * In addition all sampling points except minimum and maximum are beeing shifted by a random fraction their
46 * distance to the other points. This helps to prevent beats when sampling periodic functions.
47 *
48 * Finally the obtained data is cleaned up to reduce the amount of points, by deleting a point, when it leads to an
49 * angle between consecutive line-segments of less than dataCleanupMaxAllowedAngleDegree.
50 *
51 *
52 * \see JKQTPXYFunctionLineGraphBase for a concrete implementation with C++-functors as functions
53 */
55 Q_OBJECT
56public:
57
58 /** \brief class constructor */
60
61 /** \brief class constructor */
63
64
65 /** \brief class constructor */
66 JKQTPXYFunctionLineGraphBase(double tmin_, double tmax_, JKQTBasePlotter* parent);
67
68 /** \brief class constructor */
69 JKQTPXYFunctionLineGraphBase(double tmin_, double tmax_, JKQTPlotter* parent);
70
71 /** \brief class destructor */
73
74 /** \brief plots the graph to the plotter object specified as parent */
75 virtual void draw(JKQTPEnhancedPainter& painter) override;
76 /** \brief plots a key marker inside the specified rectangle \a rect */
77 virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) override;
78 /** \brief returns the color to be used for the key label */
79 virtual QColor getKeyLabelColor() const override;
80
81
82 /** \brief returns the t-value range for \f$ [x,y]=f(t), t \in \left[t_\text{min}, t_\text{max}\right] \f$ */
83 QPair<double,double> getTRange() const;
84 /** \copydoc tmin */
85 double getTMin() const;
86 /** \copydoc tmax */
87 double getTMax() const;
88
89public Q_SLOTS:
90 /** \copydoc tmin */
91 void setTMin(double val);
92 /** \copydoc tmax */
93 void setTMax(double val);
94 /** \brief set the t-value range for \f$ [x,y]=f(t), t \in \left[t_\text{min}, t_\text{max}\right] \f$ */
95 void setTRange(double tmin_, double tmax_);
96 /** \brief set the t-value range for \f$ [x,y]=f(t), t \in \left[t_\text{min}, t_\text{max}\right] \f$ */
97 void setTRange(const QPair<double,double>& range);
98protected:
99
100 /** \brief lower bound of t-value range for \f$ [x,y]=f(t), t \in \left[t_\text{min}, t_\text{max}\right] \f$ , i.e. \f$ t_\text{min} \f$ , default is 0
101 *
102 * \see getTMin(), getTMax(), setTMin(), setTMax(), setTRange(), getTRange() */
103 double tmin;
104 /** \brief upper bound of t-value range for \f$ [x,y]=f(t), t \in \left[t_\text{min}, t_\text{max}\right] \f$ , i.e. \f$ t_\text{min} \f$ , default is 1
105 *
106 * \see getTMin(), getTMax(), setTMin(), setTMax(), setTRange(), getTRange() */
107 double tmax;
108
109};
110
111
112
113/** \brief type of functions that may be plotted by JKQTPXYFunctionLineGraph
114 * \ingroup jkqtplotter_functiongraphs
115 *
116 * This is the type of functions \f$ [x,y]=f(t, \vec{p}) \f$ that may be plottet by JKQTPXYFunctionLineGraph.
117 * It is possible to supply parameters \f$ \vec{p} \f$ to the function that
118 * influence its result. Parameters are given as a pointer to some memory location. The function has to
119 * know on its own how to interpret these.
120*/
121typedef std::function<QPointF(double, const QVector<double>)> jkqtpParametricCurveFunctionType;
122
123/** \brief simplified type of functions (without parameters) that may be plotted by JKQTPXYFunctionLineGraph
124 * \ingroup jkqtplotter_functiongraphs
125 *
126 * This is the type of functions \f$ [x,y]=f(t) \f$ that may be plottet by JKQTPXYFunctionLineGraph
127 * and JKQTPYFunctionLineGraph.
128*/
129typedef std::function<QPointF(double)> jkqtpSimpleParametricCurveFunctionType;
130
131
132/** \brief This implements line plots where the data is taken from a user supplied function \f$ [x,y]=f(t) \f$
133 * The function is evaluated on a user-specified range \f$ t \in \left[t_\text{min}, t_\text{max}\right] \f$
134 * \ingroup jkqtplotter_functiongraphs
135 *
136 * \see JKQTPXYFunctionLineGraphBase for details on the used plotting algorithm
137 *
138 * The following image shows a Lissajou's fugure drawn with this function
139 *
140 * \image html JKQTPXYFunctionLineGraph.png
141 *
142 * The source code for this example is:
143 * \code
144 * JKQTPXYFunctionLineGraph* func1=new JKQTPXYFunctionLineGraph(plot);
145 * // here we define the C++-functor for [x,y]=f(t)
146 * func1->setPlotFunctionFunctor([](double t) -> QPointF {
147 * const double a=5;
148 * const double b=4;
149 * const double delta=JKQTPSTATISTICS_PI/4.0;
150 * return QPointF(sin(a*t+delta), sin(b*t));
151 * });
152 * // and define the range over which to evaluate
153 * func1->setTRange(0, 2.0*JKQTPSTATISTICS_PI);
154 * \endcode
155 *
156 * The source code for the same example, but using functions that also get a parameter vector:
157 * \code
158 * JKQTPXYFunctionLineGraph* func1=new JKQTPXYFunctionLineGraph(plot);
159 * // here we define the C++-functor for [x,y]=f(t)
160 * func1->setPlotFunctionFunctor([](double t, const QVector<double>& params) -> QPointF {
161 * return QPointF(3.0*sin(params[0]*t+params[2])+8.0, 3.0*sin(params[1]*t));
162 * });
163 * // now we define the 3 parameters of the function
164 * // parameters are a, b, delta, as in the example above (in that order)
165 * func1->setParamsV(5, 4, JKQTPSTATISTICS_PI/4.0);
166 * // and define the range over which to evaluate
167 * func1->setTRange(0, 2.0*JKQTPSTATISTICS_PI);
168 * \endcode
169 *
170 * \see \ref JKQTPlotterEvalCurves , JKQTPAdaptiveFunctionGraphEvaluator, JKQTPXFunctionLineGraph, JKQTPYFunctionLineGraph
171 */
173 Q_OBJECT
174 public:
175
176 /** \brief class constructor */
178
179 /** \brief class constructor */
181 /** \brief class constructor */
182 JKQTPXYFunctionLineGraph(const jkqtpSimpleParametricCurveFunctionType & f, const QString& title, double tmin_=0, double tmax_=1, JKQTBasePlotter* parent=nullptr);
183 /** \brief class constructor */
184 JKQTPXYFunctionLineGraph(const jkqtpSimpleParametricCurveFunctionType & f, const QString& title, double tmin_, double tmax_, JKQTPlotter* parent);
185 /** \brief class constructor */
186 JKQTPXYFunctionLineGraph(jkqtpSimpleParametricCurveFunctionType && f, const QString& title, double tmin_=0, double tmax_=1, JKQTBasePlotter* parent=nullptr);
187 /** \brief class constructor */
188 JKQTPXYFunctionLineGraph(jkqtpSimpleParametricCurveFunctionType && f, const QString& title, double tmin_, double tmax_, JKQTPlotter* parent);
189 /** \brief class constructor */
190 JKQTPXYFunctionLineGraph(const jkqtpParametricCurveFunctionType & f, const QString& title, double tmin_=0, double tmax_=1, JKQTBasePlotter* parent=nullptr);
191 /** \brief class constructor */
192 JKQTPXYFunctionLineGraph(const jkqtpParametricCurveFunctionType & f, const QString& title, double tmin_, double tmax_, JKQTPlotter* parent);
193 /** \brief class constructor */
194 JKQTPXYFunctionLineGraph(jkqtpParametricCurveFunctionType && f, const QString& title, double tmin_=0, double tmax_=1, JKQTBasePlotter* parent=nullptr);
195 /** \brief class constructor */
196 JKQTPXYFunctionLineGraph(jkqtpParametricCurveFunctionType && f, const QString& title, double tmin_, double tmax_, JKQTPlotter* parent);
197
198 /** \brief class destructor */
199 virtual ~JKQTPXYFunctionLineGraph() override;
200
201
202 /** \brief sets a functor to be plotted
203 *
204 * \see plotFunction
205 */
207 /** \brief sets a functor to be plotted
208 *
209 * \see plotFunction
210 */
212 /** \brief sets a functor to be plotted
213 *
214 * \see simplePlotFunction
215 */
217 /** \brief sets a functor to be plotted
218 *
219 * \see simplePlotFunction
220 */
222 /** \copydoc plotFunction
223 *
224 * \see isSimplePlotFunction() */
226 /** \copydoc simplePlotFunction
227 *
228 * \see isSimplePlotFunction() */
230
231 /** \brief returns whether the plot function was defined as a jkqtpSimpleParametricCurveFunctionType (\c true ) or
232 * a jkqtpParametricCurveFunctionType (\c false ) */
234
235
236 protected:
237 /** \copydoc JKQTPEvaluatedFunctionGraphBase::buildPlotFunctorSpec() */
239
240
241 /** \brief the function to be plotted */
243 /** \brief a simple function to be plotted, simplified form without parameters */
245
246};
247
248#endif // jkqtpevaluatedparametriccurve_H
base class for 2D plotter classes (used by the plotter widget JKQTPlotter)
Definition jkqtpbaseplotter.h:394
this class extends the QPainter
Definition jkqtpenhancedpainter.h:33
Base class for graph classes that evaluate a mathematical function (e.g. defined as a C-function),...
Definition jkqtpevaluatedfunctionbase.h:74
This Mix-In class provides setter/getter methods, storage and other facilities for the graph line sty...
Definition jkqtpgraphsbasestylingmixins.h:49
Base class for line plots where the data is taken from a user supplied function The function is eval...
Definition jkqtpevaluatedparametriccurve.h:54
double getTMax() const
upper bound of t-value range for , i.e. , default is 1
JKQTPXYFunctionLineGraphBase(JKQTPlotter *parent)
class constructor
void setTMax(double val)
upper bound of t-value range for , i.e. , default is 1
JKQTPXYFunctionLineGraphBase(double tmin_, double tmax_, JKQTBasePlotter *parent)
class constructor
void setTRange(double tmin_, double tmax_)
set the t-value range for
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
JKQTPXYFunctionLineGraphBase(JKQTBasePlotter *parent=nullptr)
class constructor
double tmin
lower bound of t-value range for , i.e. , default is 0
Definition jkqtpevaluatedparametriccurve.h:103
double tmax
upper bound of t-value range for , i.e. , default is 1
Definition jkqtpevaluatedparametriccurve.h:107
JKQTPXYFunctionLineGraphBase(double tmin_, double tmax_, JKQTPlotter *parent)
class constructor
virtual QColor getKeyLabelColor() const override
returns the color to be used for the key label
virtual ~JKQTPXYFunctionLineGraphBase() override
class destructor
QPair< double, double > getTRange() const
returns the t-value range for
double getTMin() const
lower bound of t-value range for , i.e. , default is 0
void setTRange(const QPair< double, double > &range)
set the t-value range for
virtual void drawKeyMarker(JKQTPEnhancedPainter &painter, const QRectF &rect) override
plots a key marker inside the specified rectangle rect
void setTMin(double val)
lower bound of t-value range for , i.e. , default is 0
This implements line plots where the data is taken from a user supplied function The function is eva...
Definition jkqtpevaluatedparametriccurve.h:172
void setPlotFunctionFunctor(jkqtpSimpleParametricCurveFunctionType &&__value)
sets a functor to be plotted
JKQTPXYFunctionLineGraph(jkqtpSimpleParametricCurveFunctionType &&f, const QString &title, double tmin_=0, double tmax_=1, JKQTBasePlotter *parent=nullptr)
class constructor
JKQTPXYFunctionLineGraph(const jkqtpSimpleParametricCurveFunctionType &f, const QString &title, double tmin_, double tmax_, JKQTPlotter *parent)
class constructor
jkqtpSimpleParametricCurveFunctionType simplePlotFunction
a simple function to be plotted, simplified form without parameters
Definition jkqtpevaluatedparametriccurve.h:244
virtual PlotFunctorSpec buildPlotFunctorSpec() override
this function returns a functor that is used to generate the plot data in coordinate space,...
jkqtpSimpleParametricCurveFunctionType getSimplePlotFunction() const
a simple function to be plotted, simplified form without parameters
JKQTPXYFunctionLineGraph(jkqtpParametricCurveFunctionType &&f, const QString &title, double tmin_, double tmax_, JKQTPlotter *parent)
class constructor
JKQTPXYFunctionLineGraph(JKQTPlotter *parent)
class constructor
jkqtpParametricCurveFunctionType getPlotFunctionFunctor() const
the function to be plotted
JKQTPXYFunctionLineGraph(const jkqtpSimpleParametricCurveFunctionType &f, const QString &title, double tmin_=0, double tmax_=1, JKQTBasePlotter *parent=nullptr)
class constructor
void setPlotFunctionFunctor(jkqtpParametricCurveFunctionType &&__value)
sets a functor to be plotted
JKQTPXYFunctionLineGraph(jkqtpParametricCurveFunctionType &&f, const QString &title, double tmin_=0, double tmax_=1, JKQTBasePlotter *parent=nullptr)
class constructor
void setPlotFunctionFunctor(const jkqtpParametricCurveFunctionType &__value)
sets a functor to be plotted
jkqtpParametricCurveFunctionType plotFunction
the function to be plotted
Definition jkqtpevaluatedparametriccurve.h:242
bool isSimplePlotFunction() const
returns whether the plot function was defined as a jkqtpSimpleParametricCurveFunctionType (true ) or ...
JKQTPXYFunctionLineGraph(const jkqtpParametricCurveFunctionType &f, const QString &title, double tmin_, double tmax_, JKQTPlotter *parent)
class constructor
virtual ~JKQTPXYFunctionLineGraph() override
class destructor
JKQTPXYFunctionLineGraph(const jkqtpParametricCurveFunctionType &f, const QString &title, double tmin_=0, double tmax_=1, JKQTBasePlotter *parent=nullptr)
class constructor
void setPlotFunctionFunctor(const jkqtpSimpleParametricCurveFunctionType &__value)
sets a functor to be plotted
JKQTPXYFunctionLineGraph(JKQTBasePlotter *parent=nullptr)
class constructor
JKQTPXYFunctionLineGraph(jkqtpSimpleParametricCurveFunctionType &&f, const QString &title, double tmin_, double tmax_, JKQTPlotter *parent)
class constructor
plotter widget for scientific plots (uses JKQTBasePlotter to do the actual drawing)
Definition jkqtplotter.h:364
std::function< QPointF(double)> jkqtpSimpleParametricCurveFunctionType
simplified type of functions (without parameters) that may be plotted by JKQTPXYFunctionLineGraph
Definition jkqtpevaluatedparametriccurve.h:129
std::function< QPointF(double, const QVector< double >)> jkqtpParametricCurveFunctionType
type of functions that may be plotted by JKQTPXYFunctionLineGraph
Definition jkqtpevaluatedparametriccurve.h:121
#define JKQTPLOTTER_LIB_EXPORT
Definition jkqtplotter_imexport.h:89
specifies an internal plot functor
Definition jkqtpevaluatedfunctionbase.h:152