2019-01-13 01:53:16 +08:00
|
|
|
/** \example jkqtplotter_simpletest_rgbimageplot_qt.cpp
|
2019-01-20 23:15:10 +08:00
|
|
|
* JKQTPlotter: Examples: `QImage` as a Graph
|
2019-01-13 01:53:16 +08:00
|
|
|
*
|
2019-01-20 23:15:10 +08:00
|
|
|
* \ref JKQTPlotterImagePlotQImageRGB
|
2019-01-13 01:53:16 +08:00
|
|
|
*/
|
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
#include <QApplication>
|
|
|
|
#include <cmath>
|
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
|
|
|
#include "jkqtplotter/jkqtpgraphs.h"
|
2019-02-08 00:24:46 +08:00
|
|
|
#include "jkqtplotter/jkqtpgraphsimagergb.h"
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPlotter plot;
|
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-26 03:16:04 +08:00
|
|
|
plot.getPlotter()->setUseAntiAliasingForGraphs(true); // nicer (but slower) plotting
|
|
|
|
plot.getPlotter()->setUseAntiAliasingForSystem(true); // nicer (but slower) plotting
|
|
|
|
plot.getPlotter()->setUseAntiAliasingForText(true); // nicer (but slower) text rendering
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
// 2. now we open a BMP-file and load it into an OpenCV cv::Mat
|
|
|
|
QImage image(":/example.bmp");
|
|
|
|
|
|
|
|
|
|
|
|
// 3. create a graph (JKQTPImage) with a pointer to the QImage-object, generated above
|
|
|
|
JKQTPImage* graph=new JKQTPImage(&plot);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setTitle("");
|
2018-12-29 00:46:47 +08:00
|
|
|
// copy the image into the graph (optionally you could also give a pointer to a QImage,
|
|
|
|
// but then you need to ensure that the QImage is available as long as the JKQTPImage
|
|
|
|
// instace lives)
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setImage(image);
|
2018-12-29 00:46:47 +08:00
|
|
|
// where does the image start in the plot, given in plot-axis-coordinates (bottom-left corner)
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setX(0);
|
|
|
|
graph->setY(0);
|
2018-12-29 00:46:47 +08:00
|
|
|
// width/height of the image in plot coordinates
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setWidth(image.width());
|
|
|
|
graph->setHeight(image.height());
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. add the graphs to the plot, so it is actually displayed
|
|
|
|
plot.addGraph(graph);
|
|
|
|
|
|
|
|
// 5. set axis labels
|
2019-01-26 03:16:04 +08:00
|
|
|
plot.getXAxis()->setAxisLabel("x [pixels]");
|
|
|
|
plot.getYAxis()->setAxisLabel("y [pixels]");
|
2019-02-10 05:17:01 +08:00
|
|
|
// 5.1 invert y-axis, so image is oriented correctly
|
|
|
|
plot.getYAxis()->setInverted(true);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 6. fix axis aspect ratio to width/height, so pixels are square
|
2019-01-26 03:16:04 +08:00
|
|
|
plot.getPlotter()->setMaintainAspectRatio(true);
|
|
|
|
plot.getPlotter()->setAspectRatio(double(image.width())/double(image.height()));
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 7. autoscale the plot so the graph is contained
|
|
|
|
plot.zoomToFit();
|
|
|
|
|
|
|
|
// 8. show plotter and make it a decent size
|
|
|
|
plot.show();
|
|
|
|
plot.resize(800,600);
|
|
|
|
plot.setWindowTitle("JKQTPImage");
|
|
|
|
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|