/*
Copyright (c) 2008-2019 Jan W. Krieger
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
the Free Software Foundation, either version 2.1 of the License, or
(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 .
*/
#include "jkqtplotter/jkqtpgraphsimagergb.h"
#include "jkqtplotter/jkqtpbaseplotter.h"
#include "jkqtplottertools/jkqtpimagetools.h"
#include "jkqtplottertools/jkqtptools.h"
#include "jkqtplottertools/jkqtpenhancedpainter.h"
#include "jkqtplotter/jkqtplotter.h"
#include
#include
#include
#include
#include
#include
void JKQTPRGBMathImage::initObject()
{
actSaveImage=new QAction(tr("Save JKQTPRGBMathImage ..."), this);
connect(actSaveImage, SIGNAL(triggered()), this, SLOT(saveImagePlotAsImage()));
actCopyImage=new QAction(tr("Copy JKQTPRGBMathImage ..."), this);
connect(actCopyImage, SIGNAL(triggered()), this, SLOT(copyImagePlotAsImage()));
rgbMode=JKQTPRGBMathImageModeRGBMode;
colorBarRightAxis=new JKQTPVerticalIndependentAxis(0, 100, 0, 100, parent);
colorBarRightAxis->setDrawMode1(JKQTPCADMLine);
colorBarRightAxis->setDrawMode2(JKQTPCADMcomplete);
colorBarRightAxis->setAxisLabel("");
colorBarRightAxis->setMinTicks(5);
colorBarRightAxis->setMinorTicks(0);
colorBarRightAxis->setTickOutsideLength(0);
colorBarRightAxis->setMinorTickOutsideLength(0);
colorBarRightAxis->setShowZeroAxis(false);
colorBarTopAxis=new JKQTPHorizontalIndependentAxis(0, 100, 0, 100, parent);
colorBarTopAxis->setDrawMode1(JKQTPCADMLine);
colorBarTopAxis->setDrawMode2(JKQTPCADMcomplete);
colorBarTopAxis->setAxisLabel("");
colorBarTopAxis->setMinTicks(3);
colorBarTopAxis->setMinorTicks(0);
colorBarTopAxis->setTickOutsideLength(0);
colorBarTopAxis->setMinorTickOutsideLength(0);
colorBarTopAxis->setShowZeroAxis(false);
colorBarRightAxisG=new JKQTPVerticalIndependentAxis(0, 100, 0, 100, parent);
colorBarRightAxisG->setDrawMode1(JKQTPCADMLine);
colorBarRightAxisG->setDrawMode2(JKQTPCADMcomplete);
colorBarRightAxisG->setAxisLabel("");
colorBarRightAxisG->setMinTicks(5);
colorBarRightAxisG->setShowZeroAxis(false);
colorBarRightAxisG->setMinorTicks(0);
colorBarRightAxisG->setTickOutsideLength(0);
colorBarRightAxisG->setMinorTickOutsideLength(0);
colorBarTopAxisG=new JKQTPHorizontalIndependentAxis(0, 100, 0, 100, parent);
colorBarTopAxisG->setDrawMode1(JKQTPCADMLine);
colorBarTopAxisG->setDrawMode2(JKQTPCADMcomplete);
colorBarTopAxisG->setAxisLabel("");
colorBarTopAxisG->setMinTicks(3);
colorBarTopAxisG->setShowZeroAxis(false);
colorBarTopAxisG->setMinorTicks(0);
colorBarTopAxisG->setTickOutsideLength(0);
colorBarTopAxisG->setMinorTickOutsideLength(0);
colorBarRightAxisB=new JKQTPVerticalIndependentAxis(0, 100, 0, 100, parent);
colorBarRightAxisB->setDrawMode1(JKQTPCADMLine);
colorBarRightAxisB->setDrawMode2(JKQTPCADMcomplete);
colorBarRightAxisB->setAxisLabel("");
colorBarRightAxisB->setMinTicks(5);
colorBarRightAxisB->setShowZeroAxis(false);
colorBarRightAxisB->setMinorTicks(0);
colorBarRightAxisB->setTickOutsideLength(0);
colorBarRightAxisB->setMinorTickOutsideLength(0);
colorBarTopAxisB=new JKQTPHorizontalIndependentAxis(0, 100, 0, 100, parent);
colorBarTopAxisB->setDrawMode1(JKQTPCADMLine);
colorBarTopAxisB->setDrawMode2(JKQTPCADMcomplete);
colorBarTopAxisB->setAxisLabel("");
colorBarTopAxisB->setMinTicks(3);
colorBarTopAxisB->setShowZeroAxis(false);
colorBarTopAxisB->setMinorTicks(0);
colorBarTopAxisB->setTickOutsideLength(0);
colorBarTopAxisB->setMinorTickOutsideLength(0);
this->colorBarTopVisible=true;
this->colorBarRightVisible=true;
this->imageNameFontSize=parent->getKeyFontSize();
this->imageName="";
this->showColorBar=true;
this->colorBarWidth=14;
this->colorBarRelativeHeight=0.75;
this->autoImageRange=true;
this->imageMin=0;
this->imageMax=1;
this->imageMinG=0;
this->imageMaxG=1;
this->imageMinB=0;
this->imageMaxB=1;
this->colorBarOffset=4;
this->colorBarTopVisible=false;
this->colorBarRightVisible=true;
this->colorbarsSideBySide=true;
}
JKQTPRGBMathImage::JKQTPRGBMathImage(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTBasePlotter *parent):
JKQTPMathImageBase(x, y, width, height, datatype, data, Nx, Ny, parent)
{
initObject();
}
JKQTPRGBMathImage::JKQTPRGBMathImage(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTPlotter *parent):
JKQTPMathImageBase(x, y, width, height, datatype, data, Nx, Ny, parent)
{
initObject();
}
JKQTPRGBMathImage::JKQTPRGBMathImage(JKQTBasePlotter *parent):
JKQTPMathImageBase(0,0,0,0, DoubleArray, nullptr, 0, 0, parent)
{
initObject();
}
JKQTPRGBMathImage::JKQTPRGBMathImage(JKQTPlotter *parent):
JKQTPMathImageBase(0,0,0,0, DoubleArray, nullptr, 0, 0, parent)
{
initObject();
}
void JKQTPRGBMathImage::setParent(JKQTBasePlotter* parent) {
if (this->parent) {
this->parent->deregisterAdditionalAction(actSaveImage);
this->parent->deregisterAdditionalAction(actCopyImage);
}
JKQTPMathImageBase::setParent(parent);
colorBarRightAxis->setParent(parent);
colorBarTopAxis->setParent(parent);
if (parent) {
parent->registerAdditionalAction(tr("Save Image Plot Images ..."), actSaveImage);
parent->registerAdditionalAction(tr("Copy Image Plot Images ..."), actCopyImage);
}
actSaveImage->setEnabled(parent);
actCopyImage->setEnabled(parent);
}
void JKQTPRGBMathImage::draw(JKQTPEnhancedPainter& painter) {
ensureImageData();
if (!data && !dataG && !dataB) return;
QImage img=drawImage();
plotImage(painter, img, x, y, width, height);
}
void JKQTPRGBMathImage::getOutsideSize(JKQTPEnhancedPainter& painter, int& leftSpace, int& rightSpace, int& topSpace, int& bottomSpace) {
ensureImageData();
JKQTPGraph::getOutsideSize(painter, leftSpace, rightSpace, topSpace, bottomSpace);
if (showColorBar) {
int visibleColorBars=0;
if (data) visibleColorBars++;
if (dataG) visibleColorBars++;
if (dataB) visibleColorBars++;
double sizeFactor=0.8/double(visibleColorBars);
if (!colorbarsSideBySide) sizeFactor=1;
bool firstC=false;
getDataMinMax(internalDataMin, internalDataMax);
if (data) {
if (colorBarRightVisible) {
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarRightAxis->setRange(internalDataMin, internalDataMax);
colorBarRightAxis->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotHeight());
colorBarRightAxisB->setAxisLabel(imageName);
QSizeF s2=colorBarRightAxis->getSize2(painter);
QSizeF s1=colorBarRightAxis->getSize1(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast(s2.width()+s1.width());
}
if (colorBarTopVisible) {
//if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarTopAxis->setRange(internalDataMin, internalDataMax);
colorBarTopAxis->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotWidth());
colorBarTopAxisB->setAxisLabel(imageName);
QSizeF s2=colorBarTopAxisB->getSize2(painter);
QSizeF s1=colorBarTopAxisB->getSize2(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast(s2.height()+s1.height());
}
firstC=true;
}
getDataMinMaxG(internalDataMinG, internalDataMaxG);
if (dataG) {
if (colorBarRightVisible) {
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarRightAxisG->setRange(internalDataMinG, internalDataMaxG);
colorBarRightAxisG->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotHeight());
colorBarRightAxisB->setAxisLabel(imageNameG);
QSizeF s2=colorBarRightAxis->getSize2(painter);
QSizeF s1=colorBarRightAxis->getSize1(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast(s2.width()+s1.width());
}
if (colorBarTopVisible) {
//if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarTopAxisG->setRange(internalDataMinG, internalDataMaxG);
colorBarTopAxisG->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotWidth());
colorBarTopAxisB->setAxisLabel(imageNameG);
QSizeF s2=colorBarTopAxisB->getSize2(painter);
QSizeF s1=colorBarTopAxisB->getSize1(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast(s2.height()+s1.height());
}
firstC=true;
}
getDataMinMaxB(internalDataMinB, internalDataMaxB);
if (dataB) {
if (colorBarRightVisible) {
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarRightAxisB->setRange(internalDataMinB, internalDataMaxB);
colorBarRightAxisB->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotHeight());
colorBarRightAxisB->setAxisLabel(imageNameB);
QSizeF s2=colorBarRightAxis->getSize2(painter);
QSizeF s1=colorBarRightAxis->getSize1(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast(s2.width()+s1.width());
}
if (colorBarTopVisible) {
//if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarTopAxisB->setRange(internalDataMinB, internalDataMaxB);
colorBarTopAxisB->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotWidth());
colorBarTopAxisB->setAxisLabel(imageNameB);
QSizeF s2=colorBarTopAxisB->getSize2(painter);
QSizeF s1=colorBarTopAxisB->getSize1(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast(s2.height()+s1.height());
}
firstC=true;
}
}
}
struct RGBOutsizeData {
double internalDataMin;
double internalDataMax;
void* data;
JKQTPVerticalIndependentAxis* colorBarRightAxis;
JKQTPHorizontalIndependentAxis* colorBarTopAxis;
QString name;
JKQTPMathImageColorPalette palette;
QImage paletteImage;
};
void JKQTPRGBMathImage::drawOutside(JKQTPEnhancedPainter& painter, QRect /*leftSpace*/, QRect rightSpace, QRect topSpace, QRect /*bottomSpace*/) {
ensureImageData();
if (showColorBar) {
QList l;
int visibleColorBars=0;
const int pd_size=200;
uint8_t pd[pd_size];
for (int i=0; i(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
} else if (rgbMode==JKQTPRGBMathImageModeCMYMode) {
d.palette=JKQTPMathImageINVERTED_CYANWHITE;
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
JKQTPImagePlot_array2image(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
} else if (rgbMode==JKQTPRGBMathImageModeHSVMode || rgbMode==JKQTPRGBMathImageModeHSLMode) {
d.palette=JKQTPMathImageHSV;
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
JKQTPImagePlot_array2image(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
}
l<(pd, 1, pd_size, d.paletteImage, d.palette, 0, 199);
if (rgbMode==JKQTPRGBMathImageModeRGBMode) {
d.palette=JKQTPMathImageGREEN;
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
JKQTPImagePlot_array2image(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
} else if (rgbMode==JKQTPRGBMathImageModeCMYMode) {
d.palette=JKQTPMathImageINVERTED_MAGENTAWHITE;
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
JKQTPImagePlot_array2image(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
} else if (rgbMode==JKQTPRGBMathImageModeHSVMode) {
d.palette=JKQTPMathImageGRAY;
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
//JKQTPImagePlot_array2image(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
QRgb* line=reinterpret_cast(d.paletteImage.scanLine(0));
for (int i=0; i(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
QRgb* line=reinterpret_cast(d.paletteImage.scanLine(0));
for (int i=0; i(pd, 1, pd_size, d.paletteImage, d.palette, 0, 199);
if (rgbMode==JKQTPRGBMathImageModeRGBMode) {
d.palette=JKQTPMathImageBLUE;
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
JKQTPImagePlot_array2image(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
} else if (rgbMode==JKQTPRGBMathImageModeCMYMode) {
d.palette=JKQTPMathImageINVERTED_YELLOWWHITE;
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
JKQTPImagePlot_array2image(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
} else if (rgbMode==JKQTPRGBMathImageModeHSVMode) {
d.palette=JKQTPMathImageGRAY;
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
//JKQTPImagePlot_array2image(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
QRgb* line=reinterpret_cast(d.paletteImage.scanLine(0));
for (int i=0; i(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
QRgb* line=reinterpret_cast(d.paletteImage.scanLine(0));
for (int i=0; i(round(static_cast(rightSpace.height())*icolorBarRelativeHeight)));
int gbarWidth=qMax(1, static_cast(round(static_cast(topSpace.width())*icolorBarRelativeHeight)));
double rX=rightSpace.x()+parent->pt2px(painter, colorBarOffset);
double rY=rightSpace.top()+(rightSpace.height()-gbarHeight)/2;
double tX=topSpace.x()+(topSpace.width()-gbarWidth)/2;
double tY=topSpace.bottom()-parent->pt2px(painter, colorBarOffset+colorBarWidth);
if(colorbarsSideBySide) {
rY=rightSpace.top()+(rightSpace.height()-gbarHeight*visibleColorBars)/2;
tX=topSpace.x()+(topSpace.width()-gbarWidth*visibleColorBars)/2;
}
for (int li=0; lipt2px(painter, colorBarWidth), gbarHeight);
painter.drawImage(cb, l[li].paletteImage.mirrored(true, false));
QPen p=painter.pen();
p.setColor(l[li].colorBarRightAxis->getAxisColor());
p.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, l[li].colorBarRightAxis->getLineWidth()*parent->getLineWidthMultiplier())));
painter.setPen(p);
painter.drawRect(cb);
l[li].colorBarRightAxis->setRange(l[li].internalDataMin, l[li].internalDataMax);
l[li].colorBarRightAxis->setAxisWidth(cb.height());
l[li].colorBarRightAxis->setAxisOffset(cb.top());
l[li].colorBarRightAxis->setOtherAxisOffset(cb.left());
l[li].colorBarRightAxis->setOtherAxisWidth(cb.width());
l[li].colorBarRightAxis->setLabelFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
l[li].colorBarRightAxis->setAxisLabel(l[li].name);
l[li].colorBarRightAxis->drawAxes(painter);
if (!colorbarsSideBySide) {
rX=rX+static_cast(rightSpace.width())/static_cast(visibleColorBars);
} else {
rY=rY+static_cast(rightSpace.height())*shiftSizeFactor*colorBarRelativeHeight;
}
}
if (colorBarTopVisible) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
QRect cb(tX, tY, gbarWidth, parent->pt2px(painter, colorBarWidth));
QMatrix mt;
mt.rotate(90);
painter.drawImage(cb, l[li].paletteImage.transformed(mt));
QPen p=painter.pen();
p.setColor(l[li].colorBarTopAxis->getAxisColor());
p.setWidthF(qMax(JKQTPlotterDrawinTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, l[li].colorBarTopAxis->getLineWidth()*parent->getLineWidthMultiplier())));
painter.setPen(p);
painter.drawRect(cb);
l[li].colorBarTopAxis->setRange(l[li].internalDataMin, l[li].internalDataMax);
l[li].colorBarTopAxis->setAxisWidth(cb.width());
l[li].colorBarTopAxis->setAxisOffset(cb.left());
l[li].colorBarTopAxis->setOtherAxisOffset(cb.top());
l[li].colorBarTopAxis->setOtherAxisWidth(cb.height());
l[li].colorBarTopAxis->setLabelFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
l[li].colorBarTopAxis->setAxisLabel(l[li].name);
l[li].colorBarTopAxis->drawAxes(painter);
if (!colorbarsSideBySide) {
tY=tY-topSpace.height()/double(visibleColorBars);
} else {
tX=tX+topSpace.width()*shiftSizeFactor*colorBarRelativeHeight;
}
}
}
}
}
void JKQTPRGBMathImage::getDataMinMax(double& imin, double& imax) {
ensureImageData();
if (autoImageRange) {
JKQTPMathImageBase::getDataMinMax(imin, imax);
} else {
imin=imageMin;
imax=imageMax;
}
}
void JKQTPRGBMathImage::getDataMinMaxG(double& imin, double& imax) {
ensureImageData();
if (autoImageRange) {
imin=imax=0;
if (!dataG) return;
switch(datatype) {
case JKQTPMathImageBase::DoubleArray:
imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny);
break;
case JKQTPMathImageBase::FloatArray:
imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny);
break;
case JKQTPMathImageBase::UInt8Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny);
break;
case JKQTPMathImageBase::UInt16Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny);
break;
case JKQTPMathImageBase::UInt32Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny);
break;
case JKQTPMathImageBase::UInt64Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny);
break;
case JKQTPMathImageBase::Int8Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny);
break;
case JKQTPMathImageBase::Int16Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny);
break;
case JKQTPMathImageBase::Int32Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny);
break;
case JKQTPMathImageBase::Int64Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny);
break;
}
} else {
imin=imageMinG;
imax=imageMaxG;
}
}
void JKQTPRGBMathImage::getDataMinMaxB(double& imin, double& imax) {
ensureImageData();
if (autoImageRange) {
imin=imax=0;
if (!dataG) return;
switch(datatype) {
case JKQTPMathImageBase::DoubleArray:
imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny);
break;
case JKQTPMathImageBase::FloatArray:
imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny);
break;
case JKQTPMathImageBase::UInt8Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny);
break;
case JKQTPMathImageBase::UInt16Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny);
break;
case JKQTPMathImageBase::UInt32Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny);
break;
case JKQTPMathImageBase::UInt64Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny);
break;
case JKQTPMathImageBase::Int8Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny);
break;
case JKQTPMathImageBase::Int16Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny);
break;
case JKQTPMathImageBase::Int32Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny);
break;
case JKQTPMathImageBase::Int64Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny);
break;
}
} else {
imin=imageMinB;
imax=imageMaxB;
}
}
double JKQTPRGBMathImage::getValueAt(double x, double y, int channel)
{
ensureImageData();
void* dd=data;
if (channel==0) dd=data;
if (channel==1) dd=dataG;
if (channel==2) dd=dataB;
int xx=static_cast(trunc((x-this->x)/width*Nx));
int yy=static_cast(trunc((y-this->y)/height*Ny));
if (xx>=0 && xx=0 && yy((static_cast(dd))[yy*Nx+xx]); break;
case JKQTPMathImageBase::FloatArray: return static_cast((static_cast(dd))[yy*Nx+xx]); break;
case JKQTPMathImageBase::UInt8Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break;
case JKQTPMathImageBase::UInt16Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break;
case JKQTPMathImageBase::UInt32Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break;
case JKQTPMathImageBase::UInt64Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break;
case JKQTPMathImageBase::Int8Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break;
case JKQTPMathImageBase::Int16Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break;
case JKQTPMathImageBase::Int32Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break;
case JKQTPMathImageBase::Int64Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break;
} }
return 0.0;
}
void JKQTPRGBMathImage::drawKeyMarker(JKQTPEnhancedPainter &painter, QRectF &rect)
{
painter.drawImage(rect, QPixmap(":/JKQTPlotter/jkqtp_plot_rgbimage.png").toImage());
}
void JKQTPRGBMathImage::setTitle(const QString &title)
{
JKQTPImageBase::setTitle(title);
QString t=title;
if (t.isEmpty()) t="JKQTPRGBMathImage";
actSaveImage->setText(tr("Save %1 ...").arg(t));
actCopyImage->setText(tr("Copy %1 ...").arg(t));
}
void JKQTPRGBMathImage::saveImagePlotAsImage(const QString &filename, const QByteArray &outputFormat)
{
if (parent) {
parent->loadUserSettings();
QString currentSaveDirectory=parent->getCurrentSaveDirectory();
QString currentFileFormat=parent->getCurrentFileFormat();
QString fn=filename;
QStringList filt;
QList writerformats=QImageWriter::supportedImageFormats();
for (int i=0; isetCurrentFileFormat(currentFileFormat);
parent->setCurrentSaveDirectory(currentSaveDirectory);
parent->saveUserSettings();
if (!fn.isEmpty()) {
int filtID=filt.indexOf(selFormat);
QString form="NONE";
if (filtID>=0 && filtID0) {
form =outputFormat;
}
QImage image=drawImage();
if (form=="NONE") image.save(fn);
else image.save(fn, form.toLatin1().data());
}
}
}
void JKQTPRGBMathImage::copyImagePlotAsImage()
{
QClipboard* clip=QApplication::clipboard();
if (clip) {
clip->setPixmap(QPixmap::fromImage(drawImage()));
}
}
QImage JKQTPRGBMathImage::drawImage() {
ensureImageData();
if (!data && !dataG && !dataB) return QImage();
QImage img(Nx, Ny, QImage::Format_ARGB32);
if (rgbMode==JKQTPRGBMathImageModeRGBMode) {
img.fill(Qt::transparent);
} else if (rgbMode==JKQTPRGBMathImageModeCMYMode) {
img.fill(Qt::white);
} else if (rgbMode==JKQTPRGBMathImageModeHSVMode) {
QColor c("white");
c.setHsv(0,255,255);
img.fill(c.rgba());
} else if (rgbMode==JKQTPRGBMathImageModeHSLMode) {
QColor c("white");
c.setHsv(0,255,127);
img.fill(c.rgba());
}
getDataMinMax(internalDataMin, internalDataMax);
getDataMinMaxG(internalDataMinG, internalDataMaxG);
getDataMinMaxB(internalDataMinB, internalDataMaxB);
int palette = 0;
if (data) {
switch(datatype) {
case JKQTPMathImageBase::DoubleArray: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break;
case JKQTPMathImageBase::FloatArray: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break;
case JKQTPMathImageBase::UInt8Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break;
case JKQTPMathImageBase::UInt16Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break;
case JKQTPMathImageBase::UInt32Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break;
case JKQTPMathImageBase::UInt64Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break;
case JKQTPMathImageBase::Int8Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break;
case JKQTPMathImageBase::Int16Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break;
case JKQTPMathImageBase::Int32Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break;
case JKQTPMathImageBase::Int64Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break;
}
}
palette = 1;
if (dataG) {
switch(datatypeG) {
case JKQTPMathImageBase::DoubleArray: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break;
case JKQTPMathImageBase::FloatArray: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break;
case JKQTPMathImageBase::UInt8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break;
case JKQTPMathImageBase::UInt16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break;
case JKQTPMathImageBase::UInt32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break;
case JKQTPMathImageBase::UInt64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break;
case JKQTPMathImageBase::Int8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break;
case JKQTPMathImageBase::Int16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break;
case JKQTPMathImageBase::Int32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break;
case JKQTPMathImageBase::Int64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break;
}
}
palette = 2;
if (dataB) {
switch(datatypeB) {
case JKQTPMathImageBase::DoubleArray: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break;
case JKQTPMathImageBase::FloatArray: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break;
case JKQTPMathImageBase::UInt8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break;
case JKQTPMathImageBase::UInt16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break;
case JKQTPMathImageBase::UInt32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break;
case JKQTPMathImageBase::UInt64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break;
case JKQTPMathImageBase::Int8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break;
case JKQTPMathImageBase::Int16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break;
case JKQTPMathImageBase::Int32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break;
case JKQTPMathImageBase::Int64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break;
}
}
modifyImage(img);
return img;
}
void JKQTPRGBMathImage::setData(void* data, int Nx, int Ny, DataType datatype) {
this->data=data;
this->datatype=datatype;
this->dataG=nullptr;
this->dataB=nullptr;
this->Nx=Nx;
this->Ny=Ny;
}
void JKQTPRGBMathImage::setData(void* data, int Nx, int Ny) {
this->data=data;
this->Nx=Nx;
this->Ny=Ny;
this->dataG=nullptr;
this->dataB=nullptr;
}
void JKQTPRGBMathImage::setData(void *data, void *dataG, void *dataB, int Nx, int Ny, JKQTPMathImageBase::DataType datatype) {
this->data=data;
this->datatype=datatype;
this->datatypeG=datatype;
this->datatypeB=datatype;
this->dataG=dataG;
this->dataB=dataB;
this->Nx=Nx;
this->Ny=Ny;
}
void JKQTPRGBMathImage::setData(void *data, void *dataG, void *dataB, int Nx, int Ny) {
this->data=data;
this->dataG=dataG;
this->dataB=dataB;
this->Nx=Nx;
this->Ny=Ny;
}
JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(JKQTBasePlotter *parent):
JKQTPRGBMathImage(0,0,0,0,DoubleArray,nullptr,0,0,parent)
{
this->modifierColumn=-1;
this->imageRColumn=-1;
this->imageGColumn=-1;
this->imageBColumn=-1;
this->datatype=JKQTPMathImageBase::DoubleArray;
}
JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int Nx, int Ny, JKQTBasePlotter *parent):
JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,Nx,Ny,parent)
{
this->modifierColumn=-1;
this->imageRColumn=-1;
this->imageGColumn=-1;
this->imageBColumn=-1;
this->datatype=JKQTPMathImageBase::DoubleArray;
}
JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int Nx, int Ny, JKQTBasePlotter *parent):
JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,Nx,Ny,parent)
{
this->modifierColumn=-1;
this->imageRColumn=imageRColumn;
this->imageGColumn=-1;
this->imageBColumn=-1;
this->datatype=JKQTPMathImageBase::DoubleArray;
}
JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int imageGColumn, int Nx, int Ny, JKQTBasePlotter *parent):
JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,Nx,Ny,parent)
{
this->modifierColumn=-1;
this->imageRColumn=imageRColumn;
this->imageGColumn=imageGColumn;
this->imageBColumn=-1;
this->datatype=JKQTPMathImageBase::DoubleArray;
}
JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int imageGColumn, int imageBColumn, int Nx, int Ny, JKQTBasePlotter *parent):
JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,Nx,Ny,parent)
{
this->modifierColumn=-1;
this->imageRColumn=imageRColumn;
this->imageGColumn=imageGColumn;
this->imageBColumn=imageBColumn;
this->datatype=JKQTPMathImageBase::DoubleArray;
}
JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(JKQTPlotter *parent):
JKQTPRGBMathImage(0,0,0,0,DoubleArray,nullptr,0,0,parent)
{
this->modifierColumn=-1;
this->imageRColumn=-1;
this->imageGColumn=-1;
this->imageBColumn=-1;
this->datatype=JKQTPMathImageBase::DoubleArray;
}
JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int Nx, int Ny, JKQTPlotter *parent):
JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,Nx,Ny,parent)
{
this->modifierColumn=-1;
this->imageRColumn=-1;
this->imageGColumn=-1;
this->imageBColumn=-1;
this->datatype=JKQTPMathImageBase::DoubleArray;
}
JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int Nx, int Ny, JKQTPlotter *parent):
JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,Nx,Ny,parent)
{
this->modifierColumn=-1;
this->imageRColumn=imageRColumn;
this->imageGColumn=-1;
this->imageBColumn=-1;
this->datatype=JKQTPMathImageBase::DoubleArray;
}
JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int imageGColumn, int Nx, int Ny, JKQTPlotter *parent):
JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,Nx,Ny,parent)
{
this->modifierColumn=-1;
this->imageRColumn=imageRColumn;
this->imageGColumn=imageGColumn;
this->imageBColumn=-1;
this->datatype=JKQTPMathImageBase::DoubleArray;
}
JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int imageGColumn, int imageBColumn, int Nx, int Ny, JKQTPlotter *parent):
JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,Nx,Ny,parent)
{
this->modifierColumn=-1;
this->imageRColumn=imageRColumn;
this->imageGColumn=imageGColumn;
this->imageBColumn=imageBColumn;
this->datatype=JKQTPMathImageBase::DoubleArray;
}
bool JKQTPColumnRGBMathImage::usesColumn(int c) const
{
return (c==imageRColumn)||(c==imageBColumn)||(c==imageGColumn)||(c==modifierColumn);
}
void JKQTPColumnRGBMathImage::ensureImageData()
{
this->datatype=JKQTPMathImageBase::DoubleArray;
this->datatypeG=JKQTPMathImageBase::DoubleArray;
this->datatypeB=JKQTPMathImageBase::DoubleArray;
this->data=parent->getDatastore()->getColumn(imageRColumn).getPointer(0);
this->dataG=parent->getDatastore()->getColumn(imageGColumn).getPointer(0);
this->dataB=parent->getDatastore()->getColumn(imageBColumn).getPointer(0);
this->Ny=parent->getDatastore()->getColumn(imageRColumn).getRows()/this->Nx;
this->datatypeModifier=JKQTPMathImageBase::DoubleArray;
this->dataModifier=parent->getDatastore()->getColumn(modifierColumn).getPointer(0);
}
QVector JKQTPRGBMathImage::getDataGAsDoubleVector() const
{
switch(datatype) {
case JKQTPMathImageBase::DoubleArray:
return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny);
break;
case JKQTPMathImageBase::FloatArray:
return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny);
break;
case JKQTPMathImageBase::UInt8Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny);
break;
case JKQTPMathImageBase::UInt16Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny);
break;
case JKQTPMathImageBase::UInt32Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny);
break;
case JKQTPMathImageBase::UInt64Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny);
break;
case JKQTPMathImageBase::Int8Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny);
break;
case JKQTPMathImageBase::Int16Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny);
break;
case JKQTPMathImageBase::Int32Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny);
break;
case JKQTPMathImageBase::Int64Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny);
break;
}
QVector res;
return res;
}
QVector JKQTPRGBMathImage::getDataBAsDoubleVector() const
{
switch(datatype) {
case JKQTPMathImageBase::DoubleArray:
return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny);
break;
case JKQTPMathImageBase::FloatArray:
return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny);
break;
case JKQTPMathImageBase::UInt8Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny);
break;
case JKQTPMathImageBase::UInt16Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny);
break;
case JKQTPMathImageBase::UInt32Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny);
break;
case JKQTPMathImageBase::UInt64Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny);
break;
case JKQTPMathImageBase::Int8Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny);
break;
case JKQTPMathImageBase::Int16Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny);
break;
case JKQTPMathImageBase::Int32Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny);
break;
case JKQTPMathImageBase::Int64Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny);
break;
}
QVector res;
return res;
}