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
jkqtpimage.h
1/*
2 Copyright (c) 2008-2024 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#ifndef jkqtpgraphsimage_H
22#define jkqtpgraphsimage_H
23
24
25#include <QString>
26#include <QPainter>
27#include <QImage>
28#include <QIcon>
29#include "jkqtplotter/graphs/jkqtpscatter.h"
30#include "jkqtplotter/jkqtptools.h"
31#include "jkqtplotter/jkqtpbaseelements.h"
32#include "jkqtplotter/jkqtplotter_imexport.h"
33#include "jkqtplotter/jkqtpimagetools.h"
34
35
36
37/*! \brief base class for plotting an image
38 \ingroup jkqtplotter_imagelots_elements
39 */
41 Q_OBJECT
42 public:
43 /** \brief class constructor
44 *
45 * \param parent parent plotter object
46 */
48 /** \brief class constructor
49 *
50 * \param x origin of the image (x-direction) in system coordinates
51 * \param y origin of the image (y-direction) in system coordinates
52 * \param width width of the image in system coordinates
53 * \param height height of the image in system coordinates
54 * \param parent parent plotter object
55 *
56 */
57 JKQTPImageBase(double x, double y, double width, double height, JKQTBasePlotter* parent=nullptr);
58 /** \brief class constructor
59 *
60 * \param parent parent plotter object
61 */
63 /** \brief class constructor
64 *
65 * \param x origin of the image (x-direction) in system coordinates
66 * \param y origin of the image (y-direction) in system coordinates
67 * \param width width of the image in system coordinates
68 * \param height height of the image in system coordinates
69 * \param parent parent plotter object
70 *
71 */
72 JKQTPImageBase(double x, double y, double width, double height, JKQTPlotter* parent);
73 /** \brief plots a key marker inside the specified rectangle \a rect */
74 virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) override;
75
76 /** \copydoc JKQTPPlotElement::getXMinMax() */
77 virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override;
78 /** \copydoc JKQTPPlotElement::getYMinMax() */
79 virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override;
80 /** \brief returns the color to be used for the key label */
81 virtual QColor getKeyLabelColor() const override;
82
83 /** \copydoc x */
84 double getX() const;
85 /** \copydoc y */
86 double getY() const;
87 /** \copydoc width */
88 double getWidth() const;
89 /** \copydoc height */
90 double getHeight() const;
91 public Q_SLOTS:
92
93 /** \copydoc x */
94 void setX(double __value);
95 /** \copydoc y */
96 void setY(double __value);
97 /** \copydoc width */
98 void setWidth(double __value);
99 /** \copydoc height */
100 void setHeight(double __value);
101 protected:
102
103 /** \brief x coordinate of lower left corner */
104 double x;
105 /** \brief y coordinate of lower left corner */
106 double y;
107 /** \brief width of image */
108 double width;
109 /** \brief height of image */
110 double height;
111
112 /** \brief plot the given QImage onto the widget where the QImage fills the area defined by x, y (lower left corner) and width, height
113 * in the simplest case your implementation of draw() will call
114 * <code>plotImage(painter, image, this->x, this->y, this->width, this->height);</code>
115 *
116 * \param painter the Painter to use for drawing
117 * \param image the image to draw
118 * \param x x-coordinate of lower-left corner in coordinate space
119 * \param y y-coordinate of lower-left corner in coordinate space
120 * \param width width of image in coordinate space
121 * \param height height of image in coordinate space
122 */
123 void plotImage(JKQTPEnhancedPainter& painter, QImage& image, double x, double y, double width, double height);
124
125};
126
127
128/*! \brief base class to hold an image from an 2-dimensional array of values
129 \ingroup jkqtplotter_imagelots_elements
130
131 \image html imageplot.png
132
133 */
135 Q_OBJECT
136 public:
137
138 /** \brief class constructor
139 *
140 * \param parent parent plotter object
141 */
143 /** \brief class constructor
144 *
145 * \param x origin of the image (x-direction) in system coordinates
146 * \param y origin of the image (y-direction) in system coordinates
147 * \param width width of the image in system coordinates
148 * \param height height of the image in system coordinates
149 * \param parent parent plotter object
150 *
151 */
152 JKQTPMathImageBase(double x, double y, double width, double height, JKQTBasePlotter* parent=nullptr);
153 /** \brief class constructor
154 *
155 * \param x origin of the image (x-direction) in system coordinates
156 * \param y origin of the image (y-direction) in system coordinates
157 * \param width width of the image in system coordinates
158 * \param height height of the image in system coordinates
159 * \param datatype datatype of the image given in \a data
160 * \param data points to an image to be plotted (of size \a Nx * \a Ny )
161 * \param Nx width (in number of pixels) of \a data
162 * \param Ny height (in number of pixels) of \a data
163 * \param parent parent plotter object
164 *
165 */
166 JKQTPMathImageBase(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void* data, int Nx, int Ny, JKQTBasePlotter* parent=nullptr);
167
168
169 /** \brief class constructor
170 *
171 * \param parent parent plotter object
172 */
174 /** \brief class constructor
175 *
176 * \param x origin of the image (x-direction) in system coordinates
177 * \param y origin of the image (y-direction) in system coordinates
178 * \param width width of the image in system coordinates
179 * \param height height of the image in system coordinates
180 * \param parent parent plotter object
181 *
182 */
183 JKQTPMathImageBase(double x, double y, double width, double height, JKQTPlotter* parent=nullptr);
184 /** \brief class constructor
185 *
186 * \param x origin of the image (x-direction) in system coordinates
187 * \param y origin of the image (y-direction) in system coordinates
188 * \param width width of the image in system coordinates
189 * \param height height of the image in system coordinates
190 * \param datatype datatype of the image given in \a data
191 * \param data points to an image to be plotted (of size \a Nx * \a Ny )
192 * \param Nx width (in number of pixels) of \a data
193 * \param Ny height (in number of pixels) of \a data
194 * \param parent parent plotter object
195 *
196 */
197 JKQTPMathImageBase(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void* data, int Nx, int Ny, JKQTPlotter* parent);
198
199 /** \brief plots a key marker inside the specified rectangle \a rect */
200 virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) override;
201
202 /** \copydoc Nx */
203 void setNx(int __value);
204 /** \copydoc Nx */
205 void setNx(size_t __value);
206 /** \copydoc Nx */
207 int getNx() const;
208 /** \copydoc Ny */
209 void setNy(int __value);
210 /** \copydoc Ny */
211 void setNy(size_t __value);
212 /** \copydoc Ny */
213 int getNy() const;
214 /** \copydoc data */
215 virtual void setData(const void* __value);
216 /** \copydoc data */
217 virtual const void *getData() const;
218 /** \copydoc datatype */
219 virtual void setDatatype(JKQTPMathImageDataType __value);
220 /** \copydoc datatype */
222 /** \copydoc dataModifier */
223 virtual void setDataModifier(const void* __value);
224 /** \copydoc dataModifier */
225 virtual const void *getDataModifier() const;
226 /** \copydoc datatypeModifier */
228 /** \copydoc datatypeModifier */
230 /** \brief sets dataModifier (\copybrief dataModifier ) and datatypeModifier (\copybrief datatypeModifier ) */
231 virtual void setDataModifier(const void *data, JKQTPMathImageDataType datatype);
232 /** \brief sets data (\copybrief data ) and datatype (\copybrief datatype ), as well as the size of data (Nx: \copybrief Nx and Ny: \copybrief Ny ) */
233 virtual void setData(const void* data, int Nx, int Ny, JKQTPMathImageDataType datatype);
234 /** \brief sets data (\copybrief data ), as well as the size of data (Nx: \copybrief Nx and Ny: \copybrief Ny ) */
235 virtual void setData(const void* data, int Nx, int Ny);
236 /** \brief determine min/max data value of the image */
237 virtual void getDataMinMax(double& imin, double& imax);
238 /** \brief determine min/max data value of the image */
239 virtual void getModifierMinMax(double& imin, double& imax);
240
241 /** \brief returns the contents of the internal data image as a QVector<double> */
242 QVector<double> getDataAsDoubleVector() const;
243 /** \brief returns the contents of the internal modifier image as a QVector<double> */
244 QVector<double> getDataModifierAsDoubleVector() const;
245 protected:
246 /** \brief points to the data array, holding the image */
247 const void* data;
248 /** \brief datatype of the data array data */
250 /** \brief width of the data array data in pt */
251 int Nx;
252 /** \brief height of the data array data in pt */
253 int Ny;
254
255 /** \brief points to the data array, holding the modifier image */
256 const void* dataModifier;
257 /** \brief datatype of the data array data */
259
260
261 /** \brief internal storage for minimum of the image value range
262 *
263 * This is set e.g. when calling drawImage() or draw()
264 */
266 /** \brief internal storage for maximum of the image value range
267 *
268 * This is set e.g. when calling drawImage() or draw()
269 */
271 /** \brief internal storage for minimum of the modifier image value range
272 *
273 * This is set e.g. when calling modifyImage() or draw()
274 */
276 /** \brief internal storage for maximum of the modifier image value range
277 *
278 * This is set e.g. when calling modifyImage() or draw()
279 */
281 /** \brief overwrite this to fill the data poiters before they are accessed (e.g. to load data from a column in the datastore */
282 virtual void ensureImageData();
283
284
285};
286
287
288
289/*! \brief class to plot an image from a QImage object
290 \ingroup jkqtplotter_imagelots_elements
291
292 \image html rgbimageplot_qt.png
293
294 \see \ref JKQTPlotterImagePlotQImageRGB
295 */
297 Q_OBJECT
298 public:
299
300 /** \brief class constructor
301 *
302 * \param parent parent plotter object
303 */
304 JKQTPImage(JKQTBasePlotter* parent=nullptr);
305 /** \brief class constructor
306 *
307 * \param parent parent plotter object
308 */
310 /** \brief class constructor
311 *
312 * \param x origin of the image (x-direction) in system coordinates
313 * \param y origin of the image (y-direction) in system coordinates
314 * \param width width of the image in system coordinates
315 * \param height height of the image in system coordinates
316 * \param image points to a QImage that shall be plotted (the constructed object does not take ownership!)
317 * \param parent parent plotter object
318 *
319 */
320 JKQTPImage(double x, double y, double width, double height, QImage* image, JKQTBasePlotter* parent=nullptr);
321 /** \brief class constructor
322 *
323 * \param x origin of the image (x-direction) in system coordinates
324 * \param y origin of the image (y-direction) in system coordinates
325 * \param width width of the image in system coordinates
326 * \param height height of the image in system coordinates
327 * \param image points to a QImage that shall be plotted (the constructed object does not take ownership!)
328 * \param parent parent plotter object
329 *
330 */
331 JKQTPImage(double x, double y, double width, double height, QImage* image, JKQTPlotter* parent);
332 /** \brief class constructor
333 *
334 * \param x origin of the image (x-direction) in system coordinates
335 * \param y origin of the image (y-direction) in system coordinates
336 * \param width width of the image in system coordinates
337 * \param height height of the image in system coordinates
338 * \param image a QImage that shall be plotted (the constructed object copies the contents into an internally owned variable)
339 * \param parent parent plotter object
340 *
341 */
342 JKQTPImage(double x, double y, double width, double height, const QImage& image, JKQTBasePlotter* parent=nullptr);
343 /** \brief class constructor
344 *
345 * \param x origin of the image (x-direction) in system coordinates
346 * \param y origin of the image (y-direction) in system coordinates
347 * \param width width of the image in system coordinates
348 * \param height height of the image in system coordinates
349 * \param image a QImage that shall be plotted (the constructed object copies the contents into an internally owned variable)
350 * \param parent parent plotter object
351 *
352 */
353 JKQTPImage(double x, double y, double width, double height, const QImage& image, JKQTPlotter* parent);
354
355 virtual ~JKQTPImage() override;
356
357 /** \brief plots the graph to the plotter object specified as parent */
358 virtual void draw(JKQTPEnhancedPainter& painter) override;
359
360 /** \brief plots a key marker inside the specified rectangle \a rect */
361 virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) override;
362
363 /** \brief copy an external image into an internally owned copy */
364 virtual void setImage(const QImage& image);
365
366 /** \brief set an external image to be plotted, the image will NOT BE OWNED by the graph-object */
367 virtual void setImage(QImage* image);
368
369 /** \brief deletes the internal image */
371
372 /** \copydoc image */
373 inline QImage* getImage() { return this->image; }
374 /** \copydoc image */
375 inline const QImage* getImage() const { return this->image; }
376 protected:
377 /** \brief the image to be plotted. This is freed by the destructor, iff \a image_owned is set to \c true (.e.g by QImage-copy-constructors) */
378 QImage* image;
379 /** \brief indicates that the image \a image is owned by this object (i.e. freed, when the object is destroyed) */
381
382 /** \brief create QActions that are shown in the context menu of the JKQTPlotter
383 *
384 * \see actSaveImage, actCopyImage, saveImagePlotAsImage(), copyImagePlotAsImage()
385 */
387
388 protected:
389 /** \brief QActions that saves the image (asking the user for a filename)
390 *
391 * \see actSaveImage, saveImagePlotAsImage()
392 */
393 QAction* actSaveImage;
394 /** \brief QActions that copies the image into the clipboard
395 *
396 * \see actCopyImage, copyImagePlotAsImage()
397 */
398 QAction* actCopyImage;
399 public:
400 /** \copydoc JKQTPImageBase::setParent() */
401 virtual void setParent(JKQTBasePlotter* parent) override;
402 /** \copydoc JKQTPImageBase::setTitle() */
403 virtual void setTitle(const QString& title) override;
404 public Q_SLOTS:
405 /** \brief saves the image (asking the user for a filename, if \a filename is empty)
406 *
407 * \param filename name of the file that should be create (if empty, a file save dialog is shown)
408 * \param outputFormat format of the output file, see <a href="https://doc.qt.io/qt-5/qimage.html#save">QImage::save()</a>
409 *
410 * \see actSaveImage, saveImagePlotAsImage(), <a href="https://doc.qt.io/qt-5/qimage.html#save">QImage::save()</a>
411 */
412 void saveImagePlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray());
413 /** \brief copies the image into the clipboard
414 *
415 * \see actCopyImage, copyImagePlotAsImage()
416 */
418};
419
420
421
422
423
424/*! \brief class to plot an image from an 2-dimensional array of values
425 \ingroup jkqtplotter_imagelots_elements
426
427 \image html imageplot.png
428 \image html imageplot_modifier.png
429 \image html imageplot__smallscaletransparent.png
430
431 \see \ref JKQTPlotterImagePlotNoDatastore
432 */
434 Q_OBJECT
435 public:
436
437 /** \brief class constructor
438 *
439 * \param parent parent plotter object
440 */
442 /** \brief class constructor
443 *
444 * \param x origin of the image (x-direction) in system coordinates
445 * \param y origin of the image (y-direction) in system coordinates
446 * \param width width of the image in system coordinates
447 * \param height height of the image in system coordinates
448 * \param datatype datatype of the image given in \a data
449 * \param data points to an image to be plotted (of size \a Nx * \a Ny )
450 * \param Nx width (in number of pixels) of \a data
451 * \param Ny height (in number of pixels) of \a data
452 * \param palette color palette to use for plotting
453 * \param parent parent plotter object
454 *
455 */
456 JKQTPMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette=JKQTPMathImageGRAY, JKQTBasePlotter* parent=nullptr);
457 /** \brief class constructor
458 *
459 * \param x origin of the image (x-direction) in system coordinates
460 * \param y origin of the image (y-direction) in system coordinates
461 * \param width width of the image in system coordinates
462 * \param height height of the image in system coordinates
463 * \param datatype datatype of the image given in \a data
464 * \param data points to an image to be plotted (of size \a Nx * \a Ny )
465 * \param Nx width (in number of pixels) of \a data
466 * \param Ny height (in number of pixels) of \a data
467 * \param palette color palette to use for plotting
468 * \param parent parent plotter object
469 *
470 */
471 JKQTPMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette, JKQTPlotter* parent);
472 /** \brief class constructor
473 *
474 * \param parent parent plotter object
475 */
477
478 /** \brief plots the graph to the plotter object specified as parent */
479 virtual void draw(JKQTPEnhancedPainter& painter) override;
480
481 virtual void setParent(JKQTBasePlotter* parent) override;
482
483
484
485 /*! \brief if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
486
487 \note If you want to draw outside, then you'll also have to implement drawOutside()
488 */
489 virtual void getOutsideSize(JKQTPEnhancedPainter& painter, int& leftSpace, int& rightSpace, int& topSpace, int& bottomSpace) override;
490
491 /*! \brief plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
492
493 \note If you want to draw outside, then you'll also have to implement getOutsideSize(), so enough space is reserved
494
495 The four value supplied tell the method where to draw (inside one of the rectangles).
496 */
497 virtual void drawOutside(JKQTPEnhancedPainter& painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace) override;
498
499 /** \brief returns a QImage, which contains the plaette drawn outside the plot. \a steps is the number of data-setps (and the size of the output image) used for the palette image. */
500 virtual QImage drawOutsidePalette(uint8_t steps=200);
501
502 /** \brief return the plotted image only as a QImage */
503 virtual QImage drawImage();
504
505 /** \brief determine min/max data value of the image */
506 virtual void getDataMinMax(double& imin, double& imax) override;
507
508 /** \brief determine min/max data value of the image */
509 virtual void getModifierMinMax(double& imin, double& imax) override;
510
511 /** \brief return the value (raw data!) of the contained image at the given coordinate */
512 inline double getValueAt(double x, double y);
513
514 /** \brief retrieve size of a single sample in the image data (i.e. size of the datatype) */
515 inline int getSampleSize() const;
516 /** \brief retrieve image data at a given position as double */
517 inline double getPixelValue(int xIdx, int yIdx) const;
518
519 /** \brief return the value (raw data!) of the contained modifier image at the given coordinate */
520 inline double getModifierValueAt(double x, double y);
521
522 /** \brief retrieve size of a single sample in the modifier image data (i.e. size of the datatype) */
523 inline int getModifierSampleSize() const;
524 /** \brief retrieve modifier image data at a given position as double */
525 inline double getModifierPixelValue(int xIdx, int yIdx) const;
526
527 /** \brief plots a key marker inside the specified rectangle \a rect */
528 virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) override;
529 /** \brief determine min/max data value of the image */
530 virtual void cbGetDataMinMax(double& imin, double& imax) override;
531 /** \brief determine min/max data value of the modifier image */
532 virtual void cbGetModifierDataMinMax(double& imin, double& imax) override;
533
534 protected:
536
537 protected:
538 /** \brief QActions that saves the image (asking the user for a filename)
539 *
540 * \see actSaveImage, saveImagePlotAsImage()
541 */
542 QAction* actSaveImage;
543 /** \brief QActions that copies the image into the clipboard
544 *
545 * \see actCopyImage, copyImagePlotAsImage()
546 */
547 QAction* actCopyImage;
548 /** \brief QActions that saves the current palette
549 *
550 * \see actSaveImage, saveColorbarPlotAsImage()
551 */
553 /** \brief QActions that copies the current palette
554 *
555 * \see actCopyImage, copyColorbarPlotAsImage()
556 */
558 public:
559 /** \copydoc JKQTPImageBase::setTitle() */
560 virtual void setTitle(const QString& title) override;
561 public Q_SLOTS:
562 /** \brief saves the image (asking the user for a filename, if \a filename is empty)
563 *
564 * \param filename name of the file that should be create (if empty, a file save dialog is shown)
565 * \param outputFormat format of the output file, see <a href="https://doc.qt.io/qt-5/qimage.html#save">QImage::save()</a>
566 *
567 * \see actSaveImage, saveImagePlotAsImage(), <a href="https://doc.qt.io/qt-5/qimage.html#save">QImage::save()</a>
568 */
569 void saveImagePlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray());
570 /** \brief copies the image into the clipboard
571 *
572 * \see actCopyImage, copyImagePlotAsImage()
573 */
575 /** \brief saves an image of the current palette (asking the user for a filename, if \a filename is empty)
576 *
577 * \param filename name of the file that should be create (if empty, a file save dialog is shown)
578 * \param outputFormat format of the output file, see <a href="https://doc.qt.io/qt-5/qimage.html#save">QImage::save()</a>
579 *
580 * \see actSavePalette, saveColorbarPlotAsImage(), <a href="https://doc.qt.io/qt-5/qimage.html#save">QImage::save()</a>
581 */
582 void saveColorbarPlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray());
583 /** \brief copies an image of the current palette into the clipboard
584 *
585 * \see actCopyPalette, copyColorbarPlotAsImage()
586 */
588
589};
590
591////////////////////////////////////////////////////////////////////////////////////////////////
592double JKQTPMathImage::getValueAt(double x, double y)
593{
595 const int xx=jkqtp_truncTo<int>((x-this->x)/width*double(Nx));
596 const int yy=jkqtp_truncTo<int>((y-this->y)/height*double(Ny));
597 if (xx>=0 && xx<static_cast<int64_t>(Nx) && yy>=0 && yy<static_cast<int64_t>(Ny)) {
598 switch(datatype) {
599 case JKQTPMathImageDataType::DoubleArray: return static_cast<double>((static_cast<const double*>(data))[yy*Nx+xx]);
600 case JKQTPMathImageDataType::FloatArray: return static_cast<double>((static_cast<const float*>(data))[yy*Nx+xx]);
601 case JKQTPMathImageDataType::UInt8Array: return static_cast<double>((static_cast<const uint8_t*>(data))[yy*Nx+xx]);
602 case JKQTPMathImageDataType::UInt16Array: return static_cast<double>((static_cast<const uint16_t*>(data))[yy*Nx+xx]);
603 case JKQTPMathImageDataType::UInt32Array: return static_cast<double>((static_cast<const uint32_t*>(data))[yy*Nx+xx]);
604 case JKQTPMathImageDataType::UInt64Array: return static_cast<double>((static_cast<const uint64_t*>(data))[yy*Nx+xx]);
605 case JKQTPMathImageDataType::Int8Array: return static_cast<double>((static_cast<const int8_t*>(data))[yy*Nx+xx]);
606 case JKQTPMathImageDataType::Int16Array: return static_cast<double>((static_cast<const int16_t*>(data))[yy*Nx+xx]);
607 case JKQTPMathImageDataType::Int32Array: return static_cast<double>((static_cast<const int32_t*>(data))[yy*Nx+xx]);
608 case JKQTPMathImageDataType::Int64Array: return static_cast<double>((static_cast<const int64_t*>(data))[yy*Nx+xx]);
609 } }
610 return 0.0;
611}
612
613
614////////////////////////////////////////////////////////////////////////////////////////////////
615double JKQTPMathImage::getPixelValue(int xIdx, int yIdx) const {
616 // row-major in datastore
617 //ensureImageData();
618 if (!data) return 0;
619 switch(datatype) {
621 return (static_cast<const double*>(data))[yIdx*getNx()+xIdx];
623 return static_cast<double>((static_cast<const float*>(data))[yIdx*getNx()+xIdx]);
625 return static_cast<double>((static_cast<const uint8_t*>(data))[yIdx*getNx()+xIdx]);
627 return static_cast<double>((static_cast<const uint16_t*>(data))[yIdx*getNx()+xIdx]);
629 return static_cast<double>((static_cast<const uint32_t*>(data))[yIdx*getNx()+xIdx]);
631 return static_cast<double>((static_cast<const uint64_t*>(data))[yIdx*getNx()+xIdx]);
633 return static_cast<double>((static_cast<const int8_t*>(data))[yIdx*getNx()+xIdx]);
635 return static_cast<double>((static_cast<const int16_t*>(data))[yIdx*getNx()+xIdx]);
637 return static_cast<double>((static_cast<const int32_t*>(data))[yIdx*getNx()+xIdx]);
639 return static_cast<double>((static_cast<const int64_t*>(data))[yIdx*getNx()+xIdx]);
640 default:
641 return 0;
642 }
643}
644
645
646////////////////////////////////////////////////////////////////////////////////////////////////
648 switch(datatype) {
650 return sizeof(double);
652 return sizeof(float);
654 return sizeof(uint8_t);
656 return sizeof(uint16_t);
658 return sizeof(uint32_t);
660 return sizeof(uint64_t);
662 return sizeof(int8_t);
664 return sizeof(int16_t);
666 return sizeof(int32_t);
668 return sizeof(int64_t);
669 default:
670 return 0;
671 }
672}
673
674
675
676////////////////////////////////////////////////////////////////////////////////////////////////
677double JKQTPMathImage::getModifierValueAt(double x, double y)
678{
680 const int xx=jkqtp_truncTo<int>((x-this->x)/width*double(Nx));
681 const int yy=jkqtp_truncTo<int>((y-this->y)/height*double(Ny));
682 if (xx>=0 && xx<(int64_t)Nx && yy>=0 && yy<(int64_t)Ny) {
683 switch(datatypeModifier) {
684 case JKQTPMathImageDataType::DoubleArray: return (static_cast<const double*>(dataModifier))[yy*Nx+xx];
685 case JKQTPMathImageDataType::FloatArray: return static_cast<double>((static_cast<const float*>(dataModifier))[yy*Nx+xx]);
686 case JKQTPMathImageDataType::UInt8Array: return static_cast<double>((static_cast<const uint8_t*>(dataModifier))[yy*Nx+xx]);
687 case JKQTPMathImageDataType::UInt16Array: return static_cast<double>((static_cast<const uint16_t*>(dataModifier))[yy*Nx+xx]);
688 case JKQTPMathImageDataType::UInt32Array: return static_cast<double>((static_cast<const uint32_t*>(dataModifier))[yy*Nx+xx]);
689 case JKQTPMathImageDataType::UInt64Array: return static_cast<double>((static_cast<const uint64_t*>(dataModifier))[yy*Nx+xx]);
690 case JKQTPMathImageDataType::Int8Array: return static_cast<double>((static_cast<const int8_t*>(dataModifier))[yy*Nx+xx]);
691 case JKQTPMathImageDataType::Int16Array: return static_cast<double>((static_cast<const int16_t*>(dataModifier))[yy*Nx+xx]);
692 case JKQTPMathImageDataType::Int32Array: return static_cast<double>((static_cast<const int32_t*>(dataModifier))[yy*Nx+xx]);
693 case JKQTPMathImageDataType::Int64Array: return static_cast<double>((static_cast<const int64_t*>(dataModifier))[yy*Nx+xx]);
694 } }
695 return 0.0;
696}
697
698
699////////////////////////////////////////////////////////////////////////////////////////////////
700double JKQTPMathImage::getModifierPixelValue(int xIdx, int yIdx) const {
701 // row-major in datastore
702 //ensureImageData();
703 if (!dataModifier) return 0;
704 switch(datatypeModifier) {
706 return (static_cast<const double*>(dataModifier))[yIdx*getNx()+xIdx];
708 return static_cast<double>((static_cast<const float*>(dataModifier))[yIdx*getNx()+xIdx]);
710 return static_cast<double>((static_cast<const uint8_t*>(dataModifier))[yIdx*getNx()+xIdx]);
712 return static_cast<double>((static_cast<const uint16_t*>(dataModifier))[yIdx*getNx()+xIdx]);
714 return static_cast<double>((static_cast<const uint32_t*>(dataModifier))[yIdx*getNx()+xIdx]);
716 return static_cast<double>((static_cast<const uint64_t*>(dataModifier))[yIdx*getNx()+xIdx]);
718 return static_cast<double>((static_cast<const int8_t*>(dataModifier))[yIdx*getNx()+xIdx]);
720 return static_cast<double>((static_cast<const int16_t*>(dataModifier))[yIdx*getNx()+xIdx]);
722 return static_cast<double>((static_cast<const int32_t*>(dataModifier))[yIdx*getNx()+xIdx]);
724 return static_cast<double>((static_cast<const int64_t*>(dataModifier))[yIdx*getNx()+xIdx]);
725 default:
726 return 0;
727 }
728}
729
730
731////////////////////////////////////////////////////////////////////////////////////////////////
733 switch(datatypeModifier) {
735 return sizeof(double);
737 return sizeof(float);
739 return sizeof(uint8_t);
741 return sizeof(uint16_t);
743 return sizeof(uint32_t);
745 return sizeof(uint64_t);
747 return sizeof(int8_t);
749 return sizeof(int16_t);
751 return sizeof(int32_t);
753 return sizeof(int64_t);
754 default:
755 return 0;
756 }
757}
758
759
760
761
762/*! \brief class to plot an image from an 2-dimensional array of values stored in a column of the datastore
763 \ingroup jkqtplotter_imagelots_elements
764
765 \image html imageplot.png
766 \image html imageplot_modifier.png
767 \image html imageplot__smallscaletransparent.png
768
769 \see jkqtpstatAddKDE2DImage(), jkqtpstatAddHistogram2DImage(), \ref JKQTPlotterImagePlot, \ref JKQTPlotterImagePlotModifier, \ref JKQTPlotterImagePlotOpenCV
770 */
772 Q_OBJECT
773 public:
774
775 /** \brief class constructor
776 *
777 * \param parent parent plotter object
778 */
780 /** \brief class constructor
781 *
782 * \param x origin of the image (x-direction) in system coordinates
783 * \param y origin of the image (y-direction) in system coordinates
784 * \param width width of the image in system coordinates
785 * \param height height of the image in system coordinates
786 * \param parent parent plotter object
787 *
788 */
789 JKQTPColumnMathImage(double x, double y, double width, double height, JKQTBasePlotter* parent=nullptr);
790 /** \brief class constructor
791 *
792 * \param x origin of the image (x-direction) in system coordinates
793 * \param y origin of the image (y-direction) in system coordinates
794 * \param width width of the image in system coordinates
795 * \param height height of the image in system coordinates
796 * \param imageColumn column to be plotted
797 * \param palette color palette to use for the plotting
798 * \param parent parent plotter object
799 *
800 */
801 JKQTPColumnMathImage(double x, double y, double width, double height, int imageColumn, JKQTPMathImageColorPalette palette=JKQTPMathImageGRAY, JKQTBasePlotter* parent=nullptr);
802 /** \brief class constructor
803 *
804 * \param parent parent plotter object
805 */
807 /** \brief class constructor
808 *
809 * \param x origin of the image (x-direction) in system coordinates
810 * \param y origin of the image (y-direction) in system coordinates
811 * \param width width of the image in system coordinates
812 * \param height height of the image in system coordinates
813 * \param parent parent plotter object
814 *
815 */
816 JKQTPColumnMathImage(double x, double y, double width, double height, JKQTPlotter* parent);
817 /** \brief class constructor
818 *
819 * \param x origin of the image (x-direction) in system coordinates
820 * \param y origin of the image (y-direction) in system coordinates
821 * \param width width of the image in system coordinates
822 * \param height height of the image in system coordinates
823 * \param imageColumn column to be plotted
824 * \param palette color palette to use for the plotting
825 * \param parent parent plotter object
826 *
827 */
828 JKQTPColumnMathImage(double x, double y, double width, double height, int imageColumn, JKQTPMathImageColorPalette palette, JKQTPlotter* parent);
829 /** \brief class constructor
830 *
831 * \param x origin of the image (x-direction) in system coordinates
832 * \param y origin of the image (y-direction) in system coordinates
833 * \param width width of the image in system coordinates
834 * \param height height of the image in system coordinates
835 * \param imageColumn column to be plotted
836 * \param parent parent plotter object
837 *
838 */
839 JKQTPColumnMathImage(double x, double y, double width, double height, int imageColumn, JKQTPlotter* parent);
840
841 /** \copydoc imageColumn */
842 virtual void setImageColumn(int __value);
843
844 /** \copydoc imageColumn */
845 virtual void setImageColumn(size_t __value);
846 /** \copydoc imageColumn */
847 int getImageColumn() const;
848 /** \copydoc modifierColumn */
849 virtual void setModifierColumn(int __value);
850 /** \copydoc modifierColumn */
851 virtual void setModifierColumn(size_t __value);
852 /** \copydoc modifierColumn */
853 int getModifierColumn() const;
854
855 /** \copydoc JKQTPGraph::usesColumn() */
856 virtual bool usesColumn(int c) const override;
857
858
859
860 protected:
861 /** \brief column containing the displayed image */
863 /** \brief column containing the modifier image */
865
866 /** \copydoc JKQTPMathImage::ensureImageData() */
867 virtual void ensureImageData() override;
868
869 private:
874};
875
876
877
878#endif // jkqtpgraphsimage_H
879
base class for 2D plotter classes (used by the plotter widget JKQTPlotter)
Definition jkqtpbaseplotter.h:394
if a class is derived from this class, it may use color bars that have 2 axes (one "data"/color axis ...
Definition jkqtpimagetools.h:256
class to plot an image from an 2-dimensional array of values stored in a column of the datastore
Definition jkqtpimage.h:771
JKQTPColumnMathImage(double x, double y, double width, double height, JKQTPlotter *parent)
class constructor
virtual bool usesColumn(int c) const override
returns true if the given column is used by the graph
JKQTPColumnMathImage(double x, double y, double width, double height, int imageColumn, JKQTPMathImageColorPalette palette, JKQTPlotter *parent)
class constructor
virtual void ensureImageData() override
overwrite this to fill the data poiters before they are accessed (e.g. to load data from a column in ...
JKQTPColumnMathImage(JKQTBasePlotter *parent=nullptr)
class constructor
JKQTPColumnMathImage(JKQTPlotter *parent)
class constructor
int getImageColumn() const
column containing the displayed image
int getModifierColumn() const
column containing the modifier image
virtual void setImageColumn(int __value)
column containing the displayed image
virtual void setModifierColumn(int __value)
column containing the modifier image
int modifierColumn
column containing the modifier image
Definition jkqtpimage.h:864
int imageColumn
column containing the displayed image
Definition jkqtpimage.h:862
JKQTPColumnMathImage(double x, double y, double width, double height, JKQTBasePlotter *parent=nullptr)
class constructor
virtual void setImageColumn(size_t __value)
column containing the displayed image
JKQTPColumnMathImage(double x, double y, double width, double height, int imageColumn, JKQTPMathImageColorPalette palette=JKQTPMathImageGRAY, JKQTBasePlotter *parent=nullptr)
class constructor
JKQTPColumnMathImage(double x, double y, double width, double height, int imageColumn, JKQTPlotter *parent)
class constructor
virtual void setModifierColumn(size_t __value)
column containing the modifier image
this class extends the QPainter
Definition jkqtpenhancedpainter.h:33
this virtual base class of the (data-column based) graphs, which are part of a JKQTPlotter plot and w...
Definition jkqtpgraphsbase.h:429
base class for plotting an image
Definition jkqtpimage.h:40
virtual QColor getKeyLabelColor() const override
returns the color to be used for the key label
JKQTPImageBase(double x, double y, double width, double height, JKQTPlotter *parent)
class constructor
virtual bool getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) override
get the maximum and minimum y-value of the graph
JKQTPImageBase(double x, double y, double width, double height, JKQTBasePlotter *parent=nullptr)
class constructor
double getWidth() const
width of image
virtual bool getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) override
get the maximum and minimum x-value of the graph
void setHeight(double __value)
height of image
double x
x coordinate of lower left corner
Definition jkqtpimage.h:104
double y
y coordinate of lower left corner
Definition jkqtpimage.h:106
JKQTPImageBase(JKQTBasePlotter *parent=nullptr)
class constructor
void setX(double __value)
x coordinate of lower left corner
double getHeight() const
height of image
double getY() const
y coordinate of lower left corner
double getX() const
x coordinate of lower left corner
virtual void drawKeyMarker(JKQTPEnhancedPainter &painter, const QRectF &rect) override
plots a key marker inside the specified rectangle rect
JKQTPImageBase(JKQTPlotter *parent)
class constructor
void setWidth(double __value)
width of image
void plotImage(JKQTPEnhancedPainter &painter, QImage &image, double x, double y, double width, double height)
plot the given QImage onto the widget where the QImage fills the area defined by x,...
double height
height of image
Definition jkqtpimage.h:110
void setY(double __value)
y coordinate of lower left corner
double width
width of image
Definition jkqtpimage.h:108
class to plot an image from a QImage object
Definition jkqtpimage.h:296
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
virtual void setImage(QImage *image)
set an external image to be plotted, the image will NOT BE OWNED by the graph-object
virtual void drawKeyMarker(JKQTPEnhancedPainter &painter, const QRectF &rect) override
plots a key marker inside the specified rectangle rect
const QImage * getImage() const
the image to be plotted. This is freed by the destructor, iff image_owned is set to true (....
Definition jkqtpimage.h:375
JKQTPImage(JKQTPlotter *parent)
class constructor
QAction * actCopyImage
QActions that copies the image into the clipboard.
Definition jkqtpimage.h:398
virtual void setImage(const QImage &image)
copy an external image into an internally owned copy
void saveImagePlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray())
saves the image (asking the user for a filename, if filename is empty)
QAction * actSaveImage
QActions that saves the image (asking the user for a filename)
Definition jkqtpimage.h:393
JKQTPImage(JKQTBasePlotter *parent=nullptr)
class constructor
void copyImagePlotAsImage()
copies the image into the clipboard
QImage * image
the image to be plotted. This is freed by the destructor, iff image_owned is set to true (....
Definition jkqtpimage.h:378
bool image_owned
indicates that the image image is owned by this object (i.e. freed, when the object is destroyed)
Definition jkqtpimage.h:380
void clear_image()
deletes the internal image
JKQTPImage(double x, double y, double width, double height, const QImage &image, JKQTBasePlotter *parent=nullptr)
class constructor
JKQTPImage(double x, double y, double width, double height, QImage *image, JKQTPlotter *parent)
class constructor
virtual void setParent(JKQTBasePlotter *parent) override
sets the parent painter class
virtual void setTitle(const QString &title) override
sets the title of the plot (for display in key!).
JKQTPImage(double x, double y, double width, double height, QImage *image, JKQTBasePlotter *parent=nullptr)
class constructor
QImage * getImage()
the image to be plotted. This is freed by the destructor, iff image_owned is set to true (....
Definition jkqtpimage.h:373
virtual ~JKQTPImage() override
JKQTPImage(double x, double y, double width, double height, const QImage &image, JKQTPlotter *parent)
class constructor
void createImageActions()
create QActions that are shown in the context menu of the JKQTPlotter
base class to hold an image from an 2-dimensional array of values
Definition jkqtpimage.h:134
double internalDataMin
internal storage for minimum of the image value range
Definition jkqtpimage.h:265
int getNx() const
width of the data array data in pt
JKQTPMathImageBase(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void *data, int Nx, int Ny, JKQTBasePlotter *parent=nullptr)
class constructor
QVector< double > getDataAsDoubleVector() const
returns the contents of the internal data image as a QVector<double>
double internalDataMax
internal storage for maximum of the image value range
Definition jkqtpimage.h:270
void setNx(size_t __value)
width of the data array data in pt
int Ny
height of the data array data in pt
Definition jkqtpimage.h:253
void setNy(size_t __value)
height of the data array data in pt
virtual JKQTPMathImageDataType getDatatype() const
datatype of the data array data
virtual void setDatatypeModifier(JKQTPMathImageDataType __value)
datatype of the data array data
virtual const void * getDataModifier() const
points to the data array, holding the modifier image
virtual void setDatatype(JKQTPMathImageDataType __value)
datatype of the data array data
virtual JKQTPMathImageDataType getDatatypeModifier() const
datatype of the data array data
double internalModifierMax
internal storage for maximum of the modifier image value range
Definition jkqtpimage.h:280
const void * data
points to the data array, holding the image
Definition jkqtpimage.h:247
virtual const void * getData() const
points to the data array, holding the image
virtual void setDataModifier(const void *__value)
points to the data array, holding the modifier image
JKQTPMathImageDataType datatype
datatype of the data array data
Definition jkqtpimage.h:249
JKQTPMathImageBase(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void *data, int Nx, int Ny, JKQTPlotter *parent)
class constructor
JKQTPMathImageDataType datatypeModifier
datatype of the data array data
Definition jkqtpimage.h:258
virtual void drawKeyMarker(JKQTPEnhancedPainter &painter, const QRectF &rect) override
plots a key marker inside the specified rectangle rect
virtual void getModifierMinMax(double &imin, double &imax)
determine min/max data value of the image
virtual void setDataModifier(const void *data, JKQTPMathImageDataType datatype)
sets dataModifier ( points to the data array, holding the modifier image ) and datatypeModifier ( ...
int getNy() const
height of the data array data in pt
virtual void setData(const void *data, int Nx, int Ny)
sets data ( points to the data array, holding the image ), as well as the size of data (Nx: width...
void setNy(int __value)
height of the data array data in pt
void setNx(int __value)
width of the data array data in pt
QVector< double > getDataModifierAsDoubleVector() const
returns the contents of the internal modifier image as a QVector<double>
JKQTPMathImageBase(double x, double y, double width, double height, JKQTBasePlotter *parent=nullptr)
class constructor
JKQTPMathImageBase(JKQTBasePlotter *parent=nullptr)
class constructor
int Nx
width of the data array data in pt
Definition jkqtpimage.h:251
virtual void ensureImageData()
overwrite this to fill the data poiters before they are accessed (e.g. to load data from a column in ...
JKQTPMathImageBase(double x, double y, double width, double height, JKQTPlotter *parent=nullptr)
class constructor
virtual void setData(const void *__value)
points to the data array, holding the image
virtual void setData(const void *data, int Nx, int Ny, JKQTPMathImageDataType datatype)
sets data ( points to the data array, holding the image ) and datatype ( datatype of the data arr...
virtual void getDataMinMax(double &imin, double &imax)
determine min/max data value of the image
double internalModifierMin
internal storage for minimum of the modifier image value range
Definition jkqtpimage.h:275
JKQTPMathImageBase(JKQTPlotter *parent)
class constructor
const void * dataModifier
points to the data array, holding the modifier image
Definition jkqtpimage.h:256
class to plot an image from an 2-dimensional array of values
Definition jkqtpimage.h:433
void saveColorbarPlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray())
saves an image of the current palette (asking the user for a filename, if filename is empty)
double getModifierValueAt(double x, double y)
return the value (raw data!) of the contained modifier image at the given coordinate
Definition jkqtpimage.h:677
virtual void setTitle(const QString &title) override
sets the title of the plot (for display in key!).
virtual QImage drawImage()
return the plotted image only as a QImage
JKQTPMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void *data, int Nx, int Ny, JKQTPMathImageColorPalette palette, JKQTPlotter *parent)
class constructor
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
JKQTPMathImage(JKQTBasePlotter *parent=nullptr)
class constructor
QAction * actCopyImage
QActions that copies the image into the clipboard.
Definition jkqtpimage.h:547
void saveImagePlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray())
saves the image (asking the user for a filename, if filename is empty)
QAction * actSavePalette
QActions that saves the current palette.
Definition jkqtpimage.h:552
int getSampleSize() const
retrieve size of a single sample in the image data (i.e. size of the datatype)
Definition jkqtpimage.h:647
void copyImagePlotAsImage()
copies the image into the clipboard
void copyColorbarPlotAsImage()
copies an image of the current palette into the clipboard
double getModifierPixelValue(int xIdx, int yIdx) const
retrieve modifier image data at a given position as double
Definition jkqtpimage.h:700
virtual void drawOutside(JKQTPEnhancedPainter &painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace) override
plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
virtual QImage drawOutsidePalette(uint8_t steps=200)
returns a QImage, which contains the plaette drawn outside the plot. steps is the number of data-setp...
int getModifierSampleSize() const
retrieve size of a single sample in the modifier image data (i.e. size of the datatype)
Definition jkqtpimage.h:732
double getValueAt(double x, double y)
return the value (raw data!) of the contained image at the given coordinate
Definition jkqtpimage.h:592
virtual void cbGetDataMinMax(double &imin, double &imax) override
determine min/max data value of the image
JKQTPMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void *data, int Nx, int Ny, JKQTPMathImageColorPalette palette=JKQTPMathImageGRAY, JKQTBasePlotter *parent=nullptr)
class constructor
virtual void drawKeyMarker(JKQTPEnhancedPainter &painter, const QRectF &rect) override
plots a key marker inside the specified rectangle rect
void initJKQTPMathImage()
virtual void cbGetModifierDataMinMax(double &imin, double &imax) override
determine min/max data value of the modifier image
QAction * actCopyPalette
QActions that copies the current palette.
Definition jkqtpimage.h:557
virtual void getOutsideSize(JKQTPEnhancedPainter &painter, int &leftSpace, int &rightSpace, int &topSpace, int &bottomSpace) override
if the graph plots outside the actual plot field of view (e.g. color bars, scale bars,...
virtual void setParent(JKQTBasePlotter *parent) override
sets the parent painter class
virtual void getModifierMinMax(double &imin, double &imax) override
determine min/max data value of the image
double getPixelValue(int xIdx, int yIdx) const
retrieve image data at a given position as double
Definition jkqtpimage.h:615
JKQTPMathImage(JKQTPlotter *parent)
class constructor
QAction * actSaveImage
QActions that saves the image (asking the user for a filename)
Definition jkqtpimage.h:542
virtual void getDataMinMax(double &imin, double &imax) override
determine min/max data value of the image
plotter widget for scientific plots (uses JKQTBasePlotter to do the actual drawing)
Definition jkqtplotter.h:364
JKQTPMathImageDataType
possible datatypes of the data array, plotted by this class.
Definition jkqtpbasicimagetools.h:41
JKQTPMathImageColorPalette
available palettes for coloring an image
Definition jkqtpbasicimagetools.h:84
@ JKQTPMathImageGRAY
Definition jkqtpbasicimagetools.h:85
#define JKQTPLOTTER_LIB_EXPORT
Definition jkqtplotter_imexport.h:89