2018-12-24 03:27:24 +08:00
|
|
|
/*
|
2019-01-20 23:15:10 +08:00
|
|
|
Copyright (c) 2008-2019 Jan W. Krieger (<jan@jkrieger.de>)
|
2018-12-24 03:27:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This software is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License (LGPL) as published by
|
2019-02-08 00:24:46 +08:00
|
|
|
the Free Software Foundation, either version 2.1 of the License, or
|
2018-12-24 03:27:24 +08:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License (LGPL) for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License (LGPL)
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "jkqtplotter/jkqtpgraphsevaluatedfunction.h"
|
|
|
|
#include "jkqtplotter/jkqtpbaseplotter.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <iostream>
|
|
|
|
#include "jkqtplottertools/jkqtptools.h"
|
|
|
|
#include "jkqtplotter/jkqtpgraphsimage.h"
|
|
|
|
#include "jkqtplotter/jkqtpbaseelements.h"
|
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
2018-12-24 19:29:33 +08:00
|
|
|
#include "jkqtpgraphsevaluatedfunction.h"
|
2018-12-24 03:27:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPXFunctionLineGraph::JKQTPXFunctionLineGraph(JKQTBasePlotter* parent):
|
|
|
|
JKQTPGraph(parent)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
2018-12-24 19:29:33 +08:00
|
|
|
functionType=SpecialFunction::UserFunction;
|
2018-12-24 03:27:24 +08:00
|
|
|
color=QColor("red");
|
|
|
|
fillColor=color.lighter();
|
|
|
|
style=Qt::SolidLine;
|
|
|
|
lineWidth=2;
|
|
|
|
fillStyle=Qt::SolidPattern;
|
|
|
|
drawLine=true;
|
|
|
|
fillCurve=false;
|
|
|
|
params=nullptr;
|
|
|
|
minSamples=10;
|
|
|
|
maxRefinementDegree=7;
|
|
|
|
slopeTolerance=0.005;
|
|
|
|
minPixelPerSample=32;
|
|
|
|
plotRefinement=true;
|
|
|
|
displaySamplePoints=false;
|
|
|
|
data=nullptr;
|
|
|
|
|
|
|
|
drawErrorPolygons=false;
|
|
|
|
drawErrorLines=false;
|
|
|
|
errorParams=nullptr;
|
|
|
|
errorColor=color.lighter();
|
|
|
|
errorFillColor=color.lighter();
|
|
|
|
errorStyle=Qt::SolidLine;
|
|
|
|
errorLineWidth=1;
|
|
|
|
errorFillStyle=Qt::SolidPattern;
|
|
|
|
|
|
|
|
parameterColumn=-1;
|
|
|
|
errorParameterColumn=-1;
|
|
|
|
|
|
|
|
|
|
|
|
if (parent) { // get style settings from parent object
|
|
|
|
parentPlotStyle=parent->getNextStyle();
|
|
|
|
//std::cout<<"got style settings from parent: "<<parentPlotStyle<<std::endl;
|
|
|
|
color=parent->getPlotStyle(parentPlotStyle).color();
|
2019-02-08 00:24:46 +08:00
|
|
|
fillColor=parent->getPlotStyle(parentPlotStyle).fillColor();
|
2018-12-24 03:27:24 +08:00
|
|
|
style=parent->getPlotStyle(parentPlotStyle).style();
|
2019-02-08 00:24:46 +08:00
|
|
|
lineWidth=parent->getPlotStyle(parentPlotStyle).widthF();
|
|
|
|
fillStyle=parent->getPlotStyle(parentPlotStyle).fillStyle();
|
|
|
|
errorColor=parent->getPlotStyle(parentPlotStyle).errorColor();
|
|
|
|
errorStyle=parent->getPlotStyle(parentPlotStyle).errorStyle();
|
|
|
|
errorLineWidth=parent->getPlotStyle(parentPlotStyle).errorWidthF();
|
|
|
|
errorFillStyle=parent->getPlotStyle(parentPlotStyle).errorFillStyle();
|
|
|
|
errorFillColor=parent->getPlotStyle(parentPlotStyle).errorFillColor();
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
fillColor.setAlphaF(0.5);
|
|
|
|
errorFillColor.setAlphaF(0.5);
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPXFunctionLineGraph::JKQTPXFunctionLineGraph(JKQTPlotter* parent):
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPGraph(parent)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
2018-12-24 19:29:33 +08:00
|
|
|
functionType=SpecialFunction::UserFunction;
|
2018-12-24 03:27:24 +08:00
|
|
|
color=QColor("red");
|
|
|
|
fillColor=color.lighter();
|
|
|
|
style=Qt::SolidLine;
|
|
|
|
lineWidth=2;
|
|
|
|
fillStyle=Qt::SolidPattern;
|
|
|
|
drawLine=true;
|
|
|
|
fillCurve=false;
|
|
|
|
params=nullptr;
|
|
|
|
minSamples=10;
|
|
|
|
maxRefinementDegree=7;
|
|
|
|
slopeTolerance=0.005;
|
|
|
|
minPixelPerSample=32;
|
|
|
|
plotRefinement=true;
|
|
|
|
displaySamplePoints=false;
|
|
|
|
data=nullptr;
|
|
|
|
|
|
|
|
drawErrorPolygons=false;
|
|
|
|
drawErrorLines=false;
|
|
|
|
errorParams=nullptr;
|
|
|
|
errorColor=color.lighter();
|
|
|
|
errorFillColor=color.lighter();
|
|
|
|
errorStyle=Qt::SolidLine;
|
|
|
|
errorLineWidth=1;
|
|
|
|
errorFillStyle=Qt::SolidPattern;
|
|
|
|
|
|
|
|
parameterColumn=-1;
|
|
|
|
errorParameterColumn=-1;
|
|
|
|
|
|
|
|
|
|
|
|
if (parent) { // get style settings from parent object
|
|
|
|
parentPlotStyle=parent->getNextStyle();
|
|
|
|
//std::cout<<"got style settings from parent: "<<parentPlotStyle<<std::endl;
|
|
|
|
color=parent->getPlotStyle(parentPlotStyle).color();
|
2019-02-08 00:24:46 +08:00
|
|
|
fillColor=parent->getPlotStyle(parentPlotStyle).fillColor();
|
2018-12-24 03:27:24 +08:00
|
|
|
style=parent->getPlotStyle(parentPlotStyle).style();
|
2019-02-08 00:24:46 +08:00
|
|
|
lineWidth=parent->getPlotStyle(parentPlotStyle).widthF();
|
|
|
|
fillStyle=parent->getPlotStyle(parentPlotStyle).fillStyle();
|
|
|
|
errorColor=parent->getPlotStyle(parentPlotStyle).errorColor();
|
|
|
|
errorStyle=parent->getPlotStyle(parentPlotStyle).errorStyle();
|
|
|
|
errorLineWidth=parent->getPlotStyle(parentPlotStyle).errorWidthF();
|
|
|
|
errorFillStyle=parent->getPlotStyle(parentPlotStyle).errorFillStyle();
|
|
|
|
errorFillColor=parent->getPlotStyle(parentPlotStyle).errorFillColor();
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
fillColor.setAlphaF(0.5);
|
|
|
|
errorFillColor.setAlphaF(0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPXFunctionLineGraph::~JKQTPXFunctionLineGraph() {
|
2018-12-24 03:27:24 +08:00
|
|
|
clearData();
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPXFunctionLineGraph::clearData() {
|
2018-12-24 03:27:24 +08:00
|
|
|
while (data!=nullptr) {
|
|
|
|
doublePair* d=data;
|
|
|
|
data=data->next;
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
data=nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setPlotFunction(const jkqtpPlotFunctionType &__value)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
2018-12-24 19:29:33 +08:00
|
|
|
simplePlotFunction=jkqtpSimplePlotFunctionType();
|
|
|
|
plotFunction = __value;
|
|
|
|
functionType=SpecialFunction::UserFunction;
|
|
|
|
|
|
|
|
clearData();
|
|
|
|
}
|
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setPlotFunction(const jkqtpSimplePlotFunctionType &__value)
|
2018-12-24 19:29:33 +08:00
|
|
|
{
|
|
|
|
plotFunction=jkqtpPlotFunctionType();
|
|
|
|
simplePlotFunction=__value;
|
|
|
|
functionType=SpecialFunction::UserFunction;
|
|
|
|
|
2018-12-24 03:27:24 +08:00
|
|
|
clearData();
|
|
|
|
}
|
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setPlotFunction(jkqtpPlotFunctionType &&__value)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
2018-12-24 19:29:33 +08:00
|
|
|
simplePlotFunction=jkqtpSimplePlotFunctionType();
|
|
|
|
plotFunction = std::move(__value);
|
|
|
|
functionType=SpecialFunction::UserFunction;
|
|
|
|
clearData();
|
|
|
|
}
|
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setPlotFunction(jkqtpSimplePlotFunctionType &&__value)
|
2018-12-24 19:29:33 +08:00
|
|
|
{
|
|
|
|
plotFunction=jkqtpPlotFunctionType();
|
|
|
|
simplePlotFunction=std::move(__value);
|
|
|
|
functionType=SpecialFunction::UserFunction;
|
|
|
|
|
2018-12-24 03:27:24 +08:00
|
|
|
clearData();
|
|
|
|
}
|
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
jkqtpPlotFunctionType JKQTPXFunctionLineGraph::getPlotFunction() const
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
2018-12-24 19:29:33 +08:00
|
|
|
return plotFunction;
|
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
jkqtpSimplePlotFunctionType JKQTPXFunctionLineGraph::getSimplePlotFunction() const
|
2018-12-24 19:29:33 +08:00
|
|
|
{
|
|
|
|
return simplePlotFunction;
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPXFunctionLineGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
|
2019-02-08 00:24:46 +08:00
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2018-12-24 03:27:24 +08:00
|
|
|
QPen p=painter.pen();
|
|
|
|
p.setJoinStyle(Qt::RoundJoin);
|
|
|
|
p.setCapStyle(Qt::RoundCap);
|
|
|
|
QPen np(Qt::NoPen);
|
|
|
|
p.setColor(color);
|
|
|
|
p.setStyle(style);
|
|
|
|
QBrush b=painter.brush();
|
|
|
|
b.setColor(fillColor);
|
|
|
|
b.setStyle(fillStyle);
|
2018-12-24 19:29:33 +08:00
|
|
|
const double y=rect.top()+rect.height()/2.0;
|
2018-12-24 03:27:24 +08:00
|
|
|
painter.setPen(np);
|
|
|
|
if (drawLine) painter.setPen(p);
|
|
|
|
painter.setBrush(b);
|
|
|
|
if (fillCurve) painter.drawRect(rect);
|
|
|
|
if (!fillCurve & drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
|
2019-02-08 00:24:46 +08:00
|
|
|
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
QColor JKQTPXFunctionLineGraph::getKeyLabelColor() {
|
2018-12-24 03:27:24 +08:00
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
bool JKQTPXFunctionLineGraph::getXMinMax(double &minx, double &maxx, double &smallestGreaterZero)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
|
|
|
smallestGreaterZero=minx=maxx=0; return false;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
bool JKQTPXFunctionLineGraph::getYMinMax(double &miny, double &maxy, double &smallestGreaterZero)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
|
|
|
smallestGreaterZero=miny=maxy=0; return false;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPXFunctionLineGraph::createPlotData(bool collectParams) {
|
2018-12-24 03:27:24 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPAutoOutputTimer jkaat(QString("JKQTPXFunctionLineGraph[%1]::createPlotData()").arg(title));
|
2018-12-24 03:27:24 +08:00
|
|
|
#endif
|
|
|
|
clearData();
|
|
|
|
if (collectParams) collectParameters();
|
|
|
|
|
|
|
|
if (parent==nullptr) return;
|
2018-12-24 19:29:33 +08:00
|
|
|
if (!plotFunction && !simplePlotFunction) return;
|
|
|
|
|
|
|
|
jkqtpSimplePlotFunctionType func;
|
|
|
|
if (plotFunction) func=std::bind(plotFunction, std::placeholders::_1, params);
|
|
|
|
else if (simplePlotFunction) func=simplePlotFunction;
|
2018-12-24 03:27:24 +08:00
|
|
|
|
|
|
|
double xmin=parent->getXMin();
|
|
|
|
double xmax=parent->getXMax();
|
2018-12-28 05:52:00 +08:00
|
|
|
double pxmin=transformX(xmin);
|
|
|
|
double pxmax=transformX(xmax);
|
2019-01-26 20:00:40 +08:00
|
|
|
double delta0=(pxmax-pxmin)/static_cast<double>(minSamples);
|
|
|
|
//double logdelta0=(log(xmax)-log(xmin))/static_cast<double>(minSamples);
|
2018-12-24 03:27:24 +08:00
|
|
|
|
|
|
|
// initially sample function
|
|
|
|
doublePair* d=new doublePair;
|
|
|
|
d->x=xmin;
|
2018-12-24 19:29:33 +08:00
|
|
|
d->f=func(xmin);
|
2018-12-24 03:27:24 +08:00
|
|
|
d->next=nullptr;
|
|
|
|
data=d;
|
2019-01-26 03:16:04 +08:00
|
|
|
/*if (parent && parent->getXAxis()->isLogAxis()) {
|
2018-12-24 03:27:24 +08:00
|
|
|
for (double x=log(xmin)+logdelta0; x<log(xmax); x=x+logdelta0) {
|
|
|
|
d->next = new doublePair;
|
2019-01-10 04:23:24 +08:00
|
|
|
d->next->x=exp(x+(static_cast<double>(rand())/static_cast<double>(RAND_MAX)-0.5)*delta0/2.0);
|
2018-12-24 19:29:33 +08:00
|
|
|
d->next->f=func(d->next->x,);
|
2018-12-24 03:27:24 +08:00
|
|
|
d->next->next=nullptr;
|
|
|
|
doublePair* dd=d;
|
|
|
|
d=d->next;
|
|
|
|
refine(dd, d);
|
|
|
|
}
|
|
|
|
} else {*/
|
|
|
|
QVector<double>* dv=static_cast<QVector<double>*>(params);
|
2018-12-24 19:29:33 +08:00
|
|
|
if (functionType==Polynomial && dv && dv->size()<=2) {
|
|
|
|
// we only need the first and last datapoint
|
|
|
|
} else {
|
|
|
|
for (double x=pxmin+delta0; x<pxmax; x=x+delta0) {
|
|
|
|
d->next = new doublePair;
|
2019-01-10 04:23:24 +08:00
|
|
|
d->next->x=parent->p2x(x+(static_cast<double>(rand())/static_cast<double>(RAND_MAX)-0.5)*delta0/2.0);
|
2018-12-24 19:29:33 +08:00
|
|
|
d->next->f=func(d->next->x);
|
|
|
|
d->next->next=nullptr;
|
|
|
|
doublePair* dd=d;
|
|
|
|
d=d->next;
|
|
|
|
refine(dd, d);
|
|
|
|
}
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//}
|
|
|
|
d->next = new doublePair;
|
|
|
|
d->next->x=xmax;
|
2018-12-24 19:29:33 +08:00
|
|
|
d->next->f=func(xmax);
|
2018-12-24 03:27:24 +08:00
|
|
|
d->next->next=nullptr;
|
|
|
|
refine(d, d->next);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPXFunctionLineGraph::collectParameters()
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
|
|
|
if (parent && parameterColumn>=0) {
|
|
|
|
iparams.clear();
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* datastore=parent->getDatastore();
|
2018-12-24 03:27:24 +08:00
|
|
|
int imin=0;
|
|
|
|
int imax=datastore->getColumn(parameterColumn).getRows();
|
|
|
|
|
|
|
|
for (int i=imin; i<imax; i++) {
|
|
|
|
double xv=datastore->get(parameterColumn,i);
|
|
|
|
iparams<<xv;
|
|
|
|
}
|
|
|
|
//qDebug()<<"iparams_beforeclean:";
|
|
|
|
//for (int i=0; i<iparams.size(); i++) qDebug()<<iparams[i];
|
|
|
|
int i=iparams.size()-1;
|
|
|
|
while (i>=0 && !JKQTPIsOKFloat(iparams[i])) {
|
|
|
|
iparams.remove(i,1);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
|
|
|
|
//qDebug()<<"iparams:";
|
|
|
|
//for (i=0; i<iparams.size(); i++) qDebug()<<iparams[i];
|
|
|
|
|
|
|
|
params=&iparams;
|
|
|
|
}
|
|
|
|
if (parent && errorParameterColumn>=0) {
|
|
|
|
ierrorparams.clear();
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* datastore=parent->getDatastore();
|
2018-12-24 03:27:24 +08:00
|
|
|
int imin=0;
|
|
|
|
int imax=datastore->getColumn(errorParameterColumn).getRows();
|
|
|
|
|
|
|
|
for (int i=imin; i<imax; i++) {
|
|
|
|
double xv=datastore->get(errorParameterColumn,i);
|
|
|
|
ierrorparams<<xv;
|
|
|
|
}
|
|
|
|
int i=ierrorparams.size()-1;
|
|
|
|
while (i>=0 && !JKQTPIsOKFloat(ierrorparams[i])) {
|
|
|
|
ierrorparams.remove(i,1);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
|
|
|
|
errorParams=&ierrorparams;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPXFunctionLineGraph::refine(doublePair* a, doublePair* b, unsigned int degree) {
|
2018-12-24 03:27:24 +08:00
|
|
|
if (degree>=maxRefinementDegree) return;
|
2018-12-28 05:52:00 +08:00
|
|
|
double ax=transformX(a->x);
|
|
|
|
double af=transformX(a->f);
|
|
|
|
double bx=transformX(b->x);
|
|
|
|
double bf=transformX(b->f);
|
2018-12-24 03:27:24 +08:00
|
|
|
|
|
|
|
double delta=bx - ax;
|
|
|
|
//double logdelta=log(bx) - log(ax);
|
|
|
|
double xmid=ax+(delta)/2.0;
|
2019-01-26 03:16:04 +08:00
|
|
|
/*if (parent && parent->getXAxis()->isLogAxis()) {
|
2018-12-24 03:27:24 +08:00
|
|
|
xmid=log(a->x)+(logdelta)/2.0;
|
2019-01-10 04:23:24 +08:00
|
|
|
xmid=xmid+(static_cast<double>(rand())/static_cast<double>(RAND_MAX)-0.5)*delta/5.0;
|
2018-12-24 03:27:24 +08:00
|
|
|
xmid=exp(xmid);
|
|
|
|
} else {*/
|
2019-01-10 04:23:24 +08:00
|
|
|
xmid=xmid+(static_cast<double>(rand())/static_cast<double>(RAND_MAX)-0.5)*delta/5.0; // shake by 10%
|
2018-12-24 03:27:24 +08:00
|
|
|
//}
|
|
|
|
double realxmid=parent->p2x(xmid);
|
2018-12-24 19:29:33 +08:00
|
|
|
double realfmid;
|
|
|
|
if (plotFunction) realfmid=plotFunction(realxmid, params);
|
|
|
|
else if (simplePlotFunction) realfmid=simplePlotFunction(realxmid);
|
2018-12-28 05:52:00 +08:00
|
|
|
double fmid=transformY(realfmid);
|
2018-12-24 03:27:24 +08:00
|
|
|
double a1=(fmid - af)/(xmid - ax);
|
|
|
|
double a2=(bf - fmid)/(bx - xmid);
|
|
|
|
//std::cout<<std::string(degree*2, ' ')<<"refine( ["<<a->x<<", "<<a->f<<"], ["<<xmid<<", "<<fmid<<"], ["<<b->x<<", "<<b->f<<"] ): a1="<<a1<<", a2="<<a2<<" acrit="<<abs(a2/a1)-1.0<<"\n";
|
|
|
|
//std::cout<<std::string(degree*2, ' ')<<"refine(): a1="<<a1<<", a2="<<a2<<" acrit="<<fabs(a2-a1)<<"\n";
|
|
|
|
if (fabs(a2-a1)>slopeTolerance || delta>minPixelPerSample) {
|
|
|
|
doublePair* dmid = new doublePair;
|
|
|
|
dmid->x=realxmid;
|
|
|
|
dmid->f=realfmid;
|
|
|
|
a->next=dmid;
|
|
|
|
dmid->next=b;
|
|
|
|
refine(a, dmid, degree+1);
|
|
|
|
refine(dmid, b, degree+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPXFunctionLineGraph::draw(JKQTPEnhancedPainter& painter) {
|
2018-12-24 03:27:24 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot("JKQTPXFunctionLineGraph::draw");
|
2018-12-24 03:27:24 +08:00
|
|
|
#endif
|
|
|
|
if (parent==nullptr) return;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* datastore=parent->getDatastore();
|
2018-12-24 03:27:24 +08:00
|
|
|
if (datastore==nullptr) return;
|
|
|
|
|
|
|
|
//qDebug()<<"start plot\n";
|
|
|
|
createPlotData();
|
|
|
|
//qDebug()<<"plot data created\n";
|
|
|
|
|
|
|
|
drawErrorsBefore(painter);
|
2019-02-08 00:24:46 +08:00
|
|
|
{
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
|
|
|
|
QPen p=painter.pen();
|
|
|
|
p.setColor(color);
|
|
|
|
p.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, lineWidth*parent->getLineWidthMultiplier())));
|
|
|
|
p.setStyle(style);
|
|
|
|
p.setJoinStyle(Qt::RoundJoin);
|
|
|
|
p.setJoinStyle(Qt::RoundJoin);
|
|
|
|
p.setCapStyle(Qt::RoundCap);
|
|
|
|
QPen np(Qt::NoPen);
|
|
|
|
|
|
|
|
QPen ep=painter.pen();
|
|
|
|
ep.setColor(errorColor);
|
|
|
|
ep.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, errorLineWidth*parent->getLineWidthMultiplier())));
|
|
|
|
ep.setStyle(errorStyle);
|
|
|
|
ep.setJoinStyle(Qt::RoundJoin);
|
|
|
|
|
|
|
|
QBrush b=painter.brush();
|
|
|
|
b.setColor(fillColor);
|
|
|
|
b.setStyle(fillStyle);
|
|
|
|
|
|
|
|
QBrush eb=painter.brush();
|
|
|
|
eb.setColor(errorFillColor);
|
|
|
|
eb.setStyle(errorFillStyle);
|
|
|
|
|
|
|
|
|
|
|
|
// double xold=-1;
|
|
|
|
// double yold=-1;
|
|
|
|
// double ypeold=-1;
|
|
|
|
// double ymeold=-1;
|
|
|
|
|
|
|
|
// double x0=transformX(0);
|
|
|
|
// if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin());
|
|
|
|
double y0=transformY(0);
|
|
|
|
if (parent->getYAxis()->isLogAxis()) y0=transformY(parent->getYAxis()->getMin());
|
|
|
|
bool first=false;
|
|
|
|
doublePair* d=data;
|
|
|
|
//QPainterPath pa, pfill;
|
|
|
|
//QPainterPath pel, pef;
|
|
|
|
QPolygonF filledPolygon, linePolygon, errorLineTop, errorLineBottom;
|
|
|
|
QList<QPointF> epTop, epBottom;
|
|
|
|
double yami=qMin(transformY(parent->getYAxis()->getMin()),transformY(parent->getYAxis()->getMax()));
|
|
|
|
double yama=qMax(transformY(parent->getYAxis()->getMin()),transformY(parent->getYAxis()->getMax()));
|
|
|
|
double dypix=fabs(yama-yami);
|
|
|
|
yami=yami-2*dypix;
|
|
|
|
yama=yama+2*dypix;
|
|
|
|
while (d!=nullptr) {
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
double xv=d->x;
|
|
|
|
double yv=d->f;
|
|
|
|
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
|
|
|
|
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
|
|
|
double x=transformX(xv);
|
|
|
|
double y=transformY(yv);
|
|
|
|
double ype=0, yme=0;
|
|
|
|
if ((drawErrorLines || drawErrorPolygons) && (static_cast<bool>(errorPlotFunction))) {
|
|
|
|
double e=errorPlotFunction(xv, errorParams);
|
|
|
|
ype=transformY(yv+e);
|
|
|
|
yme=transformY(yv-e);
|
|
|
|
ype=qBound(yami, ype, yama);
|
|
|
|
yme=qBound(yami, yme, yama);
|
|
|
|
}
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
y=qBound(yami, y, yama);
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
if (fillCurve) {
|
|
|
|
if (!first) filledPolygon<<QPointF(x, y0);
|
|
|
|
filledPolygon<<QPointF(x, y);
|
|
|
|
if (!d->next) filledPolygon<<QPointF(x, y0);
|
|
|
|
}
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
if (drawErrorPolygons && (static_cast<bool>(errorPlotFunction))) {
|
|
|
|
epTop<<QPointF(x, ype);
|
|
|
|
epBottom<<QPointF(x, yme);
|
|
|
|
}
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
if (drawLine) {
|
|
|
|
linePolygon<<QPointF(x, y);
|
|
|
|
}
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
if (drawErrorLines && (static_cast<bool>(errorPlotFunction))) {
|
|
|
|
errorLineTop<<QPointF(x, ype);
|
|
|
|
errorLineBottom<<QPointF(x, yme);
|
|
|
|
}
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
// xold=x;
|
|
|
|
// yold=y;
|
|
|
|
// ypeold=ype;
|
|
|
|
// ymeold=yme;
|
|
|
|
first=true;
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
2019-02-08 00:24:46 +08:00
|
|
|
d=d->next;
|
|
|
|
}
|
|
|
|
if (drawErrorPolygons) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
painter.setBrush(eb);
|
|
|
|
painter.setPen(np);
|
|
|
|
QPolygonF poly;
|
|
|
|
//poly << QPointF(xold, ypeold) << QPointF(x, ype)<< QPointF(x, yme) << QPointF(xold, ymeold) ;
|
|
|
|
for (int i=0; i<epTop.size(); i++) {
|
|
|
|
poly<<epTop[i];
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
2019-02-08 00:24:46 +08:00
|
|
|
for (int i=epBottom.size()-1; i>=0; i--) {
|
|
|
|
poly<<epBottom[i];
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
2019-02-08 00:24:46 +08:00
|
|
|
painter.drawPolygon(poly, Qt::OddEvenFill);
|
2018-12-24 03:27:24 +08:00
|
|
|
|
|
|
|
}
|
2019-02-08 00:24:46 +08:00
|
|
|
if (fillCurve) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
painter.setBrush(b);
|
|
|
|
painter.setPen(np);
|
|
|
|
painter.drawPolygon(filledPolygon, Qt::OddEvenFill);
|
|
|
|
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
2019-02-08 00:24:46 +08:00
|
|
|
if (drawLine) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
painter.setPen(p);
|
|
|
|
painter.drawPolyline(linePolygon);
|
|
|
|
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
if (drawErrorLines && (static_cast<bool>(errorPlotFunction))) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
painter.setPen(ep);
|
|
|
|
painter.drawPolyline(errorLineTop);
|
|
|
|
painter.drawPolyline(errorLineBottom);
|
2018-12-24 03:27:24 +08:00
|
|
|
|
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
}
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
|
|
|
|
QColor c=color;
|
|
|
|
c.setHsv(fmod(color.hue()+90, 360), color.saturation(), color.value());
|
|
|
|
d=data;
|
|
|
|
if (displaySamplePoints) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
while (d!=nullptr) {
|
|
|
|
double xv=d->x;
|
|
|
|
double yv=d->f;
|
|
|
|
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
|
|
|
|
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
|
|
|
double x=transformX(xv);
|
|
|
|
double y=transformY(yv);
|
|
|
|
JKQTPPlotSymbol(painter, x, y, JKQTPCross, 6,1*parent->getLineWidthMultiplier(), c, QColor(Qt::transparent));
|
|
|
|
}
|
|
|
|
d=d->next;
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
2019-02-08 00:24:46 +08:00
|
|
|
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
drawErrorsAfter(painter);
|
|
|
|
//std::cout<<"plot done\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(JKQTBasePlotter *parent):JKQTPXFunctionLineGraph(parent) {}
|
2018-12-28 05:52:00 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(JKQTPlotter *parent):JKQTPYFunctionLineGraph(parent->getPlotter()) {}
|
2018-12-28 05:52:00 +08:00
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPYFunctionLineGraph::draw(JKQTPEnhancedPainter& painter) {
|
2018-12-24 03:27:24 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot("JKQTPYFunctionLineGraph::draw");
|
2018-12-24 03:27:24 +08:00
|
|
|
#endif
|
|
|
|
if (parent==nullptr) return;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* datastore=parent->getDatastore();
|
2018-12-24 03:27:24 +08:00
|
|
|
if (datastore==nullptr) return;
|
|
|
|
|
|
|
|
//std::cout<<"start plot\n";
|
|
|
|
createPlotData();
|
|
|
|
//std::cout<<"plot data created\n";
|
|
|
|
|
|
|
|
drawErrorsBefore(painter);
|
2019-02-08 00:24:46 +08:00
|
|
|
{
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
|
|
|
|
QPen p=painter.pen();
|
|
|
|
p.setColor(color);
|
|
|
|
p.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, lineWidth*parent->getLineWidthMultiplier())));
|
|
|
|
p.setStyle(style);
|
|
|
|
p.setJoinStyle(Qt::RoundJoin);
|
|
|
|
p.setJoinStyle(Qt::RoundJoin);
|
|
|
|
p.setCapStyle(Qt::RoundCap);
|
|
|
|
QPen np(Qt::NoPen);
|
|
|
|
|
|
|
|
QPen ep=painter.pen();
|
|
|
|
ep.setColor(errorColor);
|
|
|
|
ep.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, errorLineWidth*parent->getLineWidthMultiplier())));
|
|
|
|
ep.setStyle(errorStyle);
|
|
|
|
ep.setJoinStyle(Qt::RoundJoin);
|
|
|
|
|
|
|
|
QBrush b=painter.brush();
|
|
|
|
b.setColor(fillColor);
|
|
|
|
b.setStyle(fillStyle);
|
|
|
|
|
|
|
|
QBrush eb=painter.brush();
|
|
|
|
eb.setColor(errorFillColor);
|
|
|
|
eb.setStyle(errorFillStyle);
|
|
|
|
|
|
|
|
|
|
|
|
double xold=-1;
|
|
|
|
double yold=-1;
|
|
|
|
double xpeold=-1;
|
|
|
|
double xmeold=-1;
|
|
|
|
|
|
|
|
double x0=transformX(0);
|
|
|
|
if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin());
|
|
|
|
// double y0=transformY(0);
|
|
|
|
// if (parent->getYAxis()->isLogAxis()) y0=transformY(parent->getYAxis()->getMin());
|
|
|
|
bool first=false;
|
|
|
|
doublePair* d=data;
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
while (d!=nullptr) {
|
|
|
|
double yv=d->x;
|
|
|
|
double xv=d->f;
|
|
|
|
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
|
|
|
|
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
|
|
|
double x=transformX(xv);
|
|
|
|
double y=transformY(yv);
|
|
|
|
double xpe=0, xme=0;
|
|
|
|
if ((drawErrorLines || drawErrorPolygons) && (static_cast<bool>(errorPlotFunction))) {
|
|
|
|
double e=errorPlotFunction(xv, errorParams);
|
|
|
|
xpe=transformX(xv+e);
|
|
|
|
xme=transformX(xv-e);
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
if (first) {
|
|
|
|
double xl1=xold;
|
|
|
|
double yl1=yold;
|
|
|
|
double xl2=x;
|
|
|
|
double yl2=y;
|
|
|
|
|
|
|
|
if (fillCurve) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
painter.setBrush(b);
|
|
|
|
painter.setPen(np);
|
|
|
|
QPolygonF poly;
|
|
|
|
poly << QPointF(xl1, yl1) << QPointF(xl2, yl2) << QPointF(x0, yl2) << QPointF(x0, yl1);
|
|
|
|
painter.drawConvexPolygon(poly);
|
|
|
|
|
|
|
|
/*pfill.lineTo(x, y);
|
|
|
|
if (d->next==nullptr) { // last datapoint
|
|
|
|
pfill.lineTo(x, y0);
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drawErrorPolygons && (static_cast<bool>(errorPlotFunction))) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
painter.setBrush(eb);
|
|
|
|
painter.setPen(np);
|
|
|
|
QPolygonF poly;
|
|
|
|
poly << QPointF(xpeold, yold) << QPointF(xpe, y)<< QPointF(xme, y) << QPointF(xmeold, yold) ;
|
|
|
|
painter.drawConvexPolygon(poly);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drawLine) {
|
|
|
|
painter.setPen(p);
|
|
|
|
//pa.lineTo(x, y);
|
|
|
|
painter.drawLine(QLineF(xl1, yl1, xl2, yl2));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drawErrorLines && (static_cast<bool>(errorPlotFunction))) {
|
|
|
|
painter.setPen(ep);
|
|
|
|
painter.drawLine(QLineF(xpeold, yold, xpe, y));
|
|
|
|
painter.drawLine(QLineF(xmeold, yold, xme, y));
|
|
|
|
}
|
|
|
|
|
|
|
|
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl;
|
|
|
|
} /*else {
|
|
|
|
if (drawLine) {
|
|
|
|
pa.moveTo(x, y);
|
|
|
|
}
|
|
|
|
if (fillCurve) {
|
|
|
|
pfill.moveTo(x, y0);
|
|
|
|
pfill.lineTo(x, y);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
xold=x;
|
|
|
|
yold=y;
|
|
|
|
xpeold=xpe;
|
|
|
|
xmeold=xme;
|
|
|
|
first=true;
|
|
|
|
}
|
|
|
|
d=d->next;
|
|
|
|
}
|
|
|
|
/*if (fillCurve) {
|
|
|
|
pfill.closeSubpath();
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
painter.setBrush(b);
|
|
|
|
painter.setPen(np);
|
|
|
|
painter.drawPath(pfill);
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
}
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
if (drawLine) {
|
|
|
|
painter.setPen(p);
|
|
|
|
painter.drawPath(pa);
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
}*/
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
QColor c=color;
|
|
|
|
c.setHsv(fmod(color.hue()+90, 360), color.saturation(), color.value());
|
|
|
|
d=data;
|
|
|
|
if (displaySamplePoints) while (d!=nullptr) {
|
|
|
|
double yv=d->x;
|
|
|
|
double xv=d->f;
|
|
|
|
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
|
|
|
|
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
|
|
|
double x=transformX(xv);
|
|
|
|
double y=transformY(yv);
|
|
|
|
JKQTPPlotSymbol(painter, x, y, JKQTPCross, 6, 1*parent->getLineWidthMultiplier(), c, QColor(Qt::transparent));
|
|
|
|
}
|
|
|
|
d=d->next;
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
drawErrorsAfter(painter);
|
|
|
|
//std::cout<<"plot done\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPYFunctionLineGraph::createPlotData(bool collectParams) {
|
2018-12-24 03:27:24 +08:00
|
|
|
clearData();
|
2018-12-24 22:07:14 +08:00
|
|
|
if (collectParams) collectParameters();
|
2018-12-24 03:27:24 +08:00
|
|
|
|
|
|
|
if (parent==nullptr) return;
|
2018-12-24 19:29:33 +08:00
|
|
|
if (!plotFunction && !simplePlotFunction) return;
|
|
|
|
|
|
|
|
jkqtpSimplePlotFunctionType func;
|
|
|
|
if (plotFunction) func=std::bind(plotFunction, std::placeholders::_1, params);
|
|
|
|
else if (simplePlotFunction) func=simplePlotFunction;
|
2018-12-24 03:27:24 +08:00
|
|
|
|
|
|
|
double ymin=parent->getYMin();
|
|
|
|
double ymax=parent->getYMax();
|
2019-01-26 20:00:40 +08:00
|
|
|
double delta0=(ymax-ymin)/static_cast<double>(minSamples);
|
2018-12-24 03:27:24 +08:00
|
|
|
|
|
|
|
// initially sample function
|
|
|
|
doublePair* d=new doublePair;
|
|
|
|
d->x=ymin;
|
2018-12-24 19:29:33 +08:00
|
|
|
d->f=func(ymin);
|
2018-12-24 03:27:24 +08:00
|
|
|
d->next=nullptr;
|
|
|
|
data=d;
|
|
|
|
for (double y=ymin+delta0; y<ymax; y=y+delta0) {
|
|
|
|
d->next = new doublePair;
|
2019-01-10 04:23:24 +08:00
|
|
|
d->next->x=y+(static_cast<double>(rand())/static_cast<double>(RAND_MAX)-0.5)*delta0/2.0;
|
2018-12-24 19:29:33 +08:00
|
|
|
d->next->f=func(d->next->x);
|
2018-12-24 03:27:24 +08:00
|
|
|
d->next->next=nullptr;
|
|
|
|
doublePair* dd=d;
|
|
|
|
d=d->next;
|
|
|
|
refine(dd, d);
|
|
|
|
}
|
|
|
|
d->next = new doublePair;
|
|
|
|
d->next->x=ymax;
|
2018-12-24 19:29:33 +08:00
|
|
|
d->next->f=func(ymax);
|
2018-12-24 03:27:24 +08:00
|
|
|
d->next->next=nullptr;
|
|
|
|
refine(d, d->next);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
QBrush JKQTPXFunctionLineGraph::getBrush(JKQTPEnhancedPainter& /*painter*/) const {
|
2018-12-24 03:27:24 +08:00
|
|
|
QBrush b;
|
|
|
|
b.setColor(fillColor);
|
|
|
|
b.setStyle(fillStyle);
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
QPen JKQTPXFunctionLineGraph::getLinePen(JKQTPEnhancedPainter &painter) const {
|
2018-12-24 03:27:24 +08:00
|
|
|
QPen p;
|
|
|
|
p.setColor(color);
|
2019-02-08 00:24:46 +08:00
|
|
|
p.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH,parent->pt2px(painter, parent->getLineWidthMultiplier()*lineWidth)));
|
2018-12-24 03:27:24 +08:00
|
|
|
p.setStyle(style);
|
|
|
|
p.setJoinStyle(Qt::RoundJoin);
|
|
|
|
p.setCapStyle(Qt::RoundCap);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
QBrush JKQTPXFunctionLineGraph::getErrorBrush(JKQTPEnhancedPainter& /*painter*/) const {
|
2018-12-24 03:27:24 +08:00
|
|
|
QBrush b;
|
|
|
|
b.setColor(errorFillColor);
|
|
|
|
b.setStyle(errorFillStyle);
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
QPen JKQTPXFunctionLineGraph::getErrorLinePen(JKQTPEnhancedPainter& painter) const {
|
2018-12-24 03:27:24 +08:00
|
|
|
QPen p;
|
|
|
|
p.setColor(errorColor);
|
2019-02-08 00:24:46 +08:00
|
|
|
p.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH,parent->pt2px(painter, parent->getLineWidthMultiplier()*errorLineWidth)));
|
2018-12-24 03:27:24 +08:00
|
|
|
p.setStyle(errorStyle);
|
|
|
|
p.setJoinStyle(Qt::RoundJoin);
|
|
|
|
p.setCapStyle(Qt::RoundCap);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setParams(const QVector<double> ¶ms)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
|
|
|
iparams=params;
|
2019-01-26 20:00:40 +08:00
|
|
|
setParams(&iparams);
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setCopiedParams(const double *params, int N)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
|
|
|
QVector<double> v;
|
|
|
|
for (int i=0; i<N; i++) { v<<params[i]; }
|
2019-01-26 20:00:40 +08:00
|
|
|
setParams(v);
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setParamsV(double p1) {
|
2018-12-24 19:29:33 +08:00
|
|
|
QVector<double> p;
|
|
|
|
p<<p1;
|
2019-01-26 20:00:40 +08:00
|
|
|
setParams(p);
|
2018-12-24 19:29:33 +08:00
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setParamsV(double p1, double p2) {
|
2018-12-24 19:29:33 +08:00
|
|
|
QVector<double> p;
|
|
|
|
p<<p1<<p2;
|
2019-01-26 20:00:40 +08:00
|
|
|
setParams(p);
|
2018-12-24 19:29:33 +08:00
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setParamsV(double p1, double p2, double p3) {
|
2018-12-24 19:29:33 +08:00
|
|
|
QVector<double> p;
|
|
|
|
p<<p1<<p2<<p3;
|
2019-01-26 20:00:40 +08:00
|
|
|
setParams(p);
|
2018-12-24 19:29:33 +08:00
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setParamsV(double p1, double p2, double p3, double p4) {
|
2018-12-24 19:29:33 +08:00
|
|
|
QVector<double> p;
|
|
|
|
p<<p1<<p2<<p3<<p4;
|
2019-01-26 20:00:40 +08:00
|
|
|
setParams(p);
|
2018-12-24 19:29:33 +08:00
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setParamsV(double p1, double p2, double p3, double p4, double p5) {
|
2018-12-24 19:29:33 +08:00
|
|
|
QVector<double> p;
|
|
|
|
p<<p1<<p2<<p3<<p4<<p5;
|
2019-01-26 20:00:40 +08:00
|
|
|
setParams(p);
|
2018-12-24 19:29:33 +08:00
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setErrorParams(const QVector<double> &errorParams)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
|
|
|
ierrorparams=errorParams;
|
2019-01-26 20:00:40 +08:00
|
|
|
setErrorParams(&ierrorparams);
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setSpecialFunction(JKQTPXFunctionLineGraph::SpecialFunction function)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
2019-01-20 17:49:29 +08:00
|
|
|
if (function==JKQTPXFunctionLineGraph::Polynomial) {
|
2019-01-26 03:16:04 +08:00
|
|
|
setPlotFunction([](double x, void* param) {
|
2018-12-24 19:29:33 +08:00
|
|
|
double res=0;
|
|
|
|
QVector<double>* d=static_cast<QVector<double>*>(param);
|
|
|
|
if (d && d->size()>0) {
|
|
|
|
res=d->value(0,0);
|
|
|
|
double xx=x;
|
|
|
|
for (int i=1; i<d->size(); i++) {
|
|
|
|
res=res+d->value(i,0)*xx;
|
|
|
|
xx=xx*x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
});
|
|
|
|
}
|
2019-01-26 03:16:04 +08:00
|
|
|
else if (function==JKQTPXFunctionLineGraph::Exponential) setPlotFunction([](double x, void* param) {
|
2018-12-24 19:29:33 +08:00
|
|
|
double res=0;
|
|
|
|
QVector<double>* d=static_cast<QVector<double>*>(param);
|
|
|
|
if (d) {
|
|
|
|
if (d->size()>=3) {
|
|
|
|
res=d->value(0,0)+d->value(1,0)*exp(x/d->value(2,0));
|
|
|
|
} else if (d->size()>=2) {
|
|
|
|
res=d->value(0,0)*exp(x/d->value(1,0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
});
|
2019-01-26 03:16:04 +08:00
|
|
|
else if (function==JKQTPXFunctionLineGraph::PowerLaw) setPlotFunction([](double x, void* param) {
|
2018-12-24 19:29:33 +08:00
|
|
|
double res=0;
|
|
|
|
QVector<double>* d=static_cast<QVector<double>*>(param);
|
|
|
|
if (d) {
|
|
|
|
if (d->size()>=3) {
|
|
|
|
res=d->value(0,0)+d->value(1,0)*pow(x, d->value(2,1));
|
|
|
|
} else if (d->size()>=2) {
|
|
|
|
res=d->value(0,0)*pow(x, d->value(1,1));
|
|
|
|
} else if (d->size()>=1) {
|
|
|
|
res=pow(x, d->value(0,1));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
});
|
|
|
|
else throw std::runtime_error("unknown special function type");
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPXFunctionLineGraph::SpecialFunction JKQTPXFunctionLineGraph::getFunctionType() const
|
2018-12-24 19:29:33 +08:00
|
|
|
{
|
|
|
|
return functionType;
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
QVector<double> JKQTPXFunctionLineGraph::getInternalParams() const {
|
2018-12-24 03:27:24 +08:00
|
|
|
return iparams;
|
|
|
|
}
|
2019-01-26 20:00:40 +08:00
|
|
|
QVector<double> JKQTPXFunctionLineGraph::getInternalErrorParams() const {
|
2018-12-24 03:27:24 +08:00
|
|
|
return ierrorparams;
|
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setErrorPlotFunction(const jkqtpPlotFunctionType &__value)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
2018-12-24 19:29:33 +08:00
|
|
|
errorSimplePlotFunction=jkqtpSimplePlotFunctionType();
|
2018-12-24 03:27:24 +08:00
|
|
|
errorPlotFunction=__value;
|
2018-12-24 19:29:33 +08:00
|
|
|
clearData();
|
2018-12-24 03:27:24 +08:00
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setErrorPlotFunction(jkqtpPlotFunctionType &&__value)
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
2018-12-24 19:29:33 +08:00
|
|
|
errorSimplePlotFunction=jkqtpSimplePlotFunctionType();
|
|
|
|
errorPlotFunction = std::move(__value);
|
2018-12-24 03:27:24 +08:00
|
|
|
clearData();
|
|
|
|
}
|
2019-01-26 20:00:40 +08:00
|
|
|
jkqtpPlotFunctionType JKQTPXFunctionLineGraph::getErrorPlotFunction() const
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
|
|
|
return errorPlotFunction;
|
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setErrorPlotFunction(const jkqtpSimplePlotFunctionType &__value)
|
2018-12-24 19:29:33 +08:00
|
|
|
{
|
|
|
|
errorPlotFunction=jkqtpPlotFunctionType();
|
|
|
|
errorSimplePlotFunction=__value;
|
|
|
|
clearData();
|
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
void JKQTPXFunctionLineGraph::setErrorPlotFunction(jkqtpSimplePlotFunctionType &&__value)
|
2018-12-24 19:29:33 +08:00
|
|
|
{
|
|
|
|
errorPlotFunction=jkqtpPlotFunctionType();
|
|
|
|
errorSimplePlotFunction = std::move(__value);
|
|
|
|
clearData();
|
|
|
|
}
|
2019-01-26 20:00:40 +08:00
|
|
|
jkqtpSimplePlotFunctionType JKQTPXFunctionLineGraph::getErrorSimplePlotFunction() const
|
2018-12-24 19:29:33 +08:00
|
|
|
{
|
|
|
|
return errorSimplePlotFunction;
|
|
|
|
}
|
|
|
|
|
2018-12-24 03:27:24 +08:00
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
bool JKQTPXFunctionLineGraph::usesColumn(int c) const
|
2018-12-24 03:27:24 +08:00
|
|
|
{
|
|
|
|
return (c==parameterColumn)||(c==errorParameterColumn);
|
|
|
|
}
|
|
|
|
|