2018-12-29 00:46:47 +08:00
|
|
|
#include "TestWidgetImages.h"
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDate>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QApplication>
|
|
|
|
#include "jkqtplottergui/jkqtpcomboboxes.h"
|
2019-02-08 00:24:46 +08:00
|
|
|
#include "jkqtplotter/jkqtpgraphsimageoverlays.h"
|
|
|
|
#include "jkqtplotter/jkqtpgraphsimagergb.h"
|
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TestWidgetImages::TestWidgetImages(QWidget *parent) :
|
|
|
|
QWidget(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
QVBoxLayout* layouti=new QVBoxLayout(this);
|
|
|
|
QFormLayout* layWid=new QFormLayout;
|
|
|
|
layouti->addLayout(layWid);
|
|
|
|
setLayout(layouti);
|
|
|
|
resize(1000, 800);
|
2019-01-20 23:15:10 +08:00
|
|
|
plotImg=new JKQTPlotter(true, this);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImg->setPlotUpdateEnabled(false);
|
|
|
|
plotImg->getPlotter()->setPlotLabel(tr("\\textbf{image plot}"));
|
2018-12-29 00:46:47 +08:00
|
|
|
plotImg->setObjectName("plotImg");
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImg->getPlotter()->setUserSettigsFilename(QApplication::applicationDirPath()+"/usersettings.ini", "plot_img/");
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImg->getPlotter()->setMaintainAspectRatio(true);
|
|
|
|
plotImg->getPlotter()->setAspectRatio(3.0/2.0);
|
|
|
|
plotImg->getPlotter()->setMaintainAxisAspectRatio(true);
|
|
|
|
plotImg->getPlotter()->setAxisAspectRatio(4.0);
|
2019-01-26 20:00:40 +08:00
|
|
|
/*plotImg->getPlotter()->getXAxis()->setLinkedAxis(plotImg->getPlotter()->getYAxis());
|
|
|
|
plotImg->getPlotter()->getXAxis()->setChangeWidthToAspectRatio(true);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImg->getPlotter()->getXAxis()->setAspectRatio(1.0);*/
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
layouti->addWidget(plotImg);
|
|
|
|
plotImg->setXY(0,30,0,20);
|
|
|
|
plotImg->setAbsoluteXY(0,30,0,20);
|
|
|
|
img1=QImage(":/lena.png");
|
2019-01-26 03:16:04 +08:00
|
|
|
JKQTPImage* pimg1=new JKQTPImage(0,0,10,20, &img1, plotImg->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
pimg1->setTitle("LENA");
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImg->getPlotter()->addGraph(pimg1);
|
2018-12-29 00:46:47 +08:00
|
|
|
double* img2=(double*)calloc(100*100,sizeof(double));
|
|
|
|
int32_t* img2M=(int32_t*)calloc(100*100,sizeof(int32_t));
|
|
|
|
bool* bimg2=(bool*)calloc(100*100,sizeof(bool));
|
|
|
|
for (int x=0; x<100; x++) {
|
|
|
|
for (int y=0; y<100; y++) {
|
|
|
|
img2[y*100+x]=sin(2*M_PI*sqrt(1.0+x*x+y*y)/20);
|
|
|
|
img2M[y*100+x]=abs(y-x);
|
|
|
|
bimg2[y*100+x]=static_cast<double>(rand())/static_cast<double>(RAND_MAX)>0.9;
|
|
|
|
}
|
|
|
|
}
|
2019-01-26 03:16:04 +08:00
|
|
|
pimg2=new JKQTPMathImage(10,0,10,10, JKQTPMathImageBase::DoubleArray, img2, 100, 100, JKQTPMathImageGRAY, plotImg->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
pimg2->setImageMin(-1);
|
|
|
|
pimg2->setImageMax(0.5);
|
|
|
|
pimg2->setImageName("left image");
|
|
|
|
pimg2->setTitle("left image");
|
|
|
|
pimg2->setAutoImageRange(false);
|
|
|
|
pimg2->setColorBarTopVisible(true);
|
|
|
|
pimg2->setColorBarRightVisible(false);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImg->getPlotter()->addGraph(pimg2);
|
|
|
|
pimg3=new JKQTPMathImage(20,0,10,10, JKQTPMathImageBase::DoubleArray, img2, 100, 100, JKQTPMathImageMATLAB, plotImg->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
pimg3->setColorBarTopVisible(true);
|
|
|
|
pimg3->setColorBarRightVisible(true);
|
|
|
|
pimg3->setImageMax(0.5);
|
|
|
|
pimg3->setRangeMaxFailAction(JKQTPMathImageGivenColor);
|
|
|
|
pimg3->setRangeMaxFailColor(QColor("salmon"));
|
|
|
|
pimg3->setImageMin(-0.3);
|
|
|
|
pimg3->setRangeMinFailAction(JKQTPMathImageTransparent);
|
|
|
|
pimg3->setAutoImageRange(false);
|
|
|
|
pimg3->setImageName("I(x,y)=\\sin\\left(\\frac{2\\pi\\cdot\\sqrt{1+x^2+y^2}}{20}\\right)");
|
|
|
|
pimg3->setDataModifier(img2M, JKQTPMathImageBase::Int32Array);
|
|
|
|
pimg3->setModifierMode(JKQTPMathImageBase::ModifyNone);
|
|
|
|
pimg3->setTitle("right image");
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImg->getPlotter()->addGraph(pimg3);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
QColor ty=QColor("blue");
|
|
|
|
ty.setAlphaF(0.1);
|
2019-01-26 03:16:04 +08:00
|
|
|
JKQTPOverlayImage* oimg1=new JKQTPOverlayImage(10,0,10,10, bimg2, 100, 100, QColor("blue"), plotImg->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
oimg1->setTitle("overlay");
|
|
|
|
oimg1->setFalseColor(ty);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImg->getPlotter()->addGraph(oimg1);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
JKQTPOverlayImageEnhanced* oimg2=new JKQTPOverlayImageEnhanced(10,0,10,10, bimg2, 100, 100, QColor("red"), plotImg->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
oimg2->setTitle("enhanced overlay");
|
|
|
|
oimg2->setDrawAsRectangles(false);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImg->getPlotter()->addGraph(oimg2);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImg->setPlotUpdateEnabled(true);
|
2018-12-29 00:46:47 +08:00
|
|
|
plotImg->zoomToFit();
|
|
|
|
|
|
|
|
JKQTPMathImageColorPaletteComboBox* cmbPal=new JKQTPMathImageColorPaletteComboBox(this);
|
|
|
|
layWid->addRow("left image palette", cmbPal);
|
|
|
|
connect(cmbPal, SIGNAL(currentIndexChanged(int)), this, SLOT(setImgPalette1(int)));
|
|
|
|
cmbPal=new JKQTPMathImageColorPaletteComboBox(this);
|
|
|
|
layWid->addRow("right image palette", cmbPal);
|
|
|
|
connect(cmbPal, SIGNAL(currentIndexChanged(int)), this, SLOT(setImgPalette(int)));
|
|
|
|
QComboBox* cmb=new QComboBox(this);
|
|
|
|
layWid->addRow("image modifier mode", cmb);
|
|
|
|
cmb->addItem("none");
|
|
|
|
cmb->addItem("value");
|
|
|
|
cmb->addItem("lightness");
|
|
|
|
cmb->addItem("alpha");
|
|
|
|
connect(cmb, SIGNAL(currentIndexChanged(int)), this, SLOT(setImgModifier(int)));
|
|
|
|
cmb->setCurrentIndex(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TestWidgetImages::setImgPalette(int index)
|
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
pimg3->setPalette(index);
|
2019-01-26 19:28:44 +08:00
|
|
|
plotImg->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWidgetImages::setImgPalette1(int index)
|
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
pimg2->setPalette(index);
|
2019-01-26 19:28:44 +08:00
|
|
|
plotImg->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWidgetImages::setImgModifier(int index)
|
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
pimg3->setModifierMode(JKQTPMathImage::ModifierMode(index));
|
2019-01-26 19:28:44 +08:00
|
|
|
plotImg->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|