2019-01-13 01:53:16 +08:00
|
|
|
/** \example jkqtfastplotter_test_testmain.cpp
|
2019-01-20 17:49:29 +08:00
|
|
|
* Example of how to use JKQTFastPlotter
|
2019-02-09 22:25:16 +08:00
|
|
|
* \see \ref JKQTFastPlotterTest
|
2019-01-13 01:53:16 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jkqtfastplotter_test_testmain.h"
|
2018-12-29 00:46:47 +08:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QtGui>
|
|
|
|
|
|
|
|
TestMain::TestMain(QWidget *parent) :
|
|
|
|
QWidget(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
imageRed=(double*)calloc(IMAGE_N*IMAGE_N, sizeof(double));
|
|
|
|
imageGreen=(double*)calloc(IMAGE_N*IMAGE_N, sizeof(double));
|
|
|
|
imageBlue=(double*)calloc(IMAGE_N*IMAGE_N, sizeof(double));
|
|
|
|
image=(double*)calloc(IMAGE_N*IMAGE_N, sizeof(double));
|
|
|
|
ovrl=(bool*)calloc(IMAGE_N*IMAGE_N, sizeof(bool));
|
|
|
|
x=(double*)calloc(N1, sizeof(double));
|
|
|
|
y1=(double*)calloc(N1, sizeof(double));
|
|
|
|
y2=(double*)calloc(N1, sizeof(double));
|
|
|
|
y3=(double*)calloc(N1, sizeof(double));
|
|
|
|
|
|
|
|
|
2019-06-21 21:46:53 +08:00
|
|
|
QGridLayout* gl=new QGridLayout();
|
2018-12-29 00:46:47 +08:00
|
|
|
setLayout(gl);
|
|
|
|
QTabWidget* t=new QTabWidget(this);
|
|
|
|
gl->addWidget(t,0,0);
|
|
|
|
|
|
|
|
QWidget* w=new QWidget(this);
|
|
|
|
gl=new QGridLayout(w);
|
|
|
|
w->setLayout(gl);
|
|
|
|
|
|
|
|
JKQTFastPlotter* pl1=new JKQTFastPlotter(w);
|
2019-01-26 03:16:04 +08:00
|
|
|
pl1->setMaintainAspectRatio(true);
|
2018-12-29 00:46:47 +08:00
|
|
|
gl->addWidget(pl1, 0, 0);
|
|
|
|
JKQTFastPlotter* pl2=new JKQTFastPlotter(w);
|
|
|
|
pl2->setMaximumWidth(100);
|
2019-01-26 20:00:40 +08:00
|
|
|
pl2->setSynchronizeY(pl1);
|
|
|
|
pl2->setYAxisLabelVisible(false);
|
2019-01-26 03:16:04 +08:00
|
|
|
pl2->setPlotBorderLeft(10);
|
|
|
|
pl2->setPlotBorderRight(2);
|
2019-01-26 19:28:44 +08:00
|
|
|
w->connect(pl1, SIGNAL(replotting()), pl2, SLOT(redrawPlot()));
|
2018-12-29 00:46:47 +08:00
|
|
|
gl->addWidget(pl2, 0, 1);
|
|
|
|
JKQTFastPlotter* pl3=new JKQTFastPlotter(w);
|
2019-01-26 20:00:40 +08:00
|
|
|
pl3->setSynchronizeX(pl1);
|
2019-01-26 19:28:44 +08:00
|
|
|
w->connect(pl1, SIGNAL(replotting()), pl3, SLOT(redrawPlot()));
|
2018-12-29 00:46:47 +08:00
|
|
|
gl->addWidget(pl3, 1, 0);
|
|
|
|
|
|
|
|
|
|
|
|
xx.clear();
|
|
|
|
yy.clear();
|
|
|
|
for (int i=0; i<N1; i++) {
|
|
|
|
x[i]=(i+1)*XMAX/(double)N1;
|
|
|
|
xx.push_back(x[i]);
|
|
|
|
yy.push_back(sin(0.5*M_PI*x[i])+2.0);
|
|
|
|
std::cout<<xx[i]<<", "<<yy[i]<<std::endl;
|
|
|
|
y1[i]=i*XMAX/(double)N1;
|
|
|
|
y2[i]=log(x[i]);
|
|
|
|
y3[i]=log10(x[i]);
|
|
|
|
}
|
|
|
|
JKQTFPVBarPlot* p1=new JKQTFPVBarPlot(pl1, N1, x, y1);
|
|
|
|
JKQTFPLinePlot* p2=new JKQTFPLinePlot(pl1, N1, x, y2, QColor("blue"));
|
|
|
|
JKQTFPLinePlot* p3=new JKQTFPLinePlot(pl1, N1, x, y3, QColor("darkgreen"));
|
|
|
|
JKQTFPLinePlot* pv=new JKQTFPLinePlot(pl1, &xx, &yy, QColor("black"), Qt::SolidLine, 3);
|
|
|
|
|
2019-06-21 04:24:47 +08:00
|
|
|
img=QImage(":/lena.png");
|
2018-12-29 00:46:47 +08:00
|
|
|
JKQTFPQImagePlot* p4=new JKQTFPQImagePlot(pl2, &img, 0, 10, 0, 10);
|
|
|
|
|
|
|
|
for (int x=0; x<IMAGE_N; x++) {
|
|
|
|
for (int y=0; y<IMAGE_N; y++) {
|
|
|
|
image[y*IMAGE_N+x]=IMAGE_N*(1.1+sin(sqrt((x-50)*(x-50)+(y-50)*(y-50))));
|
|
|
|
if (x>50 && y>50) image[y*IMAGE_N+x]=0;
|
|
|
|
if (x<50 && y<50) image[y*IMAGE_N+x]=50;
|
|
|
|
if (abs(x-(IMAGE_N-y))<4) ovrl[y*IMAGE_N+x]=true; else ovrl[y*IMAGE_N+x]=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTFPimagePlot* p5=new JKQTFPimagePlot(pl3, image, JKQTFP_double, IMAGE_N, IMAGE_N, 0, 10, 0, 10, JKQTFP_GRAY);
|
|
|
|
QColor col=QColor("red");
|
|
|
|
col.setAlpha(127);
|
|
|
|
JKQTFPimageOverlayPlot* p5o=new JKQTFPimageOverlayPlot(pl3, ovrl, IMAGE_N, IMAGE_N, 0, 10, 0, 10, col);
|
|
|
|
JKQTFPXRangePlot* p6=new JKQTFPXRangePlot(pl1, 2.25, 7.75);
|
2019-01-26 20:00:40 +08:00
|
|
|
p6->setFillStyle(Qt::SolidPattern);
|
2018-12-29 00:46:47 +08:00
|
|
|
JKQTFPQScaleBarXPlot* sb=new JKQTFPQScaleBarXPlot(pl1, 1, QString("%1 mm"));
|
|
|
|
|
|
|
|
pl1->addPlot(p6);
|
|
|
|
pl1->addPlot(p1);
|
|
|
|
pl1->addPlot(p2);
|
|
|
|
pl1->addPlot(p3);
|
|
|
|
pl1->addPlot(pv);
|
|
|
|
pl1->addPlot(sb);
|
|
|
|
|
|
|
|
pl2->addPlot(p4);
|
|
|
|
|
|
|
|
pl3->addPlot(p5);
|
|
|
|
pl3->addPlot(p5o);
|
|
|
|
pl3->setObjectName("pl3");
|
|
|
|
|
|
|
|
QComboBox* spin=new QComboBox(w);
|
|
|
|
spin->addItems(JKQTFPimagePlot_getPalettes());
|
|
|
|
gl->addWidget(spin, 2,0);
|
2019-01-26 20:00:40 +08:00
|
|
|
connect(spin, SIGNAL(currentIndexChanged(int)), p5, SLOT(setPalette(int)));
|
2018-12-29 00:46:47 +08:00
|
|
|
QComboBox* scale=new QComboBox(w);
|
|
|
|
scale->addItem("TopLeft");
|
|
|
|
scale->addItem("TopRight");
|
|
|
|
scale->addItem("BottomLeft");
|
|
|
|
scale->addItem("BottomRight");
|
|
|
|
gl->addWidget(scale, 3,0);
|
2019-01-26 20:00:40 +08:00
|
|
|
connect(scale, SIGNAL(currentIndexChanged(int)), sb, SLOT(setPosition(int)));
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
t->addTab(w, tr("Basic Test"));
|
|
|
|
|
|
|
|
|
|
|
|
w=new QWidget(this);
|
|
|
|
gl=new QGridLayout(w);
|
|
|
|
w->setLayout(gl);
|
|
|
|
JKQTFastPlotter* p21=new JKQTFastPlotter(w);
|
|
|
|
gl->addWidget(p21, 0, 0, 1, 3);
|
|
|
|
for (int x=0; x<IMAGE_N; x++) {
|
|
|
|
for (int y=0; y<IMAGE_N; y++) {
|
|
|
|
imageRed[y*IMAGE_N+x]=(fabs(x)+fabs(y))/2.0;
|
|
|
|
imageGreen[y*IMAGE_N+x]=(fabs(double(IMAGE_N)-x)+fabs(y))/2.0;
|
|
|
|
imageBlue[y*IMAGE_N+x]=sqrt(x*x+y*y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prgb=new JKQTFPRGBImageOverlayPlot(p21);
|
2019-01-26 20:00:40 +08:00
|
|
|
prgb->setImage(imageRed, JKQTFP_double, imageGreen, JKQTFP_double, imageBlue, JKQTFP_double, IMAGE_N, IMAGE_N,0,10,0,10);
|
2018-12-29 00:46:47 +08:00
|
|
|
p21->addPlot(prgb);
|
|
|
|
|
|
|
|
QCheckBox* c=new QCheckBox(tr("red channel"), w);
|
|
|
|
c->setChecked(true);
|
|
|
|
connect(c, SIGNAL(toggled(bool)), this, SLOT(enableRed(bool)));
|
|
|
|
gl->addWidget(c, 1,0);
|
|
|
|
|
|
|
|
c=new QCheckBox(tr("green channel"), w);
|
|
|
|
c->setChecked(true);
|
|
|
|
connect(c, SIGNAL(toggled(bool)), this, SLOT(enableGreen(bool)));
|
|
|
|
gl->addWidget(c, 1,1);
|
|
|
|
|
|
|
|
c=new QCheckBox(tr("blue channel"), w);
|
|
|
|
c->setChecked(true);
|
|
|
|
connect(c, SIGNAL(toggled(bool)), this, SLOT(enableBlue(bool)));
|
|
|
|
gl->addWidget(c, 1,2);
|
|
|
|
|
|
|
|
|
|
|
|
t->addTab(w, tr("Overlay Test"));
|
|
|
|
t->setCurrentIndex(1);
|
|
|
|
|
|
|
|
resize(500,400);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TestMain::~TestMain() {
|
|
|
|
free(imageRed);
|
|
|
|
free(imageGreen);
|
|
|
|
free(imageBlue);
|
|
|
|
free(image);
|
|
|
|
free(ovrl);
|
|
|
|
free(x);
|
|
|
|
free(y1);
|
|
|
|
free(y2);
|
|
|
|
free(y3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestMain::enableRed(bool enabled) {
|
|
|
|
if (enabled) {
|
2019-01-26 20:00:40 +08:00
|
|
|
prgb->setImageRed(imageRed, JKQTFP_double);
|
2018-12-29 00:46:47 +08:00
|
|
|
} else {
|
2019-01-26 20:00:40 +08:00
|
|
|
prgb->setImageRed(NULL, JKQTFP_double);
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestMain::enableGreen(bool enabled) {
|
|
|
|
if (enabled) {
|
2019-01-26 20:00:40 +08:00
|
|
|
prgb->setImageGreen(imageGreen, JKQTFP_double);
|
2018-12-29 00:46:47 +08:00
|
|
|
} else {
|
2019-01-26 20:00:40 +08:00
|
|
|
prgb->setImageGreen(NULL, JKQTFP_double);
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestMain::enableBlue(bool enabled) {
|
|
|
|
if (enabled) {
|
2019-01-26 20:00:40 +08:00
|
|
|
prgb->setImageBlue(imageBlue, JKQTFP_double);
|
2018-12-29 00:46:47 +08:00
|
|
|
} else {
|
2019-01-26 20:00:40 +08:00
|
|
|
prgb->setImageBlue(NULL, JKQTFP_double);
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
}
|