JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtpinterfacecimg.h
1/*
2 Copyright (c) 2018-2020 Jan W. Krieger (<jan@jkrieger.de>)
3
4
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License (LGPL) as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License (LGPL) for more details.
15
16 You should have received a copy of the GNU Lesser General Public License (LGPL)
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21
22#include "jkqtplotter/jkqtpdatastorage.h"
23#include "CImg.h"
24
25#ifndef JKQTPINTERFACECIMG_H
26#define JKQTPINTERFACECIMG_H
27
28
29/** \brief add one external column to the datastore. It will be filled with the contents of the CImg image \a img.
30 * \ingroup jkqtpinterfacecimg
31 *
32 * \param datastore the datastore to which the <a href="https://cimg.eu/">CImg</a> matrix should be added (as column)
33 * \param img <a href="http://cimg.eu/reference/structcimg__library_1_1CImg.html">cimg_library::CImg<T>-image</a> to store here
34 * \param name name for the column
35 * \param channel channel to copy from \a img
36 * \param z z-plane to copy from \a img
37 * \return the ID of the newly created column
38 *
39 * \see \ref jkqtpinterfacecimg, \ref JKQTPlotterImagePlotCImg or \ref JKQTPlotterImagePlotRGBCImg for details on how to use this function.
40 */
41template<class T>
42inline size_t JKQTPCopyCImgToColumn(JKQTPDatastore* datastore, const cimg_library::CImg<T>& img, const QString& name=QString(""), int channel=0, int z=0)
43{
44 const size_t N=static_cast<size_t>(img.width()*img.height());
45 double* d=static_cast<double*>(malloc(static_cast<size_t>(N)*sizeof(double)));
46
47 size_t r=0;
48 for (int iy=0; iy<img.height(); iy++ ) {
49 for (int ix=0; ix<img.width(); ix++ ) {
50 d[r]=jkqtp_todouble(img.atXYZC(ix,iy,z,channel));
51 r++;
52 }
53 }
54
55
56 return datastore->addInternalImageColumn(d, img.width(), img.height(), name);
57}
58
59
60
61#endif // JKQTPINTERFACECIMG_H
This class manages data columns (with entries of type double ), used by JKQTPlotter/JKQTBasePlotter t...
Definition jkqtpdatastorage.h:282
size_t addInternalImageColumn(double *data, size_t width, size_t height, const QString &name)
add a column with width * height entries from the array data, ownership of the memory behind data is ...
size_t JKQTPCopyCImgToColumn(JKQTPDatastore *datastore, const cimg_library::CImg< T > &img, const QString &name=QString(""), int channel=0, int z=0)
add one external column to the datastore. It will be filled with the contents of the CImg image img.
Definition jkqtpinterfacecimg.h:42
constexpr double jkqtp_todouble(const T &d)
converts a boolean to a double, is used to convert boolean to double by JKQTPDatastore
Definition jkqtpmathtools.h:113