2019-06-21 04:24:47 +08:00
|
|
|
/** \example filledgraphs.cpp
|
2019-01-20 23:15:10 +08:00
|
|
|
* Shows how to use filled graphs with JKQTPlotter
|
2019-01-13 01:53:16 +08:00
|
|
|
*
|
2019-01-20 23:15:10 +08:00
|
|
|
* \ref JKQTPlotterFilledGraphs
|
2019-01-13 01:53:16 +08:00
|
|
|
*/
|
|
|
|
|
2022-08-27 04:32:48 +08:00
|
|
|
#include "jkqtpexampleapplication.h"
|
2018-12-29 00:46:47 +08:00
|
|
|
#include <QApplication>
|
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
2019-06-20 22:06:31 +08:00
|
|
|
#include "jkqtplotter/graphs/jkqtpfilledcurve.h"
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2022-04-16 05:01:09 +08:00
|
|
|
|
2022-08-27 04:32:48 +08:00
|
|
|
JKQTPAppSettingController highDPIController(argc, argv);
|
|
|
|
JKQTPExampleApplication app(argc, argv);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2022-04-16 05:01:09 +08:00
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPlotter plot;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* ds=plot.getDatastore();
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 2. now we create 4 datacolumns with length 256 entries in the datastore
|
|
|
|
// these will later hold the RGB-histogram and a linear x-values vector
|
|
|
|
// - the x-values are directly initialized as linear vector 0..255 in 256 steps
|
|
|
|
// - the other columns are generated and size_t-type indexes are stored for later
|
|
|
|
// reference to these columns in the graphs-
|
|
|
|
size_t columnX=ds->addLinearColumn(256, 0, 255, "x");
|
|
|
|
size_t columnR=ds->addColumn(256, "historam_R");
|
|
|
|
size_t columnG=ds->addColumn(256, "historam_G");
|
|
|
|
size_t columnB=ds->addColumn(256, "historam_B");
|
|
|
|
// - now all columns for RGB are initialized to 0
|
2019-05-13 04:22:48 +08:00
|
|
|
ds->setAll(columnG, 0);
|
|
|
|
ds->setAll(columnR, 0);
|
|
|
|
ds->setAll(columnB, 0);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 3. now we open a BMP-file and load it into a QImage
|
|
|
|
QImage image(":/example.bmp");
|
|
|
|
// ... and calculate the RGB-histograms
|
|
|
|
for (int y=0; y<image.height(); y++) {
|
|
|
|
for (int x=0; x<image.width(); x++) {
|
|
|
|
QRgb pix=image.pixel(x,y);
|
2019-05-13 04:22:48 +08:00
|
|
|
ds->inc(columnR, qRed(pix), 1);
|
|
|
|
ds->inc(columnG, qGreen(pix), 1);
|
|
|
|
ds->inc(columnB, qBlue(pix), 1);
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// ... and normalize histograms
|
2019-05-13 04:22:48 +08:00
|
|
|
ds->scaleColumnValues(columnR, 100.0/static_cast<double>(image.width()*image.height()));
|
|
|
|
ds->scaleColumnValues(columnG, 100.0/static_cast<double>(image.width()*image.height()));
|
|
|
|
ds->scaleColumnValues(columnB, 100.0/static_cast<double>(image.width()*image.height()));
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
// 4. now we add three semi-transparent, filled curve plots, one for each histogram
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPFilledCurveXGraph* graphR=new JKQTPFilledCurveXGraph(&plot);
|
|
|
|
JKQTPFilledCurveXGraph* graphG=new JKQTPFilledCurveXGraph(&plot);
|
|
|
|
JKQTPFilledCurveXGraph* graphB=new JKQTPFilledCurveXGraph(&plot);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set graph titles
|
2019-01-26 20:00:40 +08:00
|
|
|
graphR->setTitle("R-channel");
|
|
|
|
graphG->setTitle("G-channel");
|
|
|
|
graphB->setTitle("B-channel");
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set graph colors (lines: non-transparent, fill: semi-transparent) and style
|
|
|
|
QColor col;
|
2019-01-26 20:00:40 +08:00
|
|
|
col=QColor("red"); graphR->setColor(col);
|
2022-07-23 22:05:13 +08:00
|
|
|
col.setAlphaF(0.25f); graphR->setFillColor(col);
|
2019-01-26 20:00:40 +08:00
|
|
|
col=QColor("green"); graphG->setColor(col);
|
2022-07-23 22:05:13 +08:00
|
|
|
col.setAlphaF(0.25f); graphG->setFillColor(col);
|
2019-01-26 20:00:40 +08:00
|
|
|
col=QColor("blue"); graphB->setColor(col);
|
2022-07-23 22:05:13 +08:00
|
|
|
col.setAlphaF(0.25f); graphB->setFillColor(col);
|
2019-01-26 03:16:04 +08:00
|
|
|
graphR->setLineWidth(1);
|
|
|
|
graphG->setLineWidth(1);
|
|
|
|
graphB->setLineWidth(1);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set data
|
2019-01-26 20:00:40 +08:00
|
|
|
graphR->setXColumn(columnX); graphR->setYColumn(columnR);
|
|
|
|
graphG->setXColumn(columnX); graphG->setYColumn(columnG);
|
|
|
|
graphB->setXColumn(columnX); graphB->setYColumn(columnB);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
// add the graphs to the plot, so they are actually displayed
|
|
|
|
plot.addGraph(graphB);
|
|
|
|
plot.addGraph(graphG);
|
|
|
|
plot.addGraph(graphR);
|
|
|
|
|
|
|
|
// 5. set axis labels
|
2019-01-26 03:16:04 +08:00
|
|
|
plot.getXAxis()->setAxisLabel("R/G/B-value");
|
|
|
|
plot.getYAxis()->setAxisLabel("normalized frequency [%]");
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
// 4. set the maximum size of the plot to 0..100% and 0..256
|
|
|
|
plot.setAbsoluteX(0,256);
|
|
|
|
plot.setAbsoluteY(0,100);
|
|
|
|
// ... and scale plot automatically
|
|
|
|
plot.zoomToFit();
|
|
|
|
|
|
|
|
// 5. show plotter and make it a decent size
|
|
|
|
plot.show();
|
|
|
|
plot.resize(600,400);
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|