2024-02-09 04:52:30 +08:00
|
|
|
/** \example vectorfield.cpp
|
|
|
|
* Display a vector field
|
|
|
|
*
|
|
|
|
* \ref JKQTPlotterVectorFieldExample
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jkqtpexampleapplication.h"
|
|
|
|
#include <QApplication>
|
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
|
|
|
#include "jkqtplotter/graphs/jkqtpvectorfield.h"
|
|
|
|
#include "jkqtplotter/graphs/jkqtpscatter.h"
|
|
|
|
#include "jkqtpexampleapplication.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define NX 9
|
|
|
|
#define NY 9
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
|
|
|
|
JKQTPAppSettingController highDPIController(argc,argv);
|
|
|
|
JKQTPExampleApplication app(argc, argv);
|
|
|
|
|
|
|
|
|
|
|
|
// 1. setup a plotter window and get a pointer to the internal datastore (for convenience)
|
|
|
|
JKQTPlotter plot;
|
|
|
|
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
|
|
|
|
JKQTPDatastore* ds=plot.getDatastore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. make up some arbitrary data to be used for plotting
|
2024-02-09 20:48:41 +08:00
|
|
|
// this generates a 2D grid of x/y-coordinates and then calculates dx=cos(y)*sqrt(x/3.0) and dy=sin(x)*sqrt(x/3.0)
|
2024-02-09 04:52:30 +08:00
|
|
|
const auto columnXY=ds->addLinearGridColumns(NX, 0, 6, NY, -3, 3,"x","y");
|
2024-02-09 20:48:41 +08:00
|
|
|
const auto columnDX=ds->addCalculatedColumnFromColumn(columnXY.first, columnXY.second, [](double x,double y) { return sin(y)*sqrt(x/3.0); });
|
|
|
|
const auto columnDY=ds->addCalculatedColumnFromColumn(columnXY.first, columnXY.second, [](double x,double y) { return cos(x)*sqrt(x/3.0); });
|
2024-02-09 04:52:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
// 3. create JKQTPVectorFieldGraph to display the data:
|
|
|
|
JKQTPVectorFieldGraph* graph1=new JKQTPVectorFieldGraph(&plot);
|
|
|
|
graph1->setXYColumns(columnXY);
|
|
|
|
graph1->setDxColumn(columnDX);
|
|
|
|
graph1->setDyColumn(columnDY);
|
2024-02-09 20:48:41 +08:00
|
|
|
graph1->setTitle(QObject::tr("$\\vec{f}(x,y)=\\bigl[\\sin(y)\\cdot\\sqrt{x/3}, \\cos(x)\\cdot\\sqrt{x/3}\\bigr]^\\mathrm{T}$"));
|
2024-02-09 04:52:30 +08:00
|
|
|
|
|
|
|
// 4. add the graphs to the plot, so it is actually displayed
|
|
|
|
plot.addGraph(graph1);
|
|
|
|
|
|
|
|
// 5. scale the plot so the graph is contained
|
|
|
|
plot.getPlotter()->setAxisAspectRatio(1);
|
|
|
|
plot.getPlotter()->setAspectRatio(1);
|
|
|
|
plot.getPlotter()->setMaintainAxisAspectRatio(true);
|
|
|
|
plot.getPlotter()->setMaintainAspectRatio(true);
|
|
|
|
plot.zoomToFit();
|
|
|
|
|
|
|
|
// show plotter and make it a decent size
|
|
|
|
plot.setWindowTitle("JKQTPVectorFieldGraph example");
|
|
|
|
plot.show();
|
|
|
|
plot.resize(400/plot.devicePixelRatioF(),430/plot.devicePixelRatioF());
|
|
|
|
|
|
|
|
|
2024-02-09 23:45:40 +08:00
|
|
|
JKQTPXYScatterGraph* g2;
|
2024-02-09 04:52:30 +08:00
|
|
|
app.addExportStepFunctor([&](){
|
2024-02-09 23:45:40 +08:00
|
|
|
g2=new JKQTPXYScatterGraph(&plot);
|
2024-02-09 04:52:30 +08:00
|
|
|
g2->setXYColumns(columnXY);
|
|
|
|
g2->setTitle("anchor points");
|
|
|
|
g2->setSymbolSize(5);
|
|
|
|
g2->setSymbolType(JKQTPFilledCircle);
|
|
|
|
plot.addGraph(g2);
|
|
|
|
plot.redrawPlot();
|
|
|
|
});
|
|
|
|
app.addExportStepFunctor([&](){
|
|
|
|
graph1->setAnchorPoint(JKQTPVectorFieldGraph::AnchorMid);
|
2024-02-10 07:26:45 +08:00
|
|
|
plot.redrawPlot();
|
2024-02-09 04:52:30 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
app.addExportStepFunctor([&](){
|
|
|
|
graph1->setAnchorPoint(JKQTPVectorFieldGraph::AnchorTip);
|
2024-02-09 20:48:41 +08:00
|
|
|
plot.redrawPlot();
|
|
|
|
});
|
|
|
|
|
|
|
|
app.addExportStepFunctor([&](){
|
|
|
|
graph1->setAnchorPoint(JKQTPVectorFieldGraph::AnchorBottom);
|
|
|
|
graph1->setVectorLengthMode(JKQTPVectorFieldGraph::AutoscaleLength);
|
|
|
|
plot.redrawPlot();
|
|
|
|
});
|
|
|
|
app.addExportStepFunctor([&](){
|
|
|
|
graph1->setAnchorPoint(JKQTPVectorFieldGraph::AnchorBottom);
|
|
|
|
graph1->setVectorLengthMode(JKQTPVectorFieldGraph::LengthFromData);
|
|
|
|
plot.redrawPlot();
|
|
|
|
});
|
|
|
|
app.addExportStepFunctor([&](){
|
|
|
|
graph1->setAnchorPoint(JKQTPVectorFieldGraph::AnchorBottom);
|
|
|
|
graph1->setVectorLengthMode(JKQTPVectorFieldGraph::IgnoreLength);
|
|
|
|
plot.redrawPlot();
|
2024-02-09 04:52:30 +08:00
|
|
|
});
|
|
|
|
|
2024-02-09 23:45:40 +08:00
|
|
|
app.addExportStepFunctor([&](){
|
|
|
|
g2->setVisible(false);
|
|
|
|
graph1->setAnchorPoint(JKQTPVectorFieldGraph::AnchorBottom);
|
|
|
|
graph1->setVectorLengthMode(JKQTPVectorFieldGraph::IgnoreLength);
|
|
|
|
graph1->setVectorLineWidthMode(JKQTPVectorFieldGraph::AutoscaleLineWidthFromLength);
|
|
|
|
graph1->setLineWidth(4);
|
|
|
|
plot.redrawPlot();
|
|
|
|
});
|
|
|
|
|
|
|
|
app.addExportStepFunctor([&](){
|
|
|
|
g2->setVisible(false);
|
|
|
|
graph1->setAnchorPoint(JKQTPVectorFieldGraph::AnchorBottom);
|
|
|
|
graph1->setVectorLengthMode(JKQTPVectorFieldGraph::AutoscaleLength);
|
|
|
|
graph1->setVectorLineWidthMode(JKQTPVectorFieldGraph::AutoscaleLineWidthFromLength);
|
|
|
|
graph1->setLineWidth(4);
|
|
|
|
plot.redrawPlot();
|
|
|
|
});
|
|
|
|
|
2024-02-09 04:52:30 +08:00
|
|
|
return app.exec();
|
|
|
|
}
|