From 686fb1eeb1dc3e5cac11e66ee3a754d24c5ec4a6 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Wed, 31 Jul 2019 22:10:26 +0200 Subject: [PATCH] using mix-in class JKQTPColorPaletteWithModifierStyleAndToolsMixin now also in JKQTPMathImage ... --- .../imageplot_modifier/imageplot_modifier.cpp | 2 +- .../imageplot_nodatastore.cpp | 4 +- examples/jkqtplot_test/TestWidgetImages.cpp | 10 +- .../jkqtplot_test/TestWidgetRGBImages.cpp | 16 +- lib/jkqtcommon/jkqtpbasicimagetools.cpp | 64 ++ lib/jkqtcommon/jkqtpbasicimagetools.h | 41 + lib/jkqtplotter/graphs/jkqtpcontour.cpp | 6 +- lib/jkqtplotter/graphs/jkqtpimage.cpp | 856 +++--------------- lib/jkqtplotter/graphs/jkqtpimage.h | 439 ++------- lib/jkqtplotter/graphs/jkqtpimagergb.cpp | 303 ++++--- lib/jkqtplotter/graphs/jkqtpimagergb.h | 85 +- lib/jkqtplotter/gui/jkqtpcomboboxes.cpp | 24 +- lib/jkqtplotter/gui/jkqtpcomboboxes.h | 10 +- lib/jkqtplotter/jkqtpimagetools.cpp | 369 +++++++- lib/jkqtplotter/jkqtpimagetools.h | 123 ++- 15 files changed, 1034 insertions(+), 1318 deletions(-) diff --git a/examples/imageplot_modifier/imageplot_modifier.cpp b/examples/imageplot_modifier/imageplot_modifier.cpp index 7a5ce4cc63..7e9a564894 100644 --- a/examples/imageplot_modifier/imageplot_modifier.cpp +++ b/examples/imageplot_modifier/imageplot_modifier.cpp @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) graph->setModifierColumn(cModifier); graph->setAutoModifierRange(true); // ... and specify which image property is modified (here the saturation, but ModifyAlpha for the transparency and ModifyValue from the HSV color-model are also possible): - graph->setModifierMode(JKQTPMathImageBase::ModifySaturation); + graph->setModifierMode(JKQTPMathImageModifierMode::ModifySaturation); // set size of the data (the datastore does not contain this info, as it only manages 1D columns of data and this is used to assume a row-major ordering graph->setNx(NX); graph->setNy(NY); diff --git a/examples/imageplot_nodatastore/imageplot_nodatastore.cpp b/examples/imageplot_nodatastore/imageplot_nodatastore.cpp index 8453429004..05c87a6640 100644 --- a/examples/imageplot_nodatastore/imageplot_nodatastore.cpp +++ b/examples/imageplot_nodatastore/imageplot_nodatastore.cpp @@ -56,8 +56,8 @@ int main(int argc, char* argv[]) // the converted range of data is determined automatically because setAutoImageRange(true) JKQTPMathImage* graph=new JKQTPMathImage(&plot); graph->setTitle(""); - // set array as datasource, with correct size NX*NY and datatype JKQTPMathImageBase::DataType::DoubleArray - graph->setData(airydisk, NX, NY, JKQTPMathImageBase::DataType::DoubleArray); + // set array as datasource, with correct size NX*NY and datatype JKQTPMathImageDataType::DoubleArray + graph->setData(airydisk, NX, NY, JKQTPMathImageDataType::DoubleArray); // where does the image start in the plot, given in plot-axis-coordinates (bottom-left corner) graph->setX(-w/2.0); graph->setY(-h/2.0); diff --git a/examples/jkqtplot_test/TestWidgetImages.cpp b/examples/jkqtplot_test/TestWidgetImages.cpp index 3159a2f0b9..04e153c115 100644 --- a/examples/jkqtplot_test/TestWidgetImages.cpp +++ b/examples/jkqtplot_test/TestWidgetImages.cpp @@ -54,7 +54,7 @@ TestWidgetImages::TestWidgetImages(QWidget *parent) : bimg2[y*100+x]=static_cast(rand())/static_cast(RAND_MAX)>0.9; } } - pimg2=new JKQTPMathImage(10,0,10,10, JKQTPMathImageBase::DoubleArray, img2, 100, 100, JKQTPMathImageGRAY, plotImg->getPlotter()); + pimg2=new JKQTPMathImage(10,0,10,10, JKQTPMathImageDataType::DoubleArray, img2, 100, 100, JKQTPMathImageGRAY, plotImg->getPlotter()); pimg2->setImageMin(-1); pimg2->setImageMax(0.5); pimg2->setImageName("left image"); @@ -63,7 +63,7 @@ TestWidgetImages::TestWidgetImages(QWidget *parent) : pimg2->setColorBarTopVisible(true); pimg2->setColorBarRightVisible(false); plotImg->getPlotter()->addGraph(pimg2); - pimg3=new JKQTPMathImage(20,0,10,10, JKQTPMathImageBase::DoubleArray, img2, 100, 100, JKQTPMathImageMATLAB, plotImg->getPlotter()); + pimg3=new JKQTPMathImage(20,0,10,10, JKQTPMathImageDataType::DoubleArray, img2, 100, 100, JKQTPMathImageMATLAB, plotImg->getPlotter()); pimg3->setColorBarTopVisible(true); pimg3->setColorBarRightVisible(true); pimg3->setImageMax(0.5); @@ -73,8 +73,8 @@ TestWidgetImages::TestWidgetImages(QWidget *parent) : pimg3->setRangeMinFailAction(JKQTPMathImageTransparent); pimg3->setAutoImageRange(false); pimg3->setImageName("I(x,y)=\\sin\\left(\\frac{2\\pi\\cdot\\sqrt{1+x^2+y^2}}{20}\\right)"); - pimg3->setDataModifier(img2M, JKQTPMathImageBase::Int32Array); - pimg3->setModifierMode(JKQTPMathImageBase::ModifyNone); + pimg3->setDataModifier(img2M, JKQTPMathImageDataType::Int32Array); + pimg3->setModifierMode(JKQTPMathImageModifierMode::ModifyNone); pimg3->setTitle("right image"); plotImg->getPlotter()->addGraph(pimg3); @@ -131,6 +131,6 @@ void TestWidgetImages::setImgPalette1(int index) void TestWidgetImages::setImgModifier(int index) { - pimg3->setModifierMode(JKQTPMathImage::ModifierMode(index)); + pimg3->setModifierMode(static_cast(index)); plotImg->redrawPlot(); } diff --git a/examples/jkqtplot_test/TestWidgetRGBImages.cpp b/examples/jkqtplot_test/TestWidgetRGBImages.cpp index 97dcdb0d20..ef245154dc 100644 --- a/examples/jkqtplot_test/TestWidgetRGBImages.cpp +++ b/examples/jkqtplot_test/TestWidgetRGBImages.cpp @@ -50,7 +50,7 @@ TestWidgetRGBImages::TestWidgetRGBImages(QWidget *parent) : rgb_aimg2[y*100+x]=double(x)/100.0; } } - rgbimg=new JKQTPRGBMathImage(0,0,10,10, JKQTPMathImageBase::DoubleArray, rgb_rimg2, 100, 100, plotImgRGB->getPlotter()); + rgbimg=new JKQTPRGBMathImage(0,0,10,10, JKQTPMathImageDataType::DoubleArray, rgb_rimg2, 100, 100, plotImgRGB->getPlotter()); rgbimg->setImageMin(-1); rgbimg->setImageMax(0.5); rgbimg->setImageMinB(-1); @@ -58,9 +58,9 @@ TestWidgetRGBImages::TestWidgetRGBImages(QWidget *parent) : rgbimg->setImageName("R image"); rgbimg->setImageNameG("G image"); rgbimg->setImageNameB("B image"); - rgbimg->setData(rgb_rimg2, rgb_gimg2, rgb_bimg2, 100, 100, JKQTPMathImageBase::DoubleArray); - rgbimg->setDataModifier(rgb_aimg2, JKQTPMathImageBase::DoubleArray); - rgbimg->setModifierMode(JKQTPMathImageBase::ModifyNone); + rgbimg->setData(rgb_rimg2, rgb_gimg2, rgb_bimg2, 100, 100, JKQTPMathImageDataType::DoubleArray); + rgbimg->setDataModifier(rgb_aimg2, JKQTPMathImageDataType::DoubleArray); + rgbimg->setModifierMode(JKQTPMathImageModifierMode::ModifyNone); plotImgRGB->getPlotter()->addGraph(rgbimg); rgbimg->setAutoImageRange(false); rgbimg->setColorBarTopVisible(true); @@ -80,8 +80,8 @@ TestWidgetRGBImages::TestWidgetRGBImages(QWidget *parent) : rgbimg2->setImageGColumn(rgb_colg=plotImgRGB->getDatastore()->addCopiedColumn(rgb_gimg2, 100*100, "G")); rgbimg2->setImageBColumn(rgb_colb=plotImgRGB->getDatastore()->addCopiedColumn(rgb_rimg2, 100*100, "B")); rgbimg2->setModifierColumn(rgb_cola=plotImgRGB->getDatastore()->addCopiedColumn(rgb_aimg2, 100*100, "alpha")); - rgbimg2->setModifierMode(JKQTPMathImageBase::ModifyNone); - //rgbimg2->setData(rgb_rimg2, rgb_gimg2, rgb_bimg2, 100, 100, JKQTPMathImageBase::DoubleArray); + rgbimg2->setModifierMode(JKQTPMathImageModifierMode::ModifyNone); + //rgbimg2->setData(rgb_rimg2, rgb_gimg2, rgb_bimg2, 100, 100, JKQTPMathImageDataType::DoubleArray); plotImgRGB->getPlotter()->addGraph(rgbimg2); rgbimg2->setAutoImageRange(true); rgbimg2->setColorBarTopVisible(true); @@ -195,8 +195,8 @@ void TestWidgetRGBImages::updateRGBChannels() void TestWidgetRGBImages::setRGBModifier(int item) { - rgbimg->setModifierMode(JKQTPMathImage::ModifierMode(item)); - rgbimg2->setModifierMode(JKQTPMathImage::ModifierMode(item)); + rgbimg->setModifierMode(static_cast(item)); + rgbimg2->setModifierMode(static_cast(item)); plotImgRGB->redrawPlot(); } diff --git a/lib/jkqtcommon/jkqtpbasicimagetools.cpp b/lib/jkqtcommon/jkqtpbasicimagetools.cpp index b6dc9dfbe2..9bd6a1c338 100644 --- a/lib/jkqtcommon/jkqtpbasicimagetools.cpp +++ b/lib/jkqtcommon/jkqtpbasicimagetools.cpp @@ -2546,6 +2546,7 @@ JKQTPImageTools::LUTType JKQTPBuildColorPaletteLUTLinSegmentsSorted(const QList< j1++; j2++; } } + JKQTPSetColorChannel(lut[lut.size()-1], channel, jkqtp_bounded(0, items.last().colval_endprevious, 255)); } }; @@ -2584,6 +2585,7 @@ JKQTPImageTools::LUTType JKQTPBuildColorPaletteLUTLinInterpolateSorted(const QLi j1++; j2++; } } + lut[lut_size-1]=items.last().second; return lut; } @@ -2971,3 +2973,65 @@ JKQTPColorPaletteSingleColorLinSegment::JKQTPColorPaletteSingleColorLinSegment() { } + + +JKQTPMathImageModifierMode StringToModifierMode(const QString &mode) { + QString m=mode.toLower(); + if (m=="value" ) return JKQTPMathImageModifierMode::ModifyValue; + if (m=="saturation" ) return JKQTPMathImageModifierMode::ModifySaturation; + if (m=="alpha" ) return JKQTPMathImageModifierMode::ModifyAlpha; + if (m=="luminance" ) return JKQTPMathImageModifierMode::ModifyLuminance; + if (m=="hue" ) return JKQTPMathImageModifierMode::ModifyHue; + + return JKQTPMathImageModifierMode::ModifyNone; +} + +QString ModifierModeToString(const JKQTPMathImageModifierMode &mode) { + + if (mode==JKQTPMathImageModifierMode::ModifyValue) return "value"; + if (mode==JKQTPMathImageModifierMode::ModifySaturation) return "saturation"; + if (mode==JKQTPMathImageModifierMode::ModifyAlpha) return "alpha"; + if (mode==JKQTPMathImageModifierMode::ModifyLuminance) return "luminance"; + if (mode==JKQTPMathImageModifierMode::ModifyHue) return "hue"; + return "none"; +} + +void JKQTPModifyImage(QImage &img, JKQTPMathImageModifierMode modifierMode, void *dataModifier, JKQTPMathImageDataType datatypeModifier, int Nx, int Ny, double internalModifierMin, double internalModifierMax) +{ + if (!dataModifier) return; + //getModifierMinMax(internalModifierMin, internalModifierMax); + if (modifierMode!=JKQTPMathImageModifierMode::ModifyNone) { + JKQTPRGBMathImageRGBMode rgbModMode=JKQTPRGBMathImageModeRGBMode; + int modChannel=3; + if (modifierMode==JKQTPMathImageModifierMode::ModifyValue) { + modChannel=2; + rgbModMode=JKQTPRGBMathImageModeHSVMode; + } else if (modifierMode==JKQTPMathImageModifierMode::ModifySaturation) { + modChannel=1; + rgbModMode=JKQTPRGBMathImageModeHSVMode; + } else if (modifierMode==JKQTPMathImageModifierMode::ModifyAlpha) { + modChannel=3; + rgbModMode=JKQTPRGBMathImageModeRGBMode; + } else if (modifierMode==JKQTPMathImageModifierMode::ModifyLuminance) { + modChannel=2; + rgbModMode=JKQTPRGBMathImageModeHSLMode; + } else if (modifierMode==JKQTPMathImageModifierMode::ModifyHue) { + modChannel=0; + rgbModMode=JKQTPRGBMathImageModeHSLMode; + } + //qDebug()<<"mod: "<(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; + case JKQTPMathImageDataType::FloatArray: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; + case JKQTPMathImageDataType::UInt8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; + case JKQTPMathImageDataType::UInt16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; + case JKQTPMathImageDataType::UInt32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; + case JKQTPMathImageDataType::UInt64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; + case JKQTPMathImageDataType::Int8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; + case JKQTPMathImageDataType::Int16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; + case JKQTPMathImageDataType::Int32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; + case JKQTPMathImageDataType::Int64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataModifier), Nx, Ny, img, modChannel, internalModifierMin, internalModifierMax, rgbModMode); break; + } + } + +} diff --git a/lib/jkqtcommon/jkqtpbasicimagetools.h b/lib/jkqtcommon/jkqtpbasicimagetools.h index 9c5a5a5678..470ce1797c 100644 --- a/lib/jkqtcommon/jkqtpbasicimagetools.h +++ b/lib/jkqtcommon/jkqtpbasicimagetools.h @@ -31,6 +31,21 @@ #include "jkqtcommon/jkqtcommon_imexport.h" #include "jkqtcommon/jkqtpmathtools.h" +/** \brief possible datatypes of the data array, plotted by this class. + \ingroup jkqtplotter_imagelots_tools + */ +enum class JKQTPMathImageDataType { + FloatArray, /*!< Data is of type \c float */ + DoubleArray, /*!< Data is of type \c double */ + UInt8Array, /*!< Data is of type \c uint8_t */ + UInt16Array, /*!< Data is of type \c uint16_t */ + UInt32Array, /*!< Data is of type \c uint32_t */ + UInt64Array, /*!< Data is of type \c uint8_t */ + Int8Array, /*!< Data is of type \c int8_t */ + Int16Array, /*!< Data is of type \c int16_t */ + Int32Array, /*!< Data is of type \c int32_t */ + Int64Array /*!< Data is of type \c int64_t */ +}; /*! \brief retrieve an R/G/B/Alpha (\a ch == 0/1/2/3) value from the \c QRgb value \a rgb \ingroup jkqtplotter_imagelots_tools @@ -1029,6 +1044,32 @@ JKQTPImageTools::LUTType JKQTCOMMON_LIB_EXPORT JKQTPBuildColorPaletteLUT(const Q +/** \brief describes how to modify a rendered image with a second data array \see ModifierModeToString(), StringToModifierMode(), JKQTPImageModifierModeComboBox + \ingroup jkqtplotter_imagelots_tools*/ +enum class JKQTPMathImageModifierMode { + ModifyNone=0, /*!< no modification \image html JKQTPMathImageBaseModifyNone.png */ + ModifyValue=1, /*!< modify the VALUE-channel from the HSV color space \image html JKQTPMathImageBaseModifyValue.png */ + ModifySaturation=2,/*!< modify the SATURATION-channel from the HSV color space \image html JKQTPMathImageBaseModifySaturation.png */ + ModifyAlpha=3,/*!< modify the ALPHA/TRANSPARENCY-channel from the RGBA color space \image html JKQTPMathImageBaseModifyAlpha.png */ + ModifyTransparency=ModifyAlpha,/*!< \see ModifyAlpha */ + ModifyLuminance=4,/*!< modify the LUMINANCE-channel from the HSL color space \image html JKQTPMathImageBaseModifyLuminance.png */ + ModifyHue=5,/*!< modify the VALUE-channel from the HSV color space \image html JKQTPMathImageBaseModifyHue.png */ +}; + +/** \brief convert a ModifierMode to a string + \ingroup jkqtplotter_imagelots_tools + \see ModifierModeToString(), ModifierMode */ +JKQTPMathImageModifierMode JKQTCOMMON_LIB_EXPORT StringToModifierMode(const QString& mode); + +/** \brief convert a string to a ModifierMode + \ingroup jkqtplotter_imagelots_tools + \see StringToModifierMode(), ModifierMode */ +QString JKQTCOMMON_LIB_EXPORT ModifierModeToString(const JKQTPMathImageModifierMode& mode); + +/** \brief modify the given image \a img, using modifier image \a dataModifier (of type \a datatypeModifier and size \a Nx * \a Ny), using values in the range \a internalModifierMin ... \a internalModifierMax ) + \ingroup jkqtplotter_imagelots_tools + */ +void JKQTCOMMON_LIB_EXPORT JKQTPModifyImage(QImage& img, JKQTPMathImageModifierMode modifierMode, void* dataModifier, JKQTPMathImageDataType datatypeModifier, int Nx, int Ny, double internalModifierMin, double internalModifierMax); diff --git a/lib/jkqtplotter/graphs/jkqtpcontour.cpp b/lib/jkqtplotter/graphs/jkqtpcontour.cpp index 6c9eaa855a..b9583bd57b 100644 --- a/lib/jkqtplotter/graphs/jkqtpcontour.cpp +++ b/lib/jkqtplotter/graphs/jkqtpcontour.cpp @@ -429,7 +429,7 @@ JKQTPColumnContourPlot::JKQTPColumnContourPlot(JKQTBasePlotter *parent): JKQTPContourPlot(parent) { this->imageColumn=imageColumn; - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; } JKQTPColumnContourPlot::JKQTPColumnContourPlot(JKQTPlotter *parent): @@ -466,9 +466,9 @@ void JKQTPColumnContourPlot::ensureImageData() if (this->Nx==0 || imageColumn<0 || !parent->getDatastore()->getColumnPointer(imageColumn,0)) { this->Ny=0; this->data=nullptr; - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; } else { - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; this->data=parent->getDatastore()->getColumnPointer(imageColumn,0); this->Ny=static_cast(parent->getDatastore()->getRows(imageColumn)/this->Nx); } diff --git a/lib/jkqtplotter/graphs/jkqtpimage.cpp b/lib/jkqtplotter/graphs/jkqtpimage.cpp index f22227e41e..a8f94a8c30 100644 --- a/lib/jkqtplotter/graphs/jkqtpimage.cpp +++ b/lib/jkqtplotter/graphs/jkqtpimage.cpp @@ -180,7 +180,7 @@ void JKQTPImageBase::plotImage(JKQTPEnhancedPainter& painter, QImage& image, dou 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.mirrored(mirrx, mirry).scaled(QSize(fabs(p2.x()-p1.x()), fabs(p2.y()-p1.y())), Qt::IgnoreAspectRatio, Qt::FastTransformation)); + painter.drawImage(QPointF(p1.x(), p1.y()), image.mirrored(mirrx, mirry).scaled(QSize(fabs(p2.x()-p1.x()), fabs(p2.y()-p1.y())), Qt::IgnoreAspectRatio, Qt::FastTransformation)); //qDebug()<<"\nimage.size = "<(image.width()); @@ -190,13 +190,13 @@ void JKQTPImageBase::plotImage(JKQTPEnhancedPainter& painter, QImage& image, dou //qDebug()<<"pixsize = "<data=nullptr; this->Nx=0; this->Ny=0; - this->datatype=DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; dataModifier=nullptr; - datatypeModifier=DoubleArray; - modifierMode=ModifyNone; + datatypeModifier=JKQTPMathImageDataType::DoubleArray; } JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, JKQTBasePlotter *parent): @@ -532,10 +503,9 @@ JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double this->data=nullptr; this->Nx=0; this->Ny=0; - this->datatype=DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; dataModifier=nullptr; - datatypeModifier=DoubleArray; - modifierMode=ModifyNone; + datatypeModifier=JKQTPMathImageDataType::DoubleArray; } JKQTPMathImageBase::JKQTPMathImageBase(JKQTPlotter *parent): @@ -544,10 +514,9 @@ JKQTPMathImageBase::JKQTPMathImageBase(JKQTPlotter *parent): this->data=nullptr; this->Nx=0; this->Ny=0; - this->datatype=DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; dataModifier=nullptr; - datatypeModifier=DoubleArray; - modifierMode=ModifyNone; + datatypeModifier=JKQTPMathImageDataType::DoubleArray; } JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, JKQTPlotter *parent): @@ -556,13 +525,12 @@ JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double this->data=nullptr; this->Nx=0; this->Ny=0; - this->datatype=DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; dataModifier=nullptr; - datatypeModifier=DoubleArray; - modifierMode=ModifyNone; + datatypeModifier=JKQTPMathImageDataType::DoubleArray; } -void JKQTPMathImageBase::setData(void* data, int Nx, int Ny, DataType datatype) { +void JKQTPMathImageBase::setData(void* data, int Nx, int Ny, JKQTPMathImageDataType datatype) { this->data=data; this->datatype=datatype; this->Nx=Nx; @@ -575,7 +543,7 @@ void JKQTPMathImageBase::setData(void* data, int Nx, int Ny) { this->Ny=Ny; } -void JKQTPMathImageBase::setDataModifier(void *data, JKQTPMathImageBase::DataType datatype) +void JKQTPMathImageBase::setDataModifier(void *data, JKQTPMathImageDataType datatype) { this->dataModifier=data; this->datatypeModifier=datatype; @@ -587,43 +555,43 @@ void JKQTPMathImageBase::getDataMinMax(double& imin, double& imax) { imin=imax=0; if (!data) return; switch(datatype) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny); break; - case JKQTPMathImageBase::FloatArray: + case JKQTPMathImageDataType::FloatArray: imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny); break; - case JKQTPMathImageBase::UInt8Array: + case JKQTPMathImageDataType::UInt8Array: imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny); break; - case JKQTPMathImageBase::UInt16Array: + case JKQTPMathImageDataType::UInt16Array: imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny); break; - case JKQTPMathImageBase::UInt32Array: + case JKQTPMathImageDataType::UInt32Array: imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny); break; - case JKQTPMathImageBase::UInt64Array: + case JKQTPMathImageDataType::UInt64Array: imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny); break; - case JKQTPMathImageBase::Int8Array: + case JKQTPMathImageDataType::Int8Array: imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny); break; - case JKQTPMathImageBase::Int16Array: + case JKQTPMathImageDataType::Int16Array: imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny); break; - case JKQTPMathImageBase::Int32Array: + case JKQTPMathImageDataType::Int32Array: imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny); break; - case JKQTPMathImageBase::Int64Array: + case JKQTPMathImageDataType::Int64Array: imin= JKQTPImagePlot_getImageMin(static_cast(data), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(data), Nx, Ny); break; @@ -636,43 +604,43 @@ void JKQTPMathImageBase::getModifierMinMax(double &imin, double &imax) imin=imax=0; if (!dataModifier) return; switch(datatypeModifier) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny); break; - case JKQTPMathImageBase::FloatArray: + case JKQTPMathImageDataType::FloatArray: imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny); break; - case JKQTPMathImageBase::UInt8Array: + case JKQTPMathImageDataType::UInt8Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny); break; - case JKQTPMathImageBase::UInt16Array: + case JKQTPMathImageDataType::UInt16Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny); break; - case JKQTPMathImageBase::UInt32Array: + case JKQTPMathImageDataType::UInt32Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny); break; - case JKQTPMathImageBase::UInt64Array: + case JKQTPMathImageDataType::UInt64Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny); break; - case JKQTPMathImageBase::Int8Array: + case JKQTPMathImageDataType::Int8Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny); break; - case JKQTPMathImageBase::Int16Array: + case JKQTPMathImageDataType::Int16Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny); break; - case JKQTPMathImageBase::Int32Array: + case JKQTPMathImageDataType::Int32Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny); break; - case JKQTPMathImageBase::Int64Array: + case JKQTPMathImageDataType::Int64Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataModifier), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataModifier), Nx, Ny); break; @@ -682,34 +650,34 @@ void JKQTPMathImageBase::getModifierMinMax(double &imin, double &imax) QVector JKQTPMathImageBase::getDataAsDoubleVector() const { switch(datatype) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny); break; - case JKQTPMathImageBase::FloatArray: + case JKQTPMathImageDataType::FloatArray: return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny); break; - case JKQTPMathImageBase::UInt8Array: + case JKQTPMathImageDataType::UInt8Array: return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny); break; - case JKQTPMathImageBase::UInt16Array: + case JKQTPMathImageDataType::UInt16Array: return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny); break; - case JKQTPMathImageBase::UInt32Array: + case JKQTPMathImageDataType::UInt32Array: return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny); break; - case JKQTPMathImageBase::UInt64Array: + case JKQTPMathImageDataType::UInt64Array: return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny); break; - case JKQTPMathImageBase::Int8Array: + case JKQTPMathImageDataType::Int8Array: return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny); break; - case JKQTPMathImageBase::Int16Array: + case JKQTPMathImageDataType::Int16Array: return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny); break; - case JKQTPMathImageBase::Int32Array: + case JKQTPMathImageDataType::Int32Array: return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny); break; - case JKQTPMathImageBase::Int64Array: + case JKQTPMathImageDataType::Int64Array: return JKQTPImagePlot_arrayToDVector(static_cast(data), Nx*Ny); break; } @@ -720,36 +688,26 @@ QVector JKQTPMathImageBase::getDataAsDoubleVector() const QVector JKQTPMathImageBase::getDataModifierAsDoubleVector() const { switch(datatypeModifier) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny); - break; - case JKQTPMathImageBase::FloatArray: + case JKQTPMathImageDataType::FloatArray: return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny); - break; - case JKQTPMathImageBase::UInt8Array: + case JKQTPMathImageDataType::UInt8Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny); - break; - case JKQTPMathImageBase::UInt16Array: + case JKQTPMathImageDataType::UInt16Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny); - break; - case JKQTPMathImageBase::UInt32Array: + case JKQTPMathImageDataType::UInt32Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny); - break; - case JKQTPMathImageBase::UInt64Array: + case JKQTPMathImageDataType::UInt64Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny); - break; - case JKQTPMathImageBase::Int8Array: + case JKQTPMathImageDataType::Int8Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny); - break; - case JKQTPMathImageBase::Int16Array: + case JKQTPMathImageDataType::Int16Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny); - break; - case JKQTPMathImageBase::Int32Array: + case JKQTPMathImageDataType::Int32Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny); - break; - case JKQTPMathImageBase::Int64Array: + case JKQTPMathImageDataType::Int64Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataModifier), Nx*Ny); - break; } QVector res; return res; @@ -760,50 +718,6 @@ void JKQTPMathImageBase::ensureImageData() } -void JKQTPMathImageBase::modifyImage(QImage &img) -{ - getModifierMinMax(internalModifierMin, internalModifierMax); - 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=2; - rgbModMode=JKQTPRGBMathImageModeHSVMode; - } else if (modifierMode==ModifySaturation) { - modChannel=1; - rgbModMode=JKQTPRGBMathImageModeHSVMode; - } else if (modifierMode==ModifyAlpha) { - modChannel=3; - rgbModMode=JKQTPRGBMathImageModeRGBMode; - } else if (modifierMode==ModifyLuminance) { - modChannel=2; - rgbModMode=JKQTPRGBMathImageModeHSLMode; - } else if (modifierMode==ModifyHue) { - modChannel=0; - rgbModMode=JKQTPRGBMathImageModeHSLMode; - } - //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; - } - } -} @@ -819,78 +733,23 @@ void JKQTPMathImage::initJKQTPMathImage() { actCopyPalette=new QAction(tr("Copy JKQTPMathImage Palette/Colorbar ..."), this); connect(actCopyPalette, SIGNAL(triggered()), this, SLOT(copyColorbarPlotAsImage())); - 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); - modifierColorBarTopAxis=new JKQTPVerticalIndependentAxis(0, 100, 0, 100, parent); - modifierColorBarTopAxis->setDrawMode1(JKQTPCADMLine); - modifierColorBarTopAxis->setDrawMode2(JKQTPCADMcomplete); - modifierColorBarTopAxis->setAxisLabel(""); - modifierColorBarTopAxis->setMinTicks(3); - modifierColorBarTopAxis->setShowZeroAxis(false); - modifierColorBarTopAxis->setMinorTicks(0); - modifierColorBarTopAxis->setTickOutsideLength(0); - modifierColorBarTopAxis->setMinorTickOutsideLength(0); - modifierColorBarRightAxis=new JKQTPHorizontalIndependentAxis (0, 100, 0, 100, parent); - modifierColorBarRightAxis->setDrawMode1(JKQTPCADMLine); - modifierColorBarRightAxis->setDrawMode2(JKQTPCADMcomplete); - modifierColorBarRightAxis->setAxisLabel(""); - modifierColorBarRightAxis->setMinTicks(5); - modifierColorBarRightAxis->setShowZeroAxis(false); - modifierColorBarRightAxis->setMinorTicks(0); - modifierColorBarRightAxis->setTickOutsideLength(0); - modifierColorBarRightAxis->setMinorTickOutsideLength(0); - this->colorBarModifiedWidth=80; - this->colorBarTopVisible=true; - this->colorBarRightVisible=true; this->palette=JKQTPMathImageGRAY; - 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; - this->imageNameFontSize=parent->getDefaultTextSize(); } -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) +JKQTPMathImage::JKQTPMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette, JKQTBasePlotter* parent): + JKQTPMathImageBase(x, y, width, height, datatype, data, Nx, Ny, parent), + JKQTPColorPaletteWithModifierStyleAndToolsMixin(parent) { initJKQTPMathImage(); this->palette=palette; } JKQTPMathImage::JKQTPMathImage(JKQTBasePlotter *parent): - JKQTPMathImageBase(0, 0, 1, 1, JKQTPMathImageBase::UInt8Array, nullptr, 0, 0, parent) + JKQTPMathImageBase(0, 0, 1, 1, JKQTPMathImageDataType::UInt8Array, nullptr, 0, 0, parent), + JKQTPColorPaletteWithModifierStyleAndToolsMixin(parent) { initJKQTPMathImage(); if (parent) this->palette=parent->getCurrentPlotterStyle().defaultPalette; @@ -898,7 +757,7 @@ JKQTPMathImage::JKQTPMathImage(JKQTBasePlotter *parent): -JKQTPMathImage::JKQTPMathImage(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette, JKQTPlotter* parent): +JKQTPMathImage::JKQTPMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette, JKQTPlotter* parent): JKQTPMathImage(x, y, width, height, datatype, data, Nx, Ny, palette, parent->getPlotter()) { } @@ -916,10 +775,9 @@ void JKQTPMathImage::setParent(JKQTBasePlotter* parent) { this->parent->deregisterAdditionalAction(actCopyPalette); } JKQTPMathImageBase::setParent(parent); - colorBarRightAxis->setParent(parent); - colorBarTopAxis->setParent(parent); - modifierColorBarRightAxis->setParent(parent); - modifierColorBarTopAxis->setParent(parent); + + cbSetParent(parent); + if (parent) { parent->registerAdditionalAction(tr("Save Image Plot Images ..."), actSaveImage); parent->registerAdditionalAction(tr("Copy Image Plot Images ..."), actCopyImage); @@ -1052,170 +910,23 @@ void JKQTPMathImage::draw(JKQTPEnhancedPainter& painter) { 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)); - QSizeF s1=colorBarRightAxis->getSize2(painter); - QSizeF s2=colorBarRightAxis->getSize1(painter); - - QSizeF names=parent->getTextSizeSize(parent->getCurrentPlotterStyle().defaultFontName, imageNameFontSize*parent->getFontSizeMultiplier(), imageName, painter); - rightSpace+=qMax(static_cast(s1.width()+s2.width()), static_cast(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)); - QSizeF s1=colorBarTopAxis->getSize2(painter); - QSizeF s2=colorBarTopAxis->getSize1(painter); - QSizeF names=parent->getTextSizeSize(parent->getCurrentPlotterStyle().defaultFontName, imageNameFontSize*parent->getFontSizeMultiplier(), imageName, painter); - //qDebug()<pt2px(painter, colorBarWidth+colorBarOffset); - topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+qMax(static_cast(s1.height()+s2.height()), static_cast(names.height())); - if (modifierMode!=ModifyNone) { - topSpace=topSpace+(2.0*parent->pt2px(painter, colorBarModifiedWidth-colorBarWidth)); - } - //qDebug()<getTextSizeSize(parent->getCurrentPlotterStyle().defaultFontName, 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(JKQTPlotterDrawingTools::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->setOtherAxisOffset(cb.left()); - colorBarRightAxis->setOtherAxisWidth(cb.width()); - colorBarRightAxis->drawAxes(painter); - - if (modifierMode!=ModifyNone) { - modifierColorBarRightAxis->setRange(internalModifierMin, internalModifierMax); - modifierColorBarRightAxis->setAxisWidth(parent->pt2px(painter, colorBarModifiedWidth)); - modifierColorBarRightAxis->setAxisOffset(cb.left()); - modifierColorBarRightAxis->setOtherAxisOffset(cb.top()); - modifierColorBarRightAxis->setOtherAxisWidth(cb.height()); - modifierColorBarRightAxis->drawAxes(painter); - } - - parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier()); - parent->getMathText()->setFontRomanOrSpecial(parent->getCurrentPlotterStyle().defaultFontName); - parent->getMathText()->parse(imageName); - parent->getMathText()->draw(painter, Qt::AlignHCenter|Qt::AlignVCenter, QRect(rightSpace.x(), rightSpace.y(), rightSpace.width(), (rightSpace.height()-barHeight)/2)); - - - } - if (colorBarTopVisible) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); - - - - - - QImage b=drawOutsidePalette(200); - - - QSizeF names=parent->getTextSizeSize(parent->getCurrentPlotterStyle().defaultFontName, 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(JKQTPlotterDrawingTools::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->setOtherAxisOffset(cb.top()); - colorBarTopAxis->setOtherAxisWidth(cb.height()); - colorBarTopAxis->drawAxes(painter); - - if (modifierMode!=ModifyNone) { - modifierColorBarTopAxis->setRange(internalModifierMin, internalModifierMax); - modifierColorBarTopAxis->setAxisWidth(parent->pt2px(painter, colorBarModifiedWidth)); - modifierColorBarTopAxis->setAxisOffset(cb.top()); - modifierColorBarTopAxis->setOtherAxisOffset(cb.left()); - modifierColorBarTopAxis->setOtherAxisWidth(cb.width()); - modifierColorBarTopAxis->drawAxes(painter); - } - - parent->getMathText()->setFontSize(imageNameFontSize*parent->getFontSizeMultiplier()); - parent->getMathText()->setFontRomanOrSpecial(parent->getCurrentPlotterStyle().defaultFontName); - 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())); - - - } - } +void JKQTPMathImage::drawOutside(JKQTPEnhancedPainter& painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace) { + JKQTPGraph::drawOutside(painter, leftSpace, rightSpace, topSpace, bottomSpace); + if (showColorBar) cbDrawOutside(painter, leftSpace, rightSpace, topSpace, bottomSpace); } QImage JKQTPMathImage::drawOutsidePalette(uint8_t steps) { uint8_t h=1; - if (modifierMode!=ModifyNone) { + if (modifierMode!=JKQTPMathImageModifierMode::ModifyNone) { h=50; } - double* d=new double[steps*h]; - double* dd=new double[steps*h]; + std::vector d(steps*h, 0.0); + std::vector dd(steps*h, 0.0); for (uint8_t i=0; i(d,h,steps, b, palette, 0, steps-1); + JKQTPImageTools::array2image(d.data(),h,steps, b, palette, 0, steps-1); //b.save("c:/temp/b1.png"); - if (modifierMode!=ModifyNone) { - modifyImage(b, dd, DoubleArray, h,steps, 0, h-1); + if (modifierMode!=JKQTPMathImageModifierMode::ModifyNone) { + modifyImage(b, dd.data(), JKQTPMathImageDataType::DoubleArray, h,steps, 0, h-1); //b.save("c:/temp/b2.png"); } - delete[] d; - delete[] dd; return b; } @@ -1264,350 +973,17 @@ void JKQTPMathImage::drawKeyMarker(JKQTPEnhancedPainter &painter, QRectF &rect) painter.drawImage(rect, getPaletteKeyImage(palette, 32,32)); } -QStringList JKQTPMathImage::getPalettes() { - return JKQTPImageTools::getPredefinedPalettes(); -} - -int JKQTPMathImage::getPalettesCount() +void JKQTPMathImage::cbGetDataMinMax(double &imin, double &imax) { - return getPalettes().size(); + getDataMinMax(imin, imax); } -QIcon JKQTPMathImage::getPaletteIcon(int i) { - QImage img=getPaletteImage(i, JKQTPImageTools::PALETTE_ICON_WIDTH); - QPixmap pix(JKQTPImageTools::PALETTE_ICON_WIDTH,8); - QRect r(0,0,JKQTPImageTools::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(static_cast(palette)); -} - -QImage JKQTPMathImage::getPaletteImage(int i, int width, int height) +void JKQTPMathImage::cbGetModifierDataMinMax(double &imin, double &imax) { - QImage img; - double* pic=static_cast(malloc(width*sizeof(double))); - for (int j=0; j(pic, width, qMax(1,height), img, static_cast(i), 0, width-1); - free(pic); - return img; + getModifierMinMax(imin, imax); } -QImage JKQTPMathImage::getPaletteImage(JKQTPMathImageColorPalette palette, int width, int height) -{ - return getPaletteImage(static_cast(palette), width,height); -} -QIcon JKQTPMathImage::getPaletteKeyIcon(int i) -{ - QImage img=getPaletteKeyImage(i, JKQTPImageTools::PALETTE_ICON_WIDTH, JKQTPImageTools::PALETTE_IMAGEICON_HEIGHT); - QPixmap pix(JKQTPImageTools::PALETTE_ICON_WIDTH,JKQTPImageTools::PALETTE_IMAGEICON_HEIGHT); - QRect r(0,0,JKQTPImageTools::PALETTE_ICON_WIDTH-1,JKQTPImageTools::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(static_cast(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=static_cast(malloc(width*height*sizeof(double))); - double mmax=0; - for (int j=0; jmmax) mmax=pic[j]; - } - JKQTPImageTools::array2image(pic, width, height, img, static_cast(i), 0, mmax); - free(pic); - return img; -} - -QImage JKQTPMathImage::getPaletteKeyImage(JKQTPMathImageColorPalette palette, int width, int height) -{ - return getPaletteKeyImage(static_cast(palette), width, height); -} - -void JKQTPMathImage::setPalette(const JKQTPMathImageColorPalette &__value) -{ - this->palette = __value; -} - -JKQTPMathImageColorPalette JKQTPMathImage::getPalette() const -{ - return this->palette; -} - -void JKQTPMathImage::setRangeMinFailAction(const JKQTPMathImageColorRangeFailAction &__value) -{ - this->rangeMinFailAction = __value; -} - -JKQTPMathImageColorRangeFailAction JKQTPMathImage::getActionRangeMinFail() const -{ - return this->rangeMinFailAction; -} - -void JKQTPMathImage::setRangeMaxFailAction(const JKQTPMathImageColorRangeFailAction &__value) -{ - this->rangeMaxFailAction = __value; -} - -JKQTPMathImageColorRangeFailAction JKQTPMathImage::getActionRangeMaxFail() const -{ - return this->rangeMaxFailAction; -} - -void JKQTPMathImage::setRangeMinFailColor(const QColor &__value) -{ - this->rangeMinFailColor = __value; -} - -QColor JKQTPMathImage::getRangeMinFailColor() const -{ - return this->rangeMinFailColor; -} - -void JKQTPMathImage::setRangeMaxFailColor(const QColor &__value) -{ - this->rangeMaxFailColor = __value; -} - -QColor JKQTPMathImage::getRangeMaxFailColor() const -{ - return this->rangeMaxFailColor; -} - -void JKQTPMathImage::setNanColor(const QColor &__value) -{ - this->nanColor = __value; -} - -QColor JKQTPMathImage::getNanColor() const -{ - return this->nanColor; -} - -void JKQTPMathImage::setInfColor(const QColor &__value) -{ - this->infColor = __value; -} - -QColor JKQTPMathImage::getInfColor() const -{ - return this->infColor; -} - -void JKQTPMathImage::setShowColorBar(bool __value) -{ - this->showColorBar = __value; -} - -bool JKQTPMathImage::getShowColorBar() const -{ - return this->showColorBar; -} - -void JKQTPMathImage::setColorBarWidth(double __value) -{ - this->colorBarWidth = __value; -} - -double JKQTPMathImage::getColorBarWidth() const -{ - return this->colorBarWidth; -} - -void JKQTPMathImage::setColorBarModifiedWidth(double __value) -{ - this->colorBarModifiedWidth = __value; -} - -double JKQTPMathImage::getColorBarModifiedWidth() const -{ - return this->colorBarModifiedWidth; -} - -void JKQTPMathImage::setColorBarOffset(double __value) -{ - this->colorBarOffset = __value; -} - -double JKQTPMathImage::getColorBarOffset() const -{ - return this->colorBarOffset; -} - -void JKQTPMathImage::setColorBarRelativeHeight(double __value) -{ - this->colorBarRelativeHeight = __value; -} - -double JKQTPMathImage::getColorBarRelativeHeight() const -{ - return this->colorBarRelativeHeight; -} - -void JKQTPMathImage::setImageMin(double __value) -{ - this->imageMin = __value; -} - -double JKQTPMathImage::getImageMin() const -{ - return this->imageMin; -} - -void JKQTPMathImage::setImageMax(double __value) -{ - this->imageMax = __value; -} - -double JKQTPMathImage::getImageMax() const -{ - return this->imageMax; -} - -void JKQTPMathImage::setAutoImageRange(bool __value) -{ - this->autoImageRange = __value; -} - -bool JKQTPMathImage::getAutoImageRange() const -{ - return this->autoImageRange; -} - -void JKQTPMathImage::setImageName(const QString &__value) -{ - this->imageName = __value; -} - -QString JKQTPMathImage::getImageName() const -{ - return this->imageName; -} - -void JKQTPMathImage::setImageNameFontSize(double __value) -{ - this->imageNameFontSize = __value; -} - -double JKQTPMathImage::getImageNameFontSize() const -{ - return this->imageNameFontSize; -} - -JKQTPVerticalIndependentAxis *JKQTPMathImage::getColorBarRightAxis() { - return this->colorBarRightAxis; -} - -JKQTPHorizontalIndependentAxis *JKQTPMathImage::getColorBarTopAxis() { - return this->colorBarTopAxis; -} - -JKQTPVerticalIndependentAxis *JKQTPMathImage::getModifierColorBarTopAxis() { - return this->modifierColorBarTopAxis; -} - -JKQTPHorizontalIndependentAxis *JKQTPMathImage::getModifierColorBarRightAxis() { - return this->modifierColorBarRightAxis ; -} - -const JKQTPVerticalIndependentAxis *JKQTPMathImage::getColorBarRightAxis() const { - return this->colorBarRightAxis; - -} - -const JKQTPHorizontalIndependentAxis *JKQTPMathImage::getColorBarTopAxis() const { - return this->colorBarTopAxis; -} - -const JKQTPVerticalIndependentAxis *JKQTPMathImage::getModifierColorBarTopAxis() const { - return this->modifierColorBarTopAxis; -} - -const JKQTPHorizontalIndependentAxis *JKQTPMathImage::getModifierColorBarRightAxis() const { - return this->modifierColorBarRightAxis ; -} - -void JKQTPMathImage::setColorBarTopVisible(bool __value) -{ - this->colorBarTopVisible = __value; -} - -bool JKQTPMathImage::getColorBarTopVisible() const -{ - return this->colorBarTopVisible; -} - -void JKQTPMathImage::setColorBarRightVisible(bool __value) -{ - this->colorBarRightVisible = __value; -} - -bool JKQTPMathImage::getColorBarRightVisible() const -{ - return this->colorBarRightVisible; -} - -void JKQTPMathImage::setAutoModifierRange(bool __value) -{ - this->autoModifierRange = __value; -} - -bool JKQTPMathImage::getAutoModifierRange() const -{ - return this->autoModifierRange; -} - -void JKQTPMathImage::setModifierMin(double __value) -{ - this->modifierMin = __value; -} - -double JKQTPMathImage::getModifierMin() const -{ - return this->modifierMin; -} - -void JKQTPMathImage::setModifierMax(double __value) -{ - this->modifierMax = __value; -} - -double JKQTPMathImage::getModifierMax() const -{ - return this->modifierMax; -} @@ -1615,46 +991,24 @@ QImage JKQTPMathImage::drawImage() { if (!data) return QImage(); QImage img(Nx, Ny, QImage::Format_ARGB32); getDataMinMax(internalDataMin, internalDataMax); + getModifierMinMax(internalModifierMin, internalModifierMax); switch(datatype) { - case JKQTPMathImageBase::DoubleArray: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; - case JKQTPMathImageBase::FloatArray: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; - case JKQTPMathImageBase::UInt8Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; - case JKQTPMathImageBase::UInt16Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; - case JKQTPMathImageBase::UInt32Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; - case JKQTPMathImageBase::UInt64Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; - case JKQTPMathImageBase::Int8Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; - case JKQTPMathImageBase::Int16Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; - case JKQTPMathImageBase::Int32Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; - case JKQTPMathImageBase::Int64Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; + case JKQTPMathImageDataType::DoubleArray: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; + case JKQTPMathImageDataType::FloatArray: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; + case JKQTPMathImageDataType::UInt8Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; + case JKQTPMathImageDataType::UInt16Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; + case JKQTPMathImageDataType::UInt32Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; + case JKQTPMathImageDataType::UInt64Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; + case JKQTPMathImageDataType::Int8Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; + case JKQTPMathImageDataType::Int16Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; + case JKQTPMathImageDataType::Int32Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; + case JKQTPMathImageDataType::Int64Array: JKQTPImageTools::array2image(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break; } - modifyImage(img); + modifyImage(img, dataModifier, datatypeModifier, Nx, Ny, internalModifierMin, internalModifierMax); return img; } -void JKQTPMathImage::setPalette(int pal) { - palette=static_cast(pal); -} - - - - - - - - - - - - - - - - - - - - @@ -1663,19 +1017,19 @@ JKQTPColumnMathImage::JKQTPColumnMathImage(JKQTBasePlotter *parent): { this->modifierColumn=-1; this->imageColumn=-1; - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; } JKQTPColumnMathImage::JKQTPColumnMathImage(double x, double y, double width, double height, JKQTBasePlotter *parent): - JKQTPMathImage(x,y,width,height,JKQTPMathImageBase::DoubleArray,nullptr,0,0,JKQTPMathImageGRAY,parent) + JKQTPMathImage(x,y,width,height,JKQTPMathImageDataType::DoubleArray,nullptr,0,0,JKQTPMathImageGRAY,parent) { this->modifierColumn=-1; this->imageColumn=-1; - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; } JKQTPColumnMathImage::JKQTPColumnMathImage(double x, double y, double width, double height, int imageColumn, JKQTPMathImageColorPalette palette, JKQTBasePlotter *parent): - JKQTPMathImage(x,y,width,height,JKQTPMathImageBase::DoubleArray,nullptr,0,0,palette,parent) + JKQTPMathImage(x,y,width,height,JKQTPMathImageDataType::DoubleArray,nullptr,0,0,palette,parent) { this->modifierColumn=-1; this->imageColumn=imageColumn; @@ -1683,7 +1037,7 @@ JKQTPColumnMathImage::JKQTPColumnMathImage(double x, double y, double width, dou Nx= static_cast(parent->getDatastore()->getColumnImageWidth(imageColumn)); Ny= static_cast(parent->getDatastore()->getColumnImageHeight(imageColumn)); } - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; } JKQTPColumnMathImage::JKQTPColumnMathImage(JKQTPlotter *parent): @@ -1754,16 +1108,16 @@ void JKQTPColumnMathImage::ensureImageData() if (this->Nx==0 || imageColumn<0 || !parent->getDatastore()->getColumnPointer(imageColumn,0)) { this->Ny=0; this->data=nullptr; - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; } else { - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; this->data=parent->getDatastore()->getColumnPointer(imageColumn,0); this->Ny= static_cast(parent->getDatastore()->getRows(imageColumn)/this->Nx); } if (this->Nx==0 || modifierColumn<0 || !parent->getDatastore()->getColumnPointer(modifierColumn,0)) { this->dataModifier=nullptr; } else { - this->datatypeModifier=JKQTPMathImageBase::DoubleArray; + this->datatypeModifier=JKQTPMathImageDataType::DoubleArray; this->dataModifier=parent->getDatastore()->getColumnPointer(modifierColumn,0); } } diff --git a/lib/jkqtplotter/graphs/jkqtpimage.h b/lib/jkqtplotter/graphs/jkqtpimage.h index 577e8245d2..a192523609 100644 --- a/lib/jkqtplotter/graphs/jkqtpimage.h +++ b/lib/jkqtplotter/graphs/jkqtpimage.h @@ -133,38 +133,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPImageBase: public JKQTPGraph { class JKQTPLOTTER_LIB_EXPORT JKQTPMathImageBase: public JKQTPImageBase { Q_OBJECT public: - /** \brief possible datatypes of the data array, plotted by this class. */ - enum DataType { - FloatArray, /*!< Data is of type \c float */ - DoubleArray, /*!< Data is of type \c double */ - UInt8Array, /*!< Data is of type \c uint8_t */ - UInt16Array, /*!< Data is of type \c uint16_t */ - UInt32Array, /*!< Data is of type \c uint32_t */ - UInt64Array, /*!< Data is of type \c uint8_t */ - Int8Array, /*!< Data is of type \c int8_t */ - Int16Array, /*!< Data is of type \c int16_t */ - Int32Array, /*!< Data is of type \c int32_t */ - Int64Array /*!< Data is of type \c int64_t */ - }; - - /** \brief describes how to modify a rendered image with a second data array \see ModifierModeToString(), StringToModifierMode(), JKQTPImageModifierModeComboBox */ - enum ModifierMode { - ModifyNone=0, /*!< no modification \image html JKQTPMathImageBaseModifyNone.png */ - ModifyValue=1, /*!< modify the VALUE-channel from the HSV color space \image html JKQTPMathImageBaseModifyValue.png */ - ModifySaturation=2,/*!< modify the SATURATION-channel from the HSV color space \image html JKQTPMathImageBaseModifySaturation.png */ - ModifyAlpha=3,/*!< modify the ALPHA/TRANSPARENCY-channel from the RGBA color space \image html JKQTPMathImageBaseModifyAlpha.png */ - ModifyTransparency=ModifyAlpha,/*!< \see ModifyAlpha */ - ModifyLuminance=4,/*!< modify the LUMINANCE-channel from the HSL color space \image html JKQTPMathImageBaseModifyLuminance.png */ - ModifyHue=5,/*!< modify the VALUE-channel from the HSV color space \image html JKQTPMathImageBaseModifyHue.png */ - }; - - /** \brief convert a ModifierMode to a string \see ModifierModeToString(), ModifierMode */ - static ModifierMode StringToModifierMode(const QString& mode); - - /** \brief convert a string to a ModifierMode \see StringToModifierMode(), ModifierMode */ - static QString ModifierModeToString(const ModifierMode& mode); - - /** \brief class constructor * @@ -194,7 +162,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImageBase: public JKQTPImageBase { * \param parent parent plotter object * */ - JKQTPMathImageBase(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTBasePlotter* parent=nullptr); + JKQTPMathImageBase(double x, double y, double width, double height, JKQTPMathImageDataType datatype, void* data, int Nx, int Ny, JKQTBasePlotter* parent=nullptr); /** \brief class constructor @@ -225,7 +193,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImageBase: public JKQTPImageBase { * \param parent parent plotter object * */ - JKQTPMathImageBase(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTPlotter* parent); + JKQTPMathImageBase(double x, double y, double width, double height, JKQTPMathImageDataType datatype, void* data, int Nx, int Ny, JKQTPlotter* parent); /** \brief plots a key marker inside the specified rectangle \a rect */ virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) override; @@ -247,26 +215,23 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImageBase: public JKQTPImageBase { /*! \copydoc data */ virtual void *getData() const; /*! \copydoc datatype */ - virtual void setDatatype(DataType __value); + virtual void setDatatype(JKQTPMathImageDataType __value); /*! \copydoc datatype */ - virtual DataType getDatatype() const; + virtual JKQTPMathImageDataType getDatatype() const; /*! \copydoc dataModifier */ virtual void setDataModifier(void* __value); /*! \copydoc dataModifier */ virtual void *getDataModifier() const; /*! \copydoc datatypeModifier */ - virtual void setDatatypeModifier(DataType __value); + virtual void setDatatypeModifier(JKQTPMathImageDataType __value); /*! \copydoc datatypeModifier */ - virtual DataType getDatatypeModifier() const; + virtual JKQTPMathImageDataType getDatatypeModifier() const; /*! \copydoc modifierMode */ - void setModifierMode(const ModifierMode & __value); - /*! \copydoc modifierMode */ - ModifierMode getModifierMode() const; /** \brief sets dataModifier (\copybrief dataModifier ) and datatypeModifier (\copybrief datatypeModifier ) */ - virtual void setDataModifier(void* data, DataType datatype); + virtual void setDataModifier(void* data, JKQTPMathImageDataType datatype); /** \brief sets data (\copybrief data ) and datatype (\copybrief datatype ), as well as the size of data (Nx: \copybrief Nx and Ny: \copybrief Ny ) */ - virtual void setData(void* data, int Nx, int Ny, DataType datatype); + virtual void setData(void* data, int Nx, int Ny, JKQTPMathImageDataType datatype); /** \brief sets data (\copybrief data ), as well as the size of data (Nx: \copybrief Nx and Ny: \copybrief Ny ) */ virtual void setData(void* data, int Nx, int Ny); /** \brief determine min/max data value of the image */ @@ -282,7 +247,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImageBase: public JKQTPImageBase { /** \brief points to the data array, holding the image */ void* data; /** \brief datatype of the data array data */ - DataType datatype; + JKQTPMathImageDataType datatype; /** \brief width of the data array data in pt */ int Nx; /** \brief height of the data array data in pt */ @@ -291,12 +256,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImageBase: public JKQTPImageBase { /** \brief points to the data array, holding the modifier image */ void* dataModifier; /** \brief datatype of the data array data */ - DataType datatypeModifier; + JKQTPMathImageDataType datatypeModifier; - /** \brief how to apply the modifier column dataModifier - * \see ModifierMode - */ - ModifierMode modifierMode; /** \brief internal storage for minimum of the image value range * @@ -321,14 +282,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImageBase: public JKQTPImageBase { /** \brief overwrite this to fill the data poiters before they are accessed (e.g. to load data from a column in the datastore */ virtual void ensureImageData(); - /** \brief modify the given image \a img, using the internally set modifier data - * \see dataModifier, datatypeModifier - */ - void modifyImage(QImage& img); - /** \brief modify the given image \a img, using modifier image \a dataModifier (of type \a datatypeModifier and size \a Nx * \a Ny), using values in the range \a internalModifierMin ... \a internalModifierMax - */ - void modifyImage(QImage& img, void* dataModifier, DataType datatypeModifier, int Nx, int Ny, double internalModifierMin, double internalModifierMax); - }; @@ -476,7 +429,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPImage: public JKQTPImageBase { \see \ref JKQTPlotterImagePlotNoDatastore */ -class JKQTPLOTTER_LIB_EXPORT JKQTPMathImage: public JKQTPMathImageBase { +class JKQTPLOTTER_LIB_EXPORT JKQTPMathImage: public JKQTPMathImageBase, public JKQTPColorPaletteWithModifierStyleAndToolsMixin { Q_OBJECT public: @@ -499,7 +452,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImage: public JKQTPMathImageBase { * \param parent parent plotter object * */ - JKQTPMathImage(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette=JKQTPMathImageGRAY, JKQTBasePlotter* parent=nullptr); + JKQTPMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette=JKQTPMathImageGRAY, JKQTBasePlotter* parent=nullptr); /** \brief class constructor * * \param x origin of the image (x-direction) in system coordinates @@ -514,7 +467,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImage: public JKQTPMathImageBase { * \param parent parent plotter object * */ - JKQTPMathImage(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette, JKQTPlotter* parent); + JKQTPMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette, JKQTPlotter* parent); /** \brief class constructor * * \param parent parent plotter object @@ -526,136 +479,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImage: public JKQTPMathImageBase { virtual void setParent(JKQTBasePlotter* parent) override; - /*! \brief get list with all available palettes */ - static QStringList getPalettes() ; - /*! \brief get list with all available palettes */ - static int getPalettesCount() ; - /*! \brief get QIcon representing the given palette */ - static QIcon getPaletteIcon(int i) ; - /*! \brief get QIcon representing the given palette */ - static QIcon getPaletteIcon(JKQTPMathImageColorPalette palette) ; - /*! \brief get QImage representing the given palette */ - static QImage getPaletteImage(int i, int width, int height=1) ; - /*! \brief get QImage representing the given palette */ - static QImage getPaletteImage(JKQTPMathImageColorPalette palette, int width, int height=1) ; - - /*! \brief get QIcon representing the given palette */ - static QIcon getPaletteKeyIcon(int i) ; - /*! \brief get QIcon representing the given palette */ - static QIcon getPaletteKeyIcon(JKQTPMathImageColorPalette palette) ; - /*! \brief get QImage representing the given palette */ - static QImage getPaletteKeyImage(int i, int width, int height) ; - /*! \brief get QImage representing the given palette */ - static QImage getPaletteKeyImage(JKQTPMathImageColorPalette palette, int width, int height) ; - - - /*! \copydoc palette */ - void setPalette(const JKQTPMathImageColorPalette & __value); - /*! \copydoc palette */ - void setPalette(int pal); - /*! \copydoc palette */ - JKQTPMathImageColorPalette getPalette() const; - /*! \copydoc rangeMinFailAction */ - void setRangeMinFailAction(const JKQTPMathImageColorRangeFailAction & __value); - /*! \copydoc rangeMinFailAction */ - JKQTPMathImageColorRangeFailAction getActionRangeMinFail() const; - /*! \copydoc rangeMaxFailAction */ - void setRangeMaxFailAction(const JKQTPMathImageColorRangeFailAction & __value); - /*! \copydoc rangeMaxFailAction */ - JKQTPMathImageColorRangeFailAction getActionRangeMaxFail() const; - /*! \copydoc rangeMinFailColor */ - void setRangeMinFailColor(const QColor & __value); - /*! \copydoc rangeMinFailColor */ - QColor getRangeMinFailColor() const; - /*! \copydoc rangeMaxFailColor */ - void setRangeMaxFailColor(const QColor & __value); - /*! \copydoc rangeMaxFailColor */ - QColor getRangeMaxFailColor() const; - /*! \copydoc nanColor */ - void setNanColor(const QColor & __value); - /*! \copydoc nanColor */ - QColor getNanColor() const; - /*! \copydoc infColor */ - void setInfColor(const QColor & __value); - /*! \copydoc infColor */ - QColor getInfColor() const; - /*! \copydoc showColorBar */ - void setShowColorBar(bool __value); - /*! \copydoc showColorBar */ - bool getShowColorBar() const; - /*! \copydoc colorBarWidth */ - void setColorBarWidth(double __value); - /*! \copydoc colorBarWidth */ - double getColorBarWidth() const; - /*! \copydoc colorBarModifiedWidth */ - void setColorBarModifiedWidth(double __value); - /*! \copydoc colorBarModifiedWidth */ - double getColorBarModifiedWidth() const; - /*! \copydoc colorBarOffset */ - void setColorBarOffset(double __value); - /*! \copydoc colorBarOffset */ - double getColorBarOffset() const; - /*! \copydoc colorBarRelativeHeight */ - void setColorBarRelativeHeight(double __value); - /*! \copydoc colorBarRelativeHeight */ - double getColorBarRelativeHeight() const; - /*! \copydoc imageMin */ - void setImageMin(double __value); - /*! \copydoc imageMin */ - double getImageMin() const; - /*! \copydoc imageMax */ - void setImageMax(double __value); - /*! \copydoc imageMax */ - double getImageMax() const; - /*! \copydoc autoImageRange */ - void setAutoImageRange(bool __value); - /*! \copydoc autoImageRange */ - bool getAutoImageRange() const; - /*! \copydoc imageName */ - void setImageName(const QString & __value); - /*! \copydoc imageName */ - QString getImageName() const; - /*! \copydoc imageNameFontSize */ - void setImageNameFontSize(double __value); - /*! \copydoc imageNameFontSize */ - double getImageNameFontSize() const; - /*! \copydoc colorBarRightAxis */ - JKQTPVerticalIndependentAxis* getColorBarRightAxis(); - /*! \copydoc colorBarTopAxis */ - JKQTPHorizontalIndependentAxis* getColorBarTopAxis(); - /*! \copydoc modifierColorBarTopAxis */ - JKQTPVerticalIndependentAxis* getModifierColorBarTopAxis(); - /*! \copydoc modifierColorBarRightAxis */ - JKQTPHorizontalIndependentAxis* getModifierColorBarRightAxis(); - /*! \copydoc colorBarRightAxis */ - const JKQTPVerticalIndependentAxis* getColorBarRightAxis() const; - /*! \copydoc colorBarTopAxis */ - const JKQTPHorizontalIndependentAxis* getColorBarTopAxis() const; - /*! \copydoc modifierColorBarTopAxis */ - const JKQTPVerticalIndependentAxis* getModifierColorBarTopAxis() const; - /*! \copydoc modifierColorBarRightAxis */ - const JKQTPHorizontalIndependentAxis *getModifierColorBarRightAxis() const; - /*! \copydoc colorBarTopVisible */ - void setColorBarTopVisible(bool __value); - /*! \copydoc colorBarTopVisible */ - bool getColorBarTopVisible() const; - /*! \copydoc colorBarRightVisible */ - void setColorBarRightVisible(bool __value); - /*! \copydoc colorBarRightVisible */ - bool getColorBarRightVisible() const; - /*! \copydoc autoModifierRange */ - void setAutoModifierRange(bool __value); - /*! \copydoc autoModifierRange */ - bool getAutoModifierRange() const; - /*! \copydoc modifierMin */ - void setModifierMin(double __value); - /*! \copydoc modifierMin */ - double getModifierMin() const; - /*! \copydoc modifierMax */ - void setModifierMax(double __value); - /*! \copydoc modifierMax */ - double getModifierMax() const; - /*! \brief if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...) @@ -702,75 +525,13 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImage: public JKQTPMathImageBase { /** \brief plots a key marker inside the specified rectangle \a rect */ virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) override; + /** \brief determine min/max data value of the image */ + virtual void cbGetDataMinMax(double& imin, double& imax) override; + /** \brief determine min/max data value of the modifier image */ + virtual void cbGetModifierDataMinMax(double& imin, double& imax) override; protected: void initJKQTPMathImage(); - /** \brief top color bar visible */ - bool colorBarTopVisible; - /** \brief right color bar visible */ - bool colorBarRightVisible; - /** \brief name of the image displayed above color bar (may contain LaTeX markup!) */ - QString imageName; - /** \brief font size in points when displaying imageName */ - double imageNameFontSize; - /** \brief palette for plotting an image */ - JKQTPMathImageColorPalette palette; - /** \brief indicate whether to display a color bar */ - bool showColorBar; - /** \brief width of the color bar [pt] */ - double colorBarWidth; - /** \brief width of the color bar when modifier is on */ - double colorBarModifiedWidth; - /** \brief height of the color bar, as multiple of plotHeight */ - double colorBarRelativeHeight; - /** \brief indicates whether to estimate min/max of the image automatically */ - bool autoImageRange; - /** \brief image value range minimum */ - double imageMin; - /** \brief image value range maximum */ - double imageMax; - /** \brief indicates whether to estimate min/max of the modifier automatically */ - bool autoModifierRange; - /** \brief modifier value range minimum */ - double modifierMin; - /** \brief modifier value range maximum */ - double modifierMax; - /** \brief offset between outside space border and color bar [pt] */ - double colorBarOffset; - /** \brief which action to take if a color is below \a imageMin and \a autoImageRange \c ==false */ - JKQTPMathImageColorRangeFailAction rangeMinFailAction; - /** \brief which action to take if a color is above \a imageMax and \a autoImageRange \c ==false */ - JKQTPMathImageColorRangeFailAction rangeMaxFailAction; - /** \brief color to use for some settings of \a rangeMinFailAction */ - QColor rangeMinFailColor; - /** \brief color to use for some settings of \a rangeMaxFailAction */ - QColor rangeMaxFailColor; - /** \brief color to use for a not-a-number value */ - QColor nanColor; - /** \brief color to use for an infinity value */ - QColor infColor; - - - /** \brief object used for color bar axes (right border, image data) - * - * \note this axis has some kind of a special role. It is used to format color bar axes - */ - JKQTPVerticalIndependentAxis* colorBarRightAxis; - /** \brief object used for color bar axes (top border, image data) - * - * \note this axis has some kind of a special role. It is used to format color bar axes - */ - JKQTPHorizontalIndependentAxis* colorBarTopAxis; - /** \brief object used for color bar axes (right border, modifier image data) - * - * \note this axis has some kind of a special role. It is used to format color bar axes - */ - JKQTPVerticalIndependentAxis* modifierColorBarTopAxis; - /** \brief object used for color bar axes (top border, modifier image data) - * - * \note this axis has some kind of a special role. It is used to format color bar axes - */ - JKQTPHorizontalIndependentAxis* modifierColorBarRightAxis; protected: /** \brief QActions that saves the image (asking the user for a filename) @@ -830,20 +591,20 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImage: public JKQTPMathImageBase { 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) { + int xx=jkqtp_truncTo((x-this->x)/width*double(Nx)); + int yy=jkqtp_truncTo((y-this->y)/height*double(Ny)); + if (xx>=0 && xx(Nx) && yy>=0 && yy(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; + case JKQTPMathImageDataType::DoubleArray: return static_cast((static_cast(data))[yy*Nx+xx]); + case JKQTPMathImageDataType::FloatArray: return static_cast((static_cast(data))[yy*Nx+xx]); + case JKQTPMathImageDataType::UInt8Array: return static_cast((static_cast(data))[yy*Nx+xx]); + case JKQTPMathImageDataType::UInt16Array: return static_cast((static_cast(data))[yy*Nx+xx]); + case JKQTPMathImageDataType::UInt32Array: return static_cast((static_cast(data))[yy*Nx+xx]); + case JKQTPMathImageDataType::UInt64Array: return static_cast((static_cast(data))[yy*Nx+xx]); + case JKQTPMathImageDataType::Int8Array: return static_cast((static_cast(data))[yy*Nx+xx]); + case JKQTPMathImageDataType::Int16Array: return static_cast((static_cast(data))[yy*Nx+xx]); + case JKQTPMathImageDataType::Int32Array: return static_cast((static_cast(data))[yy*Nx+xx]); + case JKQTPMathImageDataType::Int64Array: return static_cast((static_cast(data))[yy*Nx+xx]); } } return 0.0; } @@ -855,26 +616,26 @@ double JKQTPMathImage::getPixelValue(int xIdx, int yIdx) const { //ensureImageData(); if (!data) return 0; switch(datatype) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: return (static_cast(data))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::FloatArray: - return (static_cast(data))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::UInt8Array: - return (static_cast(data))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::UInt16Array: - return (static_cast(data))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::UInt32Array: - return (static_cast(data))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::UInt64Array: - return (static_cast(data))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::Int8Array: - return (static_cast(data))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::Int16Array: - return (static_cast(data))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::Int32Array: - return (static_cast(data))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::Int64Array: - return (static_cast(data))[yIdx*getNx()+xIdx]; + case JKQTPMathImageDataType::FloatArray: + return static_cast((static_cast(data))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::UInt8Array: + return static_cast((static_cast(data))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::UInt16Array: + return static_cast((static_cast(data))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::UInt32Array: + return static_cast((static_cast(data))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::UInt64Array: + return static_cast((static_cast(data))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::Int8Array: + return static_cast((static_cast(data))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::Int16Array: + return static_cast((static_cast(data))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::Int32Array: + return static_cast((static_cast(data))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::Int64Array: + return static_cast((static_cast(data))[yIdx*getNx()+xIdx]); default: return 0; } @@ -884,25 +645,25 @@ double JKQTPMathImage::getPixelValue(int xIdx, int yIdx) const { //////////////////////////////////////////////////////////////////////////////////////////////// int JKQTPMathImage::getSampleSize() const { switch(datatype) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: return sizeof(double); - case JKQTPMathImageBase::FloatArray: + case JKQTPMathImageDataType::FloatArray: return sizeof(float); - case JKQTPMathImageBase::UInt8Array: + case JKQTPMathImageDataType::UInt8Array: return sizeof(uint8_t); - case JKQTPMathImageBase::UInt16Array: + case JKQTPMathImageDataType::UInt16Array: return sizeof(uint16_t); - case JKQTPMathImageBase::UInt32Array: + case JKQTPMathImageDataType::UInt32Array: return sizeof(uint32_t); - case JKQTPMathImageBase::UInt64Array: + case JKQTPMathImageDataType::UInt64Array: return sizeof(uint64_t); - case JKQTPMathImageBase::Int8Array: + case JKQTPMathImageDataType::Int8Array: return sizeof(int8_t); - case JKQTPMathImageBase::Int16Array: + case JKQTPMathImageDataType::Int16Array: return sizeof(int16_t); - case JKQTPMathImageBase::Int32Array: + case JKQTPMathImageDataType::Int32Array: return sizeof(int32_t); - case JKQTPMathImageBase::Int64Array: + case JKQTPMathImageDataType::Int64Array: return sizeof(int64_t); default: return 0; @@ -915,20 +676,20 @@ int JKQTPMathImage::getSampleSize() const { double JKQTPMathImage::getModifierValueAt(double x, double y) { ensureImageData(); - int xx=trunc((x-this->x)/width*double(Nx)); - int yy=trunc((y-this->y)/height*double(Ny)); + int xx=jkqtp_truncTo((x-this->x)/width*double(Nx)); + int yy=jkqtp_truncTo((y-this->y)/height*double(Ny)); if (xx>=0 && xx<(int64_t)Nx && yy>=0 && yy<(int64_t)Ny) { switch(datatypeModifier) { - case JKQTPMathImageBase::DoubleArray: return (static_cast(dataModifier))[yy*Nx+xx]; break; - case JKQTPMathImageBase::FloatArray: return (static_cast(dataModifier))[yy*Nx+xx]; break; - case JKQTPMathImageBase::UInt8Array: return (static_cast(dataModifier))[yy*Nx+xx]; break; - case JKQTPMathImageBase::UInt16Array: return (static_cast(dataModifier))[yy*Nx+xx]; break; - case JKQTPMathImageBase::UInt32Array: return (static_cast(dataModifier))[yy*Nx+xx]; break; - case JKQTPMathImageBase::UInt64Array: return (static_cast(dataModifier))[yy*Nx+xx]; break; - case JKQTPMathImageBase::Int8Array: return (static_cast(dataModifier))[yy*Nx+xx]; break; - case JKQTPMathImageBase::Int16Array: return (static_cast(dataModifier))[yy*Nx+xx]; break; - case JKQTPMathImageBase::Int32Array: return (static_cast(dataModifier))[yy*Nx+xx]; break; - case JKQTPMathImageBase::Int64Array: return (static_cast(dataModifier))[yy*Nx+xx]; break; + case JKQTPMathImageDataType::DoubleArray: return (static_cast(dataModifier))[yy*Nx+xx]; + case JKQTPMathImageDataType::FloatArray: return static_cast((static_cast(dataModifier))[yy*Nx+xx]); + case JKQTPMathImageDataType::UInt8Array: return static_cast((static_cast(dataModifier))[yy*Nx+xx]); + case JKQTPMathImageDataType::UInt16Array: return static_cast((static_cast(dataModifier))[yy*Nx+xx]); + case JKQTPMathImageDataType::UInt32Array: return static_cast((static_cast(dataModifier))[yy*Nx+xx]); + case JKQTPMathImageDataType::UInt64Array: return static_cast((static_cast(dataModifier))[yy*Nx+xx]); + case JKQTPMathImageDataType::Int8Array: return static_cast((static_cast(dataModifier))[yy*Nx+xx]); + case JKQTPMathImageDataType::Int16Array: return static_cast((static_cast(dataModifier))[yy*Nx+xx]); + case JKQTPMathImageDataType::Int32Array: return static_cast((static_cast(dataModifier))[yy*Nx+xx]); + case JKQTPMathImageDataType::Int64Array: return static_cast((static_cast(dataModifier))[yy*Nx+xx]); } } return 0.0; } @@ -940,26 +701,26 @@ double JKQTPMathImage::getModifierPixelValue(int xIdx, int yIdx) const { //ensureImageData(); if (!dataModifier) return 0; switch(datatypeModifier) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: return (static_cast(dataModifier))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::FloatArray: - return (static_cast(dataModifier))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::UInt8Array: - return (static_cast(dataModifier))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::UInt16Array: - return (static_cast(dataModifier))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::UInt32Array: - return (static_cast(dataModifier))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::UInt64Array: - return (static_cast(dataModifier))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::Int8Array: - return (static_cast(dataModifier))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::Int16Array: - return (static_cast(dataModifier))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::Int32Array: - return (static_cast(dataModifier))[yIdx*getNx()+xIdx]; - case JKQTPMathImageBase::Int64Array: - return (static_cast(dataModifier))[yIdx*getNx()+xIdx]; + case JKQTPMathImageDataType::FloatArray: + return static_cast((static_cast(dataModifier))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::UInt8Array: + return static_cast((static_cast(dataModifier))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::UInt16Array: + return static_cast((static_cast(dataModifier))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::UInt32Array: + return static_cast((static_cast(dataModifier))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::UInt64Array: + return static_cast((static_cast(dataModifier))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::Int8Array: + return static_cast((static_cast(dataModifier))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::Int16Array: + return static_cast((static_cast(dataModifier))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::Int32Array: + return static_cast((static_cast(dataModifier))[yIdx*getNx()+xIdx]); + case JKQTPMathImageDataType::Int64Array: + return static_cast((static_cast(dataModifier))[yIdx*getNx()+xIdx]); default: return 0; } @@ -969,25 +730,25 @@ double JKQTPMathImage::getModifierPixelValue(int xIdx, int yIdx) const { //////////////////////////////////////////////////////////////////////////////////////////////// int JKQTPMathImage::getModifierSampleSize() const { switch(datatypeModifier) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: return sizeof(double); - case JKQTPMathImageBase::FloatArray: + case JKQTPMathImageDataType::FloatArray: return sizeof(float); - case JKQTPMathImageBase::UInt8Array: + case JKQTPMathImageDataType::UInt8Array: return sizeof(uint8_t); - case JKQTPMathImageBase::UInt16Array: + case JKQTPMathImageDataType::UInt16Array: return sizeof(uint16_t); - case JKQTPMathImageBase::UInt32Array: + case JKQTPMathImageDataType::UInt32Array: return sizeof(uint32_t); - case JKQTPMathImageBase::UInt64Array: + case JKQTPMathImageDataType::UInt64Array: return sizeof(uint64_t); - case JKQTPMathImageBase::Int8Array: + case JKQTPMathImageDataType::Int8Array: return sizeof(int8_t); - case JKQTPMathImageBase::Int16Array: + case JKQTPMathImageDataType::Int16Array: return sizeof(int16_t); - case JKQTPMathImageBase::Int32Array: + case JKQTPMathImageDataType::Int32Array: return sizeof(int32_t); - case JKQTPMathImageBase::Int64Array: + case JKQTPMathImageDataType::Int64Array: return sizeof(int64_t); default: return 0; diff --git a/lib/jkqtplotter/graphs/jkqtpimagergb.cpp b/lib/jkqtplotter/graphs/jkqtpimagergb.cpp index 2877136d95..2eea70849f 100644 --- a/lib/jkqtplotter/graphs/jkqtpimagergb.cpp +++ b/lib/jkqtplotter/graphs/jkqtpimagergb.cpp @@ -121,20 +121,20 @@ void JKQTPRGBMathImage::initObject() -JKQTPRGBMathImage::JKQTPRGBMathImage(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTBasePlotter *parent): +JKQTPRGBMathImage::JKQTPRGBMathImage(double x, double y, double width, double height, JKQTPMathImageDataType 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): +JKQTPRGBMathImage::JKQTPRGBMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, void* data, int Nx, int Ny, JKQTPlotter *parent): JKQTPRGBMathImage(x, y, width, height, datatype, data, Nx, Ny, parent->getPlotter()) { } JKQTPRGBMathImage::JKQTPRGBMathImage(JKQTBasePlotter *parent): - JKQTPMathImageBase(0,0,0,0, DoubleArray, nullptr, 0, 0, parent) + JKQTPMathImageBase(0,0,0,0, JKQTPMathImageDataType::DoubleArray, nullptr, 0, 0, parent) { initObject(); } @@ -500,12 +500,12 @@ void *JKQTPRGBMathImage::getDataR() const return getData(); } -void JKQTPRGBMathImage::setDatatypeR(JKQTPMathImageBase::DataType __value) +void JKQTPRGBMathImage::setDatatypeR(JKQTPMathImageDataType __value) { setDatatype(__value); } -JKQTPMathImageBase::DataType JKQTPRGBMathImage::getDatatypeR() const +JKQTPMathImageDataType JKQTPRGBMathImage::getDatatypeR() const { return getDatatype(); } @@ -520,12 +520,12 @@ void *JKQTPRGBMathImage::getDataG() const return this->dataG; } -void JKQTPRGBMathImage::setDatatypeG(JKQTPMathImageBase::DataType __value) +void JKQTPRGBMathImage::setDatatypeG(JKQTPMathImageDataType __value) { this->datatypeG = __value; } -JKQTPMathImageBase::DataType JKQTPRGBMathImage::getDatatypeG() const +JKQTPMathImageDataType JKQTPRGBMathImage::getDatatypeG() const { return this->datatypeG; } @@ -540,12 +540,12 @@ void *JKQTPRGBMathImage::getDataB() const return this->dataB; } -void JKQTPRGBMathImage::setDatatypeB(JKQTPMathImageBase::DataType __value) +void JKQTPRGBMathImage::setDatatypeB(JKQTPMathImageDataType __value) { this->datatypeB = __value; } -JKQTPMathImageBase::DataType JKQTPRGBMathImage::getDatatypeB() const +JKQTPMathImageDataType JKQTPRGBMathImage::getDatatypeB() const { return this->datatypeB; } @@ -832,49 +832,119 @@ JKQTPRGBMathImageRGBMode JKQTPRGBMathImage::getRgbMode() const return this->rgbMode; } +void JKQTPRGBMathImage::setModifierMode(const JKQTPMathImageModifierMode &__value) +{ + this->modifierMode = __value; +} + +JKQTPMathImageModifierMode JKQTPRGBMathImage::getModifierMode() const +{ + return this->modifierMode; +} + + +void JKQTPRGBMathImage::setColorBarModifiedWidth(double __value) +{ + this->colorBarModifiedWidth = __value; +} + +double JKQTPRGBMathImage::getColorBarModifiedWidth() const +{ + return this->colorBarModifiedWidth; +} + + +JKQTPVerticalIndependentAxis *JKQTPRGBMathImage::getModifierColorBarTopAxis() { + return this->modifierColorBarTopAxis; +} + +JKQTPHorizontalIndependentAxis *JKQTPRGBMathImage::getModifierColorBarRightAxis() { + return this->modifierColorBarRightAxis ; +} + + +const JKQTPVerticalIndependentAxis *JKQTPRGBMathImage::getModifierColorBarTopAxis() const { + return this->modifierColorBarTopAxis; +} + +const JKQTPHorizontalIndependentAxis *JKQTPRGBMathImage::getModifierColorBarRightAxis() const { + return this->modifierColorBarRightAxis ; +} + + +void JKQTPRGBMathImage::setAutoModifierRange(bool __value) +{ + this->autoModifierRange = __value; +} + +bool JKQTPRGBMathImage::getAutoModifierRange() const +{ + return this->autoModifierRange; +} + +void JKQTPRGBMathImage::setModifierMin(double __value) +{ + this->modifierMin = __value; +} + +double JKQTPRGBMathImage::getModifierMin() const +{ + return this->modifierMin; +} + +void JKQTPRGBMathImage::setModifierMax(double __value) +{ + this->modifierMax = __value; +} + +double JKQTPRGBMathImage::getModifierMax() const +{ + return this->modifierMax; +} + void JKQTPRGBMathImage::getDataMinMaxG(double& imin, double& imax) { ensureImageData(); if (autoImageRange) { imin=imax=0; if (!dataG) return; switch(datatype) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny); break; - case JKQTPMathImageBase::FloatArray: + case JKQTPMathImageDataType::FloatArray: imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny); break; - case JKQTPMathImageBase::UInt8Array: + case JKQTPMathImageDataType::UInt8Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny); break; - case JKQTPMathImageBase::UInt16Array: + case JKQTPMathImageDataType::UInt16Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny); break; - case JKQTPMathImageBase::UInt32Array: + case JKQTPMathImageDataType::UInt32Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny); break; - case JKQTPMathImageBase::UInt64Array: + case JKQTPMathImageDataType::UInt64Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny); break; - case JKQTPMathImageBase::Int8Array: + case JKQTPMathImageDataType::Int8Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny); break; - case JKQTPMathImageBase::Int16Array: + case JKQTPMathImageDataType::Int16Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny); break; - case JKQTPMathImageBase::Int32Array: + case JKQTPMathImageDataType::Int32Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny); break; - case JKQTPMathImageBase::Int64Array: + case JKQTPMathImageDataType::Int64Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataG), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataG), Nx, Ny); break; @@ -891,43 +961,43 @@ void JKQTPRGBMathImage::getDataMinMaxB(double& imin, double& imax) { imin=imax=0; if (!dataG) return; switch(datatype) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny); break; - case JKQTPMathImageBase::FloatArray: + case JKQTPMathImageDataType::FloatArray: imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny); break; - case JKQTPMathImageBase::UInt8Array: + case JKQTPMathImageDataType::UInt8Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny); break; - case JKQTPMathImageBase::UInt16Array: + case JKQTPMathImageDataType::UInt16Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny); break; - case JKQTPMathImageBase::UInt32Array: + case JKQTPMathImageDataType::UInt32Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny); break; - case JKQTPMathImageBase::UInt64Array: + case JKQTPMathImageDataType::UInt64Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny); break; - case JKQTPMathImageBase::Int8Array: + case JKQTPMathImageDataType::Int8Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny); break; - case JKQTPMathImageBase::Int16Array: + case JKQTPMathImageDataType::Int16Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny); break; - case JKQTPMathImageBase::Int32Array: + case JKQTPMathImageDataType::Int32Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny); break; - case JKQTPMathImageBase::Int64Array: + case JKQTPMathImageDataType::Int64Array: imin= JKQTPImagePlot_getImageMin(static_cast(dataB), Nx, Ny); imax= JKQTPImagePlot_getImageMax(static_cast(dataB), Nx, Ny); break; @@ -949,16 +1019,16 @@ double JKQTPRGBMathImage::getValueAt(double x, double y, int channel) 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; + case JKQTPMathImageDataType::DoubleArray: return static_cast((static_cast(dd))[yy*Nx+xx]); break; + case JKQTPMathImageDataType::FloatArray: return static_cast((static_cast(dd))[yy*Nx+xx]); break; + case JKQTPMathImageDataType::UInt8Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break; + case JKQTPMathImageDataType::UInt16Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break; + case JKQTPMathImageDataType::UInt32Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break; + case JKQTPMathImageDataType::UInt64Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break; + case JKQTPMathImageDataType::Int8Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break; + case JKQTPMathImageDataType::Int16Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break; + case JKQTPMathImageDataType::Int32Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break; + case JKQTPMathImageDataType::Int64Array: return static_cast((static_cast(dd))[yy*Nx+xx]); break; } } return 0.0; } @@ -1045,61 +1115,62 @@ QImage JKQTPRGBMathImage::drawImage() { c.setHsv(0,255,127); img.fill(c.rgba()); } + getModifierMinMax(internalModifierMin, internalModifierMax); 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; + case JKQTPMathImageDataType::DoubleArray: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break; + case JKQTPMathImageDataType::FloatArray: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break; + case JKQTPMathImageDataType::UInt8Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break; + case JKQTPMathImageDataType::UInt16Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break; + case JKQTPMathImageDataType::UInt32Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break; + case JKQTPMathImageDataType::UInt64Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break; + case JKQTPMathImageDataType::Int8Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break; + case JKQTPMathImageDataType::Int16Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break; + case JKQTPMathImageDataType::Int32Array: JKQTPImagePlot_array2RGBimage(static_cast(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rgbMode); break; + case JKQTPMathImageDataType::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; + case JKQTPMathImageDataType::DoubleArray: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break; + case JKQTPMathImageDataType::FloatArray: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break; + case JKQTPMathImageDataType::UInt8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break; + case JKQTPMathImageDataType::UInt16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break; + case JKQTPMathImageDataType::UInt32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break; + case JKQTPMathImageDataType::UInt64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break; + case JKQTPMathImageDataType::Int8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break; + case JKQTPMathImageDataType::Int16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break; + case JKQTPMathImageDataType::Int32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataG), Nx, Ny, img, palette, internalDataMinG, internalDataMaxG, rgbMode); break; + case JKQTPMathImageDataType::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; + case JKQTPMathImageDataType::DoubleArray: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break; + case JKQTPMathImageDataType::FloatArray: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break; + case JKQTPMathImageDataType::UInt8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break; + case JKQTPMathImageDataType::UInt16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break; + case JKQTPMathImageDataType::UInt32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break; + case JKQTPMathImageDataType::UInt64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break; + case JKQTPMathImageDataType::Int8Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break; + case JKQTPMathImageDataType::Int16Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break; + case JKQTPMathImageDataType::Int32Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break; + case JKQTPMathImageDataType::Int64Array: JKQTPImagePlot_array2RGBimage(static_cast(dataB), Nx, Ny, img, palette, internalDataMinB, internalDataMaxB, rgbMode); break; } } - modifyImage(img); + JKQTPModifyImage(img, modifierMode, dataModifier, datatypeModifier, Nx, Ny, internalModifierMin, internalModifierMax); return img; } -void JKQTPRGBMathImage::setData(void* data, int Nx, int Ny, DataType datatype) { +void JKQTPRGBMathImage::setData(void* data, int Nx, int Ny, JKQTPMathImageDataType datatype) { this->data=data; this->datatype=datatype; this->dataG=nullptr; @@ -1117,7 +1188,7 @@ void JKQTPRGBMathImage::setData(void* data, int Nx, int Ny) { } -void JKQTPRGBMathImage::setData(void *data, void *dataG, void *dataB, int Nx, int Ny, JKQTPMathImageBase::DataType datatype) { +void JKQTPRGBMathImage::setData(void *data, void *dataG, void *dataB, int Nx, int Ny, JKQTPMathImageDataType datatype) { this->data=data; this->datatype=datatype; this->datatypeG=datatype; @@ -1139,33 +1210,33 @@ void JKQTPRGBMathImage::setData(void *data, void *dataG, void *dataB, int Nx, in JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(JKQTBasePlotter *parent): - JKQTPRGBMathImage(0,0,0,0,DoubleArray,nullptr,0,0,parent) + JKQTPRGBMathImage(0,0,0,0,JKQTPMathImageDataType::DoubleArray,nullptr,0,0,parent) { this->modifierColumn=-1; this->imageRColumn=-1; this->imageGColumn=-1; this->imageBColumn=-1; - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; } JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, JKQTBasePlotter *parent): - JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,Nx,Ny,parent) + JKQTPRGBMathImage(x,y,width,height,JKQTPMathImageDataType::DoubleArray,nullptr,Nx,Ny,parent) { this->modifierColumn=-1; this->imageRColumn=-1; this->imageGColumn=-1; this->imageBColumn=-1; - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; } JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, JKQTBasePlotter *parent): - JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,0,0,parent) + JKQTPRGBMathImage(x,y,width,height,JKQTPMathImageDataType::DoubleArray,nullptr,0,0,parent) { this->modifierColumn=-1; this->imageRColumn=imageRColumn; this->imageGColumn=-1; this->imageBColumn=-1; - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; if (parent && imageRColumn>=0 && parent->getDatastore()) { Nx= static_cast(parent->getDatastore()->getColumnImageWidth(imageRColumn)); Ny= static_cast(parent->getDatastore()->getColumnImageHeight(imageRColumn)); @@ -1173,13 +1244,13 @@ JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double widt } JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int imageGColumn, JKQTBasePlotter *parent): - JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,0,0,parent) + JKQTPRGBMathImage(x,y,width,height,JKQTPMathImageDataType::DoubleArray,nullptr,0,0,parent) { this->modifierColumn=-1; this->imageRColumn=imageRColumn; this->imageGColumn=imageGColumn; this->imageBColumn=-1; - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; if (parent && imageRColumn>=0 && parent->getDatastore()) { Nx= static_cast(parent->getDatastore()->getColumnImageWidth(imageRColumn)); Ny= static_cast(parent->getDatastore()->getColumnImageHeight(imageRColumn)); @@ -1187,13 +1258,13 @@ JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double widt } JKQTPColumnRGBMathImage::JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int imageGColumn, int imageBColumn, JKQTBasePlotter *parent): - JKQTPRGBMathImage(x,y,width,height,DoubleArray,nullptr,0,0,parent) + JKQTPRGBMathImage(x,y,width,height,JKQTPMathImageDataType::DoubleArray,nullptr,0,0,parent) { this->modifierColumn=-1; this->imageRColumn=imageRColumn; this->imageGColumn=imageGColumn; this->imageBColumn=imageBColumn; - this->datatype=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; if (parent && imageRColumn>=0 && parent->getDatastore()) { Nx= static_cast(parent->getDatastore()->getColumnImageWidth(imageRColumn)); Ny= static_cast(parent->getDatastore()->getColumnImageHeight(imageRColumn)); @@ -1234,9 +1305,9 @@ bool JKQTPColumnRGBMathImage::usesColumn(int c) const void JKQTPColumnRGBMathImage::ensureImageData() { JKQTPRGBMathImage::ensureImageData(); - this->datatype=JKQTPMathImageBase::DoubleArray; - this->datatypeG=JKQTPMathImageBase::DoubleArray; - this->datatypeB=JKQTPMathImageBase::DoubleArray; + this->datatype=JKQTPMathImageDataType::DoubleArray; + this->datatypeG=JKQTPMathImageDataType::DoubleArray; + this->datatypeB=JKQTPMathImageDataType::DoubleArray; this->data=parent->getDatastore()->getColumnPointer(imageRColumn,0); this->dataG=parent->getDatastore()->getColumnPointer(imageGColumn,0); this->dataB=parent->getDatastore()->getColumnPointer(imageBColumn,0); @@ -1248,7 +1319,7 @@ void JKQTPColumnRGBMathImage::ensureImageData() Ny=1; } }*/ - this->datatypeModifier=JKQTPMathImageBase::DoubleArray; + this->datatypeModifier=JKQTPMathImageDataType::DoubleArray; this->dataModifier=parent->getDatastore()->getColumnPointer(modifierColumn,0); } @@ -1256,36 +1327,26 @@ void JKQTPColumnRGBMathImage::ensureImageData() QVector JKQTPRGBMathImage::getDataGAsDoubleVector() const { switch(datatype) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny); - break; - case JKQTPMathImageBase::FloatArray: + case JKQTPMathImageDataType::FloatArray: return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny); - break; - case JKQTPMathImageBase::UInt8Array: + case JKQTPMathImageDataType::UInt8Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny); - break; - case JKQTPMathImageBase::UInt16Array: + case JKQTPMathImageDataType::UInt16Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny); - break; - case JKQTPMathImageBase::UInt32Array: + case JKQTPMathImageDataType::UInt32Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny); - break; - case JKQTPMathImageBase::UInt64Array: + case JKQTPMathImageDataType::UInt64Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny); - break; - case JKQTPMathImageBase::Int8Array: + case JKQTPMathImageDataType::Int8Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny); - break; - case JKQTPMathImageBase::Int16Array: + case JKQTPMathImageDataType::Int16Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny); - break; - case JKQTPMathImageBase::Int32Array: + case JKQTPMathImageDataType::Int32Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny); - break; - case JKQTPMathImageBase::Int64Array: + case JKQTPMathImageDataType::Int64Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataG), Nx*Ny); - break; } QVector res; return res; @@ -1294,36 +1355,26 @@ QVector JKQTPRGBMathImage::getDataGAsDoubleVector() const QVector JKQTPRGBMathImage::getDataBAsDoubleVector() const { switch(datatype) { - case JKQTPMathImageBase::DoubleArray: + case JKQTPMathImageDataType::DoubleArray: return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny); - break; - case JKQTPMathImageBase::FloatArray: + case JKQTPMathImageDataType::FloatArray: return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny); - break; - case JKQTPMathImageBase::UInt8Array: + case JKQTPMathImageDataType::UInt8Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny); - break; - case JKQTPMathImageBase::UInt16Array: + case JKQTPMathImageDataType::UInt16Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny); - break; - case JKQTPMathImageBase::UInt32Array: + case JKQTPMathImageDataType::UInt32Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny); - break; - case JKQTPMathImageBase::UInt64Array: + case JKQTPMathImageDataType::UInt64Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny); - break; - case JKQTPMathImageBase::Int8Array: + case JKQTPMathImageDataType::Int8Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny); - break; - case JKQTPMathImageBase::Int16Array: + case JKQTPMathImageDataType::Int16Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny); - break; - case JKQTPMathImageBase::Int32Array: + case JKQTPMathImageDataType::Int32Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny); - break; - case JKQTPMathImageBase::Int64Array: + case JKQTPMathImageDataType::Int64Array: return JKQTPImagePlot_arrayToDVector(static_cast(dataB), Nx*Ny); - break; } QVector res; return res; diff --git a/lib/jkqtplotter/graphs/jkqtpimagergb.h b/lib/jkqtplotter/graphs/jkqtpimagergb.h index 17fab82244..311cf99961 100644 --- a/lib/jkqtplotter/graphs/jkqtpimagergb.h +++ b/lib/jkqtplotter/graphs/jkqtpimagergb.h @@ -34,11 +34,18 @@ -/*! \brief class to plot an image from an 2-dimensional array of values +/*! \brief class to plot an image from an 2-dimensional array of RGB values \ingroup jkqtplotter_imagelots_elements + This class extends JKQTPMathImageBase and interprets the data array JKQTPMathImageBase::data as + the 1st (RED) color channel and adds two more channels for GREEN and BLUE. + + Using setRgbMode() you can also use a different color system than RGB. + \image html rgbimageplots.png \image html rgbimageplot_opencv.png + + \see Examples: \ref JKQTPlotterRGBImagePlot and \ref JKQTPlotterImagePlotRGBOpenCV */ class JKQTPLOTTER_LIB_EXPORT JKQTPRGBMathImage: public JKQTPMathImageBase { Q_OBJECT @@ -59,7 +66,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPRGBMathImage: public JKQTPMathImageBase { * \param parent parent plotter object * */ - JKQTPRGBMathImage(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTBasePlotter* parent=nullptr); + JKQTPRGBMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, void* data, int Nx, int Ny, JKQTBasePlotter* parent=nullptr); /** \brief class constructor * @@ -74,7 +81,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPRGBMathImage: public JKQTPMathImageBase { * \param parent parent plotter object * */ - JKQTPRGBMathImage(double x, double y, double width, double height, DataType datatype, void* data, int Nx, int Ny, JKQTPlotter* parent); + JKQTPRGBMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, void* data, int Nx, int Ny, JKQTPlotter* parent); /** \brief class constructor * @@ -97,12 +104,12 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPRGBMathImage: public JKQTPMathImageBase { /** \brief set the plot-data to a given array \a data (red), \a dataG (green), \a dataB (blue) with size \a Nx * \a Ny in row-major ordering and with the given \a datatype */ - virtual void setData(void* dataR, void* dataG, void* dataB, int Nx, int Ny, DataType datatype); + virtual void setData(void* dataR, void* dataG, void* dataB, int Nx, int Ny, JKQTPMathImageDataType datatype); /** \brief set the plot-data to a given array \a data (red), \a dataG (green), \a dataB (blue) with size \a Nx * \a Ny in row-major ordering */ virtual void setData(void* dataR, void* dataG, void* dataB, int Nx, int Ny); /** \brief set the plot-data to a given array \a data (red) with size \a Nx * \a Ny in row-major ordering and with the given \a datatype */ - virtual void setData(void* dataR, int Nx, int Ny, DataType datatype) override; + virtual void setData(void* dataR, int Nx, int Ny, JKQTPMathImageDataType datatype) override; /** \brief set the plot-data to a given array \a data (red) with size \a Nx * \a Ny in row-major ordering */ virtual void setData(void* dataR, int Nx, int Ny) override ; @@ -116,26 +123,26 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPRGBMathImage: public JKQTPMathImageBase { /*! \copydoc data */ void* getDataR() const; /*! \copydoc datatype */ - void setDatatypeR(DataType __value); + void setDatatypeR(JKQTPMathImageDataType __value); /*! \copydoc datatype */ - DataType getDatatypeR() const; + JKQTPMathImageDataType getDatatypeR() const; /*! \copydoc dataG */ virtual void setDataG(void* __value); /*! \copydoc dataG */ void* getDataG() const; /*! \copydoc datatypeG */ - void setDatatypeG(DataType __value); + void setDatatypeG(JKQTPMathImageDataType __value); /*! \copydoc datatypeG */ - DataType getDatatypeG() const; + JKQTPMathImageDataType getDatatypeG() const; /*! \copydoc dataB */ virtual void setDataB(void* __value); /*! \copydoc dataB */ void* getDataB() const; /*! \copydoc datatypeB */ - void setDatatypeB(DataType __value); + void setDatatypeB(JKQTPMathImageDataType __value); /*! \copydoc datatypeB */ - DataType getDatatypeB() const; + JKQTPMathImageDataType getDatatypeB() const; /*! \copydoc showColorBar */ void setShowColorBar(bool __value); /*! \copydoc showColorBar */ @@ -256,6 +263,35 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPRGBMathImage: public JKQTPMathImageBase { void setRgbMode(JKQTPRGBMathImageRGBMode __value); /*! \copydoc rgbMode */ JKQTPRGBMathImageRGBMode getRgbMode() const; + /*! \copydoc modifierMode */ + void setModifierMode(const JKQTPMathImageModifierMode & __value); + /*! \copydoc modifierMode */ + JKQTPMathImageModifierMode getModifierMode() const; + + /*! \copydoc colorBarModifiedWidth */ + void setColorBarModifiedWidth(double __value); + /*! \copydoc colorBarModifiedWidth */ + double getColorBarModifiedWidth() const; + /*! \copydoc modifierColorBarTopAxis */ + JKQTPVerticalIndependentAxis* getModifierColorBarTopAxis(); + /*! \copydoc modifierColorBarRightAxis */ + JKQTPHorizontalIndependentAxis* getModifierColorBarRightAxis(); + /*! \copydoc modifierColorBarTopAxis */ + const JKQTPVerticalIndependentAxis* getModifierColorBarTopAxis() const; + /*! \copydoc modifierColorBarRightAxis */ + const JKQTPHorizontalIndependentAxis *getModifierColorBarRightAxis() const; + /*! \copydoc autoModifierRange */ + void setAutoModifierRange(bool __value); + /*! \copydoc autoModifierRange */ + bool getAutoModifierRange() const; + /*! \copydoc modifierMin */ + void setModifierMin(double __value); + /*! \copydoc modifierMin */ + double getModifierMin() const; + /*! \copydoc modifierMax */ + void setModifierMax(double __value); + /*! \copydoc modifierMax */ + double getModifierMax() const; /** \brief return the data of the green channel used for plotting as a QVector in row-major data-ordering */ QVector getDataGAsDoubleVector() const; @@ -296,11 +332,11 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPRGBMathImage: public JKQTPMathImageBase { /** \brief points to the data array, holding the image */ void* dataG; /** \brief datatype of the data array data */ - DataType datatypeG; + JKQTPMathImageDataType datatypeG; /** \brief points to the data array, holding the image */ void* dataB; /** \brief datatype of the data array data */ - DataType datatypeB; + JKQTPMathImageDataType datatypeB; /** \brief how to interpret the three data channels red, green and blue */ JKQTPRGBMathImageRGBMode rgbMode; @@ -376,8 +412,31 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPRGBMathImage: public JKQTPMathImageBase { * \note this axis has some kind of a special role. It is used to format color bar axes */ JKQTPHorizontalIndependentAxis* colorBarTopAxisB; + /** \brief indicates whether to estimate min/max of the modifier automatically */ + bool autoModifierRange; + /** \brief modifier value range minimum */ + double modifierMin; + /** \brief modifier value range maximum */ + double modifierMax; + /** \brief width of the color bar when modifier is on */ + double colorBarModifiedWidth; + /** \brief how to apply the modifier column dataModifier + * \see ModifierMode + */ + JKQTPMathImageModifierMode modifierMode; + /** \brief object used for color bar axes (right border, modifier image data) + * + * \note this axis has some kind of a special role. It is used to format color bar axes + */ + JKQTPVerticalIndependentAxis* modifierColorBarTopAxis; + /** \brief object used for color bar axes (top border, modifier image data) + * + * \note this axis has some kind of a special role. It is used to format color bar axes + */ + JKQTPHorizontalIndependentAxis* modifierColorBarRightAxis; + /** \brief internal storage for minimum of the green image value range * * This is set e.g. when calling drawImage() or draw() diff --git a/lib/jkqtplotter/gui/jkqtpcomboboxes.cpp b/lib/jkqtplotter/gui/jkqtpcomboboxes.cpp index ad2a26f7b9..60a986d7ef 100644 --- a/lib/jkqtplotter/gui/jkqtpcomboboxes.cpp +++ b/lib/jkqtplotter/gui/jkqtpcomboboxes.cpp @@ -550,29 +550,29 @@ void JKQTPSpecialLineTypeComboBox::addStep(JKQTPSpecialLineType step, const QStr JKQTPImageModifierModeComboBox::JKQTPImageModifierModeComboBox(QWidget * /*parent*/) { - addMode(JKQTPMathImageBase::ModifyNone, tr("none")); - addMode(JKQTPMathImageBase::ModifyValue, tr("value")); - addMode(JKQTPMathImageBase::ModifySaturation, tr("saturation")); - addMode(JKQTPMathImageBase::ModifyAlpha, tr("alpha/transparency")); - addMode(JKQTPMathImageBase::ModifyLuminance, tr("luminance")); - addMode(JKQTPMathImageBase::ModifyHue, tr("hue")); + addMode(JKQTPMathImageModifierMode::ModifyNone, tr("none")); + addMode(JKQTPMathImageModifierMode::ModifyValue, tr("value")); + addMode(JKQTPMathImageModifierMode::ModifySaturation, tr("saturation")); + addMode(JKQTPMathImageModifierMode::ModifyAlpha, tr("alpha/transparency")); + addMode(JKQTPMathImageModifierMode::ModifyLuminance, tr("luminance")); + addMode(JKQTPMathImageModifierMode::ModifyHue, tr("hue")); } -JKQTPMathImageBase::ModifierMode JKQTPImageModifierModeComboBox::getModifierMode() const +JKQTPMathImageModifierMode JKQTPImageModifierModeComboBox::getModifierMode() const { bool ok=false; - JKQTPMathImageBase::ModifierMode m=JKQTPMathImageBase::ModifyNone; - if (currentIndex()>=0) m=JKQTPMathImageBase::ModifierMode(itemData(currentIndex()).toInt(&ok)); - if (!ok) m=JKQTPMathImageBase::ModifyNone; + JKQTPMathImageModifierMode m=JKQTPMathImageModifierMode::ModifyNone; + if (currentIndex()>=0) m=JKQTPMathImageModifierMode(itemData(currentIndex()).toInt(&ok)); + if (!ok) m=JKQTPMathImageModifierMode::ModifyNone; return m; } -void JKQTPImageModifierModeComboBox::setModifierMode(JKQTPMathImageBase::ModifierMode mode) +void JKQTPImageModifierModeComboBox::setModifierMode(JKQTPMathImageModifierMode mode) { setCurrentIndex(findData(static_cast(mode))); } -void JKQTPImageModifierModeComboBox::addMode(JKQTPMathImageBase::ModifierMode mode, const QString &name, const QIcon &icon) +void JKQTPImageModifierModeComboBox::addMode(JKQTPMathImageModifierMode mode, const QString &name, const QIcon &icon) { addItem(icon, name, static_cast(mode)); } diff --git a/lib/jkqtplotter/gui/jkqtpcomboboxes.h b/lib/jkqtplotter/gui/jkqtpcomboboxes.h index b968b19533..3290a046e9 100644 --- a/lib/jkqtplotter/gui/jkqtpcomboboxes.h +++ b/lib/jkqtplotter/gui/jkqtpcomboboxes.h @@ -250,20 +250,20 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineTypeComboBox: public QComboBox { }; -/*! \brief a QComboBox which shows JKQTPMathImageBase::ModifierMode +/*! \brief a QComboBox which shows JKQTPMathImageModifierMode \ingroup jkqtpcomboboxes - \see JKQTPMathImageBase::ModifierMode + \see JKQTPMathImageModifierMode */ class JKQTPLOTTER_LIB_EXPORT JKQTPImageModifierModeComboBox: public QComboBox { Q_OBJECT public: JKQTPImageModifierModeComboBox(QWidget* parent=nullptr); - JKQTPMathImageBase::ModifierMode getModifierMode() const; - void setModifierMode(JKQTPMathImageBase::ModifierMode mode); + JKQTPMathImageModifierMode getModifierMode() const; + void setModifierMode(JKQTPMathImageModifierMode mode); protected: - void addMode(JKQTPMathImageBase::ModifierMode mode, const QString& name, const QIcon& icon=QIcon()); + void addMode(JKQTPMathImageModifierMode mode, const QString& name, const QIcon& icon=QIcon()); }; #endif // JKQTPCOMBOBOXES_H diff --git a/lib/jkqtplotter/jkqtpimagetools.cpp b/lib/jkqtplotter/jkqtpimagetools.cpp index 35c06e4ff4..b81905b5f3 100644 --- a/lib/jkqtplotter/jkqtpimagetools.cpp +++ b/lib/jkqtplotter/jkqtpimagetools.cpp @@ -25,6 +25,7 @@ #include "jkqtplotter/jkqtpbaseelements.h" #include "jkqtplotter/jkqtpbaseplotter.h" #include "jkqtcommon/jkqtpdrawingtools.h" +#include "jkqtplotter/graphs/jkqtpimage.h" #ifdef QT_XML_LIB # include #endif @@ -87,27 +88,27 @@ void JKQTPColorPaletteStyleAndToolsMixin::cbGetOutsideSize(JKQTPEnhancedPainter& Q_UNUSED(leftSpace); Q_UNUSED(bottomSpace); if (showColorBar) { - double internalDataMin=0; - double internalDataMax=0; - cbGetDataMinMax(internalDataMin, internalDataMax); - if (colorBarRightVisible) { - rightSpace+=cbParent->pt2px(painter, colorBarWidth+colorBarOffset); - colorBarRightAxis->setRange(internalDataMin, internalDataMax); - colorBarRightAxis->setAxisWidth(colorBarRelativeHeight*cbParent->getPlotHeight()); - QSizeF s1=colorBarRightAxis->getSize2(painter); - QSizeF s2=colorBarRightAxis->getSize1(painter); - QSizeF names=cbParent->getTextSizeSize(imageNameFontName, imageNameFontSize*cbParent->getFontSizeMultiplier(), imageName, painter); - rightSpace+=qMax(static_cast(s1.width()+s2.width()), static_cast(names.width())); - } - if (colorBarTopVisible) { - //topSpace+=cbParent->pt2px(painter, colorBarWidth+colorBarOffset); - colorBarTopAxis->setRange(internalDataMin, internalDataMax); - colorBarTopAxis->setAxisWidth(colorBarRelativeHeight*cbParent->getPlotWidth()); - QSizeF s1=colorBarTopAxis->getSize2(painter); - QSizeF s2=colorBarTopAxis->getSize1(painter); - QSizeF names=cbParent->getTextSizeSize(imageNameFontName, imageNameFontSize*cbParent->getFontSizeMultiplier(), imageName, painter); - topSpace+=cbParent->pt2px(painter, colorBarWidth+colorBarOffset)+qMax(static_cast(s1.height()+s2.height()), static_cast(names.height())); - } + double internalDataMin=0; + double internalDataMax=0; + cbGetDataMinMax(internalDataMin, internalDataMax); + if (colorBarRightVisible) { + rightSpace+=cbParent->pt2px(painter, colorBarWidth+colorBarOffset); + colorBarRightAxis->setRange(internalDataMin, internalDataMax); + colorBarRightAxis->setAxisWidth(colorBarRelativeHeight*cbParent->getPlotHeight()); + QSizeF s1=colorBarRightAxis->getSize2(painter); + QSizeF s2=colorBarRightAxis->getSize1(painter); + QSizeF names=cbParent->getTextSizeSize(imageNameFontName, imageNameFontSize*cbParent->getFontSizeMultiplier(), imageName, painter); + rightSpace+=qMax(static_cast(s1.width()+s2.width()), static_cast(names.width())); + } + if (colorBarTopVisible) { + //topSpace+=cbParent->pt2px(painter, colorBarWidth+colorBarOffset); + colorBarTopAxis->setRange(internalDataMin, internalDataMax); + colorBarTopAxis->setAxisWidth(colorBarRelativeHeight*cbParent->getPlotWidth()); + QSizeF s1=colorBarTopAxis->getSize2(painter); + QSizeF s2=colorBarTopAxis->getSize1(painter); + QSizeF names=cbParent->getTextSizeSize(imageNameFontName, imageNameFontSize*cbParent->getFontSizeMultiplier(), imageName, painter); + topSpace+=cbParent->pt2px(painter, colorBarWidth+colorBarOffset)+qMax(static_cast(s1.height()+s2.height()), static_cast(names.height())); + } } } @@ -124,9 +125,9 @@ void JKQTPColorPaletteStyleAndToolsMixin::cbDrawOutside(JKQTPEnhancedPainter& pa static const uint8_t h=1; static const uint8_t dSize = 200*h; uint8_t d[dSize];//, dd[200*h]; - for (int i=0; i<200; i++) { + for (uint8_t i=0; i<200; i++) { for (int j=0; j(i)*h+j]=i; //dd[i*h+j]=j; } } @@ -137,7 +138,7 @@ void JKQTPColorPaletteStyleAndToolsMixin::cbDrawOutside(JKQTPEnhancedPainter& pa QSizeF names=cbParent->getTextSizeSize(imageNameFontName, imageNameFontSize*cbParent->getFontSizeMultiplier(), imageName, painter); double icolorBarRelativeHeight=colorBarRelativeHeight; - int barHeight=rightSpace.height()*icolorBarRelativeHeight; + int barHeight=static_cast(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, cbParent->pt2px(painter, colorBarWidth), barHeight); + QRect cb(static_cast(rightSpace.x()+cbParent->pt2px(painter, colorBarOffset)), rightSpace.top()+(rightSpace.height()-barHeight)/2, static_cast(cbParent->pt2px(painter, colorBarWidth)), barHeight); painter.drawImage(cb, b.mirrored(true, false)); QPen p=painter.pen(); p.setColor(colorBarRightAxis->getAxisColor()); @@ -176,9 +177,9 @@ void JKQTPColorPaletteStyleAndToolsMixin::cbDrawOutside(JKQTPEnhancedPainter& pa static const uint8_t h=1; static const uint8_t dSize = 200*h; uint8_t d[dSize];//, dd[200*h]; - for (int i=0; i<200; i++) { + for (uint8_t i=0; i<200; i++) { for (int j=0; j(i)*h+j]=i; //dd[i*h+j]=j; } } @@ -188,7 +189,7 @@ void JKQTPColorPaletteStyleAndToolsMixin::cbDrawOutside(JKQTPEnhancedPainter& pa QSizeF names=cbParent->getTextSizeSize(imageNameFontName, imageNameFontSize*cbParent->getFontSizeMultiplier(), imageName, painter); double icolorBarRelativeHeight=colorBarRelativeHeight; - int barWidth=topSpace.width()*icolorBarRelativeHeight; + int barWidth=static_cast(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+(colorBarWidth)), barWidth, cbParent->pt2px(painter, colorBarWidth)); + QRect cb(topSpace.x()+(topSpace.width()-barWidth)/2, static_cast(topSpace.bottom()-cbParent->pt2px(painter, colorBarOffset+(colorBarWidth))), barWidth, static_cast(cbParent->pt2px(painter, colorBarWidth))); //qDebug()<<"t: "<(JKQTPImageTools::PALETTE_ICON_WIDTH)); QPixmap pix(JKQTPImageTools::PALETTE_ICON_WIDTH,8); QRect r(0,0,JKQTPImageTools::PALETTE_ICON_WIDTH-1,7); QPainter p(&pix); @@ -254,26 +255,25 @@ QIcon JKQTPColorPaletteStyleAndToolsMixin::getPaletteIcon(JKQTPMathImageColorPal return getPaletteIcon(static_cast(palette)); } -QImage JKQTPColorPaletteStyleAndToolsMixin::getPaletteImage(int i, int width) +QImage JKQTPColorPaletteStyleAndToolsMixin::getPaletteImage(int i, size_t width) { QImage img; - double* pic=static_cast(malloc(width*sizeof(double))); - for (int j=0; j pic(static_cast(width), 0.0); + for (size_t j=0; j(pic, width, 1, img, static_cast(i), 0, width-1); - free(pic); + JKQTPImageTools::array2image(pic.data(), static_cast(width), 1, img, static_cast(i), 0, width-1); return img; } -QImage JKQTPColorPaletteStyleAndToolsMixin::getPaletteImage(JKQTPMathImageColorPalette palette, int width) +QImage JKQTPColorPaletteStyleAndToolsMixin::getPaletteImage(JKQTPMathImageColorPalette palette, size_t width) { return getPaletteImage(static_cast(palette), width); } QIcon JKQTPColorPaletteStyleAndToolsMixin::getPaletteKeyIcon(int i) { - QImage img=getPaletteKeyImage(i, JKQTPImageTools::PALETTE_ICON_WIDTH, JKQTPImageTools::PALETTE_IMAGEICON_HEIGHT); + QImage img=getPaletteKeyImage(i, static_cast(JKQTPImageTools::PALETTE_ICON_WIDTH), static_cast(JKQTPImageTools::PALETTE_IMAGEICON_HEIGHT)); QPixmap pix(JKQTPImageTools::PALETTE_ICON_WIDTH,JKQTPImageTools::PALETTE_IMAGEICON_HEIGHT); QRect r(0,0,JKQTPImageTools::PALETTE_ICON_WIDTH-1,JKQTPImageTools::PALETTE_IMAGEICON_HEIGHT-1); QPainter p(&pix); @@ -289,7 +289,7 @@ QIcon JKQTPColorPaletteStyleAndToolsMixin::getPaletteKeyIcon(JKQTPMathImageColor return getPaletteIcon(static_cast(palette)); } -QImage JKQTPColorPaletteStyleAndToolsMixin::getPaletteKeyImage(int i, int width, int height) +QImage JKQTPColorPaletteStyleAndToolsMixin::getPaletteKeyImage(int i, size_t width, size_t height) { QImage img; @@ -302,20 +302,19 @@ QImage JKQTPColorPaletteStyleAndToolsMixin::getPaletteKeyImage(int i, int width, const double w2x=double(width*width)/(8.0*8.0); const double w2y=double(height*height)/(8.0*8.0); - double* pic=static_cast(malloc(width*height*sizeof(double))); + std::vector pic(width*height, 0.0); double mmax=0; - for (int j=0; jmmax) mmax=pic[j]; } - JKQTPImageTools::array2image(pic, width, height, img, static_cast(i), 0, mmax); - free(pic); + JKQTPImageTools::array2image(pic.data(), static_cast(width), static_cast(height), img, static_cast(i), 0, mmax); return img; } -QImage JKQTPColorPaletteStyleAndToolsMixin::getPaletteKeyImage(JKQTPMathImageColorPalette palette, int width, int height) +QImage JKQTPColorPaletteStyleAndToolsMixin::getPaletteKeyImage(JKQTPMathImageColorPalette palette, size_t width, size_t height) { return getPaletteKeyImage(static_cast(palette), width, height); } @@ -538,3 +537,283 @@ bool JKQTPColorPaletteStyleAndToolsMixin::getColorBarRightVisible() const return this->colorBarRightVisible; } + +JKQTPColorPaletteWithModifierStyleAndToolsMixin::JKQTPColorPaletteWithModifierStyleAndToolsMixin(JKQTBasePlotter *parent): + JKQTPColorPaletteStyleAndToolsMixin(parent) +{ + modifierColorBarTopAxis=new JKQTPVerticalIndependentAxis(0, 100, 0, 100, parent); + modifierColorBarTopAxis->setDrawMode1(JKQTPCADMLine); + modifierColorBarTopAxis->setDrawMode2(JKQTPCADMcomplete); + modifierColorBarTopAxis->setAxisLabel(""); + modifierColorBarTopAxis->setMinTicks(3); + modifierColorBarTopAxis->setShowZeroAxis(false); + modifierColorBarTopAxis->setMinorTicks(0); + modifierColorBarTopAxis->setTickOutsideLength(0); + modifierColorBarTopAxis->setMinorTickOutsideLength(0); + modifierColorBarRightAxis=new JKQTPHorizontalIndependentAxis (0, 100, 0, 100, parent); + modifierColorBarRightAxis->setDrawMode1(JKQTPCADMLine); + modifierColorBarRightAxis->setDrawMode2(JKQTPCADMcomplete); + modifierColorBarRightAxis->setAxisLabel(""); + modifierColorBarRightAxis->setMinTicks(5); + modifierColorBarRightAxis->setShowZeroAxis(false); + modifierColorBarRightAxis->setMinorTicks(0); + modifierColorBarRightAxis->setTickOutsideLength(0); + modifierColorBarRightAxis->setMinorTickOutsideLength(0); + this->colorBarModifiedWidth=80; + modifierMode=JKQTPMathImageModifierMode::ModifyNone; +} + + + +void JKQTPColorPaletteWithModifierStyleAndToolsMixin::cbGetOutsideSize(JKQTPEnhancedPainter &painter, int &leftSpace, int &rightSpace, int &topSpace, int &bottomSpace) +{ + Q_UNUSED(leftSpace); + Q_UNUSED(bottomSpace); + if (showColorBar) { + double internalDataMin=0; + double internalDataMax=0; + double internalModifierMin=0; + double internalModifierMax=0; + cbGetDataMinMax(internalDataMin, internalDataMax); + cbGetModifierDataMinMax(internalDataMin, internalDataMax); + if (colorBarRightVisible) { + rightSpace+=cbParent->pt2px(painter, colorBarWidth+colorBarOffset); + colorBarRightAxis->setRange(internalDataMin, internalDataMax); + colorBarRightAxis->setAxisWidth(colorBarRelativeHeight*cbParent->getPlotHeight()); + modifierColorBarRightAxis->setRange(internalModifierMin, internalModifierMax); + modifierColorBarRightAxis->setAxisWidth(cbParent->pt2px(painter, colorBarModifiedWidth)); + QSizeF s1=colorBarRightAxis->getSize2(painter); + QSizeF s2=colorBarRightAxis->getSize1(painter); + QSizeF names=cbParent->getTextSizeSize(imageNameFontName, imageNameFontSize*cbParent->getFontSizeMultiplier(), imageName, painter); + rightSpace+=qMax(static_cast(s1.width()+s2.width()), static_cast(names.width())); + if (modifierMode!=JKQTPMathImageModifierMode::ModifyNone) { + rightSpace=rightSpace+static_cast(2.0*cbParent->pt2px(painter, colorBarModifiedWidth-colorBarWidth)); + } + } + if (colorBarTopVisible) { + //topSpace+=cbParent->pt2px(painter, colorBarWidth+colorBarOffset); + colorBarTopAxis->setRange(internalDataMin, internalDataMax); + colorBarTopAxis->setAxisWidth(colorBarRelativeHeight*cbParent->getPlotWidth()); + modifierColorBarTopAxis->setRange(internalModifierMin, internalModifierMax); + modifierColorBarTopAxis->setAxisWidth(cbParent->pt2px(painter, colorBarModifiedWidth)); + QSizeF s1=colorBarTopAxis->getSize2(painter); + QSizeF s2=colorBarTopAxis->getSize1(painter); + QSizeF names=cbParent->getTextSizeSize(imageNameFontName, imageNameFontSize*cbParent->getFontSizeMultiplier(), imageName, painter); + topSpace+=cbParent->pt2px(painter, colorBarWidth+colorBarOffset)+qMax(static_cast(s1.height()+s2.height()), static_cast(names.height())); + if (modifierMode!=JKQTPMathImageModifierMode::ModifyNone) { + topSpace=topSpace+static_cast(2.0*cbParent->pt2px(painter, colorBarModifiedWidth-colorBarWidth)); + } + } + } +} + +void JKQTPColorPaletteWithModifierStyleAndToolsMixin::cbDrawOutside(JKQTPEnhancedPainter &painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace) +{ + if (showColorBar) { + double internalDataMin=0; + double internalDataMax=0; + double internalModifierMin=0; + double internalModifierMax=0; + cbGetDataMinMax(internalDataMin, internalDataMax); + cbGetModifierDataMinMax(internalDataMin, internalDataMax); + uint8_t h=1; + static const uint8_t dSize = 200*h; + if (modifierMode!=JKQTPMathImageModifierMode::ModifyNone) { + h=50; + } + std::vector d(dSize, 0.0); + std::vector dd(dSize, 0.0); + for (uint8_t i=0; i(d.data(),h,dSize/h, b, palette, 0, dSize/h-1); + if (modifierMode!=JKQTPMathImageModifierMode::ModifyNone) { + modifyImage(b, dd.data(), JKQTPMathImageDataType::DoubleArray, h,dSize/h, 0, h-1); + } + + if (colorBarRightVisible) { + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + + QSizeF names=cbParent->getTextSizeSize(imageNameFontName, imageNameFontSize*cbParent->getFontSizeMultiplier(), imageName, painter); + + double icolorBarRelativeHeight=colorBarRelativeHeight; + int barHeight=static_cast(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)/2(rightSpace.x()+cbParent->pt2px(painter, colorBarOffset)), rightSpace.top()+(rightSpace.height()-barHeight)/2, static_cast(cbParent->pt2px(painter, (modifierMode==JKQTPMathImageModifierMode::ModifyNone)?colorBarWidth:colorBarModifiedWidth)), barHeight); + painter.drawImage(cb, b.mirrored(true, false)); + QPen p=painter.pen(); + p.setColor(colorBarRightAxis->getAxisColor()); + p.setWidthF(qMax(JKQTPlotterDrawingTools::ABS_MIN_LINEWIDTH, cbParent->pt2px(painter, colorBarRightAxis->getLineWidth()*cbParent->getLineWidthMultiplier()))); + painter.setPen(p); + painter.drawRect(cb); + + colorBarRightAxis->setRange(internalDataMin, internalDataMax); + colorBarRightAxis->setAxisWidth(cb.height()); + colorBarRightAxis->setAxisOffset(cb.top()); + colorBarRightAxis->setOtherAxisOffset(cb.left()); + colorBarRightAxis->setOtherAxisWidth(cb.width()); + colorBarRightAxis->drawAxes(painter); + + if (modifierMode!=JKQTPMathImageModifierMode::ModifyNone) { + modifierColorBarRightAxis->setRange(internalModifierMin, internalModifierMax); + modifierColorBarRightAxis->setAxisWidth(cbParent->pt2px(painter, colorBarModifiedWidth)); + modifierColorBarRightAxis->setAxisOffset(cb.left()); + modifierColorBarRightAxis->setOtherAxisOffset(cb.top()); + modifierColorBarRightAxis->setOtherAxisWidth(cb.height()); + modifierColorBarRightAxis->drawAxes(painter); + } + + cbParent->getMathText()->setFontSize(imageNameFontSize*cbParent->getFontSizeMultiplier()); + cbParent->getMathText()->setFontRomanOrSpecial(cbParent->getCurrentPlotterStyle().defaultFontName); + cbParent->getMathText()->parse(imageName); + cbParent->getMathText()->draw(painter, Qt::AlignHCenter|Qt::AlignVCenter, QRect(rightSpace.x(), rightSpace.y(), rightSpace.width(), (rightSpace.height()-barHeight)/2)); + + + } + if (colorBarTopVisible) { + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + + QSizeF names=cbParent->getTextSizeSize(imageNameFontName, imageNameFontSize*cbParent->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==JKQTPMathImageModifierMode::ModifyNone)?colorBarWidth:colorBarModifiedWidth)), barWidth, cbParent->pt2px(painter, (modifierMode==JKQTPMathImageModifierMode::ModifyNone)?colorBarWidth:colorBarModifiedWidth)); + //qDebug()<<"t: "<getAxisColor()); + p.setWidthF(qMax(JKQTPlotterDrawingTools::ABS_MIN_LINEWIDTH, cbParent->pt2px(painter, colorBarTopAxis->getLineWidth()*cbParent->getLineWidthMultiplier()))); + painter.setPen(p); + painter.drawRect(cb); + + + colorBarTopAxis->setRange(internalDataMin, internalDataMax); + colorBarTopAxis->setAxisWidth(cb.width()); + colorBarTopAxis->setAxisOffset(cb.left()); + colorBarTopAxis->setOtherAxisOffset(cb.top()); + colorBarTopAxis->setOtherAxisWidth(cb.height()); + colorBarTopAxis->drawAxes(painter); + + if (modifierMode!=JKQTPMathImageModifierMode::ModifyNone) { + modifierColorBarTopAxis->setRange(internalModifierMin, internalModifierMax); + modifierColorBarTopAxis->setAxisWidth(cbParent->pt2px(painter, colorBarModifiedWidth)); + modifierColorBarTopAxis->setAxisOffset(cb.top()); + modifierColorBarTopAxis->setOtherAxisOffset(cb.left()); + modifierColorBarTopAxis->setOtherAxisWidth(cb.width()); + modifierColorBarTopAxis->drawAxes(painter); + } + + cbParent->getMathText()->setFontSize(imageNameFontSize*cbParent->getFontSizeMultiplier()); + cbParent->getMathText()->setFontRomanOrSpecial(cbParent->getCurrentPlotterStyle().defaultFontName); + cbParent->getMathText()->parse(imageName); + cbParent->getMathText()->draw(painter, Qt::AlignHCenter|Qt::AlignVCenter, QRect(topSpace.right()-(topSpace.width()-barWidth)/2, topSpace.y(), (topSpace.width()-barWidth)/2, topSpace.height())); + + + } + } +} + +void JKQTPColorPaletteWithModifierStyleAndToolsMixin::cbSetParent(JKQTBasePlotter *parent) +{ + JKQTPColorPaletteStyleAndToolsMixin::cbSetParent(parent); + modifierColorBarTopAxis->setParent(parent); + modifierColorBarRightAxis->setParent(parent); +} + + +void JKQTPColorPaletteWithModifierStyleAndToolsMixin::setModifierMode(const JKQTPMathImageModifierMode &__value) +{ + this->modifierMode = __value; +} + +JKQTPMathImageModifierMode JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierMode() const +{ + return this->modifierMode; +} + + +void JKQTPColorPaletteWithModifierStyleAndToolsMixin::modifyImage(QImage &img, void *dataModifier, JKQTPMathImageDataType datatypeModifier, int Nx, int Ny, double internalModifierMin, double internalModifierMax) +{ + JKQTPModifyImage(img, modifierMode, dataModifier, datatypeModifier, Nx, Ny, internalModifierMin, internalModifierMax); +} + + +void JKQTPColorPaletteWithModifierStyleAndToolsMixin::setColorBarModifiedWidth(double __value) +{ + this->colorBarModifiedWidth = __value; +} + +double JKQTPColorPaletteWithModifierStyleAndToolsMixin::getColorBarModifiedWidth() const +{ + return this->colorBarModifiedWidth; +} + + +JKQTPVerticalIndependentAxis *JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierColorBarTopAxis() { + return this->modifierColorBarTopAxis; +} + +JKQTPHorizontalIndependentAxis *JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierColorBarRightAxis() { + return this->modifierColorBarRightAxis ; +} + + +const JKQTPVerticalIndependentAxis *JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierColorBarTopAxis() const { + return this->modifierColorBarTopAxis; +} + +const JKQTPHorizontalIndependentAxis *JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierColorBarRightAxis() const { + return this->modifierColorBarRightAxis ; +} + + +void JKQTPColorPaletteWithModifierStyleAndToolsMixin::setAutoModifierRange(bool __value) +{ + this->autoModifierRange = __value; +} + +bool JKQTPColorPaletteWithModifierStyleAndToolsMixin::getAutoModifierRange() const +{ + return this->autoModifierRange; +} + +void JKQTPColorPaletteWithModifierStyleAndToolsMixin::setModifierMin(double __value) +{ + this->modifierMin = __value; +} + +double JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierMin() const +{ + return this->modifierMin; +} + +void JKQTPColorPaletteWithModifierStyleAndToolsMixin::setModifierMax(double __value) +{ + this->modifierMax = __value; +} + +double JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierMax() const +{ + return this->modifierMax; +} diff --git a/lib/jkqtplotter/jkqtpimagetools.h b/lib/jkqtplotter/jkqtpimagetools.h index 78ff43627a..3700ec0087 100644 --- a/lib/jkqtplotter/jkqtpimagetools.h +++ b/lib/jkqtplotter/jkqtpimagetools.h @@ -36,6 +36,7 @@ class JKQTPVerticalIndependentAxis; // forward class JKQTPHorizontalIndependentAxis; // forward class JKQTBasePlotter; // forward + /*! \brief if a class is derived from this class, it may use color bars \ingroup jkqtplotter_imagelots_tools */ @@ -55,18 +56,18 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPColorPaletteStyleAndToolsMixin { /*! \brief get QIcon representing the given palette */ static QIcon getPaletteIcon(JKQTPMathImageColorPalette palette) ; /*! \brief get QIcon representing the given palette */ - static QImage getPaletteImage(int i, int width) ; + static QImage getPaletteImage(int i, size_t width) ; /*! \brief get QIcon representing the given palette */ - static QImage getPaletteImage(JKQTPMathImageColorPalette palette, int width) ; + static QImage getPaletteImage(JKQTPMathImageColorPalette palette, size_t width) ; /*! \brief get QIcon representing the given palette */ static QIcon getPaletteKeyIcon(int i) ; /*! \brief get QIcon representing the given palette */ static QIcon getPaletteKeyIcon(JKQTPMathImageColorPalette palette) ; /*! \brief get QIcon representing the given palette */ - static QImage getPaletteKeyImage(int i, int width, int height) ; + static QImage getPaletteKeyImage(int i, size_t width, size_t height) ; /*! \brief get QIcon representing the given palette */ - static QImage getPaletteKeyImage(JKQTPMathImageColorPalette palette, int width, int height) ; + static QImage getPaletteKeyImage(JKQTPMathImageColorPalette palette, size_t width, size_t height) ; @@ -75,7 +76,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPColorPaletteStyleAndToolsMixin { \note If you want to draw outside, then you'll also have to implement drawOutside() */ - void cbGetOutsideSize(JKQTPEnhancedPainter& painter, int& leftSpace, int& rightSpace, int& topSpace, int& bottomSpace); + virtual void cbGetOutsideSize(JKQTPEnhancedPainter& painter, int& leftSpace, int& rightSpace, int& topSpace, int& bottomSpace); /*! \brief plots outside the actual plot field of view (e.g. color bars, scale bars, ...) @@ -83,11 +84,11 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPColorPaletteStyleAndToolsMixin { The four value supplied tell the method where to draw (inside one of the rectangles). */ - void cbDrawOutside(JKQTPEnhancedPainter& painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace); + virtual void cbDrawOutside(JKQTPEnhancedPainter& painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace); /** \brief set the parent class for internal objects (e.g. color bars) */ - void cbSetParent(JKQTBasePlotter* parent); + virtual void cbSetParent(JKQTBasePlotter* parent); /** \brief determine min/max data value of the image */ @@ -228,11 +229,15 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPColorPaletteStyleAndToolsMixin { QColor infColor; - /** \brief object used for color bar axes + /** \brief object used for color bar axes at the right * * \note this axis has some kind of a special role. It is used to format color bar axes */ JKQTPVerticalIndependentAxis* colorBarRightAxis; + /** \brief object used for color bar axes at the top + * + * \note this axis has some kind of a special role. It is used to format color bar axes + */ JKQTPHorizontalIndependentAxis* colorBarTopAxis; @@ -240,4 +245,106 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPColorPaletteStyleAndToolsMixin { }; + +/*! \brief if a class is derived from this class, it may use color bars that have 2 axes (one "data"/color axis and one "modifier" axis) + \ingroup jkqtplotter_imagelots_tools + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPColorPaletteWithModifierStyleAndToolsMixin : public JKQTPColorPaletteStyleAndToolsMixin { + Q_GADGET + public: + + + + JKQTPColorPaletteWithModifierStyleAndToolsMixin(JKQTBasePlotter *parent); + virtual ~JKQTPColorPaletteWithModifierStyleAndToolsMixin()=default; + + /*! \brief if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...) + + \note If you want to draw outside, then you'll also have to implement drawOutside() + */ + virtual void cbGetOutsideSize(JKQTPEnhancedPainter& painter, int& leftSpace, int& rightSpace, int& topSpace, int& bottomSpace) override; + + /*! \brief plots outside the actual plot field of view (e.g. color bars, scale bars, ...) + + \note If you want to draw outside, then you'll also have to implement getOutsideSize(), so enough space is reserved + + The four value supplied tell the method where to draw (inside one of the rectangles). + */ + virtual void cbDrawOutside(JKQTPEnhancedPainter& painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace) override; + + + /** \brief set the parent class for internal objects (e.g. color bars) */ + virtual void cbSetParent(JKQTBasePlotter* parent) override; + + + /** \brief determine min/max data value of the modifier image */ + virtual void cbGetModifierDataMinMax(double& imin, double& imax)=0; + + + /*! \copydoc modifierMode */ + void setModifierMode(const JKQTPMathImageModifierMode & __value); + /*! \copydoc modifierMode */ + JKQTPMathImageModifierMode getModifierMode() const; + + /*! \copydoc colorBarModifiedWidth */ + void setColorBarModifiedWidth(double __value); + /*! \copydoc colorBarModifiedWidth */ + double getColorBarModifiedWidth() const; + /*! \copydoc modifierColorBarTopAxis */ + JKQTPVerticalIndependentAxis* getModifierColorBarTopAxis(); + /*! \copydoc modifierColorBarRightAxis */ + JKQTPHorizontalIndependentAxis* getModifierColorBarRightAxis(); + /*! \copydoc modifierColorBarTopAxis */ + const JKQTPVerticalIndependentAxis* getModifierColorBarTopAxis() const; + /*! \copydoc modifierColorBarRightAxis */ + const JKQTPHorizontalIndependentAxis *getModifierColorBarRightAxis() const; + /*! \copydoc autoModifierRange */ + void setAutoModifierRange(bool __value); + /*! \copydoc autoModifierRange */ + bool getAutoModifierRange() const; + /*! \copydoc modifierMin */ + void setModifierMin(double __value); + /*! \copydoc modifierMin */ + double getModifierMin() const; + /*! \copydoc modifierMax */ + void setModifierMax(double __value); + /*! \copydoc modifierMax */ + double getModifierMax() const; + + + /** \brief modify the given image \a img, using modifier image \a dataModifier (of type \a datatypeModifier and size \a Nx * \a Ny), using values in the range \a internalModifierMin ... \a internalModifierMax + */ + void modifyImage(QImage& img, void* dataModifier, JKQTPMathImageDataType datatypeModifier, int Nx, int Ny, double internalModifierMin, double internalModifierMax); + + protected: + + /** \brief indicates whether to estimate min/max of the modifier automatically */ + bool autoModifierRange; + /** \brief modifier value range minimum */ + double modifierMin; + /** \brief modifier value range maximum */ + double modifierMax; + /** \brief width of the color bar when modifier is on */ + double colorBarModifiedWidth; + /** \brief how to apply the modifier column dataModifier + * \see ModifierMode + */ + JKQTPMathImageModifierMode modifierMode; + + + /** \brief object used for color bar axes (right border, modifier image data) + * + * \note this axis has some kind of a special role. It is used to format color bar axes + */ + JKQTPVerticalIndependentAxis* modifierColorBarTopAxis; + /** \brief object used for color bar axes (top border, modifier image data) + * + * \note this axis has some kind of a special role. It is used to format color bar axes + */ + JKQTPHorizontalIndependentAxis* modifierColorBarRightAxis; +}; + + + + #endif // JKQTPIMAGETOOLS_H