-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW add JKQTPParametrizedVectorFieldGraph, which draws color-coded ve…
…ctor fields (color from length, angle, or user-supplied data column) + example
- Loading branch information
Showing
24 changed files
with
595 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-29.7 KB
(31%)
doc/images/JKQTPVectorFieldGraphIgnoreLengthAutoscaleLineWidthFromLength.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
cmake_minimum_required(VERSION 3.23) | ||
|
||
set(EXAMPLE_NAME paramvectorfield) | ||
set(EXENAME jkqtptest_${EXAMPLE_NAME}) | ||
|
||
message( STATUS ".. Building Example ${EXAMPLE_NAME}" ) | ||
|
||
|
||
|
||
add_executable(${EXENAME} WIN32 ${EXAMPLE_NAME}.cpp) | ||
target_link_libraries(${EXENAME} JKQTPExampleToolsLib) | ||
target_include_directories(${EXENAME} PRIVATE ../../lib) | ||
target_link_libraries(${EXENAME} ${jkqtplotter_namespace}JKQTPlotter${jkqtplotter_LIBNAME_VERSION_PART}) | ||
|
||
# precomiled headers to speed up compilation | ||
if (JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS) | ||
target_precompile_headers(${EXENAME} REUSE_FROM jkqtptest_simpletest) | ||
endif (JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS) | ||
|
||
|
||
# Installation | ||
install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
|
||
#Installation of Qt DLLs on Windows | ||
jkqtplotter_deployqt(${EXENAME}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Example (JKQTPlotter): Vector Field Plot Example {#JKQTPParametrizedVectorFieldGraphExample} | ||
This project (see [`paramvectorfield`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/paramvectorfield) demonstrates the use of JKQTPParametrizedVectorFieldGraph to visualize a vector field with additional information encoded in the color of the vectors. | ||
|
||
The source code of the main application is (see [`paramvectorfield.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/paramvectorfield/paramvectorfield.cpp). | ||
|
||
Here is a short summary of the important parts of the code: | ||
|
||
```.cpp | ||
// 1. setup a plotter window and get a pointer to the internal datastore (for convenience) | ||
JKQTPlotter plot; | ||
JKQTPDatastore* ds=plot.getDatastore(); | ||
|
||
|
||
// 2. make up some arbitrary data to be used for plotting | ||
// 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) | ||
const auto columnXY=ds->addLinearGridColumns(NX, 0, 6, NY, -3, 3,"x","y"); | ||
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); }); | ||
// now we also calulate a column that encodes some other information that can be color-coded | ||
const auto columnC=ds->addCalculatedColumnFromColumn(columnXY.first, columnXY.second, [](double x,double y) { return sqrt(fabs(y)); }); | ||
|
||
|
||
// 3. create JKQTPVectorFieldGraph to display the data: | ||
JKQTPParametrizedVectorFieldGraph* graph1=new JKQTPParametrizedVectorFieldGraph(&plot); | ||
graph1->setXYColumns(columnXY); | ||
graph1->setDxColumn(columnDX); | ||
graph1->setDyColumn(columnDY); | ||
graph1->setColorColumn(columnC); | ||
graph1->setTitle(QObject::tr("$\\vec{f}(x,y)=\\bigl[\\sin(y)\\cdot\\sqrt{x/3}, \\cos(x)\\cdot\\sqrt{x/3}\\bigr]^\\mathrm{T}$")); | ||
|
||
// 4. add the graphs to the plot, so it is actually displayed | ||
plot.addGraph(graph1); | ||
|
||
``` | ||
The result looks like this: | ||
![paramvectorfield](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/paramvectorfield.png) | ||
By default, the color of the drawn vector is determined from the color column provided to the graph object. | ||
But you can also choose to not provide a color column and instead set | ||
```.cpp | ||
graph1->setVectorColorMode(JKQTPParametrizedVectorFieldGraph::ColorFromMagnitude); | ||
``` | ||
|
||
Now the color encodes the actual length (or magnitude) of the vectors: | ||
|
||
![paramvectorfield](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/doc/images/JKQTPParametrizedVectorFieldGraphColorFromMagnitude.png) | ||
|
||
|
||
Alternatively | ||
|
||
```.cpp | ||
graph1->setVectorColorMode(JKQTPParametrizedVectorFieldGraph::ColorFromAngle); | ||
``` | ||
will color-encode the rotation angle (in radians, 3 o'clock is 0rad) of the vectors: | ||
![paramvectorfield](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/doc/images/JKQTPParametrizedVectorFieldGraphColorFromAngle.png) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** \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 | ||
// 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) | ||
const auto columnXY=ds->addLinearGridColumns(NX, 0, 6, NY, -3, 3,"x","y"); | ||
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); }); | ||
// now we also calulate a column that encodes some other information that can be color-coded | ||
const auto columnC=ds->addCalculatedColumnFromColumn(columnXY.first, columnXY.second, [](double x,double y) { return sqrt(fabs(y)); }); | ||
|
||
|
||
// 3. create JKQTPVectorFieldGraph to display the data: | ||
JKQTPParametrizedVectorFieldGraph* graph1=new JKQTPParametrizedVectorFieldGraph(&plot); | ||
graph1->setXYColumns(columnXY); | ||
graph1->setDxColumn(columnDX); | ||
graph1->setDyColumn(columnDY); | ||
graph1->setColorColumn(columnC); | ||
graph1->setTitle(QObject::tr("$\\vec{f}(x,y)=\\bigl[\\sin(y)\\cdot\\sqrt{x/3}, \\cos(x)\\cdot\\sqrt{x/3}\\bigr]^\\mathrm{T}$")); | ||
|
||
// 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()); | ||
|
||
|
||
|
||
app.addExportStepFunctor([&](){ | ||
graph1->setVectorColorMode(JKQTPParametrizedVectorFieldGraph::ColorFromMagnitude); | ||
plot.redrawPlot(); | ||
}); | ||
|
||
app.addExportStepFunctor([&](){ | ||
graph1->setVectorColorMode(JKQTPParametrizedVectorFieldGraph::ColorFromAngle); | ||
plot.redrawPlot(); | ||
}); | ||
|
||
app.addExportStepFunctor([&](){ | ||
graph1->setVectorColorMode(JKQTPParametrizedVectorFieldGraph::DefaultColor); | ||
plot.redrawPlot(); | ||
}); | ||
|
||
|
||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.