2018-12-29 00:46:47 +08:00
|
|
|
#include "TestWidgetRGBImages.h"
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDate>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TestWidgetRGBImages::TestWidgetRGBImages(QWidget *parent) :
|
|
|
|
QWidget(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
// plotter for images
|
|
|
|
QWidget* winrgb=new QWidget(this);
|
|
|
|
QVBoxLayout* layoutrgb=new QVBoxLayout(this);
|
|
|
|
QFormLayout* frm=new QFormLayout(nullptr);
|
|
|
|
winrgb->setLayout(layoutrgb);
|
|
|
|
winrgb->resize(1000, 800);
|
2019-01-20 23:15:10 +08:00
|
|
|
plotImgRGB=new JKQTPlotter(true, winrgb);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImgRGB->setPlotUpdateEnabled(false);
|
|
|
|
plotImgRGB->getPlotter()->setPlotLabel(tr("\\textbf{RGB image plot}"));
|
2018-12-29 00:46:47 +08:00
|
|
|
plotImgRGB->setObjectName("plotImgRGB");
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImgRGB->getPlotter()->setUserSettigsFilename(QApplication::applicationDirPath()+"/usersettings.ini", "plot_img_rgb/");
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
/*plotImgRGB->getPlotter()->setMaintainAspectRatio(true);
|
|
|
|
plotImgRGB->getPlotter()->setAspectRatio(1.0);
|
|
|
|
plotImgRGB->getPlotter()->setMaintainAxisAspectRatio(true);
|
|
|
|
plotImgRGB->getPlotter()->setAxisAspectRatio(1.0);*/
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
QCheckBox* chkColorbars=new QCheckBox(tr("color bars share space"), winrgb);
|
|
|
|
chkColorbars->setChecked(true);
|
|
|
|
connect(chkColorbars, SIGNAL(toggled(bool)), this, SLOT(setRGBColorBars(bool)));
|
|
|
|
layoutrgb->addWidget(chkColorbars);
|
|
|
|
layoutrgb->addLayout(frm);
|
|
|
|
layoutrgb->addWidget(plotImgRGB);
|
|
|
|
plotImgRGB->setXY(0,100,0,100);
|
|
|
|
plotImgRGB->setAbsoluteXY(0,100,0,100);
|
|
|
|
|
|
|
|
rgb_rimg2=(double*)calloc(100*100,sizeof(double));
|
|
|
|
rgb_bimg2=(double*)calloc(100*100,sizeof(double));
|
|
|
|
rgb_gimg2=(double*)calloc(100*100,sizeof(double));
|
|
|
|
rgb_aimg2=(double*)calloc(100*100,sizeof(double));
|
|
|
|
for (int x=0; x<100; x++) {
|
|
|
|
for (int y=0; y<100; y++) {
|
|
|
|
rgb_rimg2[y*100+x]=sin(2*M_PI*sqrt(1.0+x*x+y*y)/20);
|
|
|
|
rgb_bimg2[y*100+x]=sin(2*M_PI*sqrt(1.0+x*x+y*y)/30);
|
|
|
|
rgb_gimg2[y*100+x]=cos(2*M_PI*sqrt(1.0+x*x+y*y)/30);
|
|
|
|
rgb_aimg2[y*100+x]=double(x)/100.0;
|
|
|
|
}
|
|
|
|
}
|
2019-01-26 03:16:04 +08:00
|
|
|
rgbimg=new JKQTPRGBMathImage(0,0,10,10, JKQTPMathImageBase::DoubleArray, rgb_rimg2, 100, 100, plotImgRGB->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setImageMin(-1);
|
|
|
|
rgbimg->setImageMax(0.5);
|
|
|
|
rgbimg->setImageMinB(-1);
|
|
|
|
rgbimg->setImageMaxB(0.5);
|
|
|
|
rgbimg->setImageName("R image");
|
|
|
|
rgbimg->setImageNameG("G image");
|
|
|
|
rgbimg->setImageNameB("B image");
|
|
|
|
rgbimg->setData(rgb_rimg2, rgb_gimg2, rgb_bimg2, 100, 100, JKQTPMathImageBase::DoubleArray);
|
|
|
|
rgbimg->setDataModifier(rgb_aimg2, JKQTPMathImageBase::DoubleArray);
|
|
|
|
rgbimg->setModifierMode(JKQTPMathImageBase::ModifyNone);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImgRGB->getPlotter()->addGraph(rgbimg);
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setAutoImageRange(false);
|
|
|
|
rgbimg->setColorBarTopVisible(true);
|
|
|
|
rgbimg->setColorBarRightVisible(true);
|
|
|
|
rgbimg->setColorbarsSideBySide(chkColorbars->isChecked());
|
2019-01-26 03:16:04 +08:00
|
|
|
rgbimg2=new JKQTPColumnRGBMathImage(10,0,10,10,100,100, plotImgRGB->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg2->setImageMin(-1);
|
|
|
|
rgbimg2->setImageMax(0.5);
|
|
|
|
rgbimg2->setImageMinB(-1);
|
|
|
|
rgbimg2->setImageMaxB(0.5);
|
|
|
|
rgbimg2->setImageName("R image");
|
|
|
|
rgbimg2->setImageNameG("G image");
|
|
|
|
rgbimg2->setImageNameB("B image");
|
|
|
|
rgbimg2->setNx(100);
|
|
|
|
rgbimg2->setNy(100);
|
|
|
|
rgbimg2->setImageRColumn(rgb_colr=plotImgRGB->getDatastore()->addCopiedColumn(rgb_bimg2, 100*100, "R"));
|
|
|
|
rgbimg2->setImageGColumn(rgb_colg=plotImgRGB->getDatastore()->addCopiedColumn(rgb_gimg2, 100*100, "G"));
|
|
|
|
rgbimg2->setImageBColumn(rgb_colb=plotImgRGB->getDatastore()->addCopiedColumn(rgb_rimg2, 100*100, "B"));
|
|
|
|
rgbimg2->setModifierColumn(rgb_cola=plotImgRGB->getDatastore()->addCopiedColumn(rgb_aimg2, 100*100, "alpha"));
|
|
|
|
rgbimg2->setModifierMode(JKQTPMathImageBase::ModifyNone);
|
|
|
|
//rgbimg2->setData(rgb_rimg2, rgb_gimg2, rgb_bimg2, 100, 100, JKQTPMathImageBase::DoubleArray);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImgRGB->getPlotter()->addGraph(rgbimg2);
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg2->setAutoImageRange(true);
|
|
|
|
rgbimg2->setColorBarTopVisible(true);
|
|
|
|
rgbimg2->setColorBarRightVisible(true);
|
|
|
|
rgbimg2->setColorbarsSideBySide(chkColorbars->isChecked());
|
2018-12-29 00:46:47 +08:00
|
|
|
plotImgRGB->setAbsoluteXY(0,20,0,10);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotImgRGB->setPlotUpdateEnabled(true);
|
2018-12-29 00:46:47 +08:00
|
|
|
//plotImgRGB->zoomToFit();
|
|
|
|
plotImgRGB->setXY(0,20,0,10);
|
|
|
|
|
|
|
|
QComboBox* cmb=new QComboBox(winrgb);
|
|
|
|
frm->addRow(tr("mode 1:"), cmb);
|
|
|
|
cmb->addItem("RGB");
|
|
|
|
cmb->addItem("HSV");
|
|
|
|
cmb->addItem("HSL");
|
|
|
|
cmb->addItem("CMY");
|
|
|
|
cmb->setCurrentIndex(0);
|
|
|
|
connect(cmb, SIGNAL(currentIndexChanged(int)), this, SLOT(setRGBMode1(int)));
|
|
|
|
|
|
|
|
cmb=new QComboBox(winrgb);
|
|
|
|
frm->addRow(tr("mode 2:"), cmb);
|
|
|
|
cmb->addItem("RGB");
|
|
|
|
cmb->addItem("HSV");
|
|
|
|
cmb->addItem("HSL");
|
|
|
|
cmb->addItem("CMY");
|
|
|
|
connect(cmb, SIGNAL(currentIndexChanged(int)), this, SLOT(setRGBMode2(int)));
|
|
|
|
cmb->setCurrentIndex(1);
|
|
|
|
|
|
|
|
cmb=new QComboBox(winrgb);
|
|
|
|
frm->addRow(tr("modifier channel mode:"), cmb);
|
|
|
|
cmb->addItem("none");
|
|
|
|
cmb->addItem("value");
|
|
|
|
cmb->addItem("lightness");
|
|
|
|
cmb->addItem("alpha");
|
|
|
|
connect(cmb, SIGNAL(currentIndexChanged(int)), this, SLOT(setRGBModifier(int)));
|
|
|
|
cmb->setCurrentIndex(0);
|
|
|
|
|
|
|
|
QHBoxLayout* hblrgb=new QHBoxLayout();
|
|
|
|
frm->addRow(tr("use channels:"), hblrgb);
|
|
|
|
|
|
|
|
chkRGBUseR=new QCheckBox(tr("red"), winrgb);
|
|
|
|
hblrgb->addWidget(chkRGBUseR);
|
|
|
|
chkRGBUseR->setChecked(true);
|
|
|
|
connect(chkRGBUseR, SIGNAL(toggled(bool)), this, SLOT(updateRGBChannels()));
|
|
|
|
|
|
|
|
chkRGBUseG=new QCheckBox(tr("green"), winrgb);
|
|
|
|
hblrgb->addWidget(chkRGBUseG);
|
|
|
|
chkRGBUseG->setChecked(true);
|
|
|
|
connect(chkRGBUseG, SIGNAL(toggled(bool)), this, SLOT(updateRGBChannels()));
|
|
|
|
|
|
|
|
chkRGBUseB=new QCheckBox(tr("blue"), winrgb);
|
|
|
|
hblrgb->addWidget(chkRGBUseB);
|
|
|
|
chkRGBUseB->setChecked(true);
|
|
|
|
connect(chkRGBUseB, SIGNAL(toggled(bool)), this, SLOT(updateRGBChannels()));
|
|
|
|
|
|
|
|
chkRGBUseA=new QCheckBox(tr("alpha"), winrgb);
|
|
|
|
hblrgb->addWidget(chkRGBUseA);
|
|
|
|
chkRGBUseB->setChecked(false);
|
|
|
|
connect(chkRGBUseB, SIGNAL(toggled(bool)), this, SLOT(updateRGBChannels()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWidgetRGBImages::setRGBColorBars(bool checked)
|
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setColorbarsSideBySide(checked);
|
|
|
|
rgbimg2->setColorbarsSideBySide(checked);
|
2019-01-26 19:28:44 +08:00
|
|
|
plotImgRGB->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWidgetRGBImages::setRGBMode1(int mode)
|
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setRgbMode((JKQTPRGBMathImageRGBMode)mode);
|
2019-01-26 19:28:44 +08:00
|
|
|
plotImgRGB->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWidgetRGBImages::setRGBMode2(int mode)
|
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg2->setRgbMode((JKQTPRGBMathImageRGBMode)mode);
|
2019-01-26 19:28:44 +08:00
|
|
|
plotImgRGB->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWidgetRGBImages::updateRGBChannels()
|
|
|
|
{
|
|
|
|
if (chkRGBUseR->isChecked()) {
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setData(rgb_rimg2, 100, 100);
|
|
|
|
rgbimg2->setImageRColumn(rgb_colr);
|
2018-12-29 00:46:47 +08:00
|
|
|
} else {
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setData(nullptr, 100, 100);
|
|
|
|
rgbimg2->setImageRColumn(-1);
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
if (chkRGBUseG->isChecked()) {
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setDataG(rgb_gimg2);
|
|
|
|
rgbimg2->setImageGColumn(rgb_colg);
|
2018-12-29 00:46:47 +08:00
|
|
|
} else {
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setDataG(nullptr);
|
|
|
|
rgbimg2->setImageGColumn(-1);
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
if (chkRGBUseB->isChecked()) {
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setDataB(rgb_bimg2);
|
|
|
|
rgbimg2->setImageBColumn(rgb_colb);
|
2018-12-29 00:46:47 +08:00
|
|
|
} else {
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setDataB(nullptr);
|
|
|
|
rgbimg2->setImageBColumn(-1);
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
2019-01-26 19:28:44 +08:00
|
|
|
plotImgRGB->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWidgetRGBImages::setRGBModifier(int item)
|
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
rgbimg->setModifierMode(JKQTPMathImage::ModifierMode(item));
|
|
|
|
rgbimg2->setModifierMode(JKQTPMathImage::ModifierMode(item));
|
2019-01-26 19:28:44 +08:00
|
|
|
plotImgRGB->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
|