* reworked color-palette-system:
1. added several new (JKQTPMathImageBone, JKQTPMathImageCool, JKQTPMathImageCopper, JKQTPMathImageAutumn, JKQTPMathImageSeismic, JKQTPMathImageTerrain, JKQTPMathImageViridis, JKQTPMathImageMagma, JKQTPMathImageInferno, JKQTPMathImagePlasma) 2. reworked LUT-types (now a QVector, instead of a C-array, suing malloc) 3. reworked available functions to build LUTs (cleanup, more options, clearer names) 4. added functions to load palettes from files 5. Improved documentation * added example for user-controlled color palettes
@ -101,6 +101,9 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
<tr><td> \image html imageplot_small.png
|
||||
<td> \subpage JKQTPlotterImagePlot
|
||||
<td> `JKQTPColumnMathImage` <br> image data copied from C-style row-major array into a single column of the internal datastore <br> Describes several options of the image plotting classes (different ways of color coding, what to do with data above/below the limits etc.)
|
||||
<tr><td> \image html imageplot_userpal_program_small.png
|
||||
<td> \subpage JKQTPlotterImagePlotUserPalette
|
||||
<td> `JKQTPColumnMathImage` <br> user-defines palettes <br> palettes from files
|
||||
<tr><td> \image html imageplot_modifier_small.png
|
||||
<td> \subpage JKQTPlotterImagePlotModifier
|
||||
<td> `JKQTPColumnMathImage` <br> image data copied from C-style row-major array into a single column of the internal datastore <br> Image is modified by a second image to display two data dimensions at the same time
|
||||
@ -146,6 +149,9 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
<tr><td> \image html test_styling_small.png
|
||||
<td> \subpage JKQTPlotterStyling
|
||||
<td> Modifying different Aspects of the Styling of JKQTPlotter
|
||||
<tr><td> \image html imageplot_userpal_small.png
|
||||
<td> \subpage JKQTPlotterImagePlotUserPalette
|
||||
<td> `JKQTPColumnMathImage` <br> user-defines palettes <br> palettes from files
|
||||
</table>
|
||||
|
||||
|
||||
|
@ -509,6 +509,9 @@ Examples:
|
||||
\defgroup jkqtplotter_imagelots_tools Tool Functions & Classes for Image Drawing
|
||||
\ingroup jkqtplotter_imagelots
|
||||
|
||||
\defgroup jkqtplotter_imagelots_tools_LUTS Tool Functions to Build Lookup-Tables for Palettes
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
|
||||
\defgroup jkqtplotter_imagelots_contour Contour Graphs (based on Image Data)
|
||||
\ingroup jkqtplotter_imagelots
|
||||
|
||||
|
BIN
doc/images/JKQTPBuildColorPaletteLUTLinInterpolateSorted.cdr
Normal file
BIN
doc/images/JKQTPBuildColorPaletteLUTLinInterpolateSorted.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
doc/images/JKQTPBuildColorPaletteLUTSorted.cdr
Normal file
BIN
doc/images/JKQTPBuildColorPaletteLUTSorted.png
Normal file
After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 199 B After Width: | Height: | Size: 175 B |
Before Width: | Height: | Size: 394 B After Width: | Height: | Size: 362 B |
Before Width: | Height: | Size: 229 B After Width: | Height: | Size: 204 B |
Before Width: | Height: | Size: 228 B After Width: | Height: | Size: 204 B |
Before Width: | Height: | Size: 385 B After Width: | Height: | Size: 353 B |
Before Width: | Height: | Size: 364 B After Width: | Height: | Size: 307 B |
Before Width: | Height: | Size: 261 B After Width: | Height: | Size: 235 B |
Before Width: | Height: | Size: 219 B After Width: | Height: | Size: 194 B |
Before Width: | Height: | Size: 203 B After Width: | Height: | Size: 179 B |
Before Width: | Height: | Size: 377 B After Width: | Height: | Size: 356 B |
Before Width: | Height: | Size: 304 B After Width: | Height: | Size: 275 B |
Before Width: | Height: | Size: 378 B After Width: | Height: | Size: 346 B |
Before Width: | Height: | Size: 367 B After Width: | Height: | Size: 343 B |
Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 214 B |
BIN
doc/images/palettes/palette_autumn.png
Normal file
After Width: | Height: | Size: 154 B |
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 156 B |
Before Width: | Height: | Size: 341 B After Width: | Height: | Size: 331 B |
Before Width: | Height: | Size: 187 B After Width: | Height: | Size: 163 B |
Before Width: | Height: | Size: 181 B After Width: | Height: | Size: 159 B |
Before Width: | Height: | Size: 386 B After Width: | Height: | Size: 349 B |
BIN
doc/images/palettes/palette_bone.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
doc/images/palettes/palette_cool.png
Normal file
After Width: | Height: | Size: 154 B |
BIN
doc/images/palettes/palette_copper.png
Normal file
After Width: | Height: | Size: 260 B |
Before Width: | Height: | Size: 183 B After Width: | Height: | Size: 159 B |
Before Width: | Height: | Size: 188 B After Width: | Height: | Size: 164 B |
Before Width: | Height: | Size: 182 B After Width: | Height: | Size: 158 B |
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 156 B |
Before Width: | Height: | Size: 341 B After Width: | Height: | Size: 325 B |
BIN
doc/images/palettes/palette_inferno.png
Normal file
After Width: | Height: | Size: 383 B |
Before Width: | Height: | Size: 195 B After Width: | Height: | Size: 171 B |
Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 215 B |
Before Width: | Height: | Size: 220 B After Width: | Height: | Size: 195 B |
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 183 B |
Before Width: | Height: | Size: 309 B After Width: | Height: | Size: 280 B |
Before Width: | Height: | Size: 178 B After Width: | Height: | Size: 154 B |
Before Width: | Height: | Size: 181 B After Width: | Height: | Size: 157 B |
Before Width: | Height: | Size: 177 B After Width: | Height: | Size: 153 B |
Before Width: | Height: | Size: 178 B After Width: | Height: | Size: 154 B |
Before Width: | Height: | Size: 187 B After Width: | Height: | Size: 163 B |
Before Width: | Height: | Size: 202 B After Width: | Height: | Size: 176 B |
Before Width: | Height: | Size: 347 B After Width: | Height: | Size: 316 B |
Before Width: | Height: | Size: 178 B After Width: | Height: | Size: 154 B |
Before Width: | Height: | Size: 587 B After Width: | Height: | Size: 220 B |
Before Width: | Height: | Size: 189 B After Width: | Height: | Size: 165 B |
Before Width: | Height: | Size: 186 B After Width: | Height: | Size: 162 B |
Before Width: | Height: | Size: 187 B After Width: | Height: | Size: 163 B |
Before Width: | Height: | Size: 181 B After Width: | Height: | Size: 158 B |
BIN
doc/images/palettes/palette_magma.png
Normal file
After Width: | Height: | Size: 359 B |
Before Width: | Height: | Size: 203 B After Width: | Height: | Size: 178 B |
BIN
doc/images/palettes/palette_plasma.png
Normal file
After Width: | Height: | Size: 348 B |
Before Width: | Height: | Size: 346 B After Width: | Height: | Size: 316 B |
Before Width: | Height: | Size: 181 B After Width: | Height: | Size: 157 B |
Before Width: | Height: | Size: 181 B After Width: | Height: | Size: 157 B |
Before Width: | Height: | Size: 190 B After Width: | Height: | Size: 161 B |
Before Width: | Height: | Size: 364 B After Width: | Height: | Size: 343 B |
BIN
doc/images/palettes/palette_seismic.png
Normal file
After Width: | Height: | Size: 189 B |
Before Width: | Height: | Size: 221 B After Width: | Height: | Size: 198 B |
Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 216 B |
Before Width: | Height: | Size: 224 B After Width: | Height: | Size: 199 B |
Before Width: | Height: | Size: 235 B After Width: | Height: | Size: 210 B |
Before Width: | Height: | Size: 228 B After Width: | Height: | Size: 203 B |
BIN
doc/images/palettes/palette_terrain.png
Normal file
After Width: | Height: | Size: 256 B |
Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 221 B |
BIN
doc/images/palettes/palette_viridis.png
Normal file
After Width: | Height: | Size: 342 B |
Before Width: | Height: | Size: 189 B After Width: | Height: | Size: 165 B |
Before Width: | Height: | Size: 189 B After Width: | Height: | Size: 165 B |
Before Width: | Height: | Size: 188 B After Width: | Height: | Size: 164 B |
Before Width: | Height: | Size: 187 B After Width: | Height: | Size: 163 B |
Before Width: | Height: | Size: 181 B After Width: | Height: | Size: 157 B |
Before Width: | Height: | Size: 187 B After Width: | Height: | Size: 163 B |
19
doc/template_verbatimgraph.txt
Normal file
@ -0,0 +1,19 @@
|
||||
\verbatim
|
||||
colval
|
||||
^
|
||||
|
|
||||
250 -
|
||||
|
|
||||
200 -
|
||||
|
|
||||
150 -
|
||||
|
|
||||
100 -
|
||||
|
|
||||
50 -
|
||||
|
|
||||
0 -
|
||||
|
|
||||
---|----|----|----|----|----|----|----|----|----|----|--> position
|
||||
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
|
||||
\endverbatim
|
@ -29,6 +29,7 @@ add_subdirectory(filledgraphs)
|
||||
add_subdirectory(functionplot)
|
||||
add_subdirectory(geometric)
|
||||
add_subdirectory(imageplot)
|
||||
add_subdirectory(imageplot_userpal)
|
||||
add_subdirectory(imageplot_modifier)
|
||||
add_subdirectory(imageplot_nodatastore)
|
||||
add_subdirectory(imageplot_opencv)
|
||||
|
@ -42,6 +42,7 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
|:-------------:| ------------- | ------------- |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/rgbimageplot_qt_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot_qt) | [`QImage` as a Graph](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot_qt) | `JKQTPImage` <br> `QImage` drawn onto a plot with arbitrary scaling <br> inverted coordinate axes |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot) | [Basic 1-channel Raw C Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot) | `JKQTPColumnMathImage` <br> image data copied from C-style row-major array into a single column of the internal datastore <br> Describes several options of the image plotting classes (different ways of color coding, what to do with data above/below the limits etc.) |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_userpal_program_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_userpal) | [Image Plots with User-Defined Palettes](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_userpal) | `JKQTPColumnMathImage` <br> user-defines palettes <br> palettes from files |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_modifier_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_modifier) | [Modifier-Feature of Image Plots](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_modifier) | `JKQTPColumnMathImage` <br> image data copied from C-style row-major array into a single column of the internal datastore <br> Image is modified by a second image to display two data dimensions at the same time |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_nodatastore_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_nodatastore) | [Basic 1-channel Raw C Image Plot <br> without the internal datastore](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_nodatastore) | `JKQTPMathImage` <br> image data in a C-style row-major array, not using internal datastore |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/rgbimageplot_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot) | [Simple 3-channel Math RGB/CMY Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot) | `JKQTPColumnRGBMathImage` <br> image data in a C-style row-major array, not using internal datastore <br> RGB/CMY color compositing |
|
||||
|
28
examples/imageplot_userpal/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
set(EXAMPLE_NAME imageplot_userpal)
|
||||
set(EXENAME jkqtptest_${EXAMPLE_NAME})
|
||||
|
||||
message( STATUS ".. Building Example ${EXAMPLE_NAME}" )
|
||||
|
||||
|
||||
# Set up source files
|
||||
set(SOURCES ${EXAMPLE_NAME}.cpp)
|
||||
set(HEADERS )
|
||||
set(RESOURCES imageplot_userpal.qrc )
|
||||
set(UIS )
|
||||
|
||||
add_executable(${EXENAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} ${UIS})
|
||||
target_include_directories(${EXENAME} PRIVATE ../../lib)
|
||||
if(BUILD_STATIC_LIBS)
|
||||
target_link_libraries(${EXENAME} JKQTPlotterLib)
|
||||
elseif(BUILD_SHARED_LIBS)
|
||||
target_link_libraries(${EXENAME} JKQTPlotterSharedLib)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
# Installation
|
||||
if(LIB_INSTALL)
|
||||
install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif(LIB_INSTALL)
|
210
examples/imageplot_userpal/README.md
Normal file
@ -0,0 +1,210 @@
|
||||
# Example (JKQTPlotter): Image Plots with Custom Palettes {#JKQTPlotterImagePlotUserPalette}
|
||||
|
||||
This project (see `./examples/imageplot_userpal/`) demonstrates how to use user-defined color-palettes for image plots.
|
||||
The source code of the main application is (see [`imageplot_userpal.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_userpal/imageplot_userpal.cpp)).
|
||||
|
||||
# Build Palettes Programmatically
|
||||
|
||||
JKQTPlotter comes with a large set of predefined color palettes, which are enumerated in `JKQTPMathImageColorPalette`.
|
||||
In addition you can build your own palettes as simple lookup-tables of type `JKQTPImageTools::LUTType` (which is a `QVector<QRgb>`) and register them in the system (using `JKQTPImageTools::registerPalette()`). There are several options available for building such a palette:
|
||||
1. you can simply define a palette from single colors:
|
||||
```.cpp
|
||||
JKQTPImageTools::LUTType pal{
|
||||
QColor("blue").rgb(),
|
||||
QColor("green").rgb(),
|
||||
QColor("white").rgb(),
|
||||
QColor("yellow").rgb(),
|
||||
QColor("red").rgb(),
|
||||
QColor("red").rgb()
|
||||
};
|
||||
```
|
||||
Such a palette will have exactly as many entries, as you specified: ![palsimple](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_userpal_palsimple.png)
|
||||
2. Alternatively you can build a palette from a set of colors with assocziated positions on the values axis (typically 0..1 as these are in any way later mapped to the actual data range):
|
||||
```.cpp
|
||||
QList<QPair<double, QRgb> > palsteps2;
|
||||
palsteps2<<qMakePair<double, QRgb>(0.00, QColor("blue").rgba());
|
||||
palsteps2<<qMakePair<double, QRgb>(0.05, QColor("green").rgba());
|
||||
palsteps2<<qMakePair<double, QRgb>(0.45, QColor("white").rgba());
|
||||
palsteps2<<qMakePair<double, QRgb>(0.55, QColor("yellow").rgba());
|
||||
palsteps2<<qMakePair<double, QRgb>(0.95, QColor("red").rgba());
|
||||
palsteps2<<qMakePair<double, QRgb>(1.00, QColor("red").rgba());
|
||||
|
||||
pal=JKQTPBuildColorPaletteLUT(palsteps2, JKQTPImageTools::LUTSIZE);
|
||||
```
|
||||
Such a palette will have `JKQTPImageTools::LUTSIZE (=255)` entries and the colors are not spaced equally: ![palsteps2](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_userpal_palsteps2.png)
|
||||
3. The palettes so far had steps, but you can also give a series of nodes with positions (on the value axis) and RGB-colors there (e.g. `palsteps2` above) but then linearly interpolate between these by calling:
|
||||
```.cpp
|
||||
pal=JKQTPBuildColorPaletteLUTLinInterpolate(palsteps2, JKQTPImageTools::LUTSIZE);
|
||||
```
|
||||
The resulting LUT is then: ![imageplot_userpal_2_linear](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_userpal_2_linear.png)
|
||||
4. Finally there is a second way of linear interpolation, where linear segments are given for the three color channels separately. To use such a definition, call `JKQTPBuildColorPaletteLUTLinSegments` instead (see documenttaion there).
|
||||
|
||||
For each of these options, you finally call `JKQTPImageTools::registerPalette()` to make them known to the system:
|
||||
```.cpp
|
||||
int userpalette_id=JKQTPImageTools::registerPalette("userpal_computer_readable_name", pal, QObject::tr("User Palette Human-Readable Name"));
|
||||
```
|
||||
This function returns an integer, which you can cast to a `JKQTPMathImageColorPalette` to use your new palette:
|
||||
```.cpp
|
||||
JKQTPColumnMathImage* graph=new JKQTPColumnMathImage(plot);
|
||||
// ...
|
||||
graph->setPalette(static_cast<JKQTPMathImageColorPalette>(userpalette_id));
|
||||
```
|
||||
|
||||
# Load Palettes from Files
|
||||
|
||||
In addition to building palettes/LUTs programmatically, as shown above, you can simply load palettes from files using:
|
||||
```.cpp
|
||||
JKQTPImageTools::registerPalettesFromFile(":/usercolorpalettes/palettes/All_idl_cmaps.xml");
|
||||
```
|
||||
|
||||
This function may load different file formats (discriminated by the extension):
|
||||
1. XML-files (extension `.xml`) may contain one or more color palettes and should be formatted as follows:
|
||||
```.xml
|
||||
<ColorMap name="PALETTENAME" space="RGB">
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
...
|
||||
</ColorMap>
|
||||
```
|
||||
or with several palettes in one file:
|
||||
```.xml
|
||||
<ColorMaps>
|
||||
<ColorMap name="PALETTENAME" space="RGB">
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
...
|
||||
</ColorMap>
|
||||
<ColorMap name="PALETTENAME" space="RGB">
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
...
|
||||
</ColorMap>
|
||||
...
|
||||
</ColorMaps>
|
||||
```
|
||||
|
||||
2. CSV-files (extensions `.csv`, `.rgb`, `.pal`) are simply a list of 3 or 4 comma-separated values:
|
||||
```
|
||||
red, green, blue
|
||||
red, green, blue
|
||||
...
|
||||
```
|
||||
or:
|
||||
```
|
||||
scalar, red, green, blue
|
||||
scalar, red, green, blue
|
||||
...
|
||||
```
|
||||
|
||||
By default the palettes are simply read from the files as raw data. Alternatively you can linearly interpolate between the nodes in the file by calling
|
||||
```.cpp
|
||||
JKQTPImageTools::registerPalettesFromFile(":/usercolorpalettes/palettes/All_idl_cmaps.xml", true);
|
||||
```
|
||||
|
||||
Examples for such palette files can be found here: [/examples/imageplot_userpal/palettes/](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_userpal/palettes/)
|
||||
|
||||
# Main Program of the Example (GUI)
|
||||
|
||||
The rest of the example program [`imageplot_userpal.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_userpal/imageplot_userpal.cpp) just generates a 2D function plot as a color-map and displays it ...
|
||||
```.cpp
|
||||
// 1. create a window containing a plotter and a combobox to select the color palette
|
||||
// ... and get a pointer to the internal datastore (for convenience)
|
||||
QWidget win;
|
||||
QVBoxLayout* lay=new QVBoxLayout();
|
||||
win.setLayout(lay);
|
||||
JKQTPMathImageColorPaletteComboBox* cmbPalette=new JKQTPMathImageColorPaletteComboBox(&win);
|
||||
lay->addWidget(cmbPalette);
|
||||
JKQTPlotter* plot=new JKQTPlotter(&win);
|
||||
lay->addWidget(plot);
|
||||
JKQTPDatastore* ds=plot->getDatastore();
|
||||
|
||||
// 2. now we create data for the charts (taken from https://commons.wikimedia.org/wiki/File:Energiemix_Deutschland.svg)
|
||||
const int NX=100; // image dimension in x-direction [pixels]
|
||||
const int NY=NX; // image dimension in x-direction [pixels]
|
||||
const double dx=0.6e-2; // size of a pixel in x-direction [micrometers]
|
||||
const double dy=0.6e-2; // size of a pixel in x-direction [micrometers]
|
||||
|
||||
// 2.1 Parameters for airy disk plot (see https://en.wikipedia.org/wiki/Airy_disk)
|
||||
double NA=1.1; // numerical aperture of lens
|
||||
double wavelength=488e-3; // wavelength of the light [micrometers]
|
||||
|
||||
// 2.2 calculate image of airy disk in a row-major array and immediately store the values
|
||||
// in a new image column cAiryDisk
|
||||
size_t cAiryDisk=ds->addCalculatedImageColumn(NX, NY, [&](size_t ix, size_t iy)->double {
|
||||
double x=static_cast<double>(static_cast<int>(ix)-NX/2)*dx;
|
||||
double y=static_cast<double>(static_cast<int>(iy)-NY/2)*dy;
|
||||
const double r=sqrt(x*x+y*y);
|
||||
const double v=2.0*M_PI*NA*r/wavelength;
|
||||
if (ix==NX/2 && iy==NY/2) return 1.0;
|
||||
else return pow(2.0*j1(v)/v, 2);
|
||||
}, "imagedata");
|
||||
|
||||
|
||||
|
||||
|
||||
// 3. create a graph (JKQTPColumnMathImage) with the column created above as data
|
||||
// The data is color-coded with the color-palette JKQTPMathImageMATLAB
|
||||
// the converted range of data is determined automatically because setAutoImageRange(true)
|
||||
JKQTPColumnMathImage* graph=new JKQTPColumnMathImage(plot);
|
||||
graph->setTitle("default MATLAB palette");
|
||||
// set the image column with the data
|
||||
graph->setImageColumn(cAiryDisk);
|
||||
// where does the image start in the plot, given in plot-axis-coordinates (bottom-left corner)
|
||||
graph->setX(0);
|
||||
graph->setY(0);
|
||||
// width and height of the image in plot-axis-coordinates
|
||||
graph->setWidth(1);
|
||||
graph->setHeight(1);
|
||||
// color-map is taken from cmbPalette
|
||||
plot->connect(cmbPalette, &JKQTPMathImageColorPaletteComboBox::currentPaletteChanged,[&](JKQTPMathImageColorPalette p) { graph->setPalette(p); plot->redrawPlot(); });
|
||||
cmbPalette->setCurrentColorPalette(graph->getPalette());
|
||||
|
||||
|
||||
// 4. add the graphs to the plot, so it is actually displayed
|
||||
plot->addGraph(graph);
|
||||
|
||||
|
||||
// 5. fix axis and plot aspect ratio to 1
|
||||
plot->getPlotter()->setMaintainAspectRatio(true);
|
||||
plot->getPlotter()->setMaintainAxisAspectRatio(true);
|
||||
|
||||
// 6. autoscale the plot so the graph is contained
|
||||
plot->zoomToFit();
|
||||
|
||||
|
||||
// 8. show plotter and make it a decent size
|
||||
win.show();
|
||||
win.resize(500,550);
|
||||
win.setWindowTitle("JKQTPColumnMathImage, User Palettes");
|
||||
```
|
||||
...along with a `JKQTPMathImageColorPaletteComboBox` to select a colormap and redraw the plot:
|
||||
```.cpp
|
||||
JKQTPMathImageColorPaletteComboBox* cmbPalette=new JKQTPMathImageColorPaletteComboBox(&win);
|
||||
// ...
|
||||
plot->connect(cmbPalette, &JKQTPMathImageColorPaletteComboBox::currentPaletteChanged,[&](JKQTPMathImageColorPalette p) { graph->setPalette(p); plot->redrawPlot(); });
|
||||
cmbPalette->setCurrentColorPalette(graph->getPalette());
|
||||
```
|
||||
|
||||
It also adds two `QPushButton`s that allow to save the current or all registered color-palettes to small PNG-Files:
|
||||
```.cpp
|
||||
QPushButton* btnSavePal=new QPushButton(QObject::tr("save current palette"), &win);
|
||||
btnSavePal->connect(btnSavePal, &QPushButton::clicked, [&]() {
|
||||
auto img=JKQTPImageTools::GetPaletteImage(cmbPalette->currentColorPalette(), JKQTPImageTools::LUTSIZE, 16);
|
||||
img.save(JKQTPImageTools::JKQTPMathImageColorPalette2String(cmbPalette->currentColorPalette())+".png");
|
||||
});
|
||||
lay->addWidget(btnSavePal);
|
||||
QPushButton* btnSaveAllPal=new QPushButton(QObject::tr("save all palettes"), &win);
|
||||
btnSavePal->connect(btnSaveAllPal, &QPushButton::clicked, [&]() {
|
||||
for (auto pn: JKQTPImageTools::getPredefinedPalettes()) {
|
||||
auto p=JKQTPImageTools::String2JKQTPMathImageColorPalette(pn);
|
||||
auto img=JKQTPImageTools::GetPaletteImage(p, JKQTPImageTools::LUTSIZE, 16);
|
||||
img.save("palette_"+JKQTPImageTools::JKQTPMathImageColorPalette2String(p)+".png");
|
||||
}
|
||||
});
|
||||
lay->addWidget(btnSaveAllPal);
|
||||
```
|
||||
|
||||
The whole program looks like this:
|
||||
|
||||
![imageplot_userpal_program](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_userpal_program.png)
|
||||
|
173
examples/imageplot_userpal/imageplot_userpal.cpp
Normal file
@ -0,0 +1,173 @@
|
||||
/** \example imageplot_userpal.cpp
|
||||
* Shows how to plot colored math images/matrices with JKQTPlotter, using user-defined image palettes
|
||||
*
|
||||
* \ref JKQTPlotterImagePlot
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
#include <QWidget>
|
||||
#include <QBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpimage.h"
|
||||
#include "jkqtplotter/gui/jkqtpcomboboxes.h"
|
||||
#include "jkqtcommon/jkqtpbasicimagetools.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// 0. tell the library where to find additional palettes.
|
||||
// this needs to be done BEFORE first using JKQTPlotter
|
||||
// 0.1 first we want to build a user-defined palette with five colors
|
||||
// from a simple list of these colors:
|
||||
JKQTPImageTools::LUTType pal{
|
||||
QColor("blue").rgb(),
|
||||
QColor("green").rgb(),
|
||||
QColor("white").rgb(),
|
||||
QColor("yellow").rgb(),
|
||||
QColor("red").rgb(),
|
||||
QColor("red").rgb()
|
||||
};
|
||||
JKQTPImageTools::registerPalette("userpal_list", pal, QObject::tr("User Palette simple list"));
|
||||
|
||||
// 0.2 first we want to build a user-defined palette with five colors
|
||||
// the function JKQTPBuildColorPaletteLUT builds a full-sized palette
|
||||
// with steps from the given 5 colors.
|
||||
// Note that you need to double the last color in order to define its range's
|
||||
// beginning and end
|
||||
QList<QPair<double, QRgb> > palsteps1;
|
||||
palsteps1<<qMakePair<double, QRgb>(0.0, QColor("blue").rgba());
|
||||
palsteps1<<qMakePair<double, QRgb>(0.2, QColor("green").rgba());
|
||||
palsteps1<<qMakePair<double, QRgb>(0.4, QColor("white").rgba());
|
||||
palsteps1<<qMakePair<double, QRgb>(0.6, QColor("yellow").rgba());
|
||||
palsteps1<<qMakePair<double, QRgb>(0.8, QColor("red").rgba());
|
||||
palsteps1<<qMakePair<double, QRgb>(1.0, QColor("red").rgba());
|
||||
JKQTPImageTools::registerPalette("userpal_1_steps", JKQTPBuildColorPaletteLUT(palsteps1), QObject::tr("User Palette 1, steps"));
|
||||
|
||||
|
||||
// With the double value (first argument), you can determine where the next color
|
||||
// band starts, with respect to the other colors. As an example, we make the central
|
||||
// white band narrow, as well as the bands at the borders:
|
||||
QList<QPair<double, QRgb> > palsteps2;
|
||||
palsteps2<<qMakePair<double, QRgb>(0.00, QColor("blue").rgba());
|
||||
palsteps2<<qMakePair<double, QRgb>(0.05, QColor("green").rgba());
|
||||
palsteps2<<qMakePair<double, QRgb>(0.45, QColor("white").rgba());
|
||||
palsteps2<<qMakePair<double, QRgb>(0.55, QColor("yellow").rgba());
|
||||
palsteps2<<qMakePair<double, QRgb>(0.95, QColor("red").rgba());
|
||||
palsteps2<<qMakePair<double, QRgb>(1.00, QColor("red").rgba());
|
||||
int userpalette_id=JKQTPImageTools::registerPalette("userpal_2_steps", JKQTPBuildColorPaletteLUT(palsteps2), QObject::tr("User Palette 2, steps"));
|
||||
|
||||
|
||||
// 0.2 If we use JKQTPBuildColorPaletteLUTLinInterpolate() instead of JKQTPBuildColorPaletteLUT(),
|
||||
// the palettes will be smooth (linearly interpolated between the single given colors:
|
||||
JKQTPImageTools::registerPalette("userpal_1_linear", JKQTPBuildColorPaletteLUTLinInterpolate(palsteps1), QObject::tr("User Palette 1, linear"));
|
||||
JKQTPImageTools::registerPalette("userpal_2_linear", JKQTPBuildColorPaletteLUTLinInterpolate(palsteps2), QObject::tr("User Palette 2, linear"));
|
||||
|
||||
// 0.3 Now we load a whole set of additional palettes from an XML-file:
|
||||
JKQTPImageTools::registerPalettesFromFile(":/usercolorpalettes/palettes/All_idl_cmaps.xml");
|
||||
JKQTPImageTools::registerPalettesFromFile(":/usercolorpalettes/palettes/All_mpl_cmaps.xml");
|
||||
JKQTPImageTools::registerPalettesFromFile(":/usercolorpalettes/palettes/CoolWarmUChar33.csv");
|
||||
JKQTPImageTools::registerPalettesFromFile(":/usercolorpalettes/palettes/CoolWarmUChar257.csv");
|
||||
JKQTPImageTools::registerPalettesFromFile(":/usercolorpalettes/palettes/NSW_Discrete_Z_ColorMap.xml");
|
||||
|
||||
|
||||
// 1. create a window containing a plotter and a combobox to select the color palette
|
||||
// ... and get a pointer to the internal datastore (for convenience)
|
||||
QWidget win;
|
||||
QVBoxLayout* lay=new QVBoxLayout();
|
||||
win.setLayout(lay);
|
||||
JKQTPMathImageColorPaletteComboBox* cmbPalette=new JKQTPMathImageColorPaletteComboBox(&win);
|
||||
lay->addWidget(cmbPalette);
|
||||
JKQTPlotter* plot=new JKQTPlotter(&win);
|
||||
lay->addWidget(plot);
|
||||
JKQTPDatastore* ds=plot->getDatastore();
|
||||
|
||||
// 2. now we create data for the charts (taken from https://commons.wikimedia.org/wiki/File:Energiemix_Deutschland.svg)
|
||||
const int NX=100; // image dimension in x-direction [pixels]
|
||||
const int NY=NX; // image dimension in x-direction [pixels]
|
||||
const double dx=0.6e-2; // size of a pixel in x-direction [micrometers]
|
||||
const double dy=0.6e-2; // size of a pixel in x-direction [micrometers]
|
||||
|
||||
// 2.1 Parameters for airy disk plot (see https://en.wikipedia.org/wiki/Airy_disk)
|
||||
double NA=1.1; // numerical aperture of lens
|
||||
double wavelength=488e-3; // wavelength of the light [micrometers]
|
||||
|
||||
// 2.2 calculate image of airy disk in a row-major array and immediately store the values
|
||||
// in a new image column cAiryDisk
|
||||
size_t cAiryDisk=ds->addCalculatedImageColumn(NX, NY, [&](size_t ix, size_t iy)->double {
|
||||
double x=static_cast<double>(static_cast<int>(ix)-NX/2)*dx;
|
||||
double y=static_cast<double>(static_cast<int>(iy)-NY/2)*dy;
|
||||
const double r=sqrt(x*x+y*y);
|
||||
const double v=2.0*M_PI*NA*r/wavelength;
|
||||
if (ix==NX/2 && iy==NY/2) return 1.0;
|
||||
else return pow(2.0*j1(v)/v, 2);
|
||||
}, "imagedata");
|
||||
|
||||
|
||||
|
||||
|
||||
// 3. create a graph (JKQTPColumnMathImage) with the column created above as data
|
||||
// The data is color-coded with the color-palette JKQTPMathImageMATLAB
|
||||
// the converted range of data is determined automatically because setAutoImageRange(true)
|
||||
JKQTPColumnMathImage* graph=new JKQTPColumnMathImage(plot);
|
||||
graph->setTitle("default MATLAB palette");
|
||||
// set the image column with the data
|
||||
graph->setImageColumn(cAiryDisk);
|
||||
// where does the image start in the plot, given in plot-axis-coordinates (bottom-left corner)
|
||||
graph->setX(0);
|
||||
graph->setY(0);
|
||||
// width and height of the image in plot-axis-coordinates
|
||||
graph->setWidth(1);
|
||||
graph->setHeight(1);
|
||||
// color-map is taken from cmbPalette
|
||||
plot->connect(cmbPalette, &JKQTPMathImageColorPaletteComboBox::currentPaletteChanged,[&](JKQTPMathImageColorPalette p) { graph->setPalette(p); plot->redrawPlot(); });
|
||||
graph->setPalette(static_cast<JKQTPMathImageColorPalette>(userpalette_id));
|
||||
cmbPalette->setCurrentColorPalette(graph->getPalette());
|
||||
|
||||
|
||||
// 4. add the graphs to the plot, so it is actually displayed
|
||||
plot->addGraph(graph);
|
||||
|
||||
|
||||
// 5. fix axis and plot aspect ratio to 1
|
||||
plot->getPlotter()->setMaintainAspectRatio(true);
|
||||
plot->getPlotter()->setMaintainAxisAspectRatio(true);
|
||||
|
||||
// 6. autoscale the plot so the graph is contained
|
||||
plot->zoomToFit();
|
||||
|
||||
|
||||
// 7. Finally we add two buttons that save the current palette to a PNG-file and all loaded palettes:
|
||||
QPushButton* btnSavePal=new QPushButton(QObject::tr("save current palette"), &win);
|
||||
btnSavePal->connect(btnSavePal, &QPushButton::clicked, [&]() {
|
||||
auto img=JKQTPImageTools::GetPaletteImage(cmbPalette->currentColorPalette(), JKQTPImageTools::LUTSIZE, 16);
|
||||
img.save(JKQTPImageTools::JKQTPMathImageColorPalette2String(cmbPalette->currentColorPalette())+".png");
|
||||
});
|
||||
lay->addWidget(btnSavePal);
|
||||
QPushButton* btnSaveAllPal=new QPushButton(QObject::tr("save all palettes"), &win);
|
||||
btnSavePal->connect(btnSaveAllPal, &QPushButton::clicked, [&]() {
|
||||
for (auto pn: JKQTPImageTools::getPredefinedPalettes()) {
|
||||
auto p=JKQTPImageTools::String2JKQTPMathImageColorPalette(pn);
|
||||
auto img=JKQTPImageTools::GetPaletteImage(p, JKQTPImageTools::LUTSIZE, 16);
|
||||
img.save("palette_"+JKQTPImageTools::JKQTPMathImageColorPalette2String(p)+".png");
|
||||
}
|
||||
});
|
||||
lay->addWidget(btnSaveAllPal);
|
||||
|
||||
|
||||
|
||||
// 8. show plotter and make it a decent size
|
||||
win.show();
|
||||
win.resize(500,550);
|
||||
win.setWindowTitle("JKQTPColumnMathImage, USer Palettes");
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
27
examples/imageplot_userpal/imageplot_userpal.pro
Normal file
@ -0,0 +1,27 @@
|
||||
# source code for this simple demo
|
||||
SOURCES = imageplot_userpal.cpp
|
||||
|
||||
# configure Qt
|
||||
CONFIG += link_prl qt
|
||||
QT += core gui xml svg
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
|
||||
|
||||
# output executable name
|
||||
TARGET = imageplot_userpal
|
||||
|
||||
# include JKQTPlotter source code
|
||||
DEPENDPATH += ../../lib ../../qmake/staticlib/jkqtplotterlib
|
||||
INCLUDEPATH += ../../lib
|
||||
CONFIG (debug, debug|release) {
|
||||
LIBS += -L../../qmake/staticlib/jkqtplotterlib/debug -ljkqtplotterlib_debug
|
||||
} else {
|
||||
LIBS += -L../../qmake/staticlib/jkqtplotterlib/release -ljkqtplotterlib
|
||||
}
|
||||
message("LIBS = $$LIBS")
|
||||
|
||||
win32-msvc*: DEFINES += _USE_MATH_DEFINES
|
||||
win32-msvc*: DEFINES += NOMINMAX
|
||||
|
||||
|
||||
|
||||
|
9
examples/imageplot_userpal/imageplot_userpal.qrc
Normal file
@ -0,0 +1,9 @@
|
||||
<RCC>
|
||||
<qresource prefix="/usercolorpalettes">
|
||||
<file>palettes/All_idl_cmaps.xml</file>
|
||||
<file>palettes/All_mpl_cmaps.xml</file>
|
||||
<file>palettes/CoolWarmUChar33.csv</file>
|
||||
<file>palettes/CoolWarmUChar257.csv</file>
|
||||
<file>palettes/NSW_Discrete_Z_ColorMap.xml</file>
|
||||
</qresource>
|
||||
</RCC>
|
8
examples/imageplot_userpal/imageplot_userpal_and_lib.pro
Normal file
@ -0,0 +1,8 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += jkqtplotterlib imageplot
|
||||
|
||||
jkqtplotterlib.file = ../../qmake/staticlib/jkqtplotterlib/jkqtplotterlib.pro
|
||||
|
||||
imageplot.file=$$PWD/imageplot.pro
|
||||
imageplot.depends = jkqtplotterlib
|
10581
examples/imageplot_userpal/palettes/All_idl_cmaps.xml
Normal file
12903
examples/imageplot_userpal/palettes/All_mpl_cmaps.xml
Normal file
258
examples/imageplot_userpal/palettes/CoolWarmUChar257.csv
Normal file
@ -0,0 +1,258 @@
|
||||
Scalar,R,G,B
|
||||
0,59,76,192
|
||||
0.00390625,60,78,194
|
||||
0.0078125,61,80,195
|
||||
0.01171875,62,81,197
|
||||
0.015625,63,83,198
|
||||
0.01953125,64,85,200
|
||||
0.0234375,66,87,201
|
||||
0.02734375,67,88,203
|
||||
0.03125,68,90,204
|
||||
0.03515625,69,92,206
|
||||
0.0390625,70,93,207
|
||||
0.04296875,71,95,209
|
||||
0.046875,73,97,210
|
||||
0.05078125,74,99,211
|
||||
0.0546875,75,100,213
|
||||
0.05859375,76,102,214
|
||||
0.0625,77,104,215
|
||||
0.06640625,79,105,217
|
||||
0.0703125,80,107,218
|
||||
0.07421875,81,109,219
|
||||
0.078125,82,110,221
|
||||
0.08203125,84,112,222
|
||||
0.0859375,85,114,223
|
||||
0.08984375,86,115,224
|
||||
0.09375,87,117,225
|
||||
0.09765625,89,119,226
|
||||
0.1015625,90,120,228
|
||||
0.10546875,91,122,229
|
||||
0.109375,93,123,230
|
||||
0.11328125,94,125,231
|
||||
0.1171875,95,127,232
|
||||
0.12109375,96,128,233
|
||||
0.125,98,130,234
|
||||
0.12890625,99,131,235
|
||||
0.1328125,100,133,236
|
||||
0.13671875,102,135,237
|
||||
0.140625,103,136,238
|
||||
0.14453125,104,138,239
|
||||
0.1484375,106,139,239
|
||||
0.15234375,107,141,240
|
||||
0.15625,108,142,241
|
||||
0.16015625,110,144,242
|
||||
0.1640625,111,145,243
|
||||
0.16796875,112,147,243
|
||||
0.171875,114,148,244
|
||||
0.17578125,115,150,245
|
||||
0.1796875,116,151,246
|
||||
0.18359375,118,153,246
|
||||
0.1875,119,154,247
|
||||
0.19140625,120,156,247
|
||||
0.1953125,122,157,248
|
||||
0.19921875,123,158,249
|
||||
0.203125,124,160,249
|
||||
0.20703125,126,161,250
|
||||
0.2109375,127,163,250
|
||||
0.21484375,129,164,251
|
||||
0.21875,130,165,251
|
||||
0.22265625,131,167,252
|
||||
0.2265625,133,168,252
|
||||
0.23046875,134,169,252
|
||||
0.234375,135,171,253
|
||||
0.23828125,137,172,253
|
||||
0.2421875,138,173,253
|
||||
0.24609375,140,174,254
|
||||
0.25,141,176,254
|
||||
0.25390625,142,177,254
|
||||
0.2578125,144,178,254
|
||||
0.26171875,145,179,254
|
||||
0.265625,147,181,255
|
||||
0.26953125,148,182,255
|
||||
0.2734375,149,183,255
|
||||
0.27734375,151,184,255
|
||||
0.28125,152,185,255
|
||||
0.28515625,153,186,255
|
||||
0.2890625,155,187,255
|
||||
0.29296875,156,188,255
|
||||
0.296875,158,190,255
|
||||
0.30078125,159,191,255
|
||||
0.3046875,160,192,255
|
||||
0.30859375,162,193,255
|
||||
0.3125,163,194,255
|
||||
0.31640625,164,195,254
|
||||
0.3203125,166,196,254
|
||||
0.32421875,167,197,254
|
||||
0.328125,168,198,254
|
||||
0.33203125,170,199,253
|
||||
0.3359375,171,199,253
|
||||
0.33984375,172,200,253
|
||||
0.34375,174,201,253
|
||||
0.34765625,175,202,252
|
||||
0.3515625,176,203,252
|
||||
0.35546875,178,204,251
|
||||
0.359375,179,205,251
|
||||
0.36328125,180,205,251
|
||||
0.3671875,182,206,250
|
||||
0.37109375,183,207,250
|
||||
0.375,184,208,249
|
||||
0.37890625,185,208,248
|
||||
0.3828125,187,209,248
|
||||
0.38671875,188,210,247
|
||||
0.390625,189,210,247
|
||||
0.39453125,190,211,246
|
||||
0.3984375,192,212,245
|
||||
0.40234375,193,212,245
|
||||
0.40625,194,213,244
|
||||
0.41015625,195,213,243
|
||||
0.4140625,197,214,243
|
||||
0.41796875,198,214,242
|
||||
0.421875,199,215,241
|
||||
0.42578125,200,215,240
|
||||
0.4296875,201,216,239
|
||||
0.43359375,203,216,238
|
||||
0.4375,204,217,238
|
||||
0.44140625,205,217,237
|
||||
0.4453125,206,217,236
|
||||
0.44921875,207,218,235
|
||||
0.453125,208,218,234
|
||||
0.45703125,209,219,233
|
||||
0.4609375,210,219,232
|
||||
0.46484375,211,219,231
|
||||
0.46875,213,219,230
|
||||
0.47265625,214,220,229
|
||||
0.4765625,215,220,228
|
||||
0.48046875,216,220,227
|
||||
0.484375,217,220,225
|
||||
0.48828125,218,220,224
|
||||
0.4921875,219,220,223
|
||||
0.49609375,220,221,222
|
||||
0.5,221,221,221
|
||||
0.50390625,222,220,219
|
||||
0.5078125,223,220,218
|
||||
0.51171875,224,219,216
|
||||
0.515625,225,219,215
|
||||
0.51953125,226,218,214
|
||||
0.5234375,227,218,212
|
||||
0.52734375,228,217,211
|
||||
0.53125,229,216,209
|
||||
0.53515625,230,216,208
|
||||
0.5390625,231,215,206
|
||||
0.54296875,232,215,205
|
||||
0.546875,232,214,203
|
||||
0.55078125,233,213,202
|
||||
0.5546875,234,212,200
|
||||
0.55859375,235,212,199
|
||||
0.5625,236,211,197
|
||||
0.56640625,236,210,196
|
||||
0.5703125,237,209,194
|
||||
0.57421875,238,209,193
|
||||
0.578125,238,208,191
|
||||
0.58203125,239,207,190
|
||||
0.5859375,240,206,188
|
||||
0.58984375,240,205,187
|
||||
0.59375,241,204,185
|
||||
0.59765625,241,203,184
|
||||
0.6015625,242,202,182
|
||||
0.60546875,242,201,181
|
||||
0.609375,243,200,179
|
||||
0.61328125,243,199,178
|
||||
0.6171875,244,198,176
|
||||
0.62109375,244,197,174
|
||||
0.625,245,196,173
|
||||
0.62890625,245,195,171
|
||||
0.6328125,245,194,170
|
||||
0.63671875,245,193,168
|
||||
0.640625,246,192,167
|
||||
0.64453125,246,191,165
|
||||
0.6484375,246,190,163
|
||||
0.65234375,246,188,162
|
||||
0.65625,247,187,160
|
||||
0.66015625,247,186,159
|
||||
0.6640625,247,185,157
|
||||
0.66796875,247,184,156
|
||||
0.671875,247,182,154
|
||||
0.67578125,247,181,152
|
||||
0.6796875,247,180,151
|
||||
0.68359375,247,178,149
|
||||
0.6875,247,177,148
|
||||
0.69140625,247,176,146
|
||||
0.6953125,247,174,145
|
||||
0.69921875,247,173,143
|
||||
0.703125,247,172,141
|
||||
0.70703125,247,170,140
|
||||
0.7109375,247,169,138
|
||||
0.71484375,247,167,137
|
||||
0.71875,247,166,135
|
||||
0.72265625,246,164,134
|
||||
0.7265625,246,163,132
|
||||
0.73046875,246,161,131
|
||||
0.734375,246,160,129
|
||||
0.73828125,245,158,127
|
||||
0.7421875,245,157,126
|
||||
0.74609375,245,155,124
|
||||
0.75,244,154,123
|
||||
0.75390625,244,152,121
|
||||
0.7578125,244,151,120
|
||||
0.76171875,243,149,118
|
||||
0.765625,243,147,117
|
||||
0.76953125,242,146,115
|
||||
0.7734375,242,144,114
|
||||
0.77734375,241,142,112
|
||||
0.78125,241,141,111
|
||||
0.78515625,240,139,109
|
||||
0.7890625,240,137,108
|
||||
0.79296875,239,136,106
|
||||
0.796875,238,134,105
|
||||
0.80078125,238,132,103
|
||||
0.8046875,237,130,102
|
||||
0.80859375,236,129,100
|
||||
0.8125,236,127,99
|
||||
0.81640625,235,125,97
|
||||
0.8203125,234,123,96
|
||||
0.82421875,233,121,95
|
||||
0.828125,233,120,93
|
||||
0.83203125,232,118,92
|
||||
0.8359375,231,116,90
|
||||
0.83984375,230,114,89
|
||||
0.84375,229,112,88
|
||||
0.84765625,228,110,86
|
||||
0.8515625,227,108,85
|
||||
0.85546875,227,106,83
|
||||
0.859375,226,104,82
|
||||
0.86328125,225,102,81
|
||||
0.8671875,224,100,79
|
||||
0.87109375,223,98,78
|
||||
0.875,222,96,77
|
||||
0.87890625,221,94,75
|
||||
0.8828125,220,92,74
|
||||
0.88671875,218,90,73
|
||||
0.890625,217,88,71
|
||||
0.89453125,216,86,70
|
||||
0.8984375,215,84,69
|
||||
0.90234375,214,82,67
|
||||
0.90625,213,80,66
|
||||
0.91015625,212,78,65
|
||||
0.9140625,210,75,64
|
||||
0.91796875,209,73,62
|
||||
0.921875,208,71,61
|
||||
0.92578125,207,69,60
|
||||
0.9296875,205,66,59
|
||||
0.93359375,204,64,57
|
||||
0.9375,203,62,56
|
||||
0.94140625,202,59,55
|
||||
0.9453125,200,57,54
|
||||
0.94921875,199,54,53
|
||||
0.953125,198,51,52
|
||||
0.95703125,196,49,50
|
||||
0.9609375,195,46,49
|
||||
0.96484375,193,43,48
|
||||
0.96875,192,40,47
|
||||
0.97265625,190,37,46
|
||||
0.9765625,189,34,45
|
||||
0.98046875,188,30,44
|
||||
0.984375,186,26,43
|
||||
0.98828125,185,22,41
|
||||
0.9921875,183,17,40
|
||||
0.99609375,181,11,39
|
||||
1,180,4,38
|
|
34
examples/imageplot_userpal/palettes/CoolWarmUChar33.csv
Normal file
@ -0,0 +1,34 @@
|
||||
Scalar,R,G,B
|
||||
0,59,76,192
|
||||
0.03125,68,90,204
|
||||
0.0625,77,104,215
|
||||
0.09375,87,117,225
|
||||
0.125,98,130,234
|
||||
0.15625,108,142,241
|
||||
0.1875,119,154,247
|
||||
0.21875,130,165,251
|
||||
0.25,141,176,254
|
||||
0.28125,152,185,255
|
||||
0.3125,163,194,255
|
||||
0.34375,174,201,253
|
||||
0.375,184,208,249
|
||||
0.40625,194,213,244
|
||||
0.4375,204,217,238
|
||||
0.46875,213,219,230
|
||||
0.5,221,221,221
|
||||
0.53125,229,216,209
|
||||
0.5625,236,211,197
|
||||
0.59375,241,204,185
|
||||
0.625,245,196,173
|
||||
0.65625,247,187,160
|
||||
0.6875,247,177,148
|
||||
0.71875,247,166,135
|
||||
0.75,244,154,123
|
||||
0.78125,241,141,111
|
||||
0.8125,236,127,99
|
||||
0.84375,229,112,88
|
||||
0.875,222,96,77
|
||||
0.90625,213,80,66
|
||||
0.9375,203,62,56
|
||||
0.96875,192,40,47
|
||||
1,180,4,38
|
|
@ -0,0 +1,47 @@
|
||||
<!-- downloaded from http://www.rasmsys.com/page6/page14/page14.html -->
|
||||
<ColorMap name="NWS Discrete Z" space="RGB">
|
||||
<Point x="-30.0" o="1" r="0.797" g="1.00" b="1.0"/>
|
||||
<Point x="-25.01" o="1" r="0.797" g="1.00" b="1.0"/>
|
||||
<Point x="-25.0" o="1" r="0.800" g="0.600" b="0.800"/>
|
||||
<Point x="-20.01" o="1" r="0.800" g="0.600" b="0.800"/>
|
||||
<Point x="-20.0" o="1" r="0.600" g="0.400" b="0.600"/>
|
||||
<Point x="-15.01" o="1" r="0.600" g="0.400" b="0.600"/>
|
||||
<Point x="-15.0" o="1" r="0.400" g="0.200" b="0.400"/>
|
||||
<Point x="-10.01" o="1" r="0.400" g="0.200" b="0.400"/>
|
||||
<Point x="-10.0" o="1" r="0.800" g="0.800" b="0.600"/>
|
||||
<Point x="-5.01" o="1" r="0.800" g="0.800" b="0.600"/>
|
||||
<Point x="-5.0" o="1" r="0.600" g="0.600" b="0.400"/>
|
||||
<Point x="-0.01" o="1" r="0.600" g="0.600" b="0.400"/>
|
||||
<Point x="0.0" o="1" r="0.392" g="0.392" b="0.392"/>
|
||||
<Point x="4.99" o="1" r="0.392" g="0.392" b="0.392"/>
|
||||
<Point x="5.0" o="1" r="0.016" g="0.914" b="0.906"/>
|
||||
<Point x="9.99" o="1" r="0.016" g="0.914" b="0.906"/>
|
||||
<Point x="10.0" o="1" r="0.004" g="0.624" b="0.957"/>
|
||||
<Point x="14.99" o="1" r="0.004" g="0.624" b="0.957"/>
|
||||
<Point x="15.0" o="1" r="0.012" g="0.000" b="0.957"/>
|
||||
<Point x="19.99" o="1" r="0.012" g="0.000" b="0.957"/>
|
||||
<Point x="20.0" o="1" r="0.008" g="0.992" b="0.008"/>
|
||||
<Point x="24.99" o="1" r="0.008" g="0.992" b="0.008"/>
|
||||
<Point x="25.0" o="1" r="0.004" g="0.773" b="0.004"/>
|
||||
<Point x="29.99" o="1" r="0.004" g="0.773" b="0.004"/>
|
||||
<Point x="30.0" o="1" r="0.000" g="0.557" b="0.000"/>
|
||||
<Point x="34.99" o="1" r="0.000" g="0.557" b="0.000"/>
|
||||
<Point x="35.0" o="1" r="0.992" g="0.973" b="0.008"/>
|
||||
<Point x="39.99" o="1" r="0.992" g="0.973" b="0.008"/>
|
||||
<Point x="40.0" o="1" r="0.898" g="0.737" b="0.000"/>
|
||||
<Point x="44.99" o="1" r="0.898" g="0.737" b="0.000"/>
|
||||
<Point x="45.0" o="1" r="0.992" g="0.584" b="0.000"/>
|
||||
<Point x="49.99" o="1" r="0.992" g="0.584" b="0.000"/>
|
||||
<Point x="50.0" o="1" r="0.992" g="0.000" b="0.000"/>
|
||||
<Point x="54.99" o="1" r="0.992" g="0.000" b="0.000"/>
|
||||
<Point x="55.0" o="1" r="0.831" g="0.000" b="0.000"/>
|
||||
<Point x="59.99" o="1" r="0.831" g="0.000" b="0.000"/>
|
||||
<Point x="60.0" o="1" r="0.737" g="0.000" b="0.000"/>
|
||||
<Point x="64.99" o="1" r="0.737" g="0.000" b="0.000"/>
|
||||
<Point x="65.0" o="1" r="0.973" g="0.000" b="0.992"/>
|
||||
<Point x="69.99" o="1" r="0.973" g="0.000" b="0.992"/>
|
||||
<Point x="70.0" o="1" r="0.596" g="0.329" b="0.776"/>
|
||||
<Point x="74.99" o="1" r="0.596" g="0.329" b="0.776"/>
|
||||
<Point x="75.0" o="1" r="1.000" g="1.000" b="1.000"/>
|
||||
<Point x="99.99" o="1" r="1.000" g="1.000" b="1.000"/>
|
||||
</ColorMap>
|
@ -73,7 +73,7 @@ if(BUILD_SHARED_LIBS)
|
||||
add_library(${libsh_name} SHARED ${SOURCES} ${HEADERS})
|
||||
set_property(TARGET ${libsh_name} PROPERTY VERSION "${PROJECT_VERSION}")
|
||||
set_property(TARGET ${libsh_name} PROPERTY OUTPUT_NAME "${libsh_name_decorated}")
|
||||
target_link_libraries(${libsh_name} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport)
|
||||
target_link_libraries(${libsh_name} Qt5::Core Qt5::Gui Qt5::Xml Qt5::Widgets Qt5::PrintSupport)
|
||||
target_compile_definitions(${libsh_name} PUBLIC JKQTCOMMON_LIB_IN_DLL)
|
||||
target_compile_definitions(${libsh_name} PRIVATE JKQTCOMMON_LIB_EXPORT_LIBRARY)
|
||||
set_property(TARGET ${libsh_name} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS "ON")
|
||||
@ -86,7 +86,7 @@ if(BUILD_STATIC_LIBS)
|
||||
add_library(${lib_name} STATIC ${SOURCES} ${HEADERS})
|
||||
set_property(TARGET ${lib_name} PROPERTY VERSION "${PROJECT_VERSION}")
|
||||
set_property(TARGET ${lib_name} PROPERTY OUTPUT_NAME "${lib_name_decorated}")
|
||||
target_link_libraries(${lib_name} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport)
|
||||
target_link_libraries(${lib_name} Qt5::Core Qt5::Gui Qt5::Xml Qt5::Widgets Qt5::PrintSupport)
|
||||
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Version.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion )
|
||||
|
@ -24,38 +24,40 @@
|
||||
#include <QDebug>
|
||||
#include <QImage>
|
||||
#include <QStringList>
|
||||
#include "jkqtcommon/jkqtcommon_imexport.h"
|
||||
#include <cmath>
|
||||
#include <cfloat>
|
||||
#include <stdint.h>
|
||||
#include <QColor>
|
||||
#include "jkqtcommon/jkqtcommon_imexport.h"
|
||||
#include "jkqtcommon/jkqtpmathtools.h"
|
||||
|
||||
/*! \brief tool structure that summarizes several static properties
|
||||
\ingroup jkqtptools_qt
|
||||
\internal
|
||||
*/
|
||||
struct JKQTPImageTools {
|
||||
|
||||
/*! \brief Width of the Palette-Icons, generated e.g. by JKQTPMathImageGetPaletteIcon()
|
||||
\ingroup jkqtptools_qt */
|
||||
static JKQTCOMMON_LIB_EXPORT const int PALETTE_ICON_WIDTH;
|
||||
/*! \brief Height of the Palette-Icons, generated e.g. by JKQTPMathImageGetPaletteIcon()
|
||||
\ingroup jkqtptools_qt */
|
||||
static JKQTCOMMON_LIB_EXPORT const int PALETTE_IMAGEICON_HEIGHT;
|
||||
|
||||
/*! \brief size of the lookup tables used by JKQTFPimagePlot_array2image()
|
||||
/*! \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
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT const int LUTSIZE;
|
||||
inline int JKQTPGetColorChannel(QRgb rgb, int ch)
|
||||
{
|
||||
switch(ch) {
|
||||
case 0: return qRed(rgb);
|
||||
case 1: return qGreen(rgb);
|
||||
case 2: return qBlue(rgb);
|
||||
case 3: return qAlpha(rgb);
|
||||
}
|
||||
return qGray(rgb);
|
||||
}
|
||||
|
||||
/*! \brief internal global storage object for lookup-tables
|
||||
/*! \brief set the R/G/B/Alpha (\a ch == 0/1/2/3) value in the \c QRgb value \a rgb to \a val (0..255!)
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
\internal
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT QList<int*> global_jkqtpimagetools_lutstore;
|
||||
|
||||
};
|
||||
|
||||
inline void JKQTPSetColorChannel(QRgb& rgb, int ch, int val)
|
||||
{
|
||||
switch(ch) {
|
||||
case 0: rgb= qRgba(val, qGreen(rgb), qBlue(rgb), qAlpha(rgb)); break;
|
||||
case 1: rgb= qRgba(qRed(rgb), val, qBlue(rgb), qAlpha(rgb)); break;
|
||||
case 2: rgb= qRgba(qRed(rgb), qGreen(rgb), val, qAlpha(rgb)); break;
|
||||
case 3: rgb= qRgba(qRed(rgb), qGreen(rgb), qBlue(rgb), val); break;
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief available palettes for coloring an image
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
@ -91,10 +93,25 @@ enum JKQTPMathImageColorPalette {
|
||||
JKQTPMathImageINVERTED_OCEAN, /*!< \image html palettes/palette_invocean.png */
|
||||
JKQTPMathImageTRAFFICLIGHT, /*!< \image html palettes/palette_trafficlight.png */
|
||||
JKQTPMathImageINVERTED_TRAFFICLIGHT, /*!< \image html palettes/palette_invtrafficlight.png */
|
||||
|
||||
JKQTPMathImageBone, /*!< \image html palettes/palette_bone.png */
|
||||
JKQTPMathImageCool, /*!< \image html palettes/palette_cool.png */
|
||||
JKQTPMathImageCopper, /*!< \image html palettes/palette_copper.png */
|
||||
JKQTPMathImageAutumn, /*!< \image html palettes/palette_autumn.png */
|
||||
JKQTPMathImageSeismic, /*!< \image html palettes/palette_seismic.png */
|
||||
JKQTPMathImageTerrain, /*!< \image html palettes/palette_terrain.png */
|
||||
JKQTPMathImageViridis, /*!< \image html palettes/palette_viridis.png \see from https://github.com/BIDS/colormap/blob/master/colormaps.py https://github.com/BIDS/colormap/blob/master/colormaps.py */
|
||||
JKQTPMathImageMagma, /*!< \image html palettes/palette_magma.png \see from https://github.com/BIDS/colormap/blob/master/colormaps.py https://github.com/BIDS/colormap/blob/master/colormaps.py */
|
||||
JKQTPMathImageInferno, /*!< \image html palettes/palette_inferno.png \see from https://github.com/BIDS/colormap/blob/master/colormaps.py https://github.com/BIDS/colormap/blob/master/colormaps.py */
|
||||
JKQTPMathImagePlasma, /*!< \image html palettes/palette_plasma.png \see from https://github.com/BIDS/colormap/blob/master/colormaps.py https://github.com/BIDS/colormap/blob/master/colormaps.py */
|
||||
|
||||
|
||||
JKQTPMathImageBLUEMAGENTAYELLOW, /*!< \image html palettes/palette_BlMaYe.png */
|
||||
JKQTPMathImageINVERTED_BLUEMAGENTAYELLOW, /*!< \image html palettes/palette_YeMaBl.png */
|
||||
JKQTPMathImageYELLOWMAGENTABLUE=JKQTPMathImageINVERTED_BLUEMAGENTAYELLOW, /*!< \image html palettes/palette_YeMaBl.png */
|
||||
JKQTPMathImageBLUEYELLOW, /*!< \image html palettes/palette_BlYe.png */
|
||||
JKQTPMathImageINVERTED_BLUEYELLOW, /*!< \image html palettes/palette_YeBl.png */
|
||||
JKQTPMathImageYELLOWBLUE=JKQTPMathImageINVERTED_BLUEYELLOW, /*!< \image html palettes/palette_YeBl.png */
|
||||
|
||||
JKQTPMathImageBLUEWHITERED, /*!< \image html palettes/palette_bluewhitered.png */
|
||||
JKQTPMathImageREDWHITEBLUE, /*!< \image html palettes/palette_redwhiteblue.png */
|
||||
@ -104,10 +121,15 @@ enum JKQTPMathImageColorPalette {
|
||||
JKQTPMathImageBLACKBLUEWHITEYELLOWWHITE, /*!< \image html palettes/palette_BWprint.png */
|
||||
JKQTPMathImageWHITEYELLOWWHITEBLUEBLACK, /*!< \image html palettes/palette_invBWprint.png */
|
||||
JKQTPMathImageBR_GR, /*!< \image html palettes/palette_BrBG.png */
|
||||
JKQTPMathImageBrownGreen=JKQTPMathImageBR_GR, /*!< \image html palettes/palette_BrBG.png */
|
||||
JKQTPMathImagePU_OR, /*!< \image html palettes/palette_PuOr.png */
|
||||
JKQTPMathImageOrangeWhitePurple=JKQTPMathImagePU_OR, /*!< \image html palettes/palette_PuOr.png */
|
||||
JKQTPMathImageGN_BU, /*!< \image html palettes/palette_greenblue.png */
|
||||
JKQTPMathImageGreenBlue=JKQTPMathImageGN_BU, /*!< \image html palettes/palette_greenblue.png */
|
||||
JKQTPMathImageBU_GN, /*!< \image html palettes/palette_bluegreen.png */
|
||||
JKQTPMathImageBlueGreen=JKQTPMathImageBU_GN, /*!< \image html palettes/palette_bluegreen.png */
|
||||
JKQTPMathImageYL_GN_BU, /*!< \image html palettes/palette_YeGnBu.png */
|
||||
JKQTPMathImageYellowGreenBlue=JKQTPMathImageYL_GN_BU, /*!< \image html palettes/palette_YeGnBu.png */
|
||||
|
||||
JKQTPMathImageBR_GR_STEP, /*!< \image html palettes/palette_stepsBrBG.png */
|
||||
JKQTPMathImagePU_OR_STEP, /*!< \image html palettes/palette_stepsPuOr.png */
|
||||
@ -118,38 +140,33 @@ enum JKQTPMathImageColorPalette {
|
||||
|
||||
JKQTPMathImageCYANWHITE, /*!< \image html palettes/palette_cyanwhite.png */
|
||||
JKQTPMathImageINVERTED_CYANWHITE, /*!< \image html palettes/palette_whitecyan.png */
|
||||
JKQTPMathImageWHITECYAN=JKQTPMathImageINVERTED_CYANWHITE, /*!< \image html palettes/palette_whitecyan.png */
|
||||
JKQTPMathImageYELLOWWHITE, /*!< \image html palettes/palette_yellowwhite.png */
|
||||
JKQTPMathImageINVERTED_YELLOWWHITE, /*!< \image html palettes/palette_whiteyellow.png */
|
||||
JKQTPMathImageWHITEYELLOW=JKQTPMathImageINVERTED_YELLOWWHITE, /*!< \image html palettes/palette_whiteyellow.png */
|
||||
JKQTPMathImageMAGENTAWHITE, /*!< \image html palettes/palette_magentawhite.png */
|
||||
JKQTPMathImageINVERTED_MAGENTAWHITE, /*!< \image html palettes/palette_whitemagenta.png */
|
||||
JKQTPMathImageWHITEMAGENTA=JKQTPMathImageINVERTED_MAGENTAWHITE, /*!< \image html palettes/palette_whitemagenta.png */
|
||||
JKQTPMathImageBlueGreenRed, /*!< \image html palettes/palette_bluegreenred.png */
|
||||
JKQTPMathImageRedGreenBlue, /*!< \image html palettes/palette_redgreenblue.png */
|
||||
JKQTPMathImageMagentaYellow, /*!< \image html palettes/palette_magentayellow.png */
|
||||
JKQTPMathImageYellowMagenta, /*!< \image html palettes/palette_yellowmagenta.png */
|
||||
JKQTPMathImageRedBlue, /*!< \image html palettes/palette_redblue.png */
|
||||
JKQTPMathImageBlueRed, /*!< \image html palettes/palette_bluered.png */
|
||||
|
||||
JKQTPMathImagePREDEFINED_PALETTES_COUNT,
|
||||
JKQTPMathImagePREDEFINED_PALETTES_COUNT, /*!< \brief the number of predefined palettes */
|
||||
|
||||
JKQTPMathImageUSER_PALETTE=65000,
|
||||
JKQTPMathImageUSER_PALETTE=65000, /*!< \brief special value for JKQTPImageTools::array2image(), which signals the usage of a provided user-defined palette */
|
||||
|
||||
JKQTPMathImageALPHA=JKQTPMathImageUSER_PALETTE-2,
|
||||
JKQTPMathImageINVERTED_ALPHA=JKQTPMathImageUSER_PALETTE-1
|
||||
JKQTPMathImageALPHA=JKQTPMathImageUSER_PALETTE-2, /*!< \brief special palette with increasing alpha values */
|
||||
JKQTPMathImageINVERTED_ALPHA=JKQTPMathImageUSER_PALETTE-1, /*!< \brief special palette with decreasing alpha values */
|
||||
|
||||
JKQTPMathImageFIRST_REGISTERED_USER_PALETTE=JKQTPMathImagePREDEFINED_PALETTES_COUNT, /*!< \brief the ID of the first user-defined paletted, registered with JKQTPImageTools::registerPalette() or JKQTPImageTools::registerPalettesFromFile() */
|
||||
JKQTPMathImageLAST_POSSIBLE_REGISTERED_USER_PALETTE=JKQTPMathImageUSER_PALETTE-10, /*!< \brief the ID of the first user-defined paletted, registered with JKQTPImageTools::registerPalette() or JKQTPImageTools::registerPalettesFromFile() */
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/*! \brief convert the palette \a p to a string
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
\see String2JKQTPMathImageColorPalette()
|
||||
*/
|
||||
JKQTCOMMON_LIB_EXPORT QString JKQTPMathImageColorPalette2String(JKQTPMathImageColorPalette p);
|
||||
|
||||
/*! \brief convert the palette name \a p to JKQTPMathImageColorPalette (compatible with String2JKQTPMathImageColorPalette() )
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
\see JKQTPMathImageColorPalette2String()
|
||||
*/
|
||||
JKQTCOMMON_LIB_EXPORT JKQTPMathImageColorPalette String2JKQTPMathImageColorPalette(const QString& p);
|
||||
|
||||
|
||||
|
||||
/*! \brief modes available for image pixels that are above/below the pixel value range
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
*/
|
||||
@ -159,6 +176,316 @@ enum JKQTPMathImageColorRangeFailAction {
|
||||
JKQTPMathImageTransparent=2 /*!< set transparent */
|
||||
};
|
||||
|
||||
/*! \brief tool structure that summarizes several static properties of JKQTPlotters palette system,
|
||||
also provides functions to work with palettes and register user-defined palettes.
|
||||
\ingroup jkqtptools_qt
|
||||
|
||||
\see \ref JKQTPlotterImagePlot
|
||||
*/
|
||||
struct JKQTPImageTools {
|
||||
|
||||
/*! \brief Datatype to store lookup-tables used to map data values (scales to 0..size-1) onto RGB-colors
|
||||
\ingroup jkqtptools_qt */
|
||||
typedef QVector<QRgb> LUTType;
|
||||
|
||||
/*! \brief Width of the Palette-Icons, generated e.g. by JKQTPImageTools::GetPaletteIcon()
|
||||
\ingroup jkqtptools_qt */
|
||||
static JKQTCOMMON_LIB_EXPORT const int PALETTE_ICON_WIDTH;
|
||||
/*! \brief Height of the Palette-Icons, generated e.g. by JKQTPImageTools::GetPaletteIcon()
|
||||
\ingroup jkqtptools_qt */
|
||||
static JKQTCOMMON_LIB_EXPORT const int PALETTE_IMAGEICON_HEIGHT;
|
||||
|
||||
/*! \brief size of the lookup tables used by JKQTFPimagePlot_array2image()
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT const int LUTSIZE;
|
||||
|
||||
/*! \brief loads all palettes defined in the given palette files \a filename into global_jkqtpimagetools_userluts
|
||||
and assigns a new LUT-ID >=JKQTPMathImageFIRST_REGISTERED_USER_PALETTE to each palette
|
||||
All new IDs are returned as a list
|
||||
|
||||
|
||||
The file might either be a palette XML-file or a CSV-file:
|
||||
|
||||
\b CSV-files need to have one of the following two formats (RED/GREEN/BLUE: 0..255):
|
||||
\verbatim
|
||||
scalar, red, green, blue
|
||||
scalar, red, green, blue
|
||||
...
|
||||
\endverbatim
|
||||
or simply
|
||||
\verbatim
|
||||
red, green, blue
|
||||
red, green, blue
|
||||
...
|
||||
\endverbatim
|
||||
The parser will also allow tabs and whitespaces as column separators.
|
||||
|
||||
|
||||
\b CML-files need to have one of the following two formats (RED/GREEN/BLUE/OPACITY: 0..1):
|
||||
\verbatim
|
||||
<ColorMap name="PALETTENAME" space="RGB">
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
...
|
||||
</ColorMap>
|
||||
\endverbatim
|
||||
optionally several \c <ColorMap>...</ColorMap> definitions may be put below an arbitrarily named
|
||||
document node, e.g.:
|
||||
\verbatim
|
||||
<ColorMaps>
|
||||
<ColorMap name="PALETTENAME" space="RGB">
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
...
|
||||
</ColorMap>
|
||||
<ColorMap name="PALETTENAME" space="RGB">
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
<Point x="scalar" r="RED" g="GREEN" b="BLUE"/>
|
||||
...
|
||||
</ColorMap>
|
||||
...
|
||||
</ColorMaps>
|
||||
\endverbatim
|
||||
|
||||
\note In both cases, the palette will be formed without interpolation, i.e. using JKQTPBuildColorPaletteLUT() .
|
||||
If in addition \a interpolatePalette is set to \c true, the function JKQTPBuildColorPaletteLUTLinInterpolate()
|
||||
is used instead.
|
||||
|
||||
\see \ref JKQTPlotterImagePlot , JKQTPBuildColorPaletteLUT()
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT QVector<int> registerPalettesFromFile(const QString& filename, bool interpolatePalette=false);
|
||||
|
||||
/*! \brief registers a new LUT defined by \a paletteLut and with the given \a name (computer-readable) for later use, optionally stores also the human-readable and localized name \a nameT
|
||||
and assigns a new LUT-ID >=JKQTPMathImageFIRST_REGISTERED_USER_PALETTE to the palette and returns it
|
||||
|
||||
\see \ref JKQTPlotterImagePlot, JKQTPBuildColorPaletteLUTLinInterpolate(), JKQTPBuildColorPaletteLUT(), JKQTPBuildColorPaletteLUTLinInterpolateSorted(), JKQTPBuildColorPaletteLUTSorted(), JKQTPBuildColorPaletteLUTLinInterpolate(), JKQTPBuildColorPaletteLUT()
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT int registerPalette(const QString& name, const LUTType &paletteLut, const QString &nameT=QString());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*! \brief convert a 2D image (as 1D array) into a QImage with given palette (see JKQTFPColorPalette)
|
||||
|
||||
\param dbl_in pointer to a 1D array of template type \c T representing the image to plot. This array has to be of size \a width * \a height
|
||||
\param width width of the array in \a dbl
|
||||
\param height height of the array in \a dbl
|
||||
\param[out] img the QImage object to draw to (should be initialized as \c QImage::Format_ARGB32 )
|
||||
\param palette the color palette to use for the display
|
||||
\param minColor lower boundary of color range in \a dbl pixels, if \a minColor == \a maxColor then this function will extract the image min and image max.
|
||||
\param maxColor upper boundary of color range in \a dbl pixels, if \a minColor == \a maxColor then this function will extract the image min and image max.
|
||||
\param paletteMinFail specifies what shell happen, when a value in \a dbl is below \a minColor
|
||||
\param paletteMaxFail specifies what shell happen, when a value in \a dbl is above \a maxColor
|
||||
\param minFailColor color to use for pixels that are below \a minColor for some settings of \a paletteMinFail
|
||||
\param maxFailColor color to use for pixels that are below \a maxColor for some settings of \a paletteMaxFail
|
||||
\param nanColor color to use for pixels that are not-a-number
|
||||
\param infColor color to use for pixels that are infinity
|
||||
\param logScale create a log-scaled image
|
||||
\param logBase base for the logarithm used when \c logScale==true
|
||||
\param lutUser user define LUT, used if \a palette \c ==JKQTPMathImageUSER_PALETTE
|
||||
\note There is a variant of this function that is called with a userLUT directly, instead of \a palette
|
||||
*/
|
||||
template <class T>
|
||||
static inline void array2image(const T* dbl_in, int width, int height, QImage &img, JKQTPMathImageColorPalette palette, double minColor, double maxColor, JKQTPMathImageColorRangeFailAction paletteMinFail=JKQTPMathImageLastPaletteColor, JKQTPMathImageColorRangeFailAction paletteMaxFail=JKQTPMathImageLastPaletteColor, QColor minFailColor=QColor("black"), QColor maxFailColor=QColor("black"), QColor nanColor=QColor("black"), QColor infColor=QColor("black"), bool logScale=false, double logBase=10.0, const LUTType& lutUser=LUTType())
|
||||
{
|
||||
if (!dbl_in || width<=0 || height<=0)
|
||||
return;
|
||||
|
||||
double min = *dbl_in;
|
||||
double max = *dbl_in;
|
||||
if (jkqtp_approximatelyEqual(minColor, maxColor, JKQTP_DOUBLE_EPSILON)) {
|
||||
bool first=true;
|
||||
for (int i=1; i<width*height; ++i)
|
||||
{
|
||||
T v=dbl_in[i];
|
||||
if (!(std::isnan(static_cast<long double>(v)) || std::isinf(static_cast<long double>(v)))) {
|
||||
if (first) {
|
||||
min=max=v;
|
||||
first=false;
|
||||
} else {
|
||||
if (v < min)
|
||||
min = v;
|
||||
else if (v > max)
|
||||
max = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
min = minColor;
|
||||
max = maxColor;
|
||||
}
|
||||
|
||||
const T* dbl=dbl_in;
|
||||
QVector<T> dbl1;
|
||||
if (logScale) {
|
||||
double logB=log10(logBase);
|
||||
dbl1=QVector<T>(width*height, 0);
|
||||
for (int i=0; i<width*height; i++) {
|
||||
dbl1[i]=log10(dbl_in[i])/logB;
|
||||
}
|
||||
dbl=dbl1.data();
|
||||
min=log10(min)/logB;
|
||||
max=log10(max)/logB;
|
||||
}
|
||||
double delta=max-min;
|
||||
|
||||
|
||||
// either use lutUser (if palette==JKQTPMathImageUSER_PALETTE) or else read the LUT from the internal storage
|
||||
const LUTType& lut_used=(palette==JKQTPMathImageUSER_PALETTE)?lutUser:getLUTforPalette(JKQTPImageTools::global_jkqtpimagetools_lutstore, palette);
|
||||
|
||||
img = QImage(width, height, QImage::Format_ARGB32);
|
||||
if (jkqtp_approximatelyEqual(min, max, JKQTP_DOUBLE_EPSILON)) {
|
||||
img.fill(0);
|
||||
} else {
|
||||
const int lutSize=lut_used.size();
|
||||
if (lutSize>0) {
|
||||
// LUT found: collor the image accordingly
|
||||
for (int j=0; j<height; ++j) {
|
||||
QRgb* line=reinterpret_cast<QRgb*>(img.scanLine(height-1-j));
|
||||
for (int i=0; i<width; ++i) {
|
||||
double val=dbl[j*width+i];
|
||||
if (std::isnan(val)) {
|
||||
line[i]=nanColor.rgba();
|
||||
} else if (std::isinf(val)) {
|
||||
line[i]=infColor.rgba();
|
||||
} else {
|
||||
const int v = static_cast<int>((val-min)/delta*static_cast<double>(lutSize-1));
|
||||
const int vv = (v < 0) ? 0 : ( (v >= lutSize) ? (lutSize-1) : v);
|
||||
line[i]=lut_used[vv];
|
||||
if ((v<0)&&(paletteMinFail==JKQTPMathImageGivenColor)) {
|
||||
line[i]=minFailColor.rgba();
|
||||
} else if ((v>lutSize)&&(paletteMaxFail==JKQTPMathImageGivenColor)) {
|
||||
line[i]=maxFailColor.rgba();
|
||||
} else if ((v<0)&&(paletteMinFail==JKQTPMathImageTransparent)) {
|
||||
line[i]=QColor(Qt::transparent).rgba();
|
||||
} else if ((v>lutSize)&&(paletteMaxFail==JKQTPMathImageTransparent)) {
|
||||
line[i]=QColor(Qt::transparent).rgba();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no LUT found: paint a black image!
|
||||
img.fill(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*! \brief convert a 2D image (as 1D array) into a QImage with given palette (see JKQTFPColorPalette)
|
||||
|
||||
\param dbl_in pointer to a 1D array of template type \c T representing the image to plot. This array has to be of size \a width * \a height
|
||||
\param width width of the array in \a dbl
|
||||
\param height height of the array in \a dbl
|
||||
\param[out] img the QImage object to draw to (should be initialized as \c QImage::Format_ARGB32 )
|
||||
\param lutUser user-defined lookup-table
|
||||
\param minColor lower boundary of color range in \a dbl pixels, if \a minColor == \a maxColor then this function will extract the image min and image max.
|
||||
\param maxColor upper boundary of color range in \a dbl pixels, if \a minColor == \a maxColor then this function will extract the image min and image max.
|
||||
\param paletteMinFail specifies what shell happen, when a value in \a dbl is below \a minColor
|
||||
\param paletteMaxFail specifies what shell happen, when a value in \a dbl is above \a maxColor
|
||||
\param minFailColor color to use for pixels that are below \a minColor for some settings of \a paletteMinFail
|
||||
\param maxFailColor color to use for pixels that are below \a maxColor for some settings of \a paletteMaxFail
|
||||
\param nanColor color to use for pixels that are not-a-number
|
||||
\param infColor color to use for pixels that are infinity
|
||||
\param logScale create a log-scaled image
|
||||
\param logBase base for the logarithm used when \c logScale==true
|
||||
*/
|
||||
template <class T>
|
||||
static inline void array2image(const T* dbl_in, int width, int height, QImage &img, const LUTType& lutUser, double minColor, double maxColor, JKQTPMathImageColorRangeFailAction paletteMinFail=JKQTPMathImageLastPaletteColor, JKQTPMathImageColorRangeFailAction paletteMaxFail=JKQTPMathImageLastPaletteColor, QColor minFailColor=QColor("black"), QColor maxFailColor=QColor("black"), QColor nanColor=QColor("black"), QColor infColor=QColor("black"), bool logScale=false, double logBase=10.0)
|
||||
{
|
||||
array2image(dbl_in, width, height, img, JKQTPMathImageUSER_PALETTE, minColor, maxColor, paletteMinFail, paletteMaxFail, minFailColor, maxFailColor, nanColor, infColor, logScale, logBase, lutUser);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*! \brief return a list of all globally available LUTs, human-readable/localized form */
|
||||
static QStringList JKQTCOMMON_LIB_EXPORT getPredefinedPalettes();
|
||||
|
||||
/*! \brief return a list of all globally available LUTs, machine-readable form */
|
||||
static QStringList JKQTCOMMON_LIB_EXPORT getPredefinedPalettesMachineReadable();
|
||||
|
||||
/*! \brief convert the palette \a p to a string
|
||||
\see JKQTPImageTools::String2JKQTPMathImageColorPalette()
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT QString JKQTPMathImageColorPalette2String(JKQTPMathImageColorPalette p);
|
||||
|
||||
/*! \brief convert the palette name \a p to JKQTPMathImageColorPalette (compatible with JKQTPImageTools::String2JKQTPMathImageColorPalette() )
|
||||
\see JKQTPImageTools::JKQTPMathImageColorPalette2String()
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT JKQTPMathImageColorPalette String2JKQTPMathImageColorPalette(const QString& p);
|
||||
|
||||
|
||||
/*! \brief generates a QImage with width \a width and height 1 for the i-th color palette (\a i is based on the list returned by JKQTPImagePlot_getPredefinedPalettes() ) */
|
||||
static QImage JKQTCOMMON_LIB_EXPORT GetPaletteImage(int i, int width);
|
||||
/*! \brief generates a QImage with width \a width and height \a height for the i-th color palette (\a i is based on the list returned by JKQTPImagePlot_getPredefinedPalettes() ) */
|
||||
static QImage JKQTCOMMON_LIB_EXPORT GetPaletteImage(int i, int width, int height);
|
||||
/*! \brief generates a QImage with width \a width and height 1 for a specific JKQTPMathImageColorPalette */
|
||||
static QImage JKQTCOMMON_LIB_EXPORT GetPaletteImage(JKQTPMathImageColorPalette palette, int width);
|
||||
/*! \brief generates a QImage with width \a width and height \a height for a specific JKQTPMathImageColorPalette */
|
||||
static QImage JKQTCOMMON_LIB_EXPORT GetPaletteImage(JKQTPMathImageColorPalette palette, int width, int height);
|
||||
/*! \brief generates a QImage with width \a width and height 1 for a lookup-table \a lut */
|
||||
static QImage JKQTCOMMON_LIB_EXPORT GetPaletteImage(const LUTType& lut, int width);
|
||||
|
||||
/*! \brief generates a QIcon for the i-th color palette (\a i is based on the list returned by JKQTPImagePlot_getPredefinedPalettes() ) */
|
||||
static QIcon JKQTCOMMON_LIB_EXPORT GetPaletteIcon(int i) ;
|
||||
|
||||
|
||||
/*! \brief generates a QIcon for a specific JKQTPMathImageColorPalette */
|
||||
static QIcon JKQTCOMMON_LIB_EXPORT GetPaletteIcon(JKQTPMathImageColorPalette palette) ;
|
||||
|
||||
private:
|
||||
|
||||
/*! \brief internal datatype, representing a lookup-table and its metadata inside global_jkqtpimagetools_lutstore
|
||||
\internal
|
||||
*/
|
||||
struct LUTData {
|
||||
LUTData();
|
||||
LUTData(const LUTType& _lut, const QString& _name, const QString& _nameT);
|
||||
LUTData(const QString& _name, const QString& _nameT);
|
||||
/** \brief the LUT itself */
|
||||
LUTType lut;
|
||||
/** \brief name for the LUT (machine-readable) */
|
||||
QString name;
|
||||
/** \brief name for the LUT (localized, human-readable) */
|
||||
QString nameT;
|
||||
};
|
||||
|
||||
/*! \brief internal global storage object for lookup-tables
|
||||
\internal
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT QMap<int, LUTData > global_jkqtpimagetools_lutstore;
|
||||
|
||||
/*! \brief storage for the next ID to assign to a user-defined palette, registered with registerPalette() or registerPalettesFromFile()
|
||||
\internal
|
||||
|
||||
\see registerPalette() registerPalettesFromFile()
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT int global_next_userpalette;
|
||||
|
||||
/*! \brief returns data of the default LUTs, used to initialize global_jkqtpimagetools_lutstore
|
||||
\internal
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT QMap<int, LUTData > getDefaultLUTs();
|
||||
|
||||
|
||||
/*! \brief create a LUT for a given JKQTPMathImageColorPalette, store it in \a lutstore and return it
|
||||
\internal
|
||||
*/
|
||||
static JKQTCOMMON_LIB_EXPORT const LUTType& getLUTforPalette(QMap<int, LUTData > &lutcache, JKQTPMathImageColorPalette palette);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*! \brief modes available for RGB images
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
@ -175,19 +502,6 @@ enum JKQTPRGBMathImageRGBMode {
|
||||
};
|
||||
|
||||
|
||||
/*! \brief returns a vector containing all elements of the given array
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
|
||||
*/
|
||||
template <class T>
|
||||
inline QVector<T> JKQTPImagePlot_arrayToVector(const T* input, int N) {
|
||||
if (!input || N<=0) return QVector<double>();
|
||||
T dummy;
|
||||
QVector<T> out(N, dummy);
|
||||
memcpy(out.data(), input, N*sizeof(T));
|
||||
return out;
|
||||
}
|
||||
|
||||
/*! \brief returns a vector containing all elements of the given array as doubles
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
|
||||
@ -302,7 +616,7 @@ inline void JKQTPImagePlot_array2RGBimage(T* dbl_in, int width, int height, QIma
|
||||
double min = *dbl_in;
|
||||
double max = *dbl_in;
|
||||
bool first=true;
|
||||
if (minColor == maxColor) {
|
||||
if (jkqtp_approximatelyEqual(minColor, maxColor, JKQTP_DOUBLE_EPSILON)) {
|
||||
for (int i=1; i<width*height; ++i)
|
||||
{
|
||||
T v=dbl_in[i];
|
||||
@ -327,7 +641,7 @@ inline void JKQTPImagePlot_array2RGBimage(T* dbl_in, int width, int height, QIma
|
||||
T* dbl=dbl_in;
|
||||
if (logScale) {
|
||||
double logB=log10(logBase);
|
||||
dbl=(T*)malloc(width*height*sizeof(T));
|
||||
dbl=static_cast<T*>(malloc(width*height*sizeof(T)));
|
||||
//memcpy(dbl, dbl_in, width*height*sizeof(T));
|
||||
for (int i=0; i<width*height; i++) {
|
||||
dbl[i]=log10(dbl_in[i])/logB;
|
||||
@ -337,7 +651,7 @@ inline void JKQTPImagePlot_array2RGBimage(T* dbl_in, int width, int height, QIma
|
||||
}
|
||||
double delta=max-min;
|
||||
|
||||
if (min != max) {
|
||||
if (jkqtp_approximatelyUnequal(minColor, maxColor, JKQTP_DOUBLE_EPSILON)) {
|
||||
if (rgbMode==JKQTPRGBMathImageModeRGBMode) {
|
||||
//qDebug()<<"RGBMode";
|
||||
if (channel==0) {
|
||||
@ -539,263 +853,184 @@ inline void JKQTPImagePlot_array2RGBimage(T* dbl_in, int width, int height, QIma
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Generate a QList with \a N entries of the value \a defaultValue
|
||||
\ingroup jkqtptools_qt */
|
||||
template <typename T>
|
||||
inline QList<T> JKQTPImagePlot_makeQList(const T& defaultVal, int N=1) {
|
||||
QList<T> l;
|
||||
for (int i=0; i<N; i++) l<<defaultVal;
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*! \brief build a linearly interpolated palette in \a lut with \a N entries that are provided in \a items
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
/*! \brief for building palettes from linear segments of single colors using JKQTPBuildColorPaletteLUTLinSegmentsSorted() and JKQTPBuildColorPaletteLUTLinSegments()
|
||||
\ingroup jkqtplotter_imagelots_tools_LUTS
|
||||
|
||||
The entries in \a items are sorted by the first (double) argument and the full range is distributed
|
||||
over 0 ... lut_size. Values in the LUT in between are generated by linear interpolations
|
||||
\see JKQTPBuildColorPaletteLUTLinSegmentsSorted() and JKQTPBuildColorPaletteLUTLinSegments(), \ref JKQTPlotterImagePlotUserPalette
|
||||
|
||||
\a lut needs to have \c lut_size) entries
|
||||
*/
|
||||
void JKQTCOMMON_LIB_EXPORT JKQTPImagePlot_buildDefinedPaletteLinInterpolate(int* lut, QList<QPair<double, QRgb> > items, int lut_size=JKQTPImageTools::LUTSIZE);
|
||||
|
||||
/*! \brief build a linearly interpolated palette in \a lut with \a N entries that are provided as (double, QRgb) value pairss in the variable arguments
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
|
||||
The entries in \a items are sorted by the first (double) argument and the full range is distributed
|
||||
over 0 ... lut_size. Values in the LUT in between are generated by linear interpolations
|
||||
|
||||
\a lut needs to have \c lut_size) entries
|
||||
*/
|
||||
void JKQTCOMMON_LIB_EXPORT JKQTPImagePlot_buildDefinedPaletteLinInterpolate(int* lut, int N, ...);
|
||||
|
||||
/*! \brief build a palette in \a lut with \a N entries that are provided in \a items
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
|
||||
The entries in \a items are sorted by the first (double) argument and the full range is distributed
|
||||
over 0 ... JKQTPImageTools::LUTSIZE.
|
||||
|
||||
\a lut needs to have \c JKQTPImageTools::LUTSIZE) entries
|
||||
*/
|
||||
void JKQTCOMMON_LIB_EXPORT JKQTPImagePlot_buildDefinedPalette(int* lut, QList<QPair<double, QRgb> > items);
|
||||
|
||||
/*! \brief build a palette in \a lut with \a N entries that are provided as as (double, QRgb) value pairss in the variable arguments
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
*/
|
||||
void JKQTCOMMON_LIB_EXPORT JKQTPImagePlot_buildDefinedPalette(int* lut, int N, ...);
|
||||
|
||||
/*! \brief return a list of all globally available LUTs
|
||||
\ingroup jkqtplotter_imagelots_tools */
|
||||
QStringList JKQTCOMMON_LIB_EXPORT JKQTPImagePlot_getPredefinedPalettes();
|
||||
|
||||
|
||||
|
||||
/*! \brief create a LUT for a given JKQTPMathImageColorPalette, store it in \a lutstore and return it
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
\internal
|
||||
*/
|
||||
JKQTCOMMON_LIB_EXPORT int* JKQTPImagePlot_getCreateLUT(QList<int *> &lutstore, JKQTPMathImageColorPalette palette);
|
||||
/*! \brief frees a list of LUTs
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
\internal
|
||||
*/
|
||||
void JKQTCOMMON_LIB_EXPORT JKQTPImagePlot_freeLUTs(QList<int *> &lutstore);
|
||||
|
||||
|
||||
/*! \brief convert a 2D image (as 1D array) into a QImage with given palette (see JKQTFPColorPalette)
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
|
||||
This method uses lookup tables which are saved as static variables to convert the 2D array into
|
||||
an image. The luts are only created once, and stored then, so mor CPU time is saved. The precompiler define
|
||||
JKQTPImageTools::LUTSIZE sets the size of the LUTs. Note that if you don't use a specific color palette,
|
||||
the according LUT won't be calculated and stored!
|
||||
|
||||
\param dbl_in pointer to a 1D array of template type \c T representing the image to plot. This array has to be of size \a width * \a height
|
||||
\param width width of the array in \a dbl
|
||||
\param height height of the array in \a dbl
|
||||
\param[out] img the QImage object to draw to (should be initialized as \c QImage::Format_ARGB32 )
|
||||
\param palette the color palette to use for the display
|
||||
\param minColor lower boundary of color range in \a dbl pixels, if \a minColor == \a maxColor then this function will extract the image min and image max.
|
||||
\param maxColor upper boundary of color range in \a dbl pixels, if \a minColor == \a maxColor then this function will extract the image min and image max.
|
||||
\param paletteMinFail specifies what shell happen, when a value in \a dbl is below \a minColor
|
||||
\param paletteMaxFail specifies what shell happen, when a value in \a dbl is above \a maxColor
|
||||
\param minFailColor color to use for pixels that are below \a minColor for some settings of \a paletteMinFail
|
||||
\param maxFailColor color to use for pixels that are below \a maxColor for some settings of \a paletteMaxFail
|
||||
\param nanColor color to use for pixels that are not-a-number
|
||||
\param infColor color to use for pixels that are infinity
|
||||
\param logScale create a log-scaled image
|
||||
\param logBase base for the logarithm used when \c logScale==true
|
||||
\param lutUser user define LUT
|
||||
\param lutUserSize size of the LUT in lutUser
|
||||
*/
|
||||
template <class T>
|
||||
inline void JKQTPImagePlot_array2image(const T* dbl_in, int width, int height, QImage &img, JKQTPMathImageColorPalette palette, double minColor, double maxColor, JKQTPMathImageColorRangeFailAction paletteMinFail=JKQTPMathImageLastPaletteColor, JKQTPMathImageColorRangeFailAction paletteMaxFail=JKQTPMathImageLastPaletteColor, QColor minFailColor=QColor("black"), QColor maxFailColor=QColor("black"), QColor nanColor=QColor("black"), QColor infColor=QColor("black"), bool logScale=false, double logBase=10.0, const int* lutUser=0, int lutUserSize=0)
|
||||
{
|
||||
if (!dbl_in || width<=0 || height<=0)
|
||||
return;
|
||||
|
||||
double min = *dbl_in;
|
||||
double max = *dbl_in;
|
||||
if (minColor == maxColor) {
|
||||
bool first=true;
|
||||
for (int i=1; i<width*height; ++i)
|
||||
{
|
||||
T v=dbl_in[i];
|
||||
if (!(std::isnan(static_cast<long double>(v)) || std::isinf(static_cast<long double>(v)))) {
|
||||
if (first) {
|
||||
min=max=v;
|
||||
first=false;
|
||||
} else {
|
||||
if (v < min)
|
||||
min = v;
|
||||
else if (v > max)
|
||||
max = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
min = minColor;
|
||||
max = maxColor;
|
||||
}
|
||||
|
||||
const T* dbl=dbl_in;
|
||||
T* dbl1=nullptr;
|
||||
if (logScale) {
|
||||
double logB=log10(logBase);
|
||||
dbl1=(T*)malloc(width*height*sizeof(T));
|
||||
//memcpy(dbl, dbl_in, width*height*sizeof(T));
|
||||
for (int i=0; i<width*height; i++) {
|
||||
dbl1[i]=log10(dbl_in[i])/logB;
|
||||
}
|
||||
dbl=dbl1;
|
||||
min=log10(min)/logB;
|
||||
max=log10(max)/logB;
|
||||
}
|
||||
double delta=max-min;
|
||||
|
||||
|
||||
const int* lut_used=nullptr;
|
||||
int lutSize=JKQTPImageTools::LUTSIZE;
|
||||
if (JKQTPImageTools::global_jkqtpimagetools_lutstore.size()<=0) JKQTPImageTools::global_jkqtpimagetools_lutstore =JKQTPImagePlot_makeQList<int*>(nullptr, JKQTPImagePlot_getPredefinedPalettes().size()+2);
|
||||
|
||||
|
||||
img = QImage(width, height, QImage::Format_ARGB32);
|
||||
if (min == max)
|
||||
img.fill(0);
|
||||
else
|
||||
{
|
||||
|
||||
if (palette==JKQTPMathImageUSER_PALETTE) {
|
||||
lut_used=lutUser;
|
||||
lutSize=lutUserSize;
|
||||
//qDebug()<<"user palette "<<lutUser<<lutUserSize;
|
||||
} else {
|
||||
lut_used=JKQTPImagePlot_getCreateLUT(JKQTPImageTools::global_jkqtpimagetools_lutstore, palette);
|
||||
}
|
||||
|
||||
|
||||
if (lut_used!=nullptr && lutSize>0) {
|
||||
const unsigned int* lut_usedui=reinterpret_cast<const unsigned int*>(lut_used);
|
||||
// LUT found: collor the image accordingly
|
||||
for (int j=0; j<height; ++j) {
|
||||
QRgb* line=reinterpret_cast<QRgb*>(img.scanLine(height-1-j));
|
||||
for (int i=0; i<width; ++i) {
|
||||
double val=dbl[j*width+i];
|
||||
if (std::isnan(val)) {
|
||||
line[i]=nanColor.rgba();
|
||||
} else if (std::isinf(val)) {
|
||||
line[i]=infColor.rgba();
|
||||
} else {
|
||||
const int v = static_cast<int>((val-min)/delta*static_cast<double>(lutSize));
|
||||
const int vv = (v < 0) ? 0 : ( (v > lutSize) ? (lutSize) : v);
|
||||
line[i]=lut_usedui[vv];
|
||||
if ((v<0)&&(paletteMinFail==JKQTPMathImageGivenColor)) {
|
||||
line[i]=minFailColor.rgba();
|
||||
} else if ((v>lutSize)&&(paletteMaxFail==JKQTPMathImageGivenColor)) {
|
||||
line[i]=maxFailColor.rgba();
|
||||
} else if ((v<0)&&(paletteMinFail==JKQTPMathImageTransparent)) {
|
||||
line[i]=QColor(Qt::transparent).rgba();
|
||||
} else if ((v>lutSize)&&(paletteMaxFail==JKQTPMathImageTransparent)) {
|
||||
line[i]=QColor(Qt::transparent).rgba();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no LUT found: paint a black image!
|
||||
img.fill(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (dbl1) free(dbl1);
|
||||
|
||||
struct JKQTPColorPaletteSingleColorLinSegment {
|
||||
JKQTPColorPaletteSingleColorLinSegment(double p, uint8_t y1, uint8_t y2);
|
||||
static JKQTPColorPaletteSingleColorLinSegment makeDbl_0_1(double p, double y1, double y2);
|
||||
JKQTPColorPaletteSingleColorLinSegment();
|
||||
/** \brief scalar position of the element on the value axis */
|
||||
double position;
|
||||
/** \brief color-channel-value that ends the prevoius segment (ignored for the first entry in a table) */
|
||||
uint8_t colval_endprevious;
|
||||
/** \brief color-channel-value that starts the next segment (ignored for the last entry in a table) */
|
||||
uint8_t colval_startnext;
|
||||
};
|
||||
|
||||
/*! \brief convert a 2D image (as 1D array) into a QImage with given palette (see JKQTFPColorPalette)
|
||||
\ingroup jkqtplotter_imagelots_tools
|
||||
/*! \brief build an interpolated palette with \a lut_size entries from the linear segments defined for the color channels R, G and B in \a itemsR, \a itemG and \a itemB respectively
|
||||
\b NOTE: The entries in \a itemsR, \a itemsG, \a itemsB are assumed to be sorted by the position entry.
|
||||
\ingroup jkqtplotter_imagelots_tools_LUTS
|
||||
|
||||
This method uses lookup tables which are saved as static variables to convert the 2D array into
|
||||
an image. The luts are only created once, and stored then, so mor CPU time is saved. The precompiler define
|
||||
JKQTPImageTools::LUTSIZE sets the size of the LUTs. Note that if you don't use a specific color palette,
|
||||
the according LUT won't be calculated and stored!
|
||||
|
||||
\param dbl_in pointer to a 1D array of template type \c T representing the image to plot. This array has to be of size \a width * \a height
|
||||
\param width width of the array in \a dbl
|
||||
\param height height of the array in \a dbl
|
||||
\param[out] img the QImage object to draw to (should be initialized as \c QImage::Format_ARGB32 )
|
||||
\param lutUser user-defined lookup-table
|
||||
\param lutUserSize number of entries in \a lutUser
|
||||
\param minColor lower boundary of color range in \a dbl pixels, if \a minColor == \a maxColor then this function will extract the image min and image max.
|
||||
\param maxColor upper boundary of color range in \a dbl pixels, if \a minColor == \a maxColor then this function will extract the image min and image max.
|
||||
\param paletteMinFail specifies what shell happen, when a value in \a dbl is below \a minColor
|
||||
\param paletteMaxFail specifies what shell happen, when a value in \a dbl is above \a maxColor
|
||||
\param minFailColor color to use for pixels that are below \a minColor for some settings of \a paletteMinFail
|
||||
\param maxFailColor color to use for pixels that are below \a maxColor for some settings of \a paletteMaxFail
|
||||
\param nanColor color to use for pixels that are not-a-number
|
||||
\param infColor color to use for pixels that are infinity
|
||||
\param logScale create a log-scaled image
|
||||
\param logBase base for the logarithm used when \c logScale==true
|
||||
|
||||
|
||||
This is used to build a table of linear segments as a \c QList<JKQTPColorPaletteSingleColorLinSegment> :
|
||||
\verbatim
|
||||
i position colval1 colval2
|
||||
~~~ ~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
|
||||
0 0.0 0 (IGNORED) 0
|
||||
1 0.5 100 100
|
||||
2 0.8 255 255
|
||||
3 1.0 255 255 (IGNORED)
|
||||
\endverbatim
|
||||
|
||||
This will build a graph:
|
||||
\verbatim
|
||||
colval
|
||||
^
|
||||
|
|
||||
250 - #**********#
|
||||
| ***
|
||||
200 - ***
|
||||
| ***
|
||||
150 - **
|
||||
| **
|
||||
100 - *****#
|
||||
| ****
|
||||
50 - *****
|
||||
| *****
|
||||
0 - #*****
|
||||
|
|
||||
---|----|----|----|----|----|----|----|----|----|----|--> position
|
||||
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
|
||||
\endverbatim
|
||||
|
||||
You can also build graphs with a jump at a certain position
|
||||
\verbatim
|
||||
i position colval1 colval2
|
||||
~~~ ~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
|
||||
0 0.0 0 (IGNORED) 0
|
||||
1 0.5 100 0
|
||||
2 1.0 255 255 (IGNORED)
|
||||
\endverbatim
|
||||
|
||||
This results in:
|
||||
|
||||
\verbatim
|
||||
colval
|
||||
^
|
||||
|
|
||||
250 - **#
|
||||
| **
|
||||
200 - **
|
||||
| **
|
||||
150 - ***
|
||||
| **
|
||||
100 - # **
|
||||
| ****** **
|
||||
50 - ****** **
|
||||
| ****** **
|
||||
0 - #****** #**
|
||||
|
|
||||
---|----|----|----|----|----|----|----|----|----|----|--> position
|
||||
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
|
||||
\endverbatim
|
||||
|
||||
\see JKQTPBuildColorPaletteLUTLinSegments(), \ref JKQTPlotterImagePlotUserPalette , https://matplotlib.org/api/_as_gen/matplotlib.colors.LinearSegmentedColormap.html#matplotlib.colors.LinearSegmentedColormap
|
||||
*/
|
||||
template <class T>
|
||||
inline void JKQTPImagePlot_array2image(const T* dbl_in, int width, int height, QImage &img, const int* lutUser, int lutUserSize, double minColor, double maxColor, JKQTPMathImageColorRangeFailAction paletteMinFail=JKQTPMathImageLastPaletteColor, JKQTPMathImageColorRangeFailAction paletteMaxFail=JKQTPMathImageLastPaletteColor, QColor minFailColor=QColor("black"), QColor maxFailColor=QColor("black"), QColor nanColor=QColor("black"), QColor infColor=QColor("black"), bool logScale=false, double logBase=10.0)
|
||||
{
|
||||
JKQTPImagePlot_array2image(dbl_in, width, height, img, JKQTPMathImageUSER_PALETTE, minColor, maxColor, paletteMinFail, paletteMaxFail, minFailColor, maxFailColor, nanColor, infColor, logScale, logBase, lutUser, lutUserSize);
|
||||
}
|
||||
JKQTPImageTools::LUTType JKQTCOMMON_LIB_EXPORT JKQTPBuildColorPaletteLUTLinSegmentsSorted(const QList<JKQTPColorPaletteSingleColorLinSegment>& itemsR, const QList<JKQTPColorPaletteSingleColorLinSegment>& itemsG, const QList<JKQTPColorPaletteSingleColorLinSegment>& itemsB, int lut_size=JKQTPImageTools::LUTSIZE);
|
||||
|
||||
|
||||
|
||||
/*! \brief build a linearly interpolated palette (as a look-up table) with \a lut_size entries by linearly interpolating between the nodes in \a items .
|
||||
\b NOTE: \a items is assumed to be sorted by the first component of the \c QPair<double,QRgb> entries!
|
||||
\ingroup jkqtplotter_imagelots_tools_LUTS
|
||||
|
||||
The LUT is built following these rules:
|
||||
- the final LUT has \a lut_size entries
|
||||
- the first color in the lut is given by \c items.first().second
|
||||
- the last color in the lut is given by \c items.last().second
|
||||
- in between the colors are interpolated between the nodes in \a items and the color-nodes are
|
||||
distributed according to the first component of the \c QPair<double,QRgb> entries:<br>
|
||||
\image html JKQTPBuildColorPaletteLUTLinInterpolateSorted.png
|
||||
.
|
||||
|
||||
\see JKQTPBuildColorPaletteLUTLinInterpolate(), \ref JKQTPlotterImagePlotUserPalette
|
||||
|
||||
*/
|
||||
JKQTPImageTools::LUTType JKQTCOMMON_LIB_EXPORT JKQTPBuildColorPaletteLUTLinInterpolateSorted(const QList<QPair<double, QRgb> >& items, int lut_size=JKQTPImageTools::LUTSIZE);
|
||||
|
||||
|
||||
/*! \brief build a palette (as a look-up table) with \a lut_size entries that step between the nodes provided in \a items.
|
||||
\b NOTE: \a items is assumed to be sorted by the first component of the \c QPair<double,QRgb> entries!
|
||||
\ingroup jkqtplotter_imagelots_tools_LUTS
|
||||
|
||||
The LUT is built following these rules:
|
||||
- the final LUT has \a lut_size entries
|
||||
- the first color in the lut is given by \c items.first().second
|
||||
- the last color in the lut is given by \c items.last().second
|
||||
- in between the colors are stepped between the nodes in \a items and the color-nodes are
|
||||
distributed according to the first component of the \c QPair<double,QRgb> entries:<br>
|
||||
\image html JKQTPBuildColorPaletteLUTSorted.png
|
||||
.
|
||||
|
||||
\see JKQTPBuildColorPaletteLUT(), \ref JKQTPlotterImagePlotUserPalette
|
||||
|
||||
*/
|
||||
JKQTPImageTools::LUTType JKQTCOMMON_LIB_EXPORT JKQTPBuildColorPaletteLUTSorted(const QList<QPair<double, QRgb> >& items, int lut_size=JKQTPImageTools::LUTSIZE);
|
||||
|
||||
/*! \brief like JKQTPBuildColorPaletteLUTLinInterpolateSorted(), but sorts \a items before processing it!
|
||||
\ingroup jkqtplotter_imagelots_tools_LUTS
|
||||
|
||||
\copydetails JKQTPBuildColorPaletteLUTLinInterpolateSorted()
|
||||
*/
|
||||
JKQTPImageTools::LUTType JKQTCOMMON_LIB_EXPORT JKQTPBuildColorPaletteLUTLinInterpolate(QList<QPair<double, QRgb> > items, int lut_size=JKQTPImageTools::LUTSIZE);
|
||||
|
||||
|
||||
/*! \brief like JKQTPBuildColorPaletteLUTSorted(), but sorts \a items before processing it!
|
||||
\ingroup jkqtplotter_imagelots_tools_LUTS
|
||||
|
||||
\copydetails JKQTPBuildColorPaletteLUTSorted()
|
||||
*/
|
||||
JKQTPImageTools::LUTType JKQTCOMMON_LIB_EXPORT JKQTPBuildColorPaletteLUT(QList<QPair<double, QRgb> > items, int lut_size=JKQTPImageTools::LUTSIZE);
|
||||
|
||||
/*! \brief like JKQTPBuildColorPaletteLUTLinSegmentsSorted(), but sorts \a itemsR, \a itemB, \a itemsG before processing them!
|
||||
\ingroup jkqtplotter_imagelots_tools_LUTS
|
||||
|
||||
\copydetails JKQTPBuildColorPaletteLUTLinSegmentsSorted()
|
||||
|
||||
*/
|
||||
JKQTPImageTools::LUTType JKQTCOMMON_LIB_EXPORT JKQTPBuildColorPaletteLUTLinSegments(QList<JKQTPColorPaletteSingleColorLinSegment> itemsR, QList<JKQTPColorPaletteSingleColorLinSegment> itemsG, QList<JKQTPColorPaletteSingleColorLinSegment> itemsB, int lut_size=JKQTPImageTools::LUTSIZE);
|
||||
|
||||
|
||||
/*! \brief like JKQTPBuildColorPaletteLUTLinInterpolateSorted(), but accepts a \c QMap<double,QRgb> as parameter instead of \c QList<QPair<double,QRgb>>
|
||||
\ingroup jkqtplotter_imagelots_tools_LUTS
|
||||
|
||||
\copydetails JKQTPBuildColorPaletteLUTLinInterpolateSorted()
|
||||
|
||||
*/
|
||||
JKQTPImageTools::LUTType JKQTCOMMON_LIB_EXPORT JKQTPBuildColorPaletteLUTLinInterpolate(const QMap<double, QRgb>& items, int lut_size=JKQTPImageTools::LUTSIZE);
|
||||
|
||||
|
||||
/*! \brief like JKQTPBuildColorPaletteLUTSorted(), but accepts a \c QMap<double,QRgb> as parameter instead of \c QList<QPair<double,QRgb>>
|
||||
\ingroup jkqtplotter_imagelots_tools_LUTS
|
||||
|
||||
\copydetails JKQTPBuildColorPaletteLUTSorted()
|
||||
*/
|
||||
JKQTPImageTools::LUTType JKQTCOMMON_LIB_EXPORT JKQTPBuildColorPaletteLUT(const QMap<double, QRgb>& items, int lut_size=JKQTPImageTools::LUTSIZE);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*! \brief generates a QImage with width \a width and height 1 for the i-th color palette (\a i is based on the list returned by JKQTPImagePlot_getPredefinedPalettes() )
|
||||
\ingroup jkqtplotter_imagelots_tools */
|
||||
QImage JKQTCOMMON_LIB_EXPORT JKQTPMathImageGetPaletteImage(int i, int width);
|
||||
/*! \brief generates a QImage with width \a width and height \a height for the i-th color palette (\a i is based on the list returned by JKQTPImagePlot_getPredefinedPalettes() )
|
||||
\ingroup jkqtplotter_imagelots_tools */
|
||||
QImage JKQTCOMMON_LIB_EXPORT JKQTPMathImageGetPaletteImage(int i, int width, int height);
|
||||
/*! \brief generates a QImage with width \a width and height 1 for a specific JKQTPMathImageColorPalette
|
||||
\ingroup jkqtplotter_imagelots_tools */
|
||||
QImage JKQTCOMMON_LIB_EXPORT JKQTPMathImageGetPaletteImage(JKQTPMathImageColorPalette palette, int width);
|
||||
/*! \brief generates a QImage with width \a width and height \a height for a specific JKQTPMathImageColorPalette
|
||||
\ingroup jkqtplotter_imagelots_tools */
|
||||
QImage JKQTCOMMON_LIB_EXPORT JKQTPMathImageGetPaletteImage(JKQTPMathImageColorPalette palette, int width, int height);
|
||||
/*! \brief generates a QImage with width \a width and height 1 for a lookup-table \a lut with \a lut_size entries
|
||||
\ingroup jkqtplotter_imagelots_tools */
|
||||
QImage JKQTCOMMON_LIB_EXPORT JKQTPMathImageGetPaletteImage(int* lut, int lut_size, int width);
|
||||
/*! \brief generates a QImage with width \a width and height \a height for a lookup-table \a lut with \a lut_size entries
|
||||
\ingroup jkqtplotter_imagelots_tools */
|
||||
QImage JKQTCOMMON_LIB_EXPORT JKQTPMathImageGetAlphaPaletteImage(int* lut, int lut_size, int width, int height);
|
||||
|
||||
/*! \brief generates a QIcon for the i-th color palette (\a i is based on the list returned by JKQTPImagePlot_getPredefinedPalettes() )
|
||||
\ingroup jkqtplotter_imagelots_tools */
|
||||
QIcon JKQTCOMMON_LIB_EXPORT JKQTPMathImageGetPaletteIcon(int i) ;
|
||||
|
||||
|
||||
/*! \brief generates a QIcon for a specific JKQTPMathImageColorPalette
|
||||
\ingroup jkqtplotter_imagelots_tools */
|
||||
QIcon JKQTCOMMON_LIB_EXPORT JKQTPMathImageGetPaletteIcon(JKQTPMathImageColorPalette palette) ;
|
||||
|
||||
|
||||
|
||||
|
@ -1225,7 +1225,7 @@ QImage JKQTPMathImage::drawOutsidePalette(uint8_t steps)
|
||||
}
|
||||
|
||||
QImage b(h,200, QImage::Format_ARGB32);
|
||||
JKQTPImagePlot_array2image<double>(d,h,steps, b, palette, 0, steps-1);
|
||||
JKQTPImageTools::array2image<double>(d,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);
|
||||
@ -1265,7 +1265,7 @@ void JKQTPMathImage::drawKeyMarker(JKQTPEnhancedPainter &painter, QRectF &rect)
|
||||
}
|
||||
|
||||
QStringList JKQTPMathImage::getPalettes() {
|
||||
return JKQTPImagePlot_getPredefinedPalettes();
|
||||
return JKQTPImageTools::getPredefinedPalettes();
|
||||
}
|
||||
|
||||
int JKQTPMathImage::getPalettesCount()
|
||||
@ -1297,7 +1297,7 @@ QImage JKQTPMathImage::getPaletteImage(int i, int width, int height)
|
||||
for (int j=0; j<width; j++) {
|
||||
pic[j]=j;
|
||||
}
|
||||
JKQTPImagePlot_array2image<double>(pic, width, qMax(1,height), img, (JKQTPMathImageColorPalette)i, 0, width-1);
|
||||
JKQTPImageTools::array2image<double>(pic, width, qMax(1,height), img, static_cast<JKQTPMathImageColorPalette>(i), 0, width-1);
|
||||
free(pic);
|
||||
return img;
|
||||
}
|
||||
@ -1346,7 +1346,7 @@ QImage JKQTPMathImage::getPaletteKeyImage(int i, int width, int height)
|
||||
pic[j]=exp(-0.5*(double((x-x01)*double(x-x01))/w1x+double((y-y01)*double(y-y01))/w1y))+0.7*exp(-0.5*(double((x-x02)*double(x-x02))/w2x+double((y-y02)*double(y-y02))/w2y));
|
||||
if (pic[j]>mmax) mmax=pic[j];
|
||||
}
|
||||
JKQTPImagePlot_array2image<double>(pic, width, height, img, (JKQTPMathImageColorPalette)i, 0, mmax);
|
||||
JKQTPImageTools::array2image<double>(pic, width, height, img, static_cast<JKQTPMathImageColorPalette>(i), 0, mmax);
|
||||
free(pic);
|
||||
return img;
|
||||
}
|
||||
@ -1616,16 +1616,16 @@ QImage JKQTPMathImage::drawImage() {
|
||||
QImage img(Nx, Ny, QImage::Format_ARGB32);
|
||||
getDataMinMax(internalDataMin, internalDataMax);
|
||||
switch(datatype) {
|
||||
case JKQTPMathImageBase::DoubleArray: JKQTPImagePlot_array2image<double>(static_cast<double*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::FloatArray: JKQTPImagePlot_array2image<float>(static_cast<float*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::UInt8Array: JKQTPImagePlot_array2image<uint8_t>(static_cast<uint8_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::UInt16Array: JKQTPImagePlot_array2image<uint16_t>(static_cast<uint16_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::UInt32Array: JKQTPImagePlot_array2image<uint32_t>(static_cast<uint32_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::UInt64Array: JKQTPImagePlot_array2image<uint64_t>(static_cast<uint64_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::Int8Array: JKQTPImagePlot_array2image<int8_t>(static_cast<int8_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::Int16Array: JKQTPImagePlot_array2image<int16_t>(static_cast<int16_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::Int32Array: JKQTPImagePlot_array2image<int32_t>(static_cast<int32_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::Int64Array: JKQTPImagePlot_array2image<int64_t>(static_cast<int64_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::DoubleArray: JKQTPImageTools::array2image<double>(static_cast<double*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::FloatArray: JKQTPImageTools::array2image<float>(static_cast<float*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::UInt8Array: JKQTPImageTools::array2image<uint8_t>(static_cast<uint8_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::UInt16Array: JKQTPImageTools::array2image<uint16_t>(static_cast<uint16_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::UInt32Array: JKQTPImageTools::array2image<uint32_t>(static_cast<uint32_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::UInt64Array: JKQTPImageTools::array2image<uint64_t>(static_cast<uint64_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::Int8Array: JKQTPImageTools::array2image<int8_t>(static_cast<int8_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::Int16Array: JKQTPImageTools::array2image<int16_t>(static_cast<int16_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::Int32Array: JKQTPImageTools::array2image<int32_t>(static_cast<int32_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
case JKQTPMathImageBase::Int64Array: JKQTPImageTools::array2image<int64_t>(static_cast<int64_t*>(data), Nx, Ny, img, palette, internalDataMin, internalDataMax, rangeMinFailAction, rangeMaxFailAction, rangeMinFailColor, rangeMaxFailColor, nanColor, infColor); break;
|
||||
}
|
||||
modifyImage(img);
|
||||
return img;
|
||||
|
@ -552,6 +552,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImage: public JKQTPMathImageBase {
|
||||
/*! \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);
|
||||
@ -654,7 +656,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPMathImage: public JKQTPMathImageBase {
|
||||
/*! \copydoc modifierMax */
|
||||
double getModifierMax() const;
|
||||
|
||||
void setPalette(int pal);
|
||||
|
||||
|
||||
/*! \brief if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
|
||||
|
||||
|
@ -290,15 +290,15 @@ void JKQTPRGBMathImage::drawOutside(JKQTPEnhancedPainter& painter, QRect /*leftS
|
||||
if (rgbMode==JKQTPRGBMathImageModeRGBMode) {
|
||||
d.palette=JKQTPMathImageRED;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
JKQTPImageTools::array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
} else if (rgbMode==JKQTPRGBMathImageModeCMYMode) {
|
||||
d.palette=JKQTPMathImageINVERTED_CYANWHITE;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
JKQTPImageTools::array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
} else if (rgbMode==JKQTPRGBMathImageModeHSVMode || rgbMode==JKQTPRGBMathImageModeHSLMode) {
|
||||
d.palette=JKQTPMathImageHSV;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
JKQTPImageTools::array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
}
|
||||
|
||||
l<<d;
|
||||
@ -313,19 +313,19 @@ void JKQTPRGBMathImage::drawOutside(JKQTPEnhancedPainter& painter, QRect /*leftS
|
||||
d.colorBarRightAxis=colorBarRightAxisG;
|
||||
d.colorBarTopAxis=colorBarTopAxisG;
|
||||
d.name=imageNameG;
|
||||
JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, 199);
|
||||
JKQTPImageTools::array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, 199);
|
||||
if (rgbMode==JKQTPRGBMathImageModeRGBMode) {
|
||||
d.palette=JKQTPMathImageGREEN;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
JKQTPImageTools::array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
} else if (rgbMode==JKQTPRGBMathImageModeCMYMode) {
|
||||
d.palette=JKQTPMathImageINVERTED_MAGENTAWHITE;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
JKQTPImageTools::array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
} else if (rgbMode==JKQTPRGBMathImageModeHSVMode) {
|
||||
d.palette=JKQTPMathImageGRAY;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
//JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
|
||||
//JKQTPImageTools::JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
|
||||
QRgb* line=reinterpret_cast<QRgb *>(d.paletteImage.scanLine(0));
|
||||
for (int i=0; i<pd_size; i++) {
|
||||
QColor c=QColor("red");
|
||||
@ -335,7 +335,7 @@ void JKQTPRGBMathImage::drawOutside(JKQTPEnhancedPainter& painter, QRect /*leftS
|
||||
} else if (rgbMode==JKQTPRGBMathImageModeHSLMode) {
|
||||
d.palette=JKQTPMathImageGRAY;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
//JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
|
||||
//JKQTPImageTools::JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
|
||||
QRgb* line=reinterpret_cast<QRgb *>(d.paletteImage.scanLine(0));
|
||||
for (int i=0; i<pd_size; i++) {
|
||||
QColor c=QColor("red");
|
||||
@ -356,19 +356,19 @@ void JKQTPRGBMathImage::drawOutside(JKQTPEnhancedPainter& painter, QRect /*leftS
|
||||
d.colorBarRightAxis=colorBarRightAxisB;
|
||||
d.colorBarTopAxis=colorBarTopAxisB;
|
||||
d.name=imageNameB;
|
||||
JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, 199);
|
||||
JKQTPImageTools::array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, 199);
|
||||
if (rgbMode==JKQTPRGBMathImageModeRGBMode) {
|
||||
d.palette=JKQTPMathImageBLUE;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
JKQTPImageTools::array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
} else if (rgbMode==JKQTPRGBMathImageModeCMYMode) {
|
||||
d.palette=JKQTPMathImageINVERTED_YELLOWWHITE;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
JKQTPImageTools::array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, d.palette, 0, pd_size-1);
|
||||
} else if (rgbMode==JKQTPRGBMathImageModeHSVMode) {
|
||||
d.palette=JKQTPMathImageGRAY;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
//JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
|
||||
//JKQTPImageTools::JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
|
||||
QRgb* line=reinterpret_cast<QRgb *>(d.paletteImage.scanLine(0));
|
||||
for (int i=0; i<pd_size; i++) {
|
||||
QColor c=QColor("red");
|
||||
@ -378,7 +378,7 @@ void JKQTPRGBMathImage::drawOutside(JKQTPEnhancedPainter& painter, QRect /*leftS
|
||||
} else if (rgbMode==JKQTPRGBMathImageModeHSLMode) {
|
||||
d.palette=JKQTPMathImageGRAY;
|
||||
d.paletteImage=QImage(1, pd_size, QImage::Format_ARGB32);
|
||||
//JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
|
||||
//JKQTPImageTools::JKQTPImagePlot_array2image<uint8_t>(pd, 1, pd_size, d.paletteImage, l[li].palette, 0, pd_size-1);
|
||||
QRgb* line=reinterpret_cast<QRgb *>(d.paletteImage.scanLine(0));
|
||||
for (int i=0; i<pd_size; i++) {
|
||||
QColor c=QColor("red");
|
||||
|
@ -509,7 +509,7 @@ void JKQTPXYParametrizedScatterGraph::drawKeyMarker(JKQTPEnhancedPainter &painte
|
||||
} else {
|
||||
QImage img;
|
||||
double colorval[]={0,1};
|
||||
JKQTPImagePlot_array2image<double>(colorval, 2, 1, img, getPalette(), double(0.0), double(1.0));
|
||||
JKQTPImageTools::array2image<double>(colorval, 2, 1, img, getPalette(), double(0.0), double(1.0));
|
||||
color1=img.pixel(0,0);
|
||||
color2=img.pixel(1,0);
|
||||
}
|
||||
@ -852,7 +852,7 @@ QColor JKQTPXYParametrizedScatterGraph::getLocalColor(int i) const
|
||||
colMin=intColMin;
|
||||
colMax=intColMax;
|
||||
}
|
||||
JKQTPImagePlot_array2image(&colorval, 1, 1, img, palette, colMin, colMax);
|
||||
JKQTPImageTools::array2image(&colorval, 1, 1, img, palette, colMin, colMax);
|
||||
return img.pixel(0,0);
|
||||
}
|
||||
|
||||
|
@ -31,10 +31,10 @@ JKQTPMathImageColorPaletteComboBox::JKQTPMathImageColorPaletteComboBox(QWidget *
|
||||
QComboBox(parent)
|
||||
{
|
||||
setIconSize(QSize(JKQTPImageTools::PALETTE_ICON_WIDTH,16));
|
||||
QStringList pal=JKQTPImagePlot_getPredefinedPalettes();
|
||||
QStringList pal=JKQTPImageTools::getPredefinedPalettes();
|
||||
clear();
|
||||
for (int i=0; i<pal.size(); i++) {
|
||||
addItem(JKQTPMathImageGetPaletteIcon(i), pal[i]);
|
||||
addItem(JKQTPImageTools::GetPaletteIcon(i), pal[i]);
|
||||
}
|
||||
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(intIndexChanged(int)));
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ void JKQTBasePlotterStyle::loadSettings(const QSettings &settings, const QString
|
||||
defaultTextColor=jkqtp_String2QColor(settings.value(group+"text_default_color", jkqtp_QColor2String(defaultStyle.defaultTextColor)).toString());
|
||||
defaultFontSize=settings.value(group+"text_default_size", defaultStyle.defaultFontSize).toDouble();
|
||||
defaultFontName=settings.value(group+"text_default_font_name", defaultStyle.defaultFontName).toString();
|
||||
defaultPalette=String2JKQTPMathImageColorPalette(settings.value(group+"graph_default_palette", JKQTPMathImageColorPalette2String(defaultStyle.defaultPalette)).toString());
|
||||
defaultPalette=JKQTPImageTools::String2JKQTPMathImageColorPalette(settings.value(group+"graph_default_palette", JKQTPImageTools::JKQTPMathImageColorPalette2String(defaultStyle.defaultPalette)).toString());
|
||||
defaultGraphWidth=settings.value(group+"graph_default_linewidth", defaultStyle.debugRegionLineWidth).toDouble();
|
||||
defaultGraphSymbolSize=settings.value(group+"graph_default_symbolsize", defaultStyle.defaultGraphSymbolSize).toDouble();
|
||||
defaultGraphSymbolLineWidth=settings.value(group+"graph_default_symbol_linewidtht", defaultStyle.defaultGraphSymbolLineWidth).toDouble();
|
||||
@ -182,7 +182,7 @@ void JKQTBasePlotterStyle::saveSettings(QSettings &settings, const QString &grou
|
||||
settings.setValue(group+"graph_default_linewidth", defaultGraphWidth);
|
||||
settings.setValue(group+"graph_default_symbolsize", defaultGraphSymbolSize);
|
||||
settings.setValue(group+"graph_default_symbol_linewidtht", defaultGraphSymbolLineWidth);
|
||||
settings.setValue(group+"graph_default_palette", JKQTPMathImageColorPalette2String(defaultPalette));
|
||||
settings.setValue(group+"graph_default_palette", JKQTPImageTools::JKQTPMathImageColorPalette2String(defaultPalette));
|
||||
settings.setValue(group+"graph_default_fill_color_mode", JKQTPColorDerivationMode2String(graphFillColorDerivationMode));
|
||||
settings.setValue(group+"graph_default_error_color_mode", JKQTPColorDerivationMode2String(graphErrorColorDerivationMode));
|
||||
settings.setValue(group+"graph_default_error_fill_color_mode", JKQTPColorDerivationMode2String(graphErrorFillColorDerivationMode));
|
||||
|
@ -795,6 +795,20 @@ size_t JKQTPDatastore::addCalculatedColumn(size_t rows, const std::function<doub
|
||||
return addColumnForItem(itemid, 0, name);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t JKQTPDatastore::addCalculatedImageColumn(size_t cols, size_t rows, const std::function<double (size_t, size_t)> &f, const QString &name)
|
||||
{
|
||||
size_t col=addImageColumn(cols, rows, name);
|
||||
JKQTPColumn& colref = columns[col];
|
||||
for (size_t y=0; y<rows; y++) {
|
||||
for (size_t x=0; x<cols; x++) {
|
||||
colref.setPixelValue(x, y, f(x,y));
|
||||
}
|
||||
}
|
||||
return col;
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t JKQTPDatastore::addColumnCalculatedFromColumn(size_t otherColumn, const std::function<double (double)> &f, const QString &name)
|
||||
{
|
||||
|