/*
Copyright (c) 2008-2019 Jan W. Krieger & Sebastian Isbaner (contour plot)
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 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/jkqtpgraphsimage.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
JKQTPImageBase::JKQTPImageBase(double x, double y, double width, double height, JKQTBasePlotter* parent):
JKQTPGraph(parent)
{
title="";
this->width=width;
this->height=height;
this->x=x;
this->y=y;
}
JKQTPImageBase::JKQTPImageBase(JKQTBasePlotter *parent):
JKQTPGraph(parent)
{
title="";
this->width=0;
this->height=0;
this->x=0;
this->y=0;
}
JKQTPImageBase::JKQTPImageBase(double x, double y, double width, double height, JKQTPlotter* parent):
JKQTPGraph(parent)
{
title="";
this->width=width;
this->height=height;
this->x=x;
this->y=y;
}
JKQTPImageBase::JKQTPImageBase(JKQTPlotter *parent):
JKQTPGraph(parent)
{
title="";
this->width=0;
this->height=0;
this->x=0;
this->y=0;
}
void JKQTPImageBase::drawKeyMarker(JKQTPEnhancedPainter& /*painter*/, QRectF& /*rect*/) {
}
bool JKQTPImageBase::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) {
minx=x;
maxx=x+width;
smallestGreaterZero=0;
if (x>10.0*DBL_MIN) smallestGreaterZero=x;
return true;
}
bool JKQTPImageBase::getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) {
miny=y;
maxy=y+height;
smallestGreaterZero=0;
if (y>10.0*DBL_MIN) smallestGreaterZero=y;
return true;
}
QColor JKQTPImageBase::getKeyLabelColor() {
return QColor("black");
}
void JKQTPImageBase::plotImage(JKQTPEnhancedPainter& painter, QImage& image, double x, double y, double width, double height) {
if ((!JKQTPIsOKFloat(x))||(!JKQTPIsOKFloat(y))||(!JKQTPIsOKFloat(width))||(!JKQTPIsOKFloat(height))||(width<=0) || (height<=0) || image.isNull() || (image.width()<=0) || (image.height()<=0)) {
return;
}
painter.save();
double xmin=parent->getXMin();
double xmax=parent->getXMax();
double ymin=parent->getYMin();
double ymax=parent->getYMax();
QPointF pp1=transform(xmin,ymax);
QPointF pp2=transform(xmax,ymin);
QRectF pr(pp1, pp2);
QPointF p1=transform(x,y+height);
QPointF p2=transform(x+width,y);
QRectF r(p1, p2);
if (image.width()>0 && image.height()>0 && !image.isNull()) {
if (r.width()<2*pr.width() && r.height()<2*pr.height()) {
//painter.drawImage(QRectF(p1.x(), p2.y(), fabs(p2.x()-p1.x()), fabs(p2.y()-p1.y())), image);
painter.drawImage(QPoint(p1.x(), p1.y()), image.scaled(QSize(fabs(p2.x()-p1.x()), fabs(p2.y()-p1.y())), Qt::IgnoreAspectRatio, Qt::FastTransformation));
//qDebug()<<"\nimage.size = "<(image.width());
double pixheight=fabs(p2.y()-p1.y())/static_cast(image.height());
//qDebug()<<"\nimage.size = "<image=new QImage(image);
image_owned=true;
createImageActions();
}
void JKQTPImage::set_image(QImage *image)
{
clear_image();
this->image=image;
image_owned=false;
createImageActions();
}
void JKQTPImage::clear_image()
{
if (image_owned && image!=nullptr) {
delete image;
}
image=nullptr;
image_owned=false;
}
void JKQTPImage::createImageActions()
{
actSaveImage=new QAction(tr("Save JKQTPImage ..."), this);
connect(actSaveImage, SIGNAL(triggered()), this, SLOT(saveImagePlotAsImage()));
actCopyImage=new QAction(tr("Copy JKQTPOverlayImage ..."), this);
connect(actCopyImage, SIGNAL(triggered()), this, SLOT(copyImagePlotAsImage()));
}
void JKQTPImage::setParent(JKQTBasePlotter *parent)
{
if (this->parent) {
this->parent->deregisterAdditionalAction(actSaveImage);
this->parent->deregisterAdditionalAction(actCopyImage);
}
JKQTPImageBase::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 JKQTPImage::set_title(const QString &title)
{
JKQTPImageBase::set_title(title);
QString t=title;
if (t.isEmpty()) t="JKQTPImage";
actSaveImage->setText(tr("Save %1 ...").arg(t));
actCopyImage->setText(tr("Copy %1 ...").arg(t));
}
void JKQTPImage::saveImagePlotAsImage(const QString &filename, const QByteArray &outputFormat)
{
if (parent && image) {
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;
}
if (form=="NONE") image->save(fn);
else image->save(fn, form.toLatin1().data());
}
}
}
void JKQTPImage::copyImagePlotAsImage()
{
QClipboard* clip=QApplication::clipboard();
if (clip && image) {
clip->setPixmap(QPixmap::fromImage(*image));
}
}
JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTBasePlotter* parent):
JKQTPImageBase(x, y, width, height, parent)
{
this->data=data;
this->datatype=datatype;
this->Nx=Nx;
this->Ny=Ny;
dataModifier=nullptr;
datatypeModifier=DoubleArray;
modifierMode=ModifyNone;
}
JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTPlotter* parent):
JKQTPImageBase(x, y, width, height, parent)
{
this->data=data;
this->datatype=datatype;
this->Nx=Nx;
this->Ny=Ny;
dataModifier=nullptr;
datatypeModifier=DoubleArray;
modifierMode=ModifyNone;
}
void JKQTPMathImageBase::drawKeyMarker(JKQTPEnhancedPainter &/*painter*/, QRectF &/*rect*/)
{
}
JKQTPMathImageBase::JKQTPMathImageBase(JKQTBasePlotter *parent):
JKQTPImageBase(parent)
{
this->data=nullptr;
this->Nx=0;
this->Ny=0;
this->datatype=DoubleArray;
dataModifier=nullptr;
datatypeModifier=DoubleArray;
modifierMode=ModifyNone;
}
JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, JKQTBasePlotter *parent):
JKQTPImageBase(x,y,width,height,parent)
{
this->data=nullptr;
this->Nx=0;
this->Ny=0;
this->datatype=DoubleArray;
dataModifier=nullptr;
datatypeModifier=DoubleArray;
modifierMode=ModifyNone;
}
JKQTPMathImageBase::JKQTPMathImageBase(JKQTPlotter *parent):
JKQTPImageBase(parent)
{
this->data=nullptr;
this->Nx=0;
this->Ny=0;
this->datatype=DoubleArray;
dataModifier=nullptr;
datatypeModifier=DoubleArray;
modifierMode=ModifyNone;
}
JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, JKQTPlotter *parent):
JKQTPImageBase(x,y,width,height,parent)
{
this->data=nullptr;
this->Nx=0;
this->Ny=0;
this->datatype=DoubleArray;
dataModifier=nullptr;
datatypeModifier=DoubleArray;
modifierMode=ModifyNone;
}
void JKQTPMathImageBase::set_data(void* data, int Nx, int Ny, DataType datatype) {
this->data=data;
this->datatype=datatype;
this->Nx=Nx;
this->Ny=Ny;
}
void JKQTPMathImageBase::set_data(void* data, int Nx, int Ny) {
this->data=data;
this->Nx=Nx;
this->Ny=Ny;
}
void JKQTPMathImageBase::set_dataModifier(void *data, JKQTPMathImageBase::DataType datatype)
{
this->dataModifier=data;
this->datatypeModifier=datatype;
}
void JKQTPMathImageBase::getDataMinMax(double& imin, double& imax) {
ensureImageData();
imin=imax=0;
if (!data) return;
switch(datatype) {
case JKQTPMathImageBase::DoubleArray:
imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny);
break;
case JKQTPMathImageBase::FloatArray:
imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny);
break;
case JKQTPMathImageBase::UInt8Array:
imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny);
break;
case JKQTPMathImageBase::UInt16Array:
imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny);
break;
case JKQTPMathImageBase::UInt32Array:
imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny);
break;
case JKQTPMathImageBase::UInt64Array:
imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny);
break;
case JKQTPMathImageBase::Int8Array:
imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny);
break;
case JKQTPMathImageBase::Int16Array:
imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny);
break;
case JKQTPMathImageBase::Int32Array:
imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny);
break;
case JKQTPMathImageBase::Int64Array:
imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny);
break;
}
}
void JKQTPMathImageBase::getModifierMinMax(double &imin, double &imax)
{
ensureImageData();
imin=imax=0;
if (!dataModifier) return;
switch(datatypeModifier) {
case JKQTPMathImageBase::DoubleArray:
imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny);
break;
case JKQTPMathImageBase::FloatArray:
imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny);
break;
case JKQTPMathImageBase::UInt8Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny);
break;
case JKQTPMathImageBase::UInt16Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny);
break;
case JKQTPMathImageBase::UInt32Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny);
break;
case JKQTPMathImageBase::UInt64Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny);
break;
case JKQTPMathImageBase::Int8Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny);
break;
case JKQTPMathImageBase::Int16Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny);
break;
case JKQTPMathImageBase::Int32Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny);
break;
case JKQTPMathImageBase::Int64Array:
imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny);
imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny);
break;
}
}
QVector JKQTPMathImageBase::getDataAsDoubleVector() const
{
switch(datatype) {
case JKQTPMathImageBase::DoubleArray:
return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny);
break;
case JKQTPMathImageBase::FloatArray:
return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny);
break;
case JKQTPMathImageBase::UInt8Array:
return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny);
break;
case JKQTPMathImageBase::UInt16Array:
return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny);
break;
case JKQTPMathImageBase::UInt32Array:
return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny);
break;
case JKQTPMathImageBase::UInt64Array:
return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny);
break;
case JKQTPMathImageBase::Int8Array:
return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny);
break;
case JKQTPMathImageBase::Int16Array:
return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny);
break;
case JKQTPMathImageBase::Int32Array:
return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny);
break;
case JKQTPMathImageBase::Int64Array:
return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny);
break;
}
QVector res;
return res;
}
QVector JKQTPMathImageBase::getDataModifierAsDoubleVector() const
{
switch(datatypeModifier) {
case JKQTPMathImageBase::DoubleArray:
return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny);
break;
case JKQTPMathImageBase::FloatArray:
return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny);
break;
case JKQTPMathImageBase::UInt8Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny);
break;
case JKQTPMathImageBase::UInt16Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny);
break;
case JKQTPMathImageBase::UInt32Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny);
break;
case JKQTPMathImageBase::UInt64Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny);
break;
case JKQTPMathImageBase::Int8Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny);
break;
case JKQTPMathImageBase::Int16Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny);
break;
case JKQTPMathImageBase::Int32Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny);
break;
case JKQTPMathImageBase::Int64Array:
return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny);
break;
}
QVector res;
return res;
}
void JKQTPMathImageBase::ensureImageData()
{
}
void JKQTPMathImageBase::modifyImage(QImage &img)
{
modifyImage(img, dataModifier, datatypeModifier, Nx, Ny, internalModifierMin, internalModifierMax);
}
void JKQTPMathImageBase::modifyImage(QImage &img, void *dataModifier, JKQTPMathImageBase::DataType datatypeModifier, int Nx, int Ny, double internalModifierMin, double internalModifierMax)
{
if (!dataModifier) return;
getModifierMinMax(internalModifierMin, internalModifierMax);
if (modifierMode!=ModifyNone) {
JKQTPRGBMathImageRGBMode rgbModMode=JKQTPRGBMathImageModeRGBMode;
int modChannel=3;
if (modifierMode==ModifyValue) {
modChannel=5;
rgbModMode=JKQTPRGBMathImageModeRGBMode;
} else if (modifierMode==ModifySaturation) {
modChannel=4;
rgbModMode=JKQTPRGBMathImageModeRGBMode;
} else if (modifierMode==ModifyAlpha) {
modChannel=3;
rgbModMode=JKQTPRGBMathImageModeRGBMode;
}
//qDebug()<<"mod: "<(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break;
case JKQTPMathImageBase::FloatArray: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break;
case JKQTPMathImageBase::UInt8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break;
case JKQTPMathImageBase::UInt16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break;
case JKQTPMathImageBase::UInt32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break;
case JKQTPMathImageBase::UInt64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break;
case JKQTPMathImageBase::Int8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break;
case JKQTPMathImageBase::Int16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break;
case JKQTPMathImageBase::Int32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break;
case JKQTPMathImageBase::Int64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break;
}
}
}
void JKQTPMathImage::initJKQTPMathImage() {
actSaveImage=new QAction(tr("Save JKQTPMathImage ..."), this);
connect(actSaveImage, SIGNAL(triggered()), this, SLOT(saveImagePlotAsImage()));
actCopyImage=new QAction(tr("Copy JKQTPMathImage ..."), this);
connect(actCopyImage, SIGNAL(triggered()), this, SLOT(copyImagePlotAsImage()));
actSavePalette=new QAction(tr("Save JKQTPMathImage Palette/Colorbar ..."), this);
connect(actSavePalette, SIGNAL(triggered()), this, SLOT(saveColorbarPlotAsImage()));
actCopyPalette=new QAction(tr("Copy JKQTPMathImage Palette/Colorbar ..."), this);
connect(actCopyPalette, SIGNAL(triggered()), this, SLOT(copyColorbarPlotAsImage()));
colorBarRightAxis=new JKQTPVerticalIndependentAxis(0, 100, 0, 100, parent);
if (parent) colorBarRightAxis->loadSettings(parent->getYAxis());
colorBarRightAxis->set_drawMode1(JKQTPCADMline);
colorBarRightAxis->set_drawMode2(JKQTPCADMcomplete);
colorBarRightAxis->setAxisLabel("");
colorBarRightAxis->set_minTicks(5);
colorBarRightAxis->set_minorTicks(0);
colorBarRightAxis->set_tickOutsideLength(0);
colorBarRightAxis->set_minorTickOutsideLength(0);
colorBarRightAxis->setShowZeroAxis(false);
colorBarTopAxis=new JKQTPHorizontalIndependentAxis(0, 100, 0, 100, parent);
if (parent) colorBarTopAxis->loadSettings(parent->getXAxis());
colorBarTopAxis->set_drawMode1(JKQTPCADMline);
colorBarTopAxis->set_drawMode2(JKQTPCADMcomplete);
colorBarTopAxis->setAxisLabel("");
colorBarTopAxis->set_minTicks(3);
colorBarTopAxis->set_minorTicks(0);
colorBarTopAxis->set_tickOutsideLength(0);
colorBarTopAxis->set_minorTickOutsideLength(0);
colorBarTopAxis->setShowZeroAxis(false);
modifierColorBarTopAxis=new JKQTPVerticalIndependentAxis(0, 100, 0, 100, parent);
if (parent) modifierColorBarTopAxis->loadSettings(parent->getXAxis());
modifierColorBarTopAxis->set_drawMode1(JKQTPCADMline);
modifierColorBarTopAxis->set_drawMode2(JKQTPCADMcomplete);
modifierColorBarTopAxis->setAxisLabel("");
modifierColorBarTopAxis->set_minTicks(3);
modifierColorBarTopAxis->setShowZeroAxis(false);
modifierColorBarTopAxis->set_minorTicks(0);
modifierColorBarTopAxis->set_tickOutsideLength(0);
modifierColorBarTopAxis->set_minorTickOutsideLength(0);
modifierColorBarRightAxis=new JKQTPHorizontalIndependentAxis (0, 100, 0, 100, parent);
if (parent) modifierColorBarRightAxis->loadSettings(parent->getYAxis());
modifierColorBarRightAxis->set_drawMode1(JKQTPCADMline);
modifierColorBarRightAxis->set_drawMode2(JKQTPCADMcomplete);
modifierColorBarRightAxis->setAxisLabel("");
modifierColorBarRightAxis->set_minTicks(5);
modifierColorBarRightAxis->setShowZeroAxis(false);
modifierColorBarRightAxis->set_minorTicks(0);
modifierColorBarRightAxis->set_tickOutsideLength(0);
modifierColorBarRightAxis->set_minorTickOutsideLength(0);
this->colorBarModifiedWidth=80;
this->colorBarTopVisible=true;
this->colorBarRightVisible=true;
this->palette=JKQTPMathImageGRAY;
this->imageNameFontName=parent->getKeyFont();
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->colorBarOffset=4;
this->rangeMinFailAction=JKQTPMathImageLastPaletteColor;
this->rangeMaxFailAction=JKQTPMathImageLastPaletteColor;
this->rangeMinFailColor=QColor("black");
this->rangeMaxFailColor=QColor("black");
this->nanColor=QColor("black");
this->infColor=QColor("black");
this->colorBarTopVisible=false;
this->colorBarRightVisible=true;
this->autoModifierRange=true;
}
JKQTPMathImage::JKQTPMathImage(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette, JKQTBasePlotter* parent):
JKQTPMathImageBase(x, y, width, height, datatype, data, Nx, Ny, parent)
{
initJKQTPMathImage();
this->palette=palette;
}
JKQTPMathImage::JKQTPMathImage(JKQTBasePlotter *parent):
JKQTPMathImageBase(0, 0, 1, 1, JKQTPMathImageBase::UInt8Array, nullptr, 0, 0, parent)
{
initJKQTPMathImage();
}
JKQTPMathImage::JKQTPMathImage(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette, JKQTPlotter* parent):
JKQTPMathImageBase(x, y, width, height, datatype, data, Nx, Ny, parent)
{
initJKQTPMathImage();
this->palette=palette;
}
JKQTPMathImage::JKQTPMathImage(JKQTPlotter *parent):
JKQTPMathImageBase(0, 0, 1, 1, JKQTPMathImageBase::UInt8Array, nullptr, 0, 0, parent)
{
initJKQTPMathImage();
}
void JKQTPMathImage::setParent(JKQTBasePlotter* parent) {
if (this->parent) {
this->parent->deregisterAdditionalAction(actSaveImage);
this->parent->deregisterAdditionalAction(actCopyImage);
this->parent->deregisterAdditionalAction(actSavePalette);
this->parent->deregisterAdditionalAction(actCopyPalette);
}
JKQTPMathImageBase::setParent(parent);
colorBarRightAxis->set_parent(parent);
colorBarTopAxis->set_parent(parent);
modifierColorBarRightAxis->set_parent(parent);
modifierColorBarTopAxis->set_parent(parent);
if (parent) {
parent->registerAdditionalAction(tr("Save Image Plot Images ..."), actSaveImage);
parent->registerAdditionalAction(tr("Copy Image Plot Images ..."), actCopyImage);
parent->registerAdditionalAction(tr("Save Image Plot Images ..."), actSavePalette);
parent->registerAdditionalAction(tr("Copy Image Plot Images ..."), actCopyPalette);
}
actSaveImage->setEnabled(parent);
actCopyImage->setEnabled(parent);
actSavePalette->setEnabled(parent);
actCopyPalette->setEnabled(parent);
}
void JKQTPMathImage::set_title(const QString &title)
{
JKQTPMathImageBase::set_title(title);
QString t=title;
if (t.isEmpty()) t="JKQTPMathImage";
actSaveImage->setText(tr("Save %1 ...").arg(t));
actCopyImage->setText(tr("Copy %1 ...").arg(t));
}
void JKQTPMathImage::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 JKQTPMathImage::copyImagePlotAsImage()
{
QClipboard* clip=QApplication::clipboard();
if (clip) {
clip->setPixmap(QPixmap::fromImage(drawImage()));
}
}
void JKQTPMathImage::saveColorbarPlotAsImage(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=drawOutsidePalette(256);
if (form=="NONE") image.save(fn);
else image.save(fn, form.toLatin1().data());
}
}
}
void JKQTPMathImage::copyColorbarPlotAsImage()
{
QClipboard* clip=QApplication::clipboard();
if (clip) {
clip->setPixmap(QPixmap::fromImage(drawOutsidePalette(256)));
}
}
void JKQTPMathImage::draw(JKQTPEnhancedPainter& painter) {
ensureImageData();
if (!data) return;
QImage img=drawImage();
plotImage(painter, img, x, y, width, height);
}
void JKQTPMathImage::getOutsideSize(JKQTPEnhancedPainter& painter, int& leftSpace, int& rightSpace, int& topSpace, int& bottomSpace) {
JKQTPGraph::getOutsideSize(painter, leftSpace, rightSpace, topSpace, bottomSpace);
if (showColorBar) {
getDataMinMax(internalDataMin, internalDataMax);
getModifierMinMax(internalModifierMin, internalModifierMax);
if (colorBarRightVisible) {
rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarRightAxis->setRange(internalDataMin, internalDataMax);
colorBarRightAxis->setAxisWidth(colorBarRelativeHeight*parent->getPlotHeight());
modifierColorBarRightAxis->setRange(internalModifierMin, internalModifierMax);
modifierColorBarRightAxis->setAxisWidth(parent->pt2px(painter, colorBarModifiedWidth));
QSize s=colorBarRightAxis->getSize2(painter);
/*parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
parent->getMathText()->setFontRoman(imageNameFontName);
parent->getMathText()->parse(imageName);
QSizeF names=parent->getMathText()->getSize(painter);*/
QSizeF names=parent->getTextSizeSize(imageNameFontName, imageNameFontSize*parent->getFontSizeMultiplier(), imageName, painter);
rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+qMax((double)s.width(), (double)names.width());
//qDebug()<<"osr: "<pt2px(painter, colorBarModifiedWidth-colorBarWidth));
}
//qDebug()<<" "<pt2px(painter, colorBarWidth+colorBarOffset);
colorBarTopAxis->setRange(internalDataMin, internalDataMax);
colorBarTopAxis->setAxisWidth(colorBarRelativeHeight*parent->getPlotWidth());
modifierColorBarTopAxis->setRange(internalModifierMin, internalModifierMax);
modifierColorBarTopAxis->setAxisWidth(parent->pt2px(painter, colorBarModifiedWidth));
QSize s=colorBarTopAxis->getSize2(painter);
/*parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
parent->getMathText()->setFontRoman(imageNameFontName);
parent->getMathText()->parse(imageName);
QSizeF names=parent->getMathText()->getSize(painter);*/
QSizeF names=parent->getTextSizeSize(imageNameFontName, imageNameFontSize*parent->getFontSizeMultiplier(), imageName, painter);
//qDebug()<pt2px(painter, colorBarWidth+colorBarOffset);
topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+qMax((double)s.height(), (double)names.height());
if (modifierMode!=ModifyNone) {
topSpace=topSpace+(2*parent->pt2px(painter, colorBarModifiedWidth-colorBarWidth));
}
//qDebug()<getTextSizeSize(imageNameFontName, imageNameFontSize*parent->getFontSizeMultiplier(), imageName, painter);
double icolorBarRelativeHeight=colorBarRelativeHeight;
int barHeight=rightSpace.height()*icolorBarRelativeHeight;
if (barHeight<1) barHeight=1;
// find a height for the bar that allows to show the image name
while ((barHeight>1) && ((rightSpace.height()-barHeight)/2pt2px(painter, colorBarOffset), rightSpace.top()+(rightSpace.height()-barHeight)/2, parent->pt2px(painter, (modifierMode==ModifyNone)?colorBarWidth:colorBarModifiedWidth), barHeight);
painter.drawImage(cb, b.mirrored(true, false));
QPen p=painter.pen();
p.setColor(colorBarRightAxis->getAxisColor());
p.setWidthF(qMax(JKQTPLOTTER_ABS_MIN_LINEWIDTH, parent->pt2px(painter, colorBarRightAxis->getLineWidth()*parent->getLineWidthMultiplier())));
painter.setPen(p);
painter.drawRect(cb);
colorBarRightAxis->setRange(internalDataMin, internalDataMax);
colorBarRightAxis->setAxisWidth(cb.height());
colorBarRightAxis->setAxisOffset(cb.top());
colorBarRightAxis->set_otherAxisOffset(cb.left());
colorBarRightAxis->set_otherAxisWidth(cb.width());
colorBarRightAxis->drawAxes(painter);
if (modifierMode!=ModifyNone) {
modifierColorBarRightAxis->setRange(internalModifierMin, internalModifierMax);
modifierColorBarRightAxis->setAxisWidth(parent->pt2px(painter, colorBarModifiedWidth));
modifierColorBarRightAxis->setAxisOffset(cb.left());
modifierColorBarRightAxis->set_otherAxisOffset(cb.top());
modifierColorBarRightAxis->set_otherAxisWidth(cb.height());
modifierColorBarRightAxis->drawAxes(painter);
}
parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
parent->getMathText()->setFontRoman(imageNameFontName);
parent->getMathText()->parse(imageName);
parent->getMathText()->draw(painter, Qt::AlignHCenter|Qt::AlignVCenter, QRect(rightSpace.x(), rightSpace.y(), rightSpace.width(), (rightSpace.height()-barHeight)/2));
painter.restore();
}
if (colorBarTopVisible) {
painter.save();
QImage b=drawOutsidePalette(200);
QSizeF names=parent->getTextSizeSize(imageNameFontName, imageNameFontSize*parent->getFontSizeMultiplier(), imageName, painter);
double icolorBarRelativeHeight=colorBarRelativeHeight;
int barWidth=topSpace.width()*icolorBarRelativeHeight;
if (barWidth<1) barWidth=1;
// find a height for the bar that allows to show the image name
while ((barWidth>1) && ((topSpace.width()-barWidth)/2pt2px(painter, colorBarOffset+((modifierMode==ModifyNone)?colorBarWidth:colorBarModifiedWidth)), barWidth, parent->pt2px(painter, (modifierMode==ModifyNone)?colorBarWidth:colorBarModifiedWidth));
//qDebug()<<"t: "<getAxisColor());
p.setWidthF(qMax(JKQTPLOTTER_ABS_MIN_LINEWIDTH, parent->pt2px(painter, colorBarTopAxis->getLineWidth()*parent->getLineWidthMultiplier())));
painter.setPen(p);
painter.drawRect(cb);
colorBarTopAxis->setRange(internalDataMin, internalDataMax);
colorBarTopAxis->setAxisWidth(cb.width());
colorBarTopAxis->setAxisOffset(cb.left());
colorBarTopAxis->set_otherAxisOffset(cb.top());
colorBarTopAxis->set_otherAxisWidth(cb.height());
colorBarTopAxis->drawAxes(painter);
if (modifierMode!=ModifyNone) {
modifierColorBarTopAxis->setRange(internalModifierMin, internalModifierMax);
modifierColorBarTopAxis->setAxisWidth(parent->pt2px(painter, colorBarModifiedWidth));
modifierColorBarTopAxis->setAxisOffset(cb.top());
modifierColorBarTopAxis->set_otherAxisOffset(cb.left());
modifierColorBarTopAxis->set_otherAxisWidth(cb.width());
modifierColorBarTopAxis->drawAxes(painter);
}
parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
parent->getMathText()->setFontRoman(imageNameFontName);
parent->getMathText()->parse(imageName);
parent->getMathText()->draw(painter, Qt::AlignHCenter|Qt::AlignVCenter, QRect(topSpace.right()-(topSpace.width()-barWidth)/2, topSpace.y(), (topSpace.width()-barWidth)/2, topSpace.height()));
painter.restore();
}
}
}
QImage JKQTPMathImage::drawOutsidePalette(int steps)
{
uint8_t h=1;
if (modifierMode!=ModifyNone) {
h=50;
}
uint8_t* d=new uint8_t[steps*h];
uint8_t* dd=new uint8_t[steps*h];
for (int i=0; i(d,h,steps, b, palette, 0, steps-1);
if (modifierMode!=ModifyNone) {
modifyImage(b, dd, UInt8Array, h,steps, 0, h-1);
}
delete[] d;
delete[] dd;
return b;
}
void JKQTPMathImage::getDataMinMax(double& imin, double& imax) {
ensureImageData();
if (autoImageRange) {
JKQTPMathImageBase::getDataMinMax(imin, imax);
} else {
imin=imageMin;
imax=imageMax;
}
}
void JKQTPMathImage::getModifierMinMax(double &imin, double &imax)
{
ensureImageData();
if (autoModifierRange) {
JKQTPMathImageBase::getModifierMinMax(imin, imax);
} else {
imin=modifierMin;
imax=modifierMax;
}
}
double JKQTPMathImage::getValueAt(double x, double y)
{
ensureImageData();
int xx=trunc((x-this->x)/width*double(Nx));
int yy=trunc((y-this->y)/height*double(Ny));
if (xx>=0 && xx<(int64_t)Nx && yy>=0 && yy<(int64_t)Ny) {
switch(datatype) {
case JKQTPMathImageBase::DoubleArray: return (static_cast(data))[yy*Nx+xx]; break;
case JKQTPMathImageBase::FloatArray: return (static_cast(data))[yy*Nx+xx]; break;
case JKQTPMathImageBase::UInt8Array: return (static_cast(data))[yy*Nx+xx]; break;
case JKQTPMathImageBase::UInt16Array: return (static_cast(data))[yy*Nx+xx]; break;
case JKQTPMathImageBase::UInt32Array: return (static_cast(data))[yy*Nx+xx]; break;
case JKQTPMathImageBase::UInt64Array: return (static_cast(data))[yy*Nx+xx]; break;
case JKQTPMathImageBase::Int8Array: return (static_cast(data))[yy*Nx+xx]; break;
case JKQTPMathImageBase::Int16Array: return (static_cast(data))[yy*Nx+xx]; break;
case JKQTPMathImageBase::Int32Array: return (static_cast(data))[yy*Nx+xx]; break;
case JKQTPMathImageBase::Int64Array: return (static_cast(data))[yy*Nx+xx]; break;
} }
return 0.0;
}
void JKQTPMathImage::drawKeyMarker(JKQTPEnhancedPainter &painter, QRectF &rect)
{
painter.drawImage(rect, getPaletteKeyImage(palette, 32,32));
}
QStringList JKQTPMathImage::getPalettes() {
return JKQTPImagePlot_getPredefinedPalettes();
}
int JKQTPMathImage::getPalettesCount()
{
return getPalettes().size();
}
QIcon JKQTPMathImage::getPaletteIcon(int i) {
QImage img=getPaletteImage(i, jkqtp_PALETTE_ICON_WIDTH);
QPixmap pix(jkqtp_PALETTE_ICON_WIDTH,8);
QRect r(0,0,jkqtp_PALETTE_ICON_WIDTH-1,7);
JKQTPEnhancedPainter p(&pix);
p.drawImage(r, img);
p.setPen(QPen(QColor("black")));
p.drawRect(r);
p.end();
return QIcon(pix);
}
QIcon JKQTPMathImage::getPaletteIcon(JKQTPMathImageColorPalette palette) {
return getPaletteIcon((int)palette);
}
QImage JKQTPMathImage::getPaletteImage(int i, int width, int height)
{
QImage img;
double* pic=(double*)malloc(width*sizeof(double));
for (int j=0; j(pic, width, qMax(1,height), img, (JKQTPMathImageColorPalette)i, 0, width-1);
free(pic);
return img;
}
QImage JKQTPMathImage::getPaletteImage(JKQTPMathImageColorPalette palette, int width, int height)
{
return getPaletteImage((int)palette, width,height);
}
QIcon JKQTPMathImage::getPaletteKeyIcon(int i)
{
QImage img=getPaletteKeyImage(i, jkqtp_PALETTE_ICON_WIDTH, jkqtp_PALETTE_IMAGEICON_HEIGHT);
QPixmap pix(jkqtp_PALETTE_ICON_WIDTH,jkqtp_PALETTE_IMAGEICON_HEIGHT);
QRect r(0,0,jkqtp_PALETTE_ICON_WIDTH-1,jkqtp_PALETTE_IMAGEICON_HEIGHT-1);
JKQTPEnhancedPainter p(&pix);
p.drawImage(r, img);
p.setPen(QPen(QColor("black")));
p.drawRect(r);
p.end();
return QIcon(pix);
}
QIcon JKQTPMathImage::getPaletteKeyIcon(JKQTPMathImageColorPalette palette)
{
return getPaletteIcon((int)palette);
}
QImage JKQTPMathImage::getPaletteKeyImage(int i, int width, int height)
{
QImage img;
const double x01=double(width)/3.0;
const double y01=double(height)/3.0*2.0;
const double w1x=double(width*width)/(5.0*5.0);
const double w1y=double(height*height)/(2.0*2.0);
const double x02=double(width)/3.0*2.0;
const double y02=double(height)/4.0;
const double w2x=double(width*width)/(8.0*8.0);
const double w2y=double(height*height)/(8.0*8.0);
double* pic=(double*)malloc(width*height*sizeof(double));
double mmax=0;
for (int j=0; jmmax) mmax=pic[j];
}
JKQTPImagePlot_array2image(pic, width, height, img, (JKQTPMathImageColorPalette)i, 0, mmax);
free(pic);
return img;
}
QImage JKQTPMathImage::getPaletteKeyImage(JKQTPMathImageColorPalette palette, int width, int height)
{
return getPaletteKeyImage((int)palette, width, height);
}
QImage JKQTPMathImage::drawImage() {
if (!data) return QImage();
QImage img(Nx, Ny, QImage::Format_ARGB32);
getDataMinMax(internalDataMin, internalDataMax);
switch(datatype) {
case JKQTPMathImageBase::DoubleArray: JKQTPImagePlot_array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
case JKQTPMathImageBase::FloatArray: JKQTPImagePlot_array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
case JKQTPMathImageBase::UInt8Array: JKQTPImagePlot_array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
case JKQTPMathImageBase::UInt16Array: JKQTPImagePlot_array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
case JKQTPMathImageBase::UInt32Array: JKQTPImagePlot_array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
case JKQTPMathImageBase::UInt64Array: JKQTPImagePlot_array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
case JKQTPMathImageBase::Int8Array: JKQTPImagePlot_array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
case JKQTPMathImageBase::Int16Array: JKQTPImagePlot_array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
case JKQTPMathImageBase::Int32Array: JKQTPImagePlot_array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
case JKQTPMathImageBase::Int64Array: JKQTPImagePlot_array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
}
modifyImage(img);
return img;
}
void JKQTPMathImage::set_palette(int pal) {
palette=(JKQTPMathImageColorPalette)pal;
}
JKQTPOverlayImage::JKQTPOverlayImage(double x, double y, double width, double height, bool* data, int Nx, int Ny, QColor colTrue, JKQTBasePlotter* parent):
JKQTPImageBase(x, y, width, height, parent)
{
actSaveImage=new QAction(tr("Save JKQTPOverlayImage ..."), this);
connect(actSaveImage, SIGNAL(triggered()), this, SLOT(saveImagePlotAsImage()));
actCopyImage=new QAction(tr("Copy JKQTPOverlayImage ..."), this);
connect(actCopyImage, SIGNAL(triggered()), this, SLOT(copyImagePlotAsImage()));
this->Nx=Nx;
this->Ny=Ny;
this->data=data;
this->trueColor=colTrue;
this->falseColor=QColor(Qt::transparent);
}
JKQTPOverlayImage::JKQTPOverlayImage(JKQTBasePlotter *parent):
JKQTPImageBase(0,0,1,1, parent)
{
actSaveImage=new QAction(tr("Save JKQTPOverlayImage ..."), this);
connect(actSaveImage, SIGNAL(triggered()), this, SLOT(saveImagePlotAsImage()));
actCopyImage=new QAction(tr("Copy JKQTPOverlayImage ..."), this);
connect(actCopyImage, SIGNAL(triggered()), this, SLOT(copyImagePlotAsImage()));
this->Nx=0;
this->Ny=0;
this->data=nullptr;
this->trueColor=QColor("red");
}
JKQTPOverlayImage::JKQTPOverlayImage(double x, double y, double width, double height, bool* data, int Nx, int Ny, QColor colTrue, JKQTPlotter* parent):
JKQTPImageBase(x, y, width, height, parent)
{
actSaveImage=new QAction(tr("Save JKQTPOverlayImage ..."), this);
connect(actSaveImage, SIGNAL(triggered()), this, SLOT(saveImagePlotAsImage()));
actCopyImage=new QAction(tr("Copy JKQTPOverlayImage ..."), this);
connect(actCopyImage, SIGNAL(triggered()), this, SLOT(copyImagePlotAsImage()));
this->Nx=Nx;
this->Ny=Ny;
this->data=data;
this->trueColor=colTrue;
this->falseColor=QColor(Qt::transparent);
}
JKQTPOverlayImage::JKQTPOverlayImage(JKQTPlotter *parent):
JKQTPImageBase(0,0,1,1, parent)
{
actSaveImage=new QAction(tr("Save JKQTPOverlayImage ..."), this);
connect(actSaveImage, SIGNAL(triggered()), this, SLOT(saveImagePlotAsImage()));
actCopyImage=new QAction(tr("Copy JKQTPOverlayImage ..."), this);
connect(actCopyImage, SIGNAL(triggered()), this, SLOT(copyImagePlotAsImage()));
this->Nx=0;
this->Ny=0;
this->data=nullptr;
this->trueColor=QColor("red");
}
void JKQTPOverlayImage::draw(JKQTPEnhancedPainter& painter) {
if (!data) return;
QImage img=drawImage();
plotImage(painter, img, x, y, width, height);
}
QImage JKQTPOverlayImage::drawImage() {
if (!data) return QImage();
QImage img(Nx, Ny, QImage::Format_ARGB32);
//QRgb tc=trueColor.rgba();
//QRgb fc=falseColor.rgba();
QRgb tc=qRgba(round(trueColor.red()*trueColor.alphaF()), round(trueColor.green()*trueColor.alphaF()), round(trueColor.blue()*trueColor.alphaF()), trueColor.alpha());
QRgb fc=qRgba(round(falseColor.red()*falseColor.alphaF()), round(falseColor.green()*falseColor.alphaF()), round(falseColor.blue()*falseColor.alphaF()), falseColor.alpha());
for (int32_t y=0; ydata=data;
this->Nx=Nx;
this->Ny=Ny;
}
JKQTPOverlayImageEnhanced::JKQTPOverlayImageEnhanced(double x, double y, double width, double height, bool* data, int Nx, int Ny, QColor colTrue, JKQTBasePlotter* parent):
JKQTPOverlayImage(x, y, width, height, data, Nx, Ny, colTrue, parent)
{
symbol=JKQTPTarget;
symbolWidth=1;
drawAsRectangles=true;
symbolSizeFactor=0.9;
rectanglesAsImageOverlay=false;
}
JKQTPOverlayImageEnhanced::JKQTPOverlayImageEnhanced(JKQTBasePlotter *parent):
JKQTPOverlayImage(0,0,1,1,nullptr,0,0, QColor("red"), parent)
{
symbol=JKQTPTarget;
symbolWidth=1;
drawAsRectangles=true;
symbolSizeFactor=0.9;
rectanglesAsImageOverlay=false;
}
JKQTPOverlayImageEnhanced::JKQTPOverlayImageEnhanced(double x, double y, double width, double height, bool* data, int Nx, int Ny, QColor colTrue, JKQTPlotter* parent):
JKQTPOverlayImage(x, y, width, height, data, Nx, Ny, colTrue, parent)
{
symbol=JKQTPTarget;
symbolWidth=1;
drawAsRectangles=true;
symbolSizeFactor=0.9;
rectanglesAsImageOverlay=false;
}
JKQTPOverlayImageEnhanced::JKQTPOverlayImageEnhanced(JKQTPlotter *parent):
JKQTPOverlayImage(0,0,1,1,nullptr,0,0, QColor("red"), parent)
{
symbol=JKQTPTarget;
symbolWidth=1;
drawAsRectangles=true;
symbolSizeFactor=0.9;
rectanglesAsImageOverlay=false;
}
void JKQTPOverlayImageEnhanced::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
if (drawAsRectangles) JKQTPOverlayImage::drawKeyMarker(painter, rect);
else JKQTPPlotSymbol(painter, rect.center().x(), rect.center().y(), symbol, qMin(rect.width(), rect.height()), parent->pt2px(painter, symbolWidth*parent->getLineWidthMultiplier()), trueColor, trueColor.lighter());
}
void JKQTPOverlayImageEnhanced::draw(JKQTPEnhancedPainter& painter) {
if (!data) return;
if (drawAsRectangles && rectanglesAsImageOverlay) {
JKQTPOverlayImage::draw(painter);
} else {
painter.save();
double dx=width/(double)Nx;
double dy=height/(double)Ny;
for (int ix=0; ix<(int64_t)Nx; ix++) {
for (int iy=0; iy<(int64_t)Ny; iy++) {
QPointF p1=transform(x+static_cast(ix)*dx, y+static_cast(iy)*dy);
QPointF p2=transform(x+(double)(ix+1)*dx, y+(double)(iy+1)*dx);
if (drawAsRectangles) {
if (data[ix+iy*Nx]) {
if (trueColor.alpha()>0) {
painter.fillRect(QRectF(qMin(p1.x(), p2.x())-1.0, qMin(p2.y(), p1.y())-1.0, fabs(p2.x()-p1.x())+1.0, fabs(p2.y()-p1.y())+1.0), QBrush(trueColor));
//painter.setPen(QPen(trueColor));
//painter.drawRect(QRectF(qMin(p1.x(), p2.x()), qMin(p2.y(), p1.y()), fabs(p2.x()-p1.x()), fabs(p2.y()-p1.y())));
}
} else {
if (falseColor.alpha()>0) {
//painter.setPen(QPen(falseColor));
painter.fillRect(QRectF(qMin(p1.x(), p2.x())-1.0, qMin(p2.y(), p1.y())-1.0, fabs(p2.x()-p1.x())+1.0, fabs(p2.y()-p1.y())+1.0), QBrush(falseColor));
//painter.drawRect(QRectF(qMin(p1.x(), p2.x()), qMin(p2.y(), p1.y()), fabs(p2.x()-p1.x()), fabs(p2.y()-p1.y())));
}
}
} else {
QPointF p=(p1+p2)/2.0;
if (data[ix+iy*Nx]) {
JKQTPPlotSymbol(painter, p.x(), p.y(), symbol, fabs(p2.x()-p1.x())*symbolSizeFactor, parent->pt2px(painter, symbolWidth*parent->getLineWidthMultiplier()), trueColor, trueColor.lighter());
}
}
}
}
painter.restore();
}
}
void JKQTPRGBMathImage::initObject()
{
actSaveImage=new QAction(tr("Save JKQTPRGBMathImage ..."), this);
connect(actSaveImage, SIGNAL(triggered()), this, SLOT(saveImagePlotAsImage()));
actCopyImage=new QAction(tr("Copy JKQTPOverlayImage ..."), this);
connect(actCopyImage, SIGNAL(triggered()), this, SLOT(copyImagePlotAsImage()));
rgbMode=JKQTPRGBMathImageModeRGBMode;
colorBarRightAxis=new JKQTPVerticalIndependentAxis(0, 100, 0, 100, parent);
if (parent) colorBarRightAxis->loadSettings(parent->getYAxis());
colorBarRightAxis->set_drawMode1(JKQTPCADMline);
colorBarRightAxis->set_drawMode2(JKQTPCADMcomplete);
colorBarRightAxis->setAxisLabel("");
colorBarRightAxis->set_minTicks(5);
colorBarRightAxis->set_minorTicks(0);
colorBarRightAxis->set_tickOutsideLength(0);
colorBarRightAxis->set_minorTickOutsideLength(0);
colorBarRightAxis->setShowZeroAxis(false);
colorBarTopAxis=new JKQTPHorizontalIndependentAxis(0, 100, 0, 100, parent);
if (parent) colorBarTopAxis->loadSettings(parent->getXAxis());
colorBarTopAxis->set_drawMode1(JKQTPCADMline);
colorBarTopAxis->set_drawMode2(JKQTPCADMcomplete);
colorBarTopAxis->setAxisLabel("");
colorBarTopAxis->set_minTicks(3);
colorBarTopAxis->set_minorTicks(0);
colorBarTopAxis->set_tickOutsideLength(0);
colorBarTopAxis->set_minorTickOutsideLength(0);
colorBarTopAxis->setShowZeroAxis(false);
colorBarRightAxisG=new JKQTPVerticalIndependentAxis(0, 100, 0, 100, parent);
if (parent) colorBarRightAxisG->loadSettings(parent->getYAxis());
colorBarRightAxisG->set_drawMode1(JKQTPCADMline);
colorBarRightAxisG->set_drawMode2(JKQTPCADMcomplete);
colorBarRightAxisG->setAxisLabel("");
colorBarRightAxisG->set_minTicks(5);
colorBarRightAxisG->setShowZeroAxis(false);
colorBarRightAxisG->set_minorTicks(0);
colorBarRightAxisG->set_tickOutsideLength(0);
colorBarRightAxisG->set_minorTickOutsideLength(0);
colorBarTopAxisG=new JKQTPHorizontalIndependentAxis(0, 100, 0, 100, parent);
if (parent) colorBarTopAxisG->loadSettings(parent->getXAxis());
colorBarTopAxisG->set_drawMode1(JKQTPCADMline);
colorBarTopAxisG->set_drawMode2(JKQTPCADMcomplete);
colorBarTopAxisG->setAxisLabel("");
colorBarTopAxisG->set_minTicks(3);
colorBarTopAxisG->setShowZeroAxis(false);
colorBarTopAxisG->set_minorTicks(0);
colorBarTopAxisG->set_tickOutsideLength(0);
colorBarTopAxisG->set_minorTickOutsideLength(0);
colorBarRightAxisB=new JKQTPVerticalIndependentAxis(0, 100, 0, 100, parent);
if (parent) colorBarRightAxisB->loadSettings(parent->getYAxis());
colorBarRightAxisB->set_drawMode1(JKQTPCADMline);
colorBarRightAxisB->set_drawMode2(JKQTPCADMcomplete);
colorBarRightAxisB->setAxisLabel("");
colorBarRightAxisB->set_minTicks(5);
colorBarRightAxisB->setShowZeroAxis(false);
colorBarRightAxisB->set_minorTicks(0);
colorBarRightAxisB->set_tickOutsideLength(0);
colorBarRightAxisB->set_minorTickOutsideLength(0);
colorBarTopAxisB=new JKQTPHorizontalIndependentAxis(0, 100, 0, 100, parent);
if (parent) colorBarTopAxisB->loadSettings(parent->getXAxis());
colorBarTopAxisB->set_drawMode1(JKQTPCADMline);
colorBarTopAxisB->set_drawMode2(JKQTPCADMcomplete);
colorBarTopAxisB->setAxisLabel("");
colorBarTopAxisB->set_minTicks(3);
colorBarTopAxisB->setShowZeroAxis(false);
colorBarTopAxisB->set_minorTicks(0);
colorBarTopAxisB->set_tickOutsideLength(0);
colorBarTopAxisB->set_minorTickOutsideLength(0);
this->colorBarTopVisible=true;
this->colorBarRightVisible=true;
this->imageNameFontName=parent->getKeyFont();
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->set_parent(parent);
colorBarTopAxis->set_parent(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);
QSize s=colorBarRightAxis->getSize2(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+(double)s.width();
/*QSize s=colorBarRightAxis->getSize2(painter);
parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
parent->getMathText()->setFontRoman(imageNameFontName);
parent->getMathText()->parse(imageName);
QSizeF names=parent->getMathText()->getSize(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=colorBarWidth+colorBarOffset+qMax((double)s.width(), (double)names.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);
QSize s=colorBarTopAxisB->getSize2(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+(double)s.height();
/*QSize s=colorBarTopAxis->getSize2(painter);
parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
parent->getMathText()->setFontRoman(imageNameFontName);
parent->getMathText()->parse(imageName);
QSizeF names=parent->getMathText()->getSize(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=colorBarWidth+colorBarOffset+qMax((double)s.height(), (double)names.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);
QSize s=colorBarRightAxis->getSize2(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+(double)s.width();
/*QSize s=colorBarRightAxis->getSize2(painter);
parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
parent->getMathText()->setFontRoman(imageNameFontName);
parent->getMathText()->parse(imageNameG);
QSizeF names=parent->getMathText()->getSize(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=colorBarWidth+colorBarOffset+qMax((double)s.width(), (double)names.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);
QSize s=colorBarTopAxisB->getSize2(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+(double)s.height();
/*QSize s=colorBarTopAxisG->getSize2(painter);
parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
parent->getMathText()->setFontRoman(imageNameFontName);
parent->getMathText()->parse(imageNameG);
QSizeF names=parent->getMathText()->getSize(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=colorBarWidth+colorBarOffset+qMax((double)s.height(), (double)names.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);
QSize s=colorBarRightAxis->getSize2(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+(double)s.width();
/*
parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
parent->getMathText()->setFontRoman(imageNameFontName);
parent->getMathText()->parse(imageNameB);
QSizeF names=parent->getMathText()->getSize(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=colorBarWidth+colorBarOffset+qMax((double)s.width(), (double)names.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);
QSize s=colorBarTopAxisB->getSize2(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+(double)s.height();
/*parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
parent->getMathText()->setFontRoman(imageNameFontName);
parent->getMathText()->parse(imageNameB);
QSizeF names=parent->getMathText()->getSize(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=colorBarWidth+colorBarOffset+qMax((double)s.height(), (double)names.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=(QRgb*)(d.paletteImage.scanLine(0));
for (int i=0; i(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
QRgb* line=(QRgb*)(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=(QRgb*)(d.paletteImage.scanLine(0));
for (int i=0; i(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
QRgb* line=(QRgb*)(d.paletteImage.scanLine(0));
for (int i=0; ipt2px(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(JKQTPLOTTER_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->set_otherAxisOffset(cb.left());
l[li].colorBarRightAxis->set_otherAxisWidth(cb.width());
l[li].colorBarRightAxis->set_labelFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
l[li].colorBarRightAxis->set_labelFont(imageNameFontName);
l[li].colorBarRightAxis->setAxisLabel(l[li].name);
l[li].colorBarRightAxis->drawAxes(painter);
painter.restore();
if (!colorbarsSideBySide) {
rX=rX+(double)rightSpace.width()/double(visibleColorBars);
} else {
rY=rY+(double)rightSpace.height()*shiftSizeFactor*colorBarRelativeHeight;
}
}
if (colorBarTopVisible) {
painter.save();
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(JKQTPLOTTER_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->set_otherAxisOffset(cb.top());
l[li].colorBarTopAxis->set_otherAxisWidth(cb.height());
l[li].colorBarTopAxis->set_labelFontSize(imageNameFontSize*parent->getFontSizeMultiplier());
l[li].colorBarTopAxis->set_labelFont(imageNameFontName);
l[li].colorBarTopAxis->setAxisLabel(l[li].name);
l[li].colorBarTopAxis->drawAxes(painter);
painter.restore();
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