-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjkqtpimageelements.h
More file actions
executable file
·970 lines (760 loc) · 41.8 KB
/
Copy pathjkqtpimageelements.h
File metadata and controls
executable file
·970 lines (760 loc) · 41.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
/*
Copyright (c) 2008-2015 Jan W. Krieger & Sebastian Isbaner (contour plot), German Cancer Research Center
This software is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL) as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License (LGPL) for more details.
You should have received a copy of the GNU Lesser General Public License (LGPL)
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef JKQTPIMAGEELEMENTS_H
#define JKQTPIMAGEELEMENTS_H
/**
* \defgroup jkqtplotter_imagelots Image Plotting Elements
* \ingroup jkqtplotter_elements
*/
/** \file jkqtpimageelements.h
* \ingroup jkqtplotter_imagelots
*/
#include <QString>
#include <QPainter>
#include <QImage>
#include <QIcon>
#include "jkqtpelements.h"
#include "jkqtptools.h"
#include "jkqtpbaseelements.h"
#include "jkqtp_imexport.h"
#include "jkqtpimagetools.h"
/*! \brief base class for plotting an image
\ingroup jkqtplotter_imagelots
*/
class LIB_EXPORT JKQTPImageBase: public JKQTPgraph {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPImageBase(JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPImageBase(double x, double y, double width, double height, JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPImageBase(JKQtPlotter* parent);
/** \brief class constructor */
JKQTPImageBase(double x, double y, double width, double height, JKQtPlotter* parent);
/** \brief plots a key marker inside the specified rectangle \a rect */
virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect);
/** \brief get the maximum and minimum x-value of the graph
*
* The result is given in the two parameters which are call-by-reference parameters!
*/
virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero);
/** \brief get the maximum and minimum y-value of the graph
*
* The result is given in the two parameters which are call-by-reference parameters!
*/
virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero);
/** \brief returns the color to be used for the key label */
virtual QColor getKeyLabelColor();
JKQTPGET_SET_MACRO(double, x)
JKQTPGET_SET_MACRO(double, y)
JKQTPGET_SET_MACRO(double, width)
JKQTPGET_SET_MACRO(double, height)
protected:
/** \brief x coordinate of lower left corner */
double x;
/** \brief y coordinate of lower left corner */
double y;
/** \brief width of image */
double width;
/** \brief height of image */
double height;
/*! \brief plot the given QImage onto the widget where the QImage fills the area defined by x, y (lower left corner) and width, height
in the simplest case your implementation of draw() will call
<code>plotImage(painter, image, this->x, this->y, this->width, this->height);</code>
*/
virtual void plotImage(JKQTPEnhancedPainter& painter, QImage& image, double x, double y, double width, double height);
};
/*! \brief base class to hold an image from an 2-dimensional array of values
\ingroup jkqtplotter_imagelots
*/
class LIB_EXPORT JKQTPMathImageBase: public JKQTPImageBase {
Q_OBJECT
public:
/** \brief possible datatypes of the data array, plotted by this class. */
enum DataType {
FloatArray,
DoubleArray,
UInt8Array,
UInt16Array,
UInt32Array,
UInt64Array,
Int8Array,
Int16Array,
Int32Array,
Int64Array
};
enum ModifierMode {
ModifyNone=0,
ModifyValue=1,
ModifySaturation=2,
ModifyAlpha=3
};
static ModifierMode StringToModifierMode(const QString& mode) {
QString m=mode.toLower();
if (m=="value" ) return ModifyValue;
if (m=="saturation" ) return ModifySaturation;
if (m=="alpha" ) return ModifyAlpha;
return ModifyNone;
}
static QString ModifierModeToString(const ModifierMode& mode) {
if (mode==ModifyValue) return "value";
if (mode==ModifySaturation) return "saturation";
if (mode==ModifyAlpha) return "alpha";
return "none";
}
/** \brief class constructor */
JKQTPMathImageBase(JKQtBasePlotter* parent=NULL);
JKQTPMathImageBase(double x, double y, double width, double height, JKQtBasePlotter* parent=NULL);
JKQTPMathImageBase(double x, double y, double width, double height, DataType datatype, void* data, uint32_t Nx, uint32_t Ny, JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPMathImageBase(JKQtPlotter* parent);
JKQTPMathImageBase(double x, double y, double width, double height, JKQtPlotter* parent=NULL);
JKQTPMathImageBase(double x, double y, double width, double height, DataType datatype, void* data, uint32_t Nx, uint32_t Ny, JKQtPlotter* parent);
/** \brief plots a key marker inside the specified rectangle \a rect */
virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect);
JKQTPGET_SET_MACRO(uint32_t, Nx)
JKQTPGET_SET_MACRO(uint32_t, Ny)
JKQTPGET_SET_MACRO(void*, data)
JKQTPGET_SET_MACRO(DataType, datatype)
JKQTPGET_SET_MACRO(void*, dataModifier)
JKQTPGET_SET_MACRO(DataType, datatypeModifier)
JKQTPGET_SET_MACRO(ModifierMode, modifierMode)
virtual void set_dataModifier(void* data, DataType datatype);
virtual void set_data(void* data, uint32_t Nx, uint32_t Ny, DataType datatype);
virtual void set_data(void* data, uint32_t Nx, uint32_t Ny);
/** \brief determine min/max data value of the image */
virtual void getDataMinMax(double& imin, double& imax);
/** \brief determine min/max data value of the image */
virtual void getModifierMinMax(double& imin, double& imax);
QVector<double> getDataAsDoubleVector() const;
QVector<double> getDataModifierAsDoubleVector() const;
protected:
/** \brief points to the data array, holding the image */
void* data;
/** \brief datatype of the data array data */
DataType datatype;
/** \brief width of the data array data in pixels */
uint32_t Nx;
/** \brief height of the data array data in pixels */
uint32_t Ny;
/** \brief points to the data array, holding the modifier image */
void* dataModifier;
/** \brief datatype of the data array data */
DataType datatypeModifier;
ModifierMode modifierMode;
double internalDataMin;
double internalDataMax;
double internalModifierMin;
double internalModifierMax;
/** \brief overwrite this to fill the data poiters before they are accessed (e.g. to load data from a column in the datastore */
virtual void ensureImageData();
void modifyImage(QImage& img);
void modifyImage(QImage& img, void* dataModifier, DataType datatypeModifier, uint32_t Nx, uint32_t Ny, double internalModifierMin, double internalModifierMax);
};
/*! \brief a QComboBox which shows JKQTPMathImageBase::ModifierMode
\ingroup jkqtptools
*/
class LIB_EXPORT JKQTPImageModifierModeComboBox: public QComboBox {
Q_OBJECT
public:
JKQTPImageModifierModeComboBox(QWidget* parent=NULL);
JKQTPMathImageBase::ModifierMode getModifierMode() const;
void setModifierMode(JKQTPMathImageBase::ModifierMode mode);
protected:
void addMode(JKQTPMathImageBase::ModifierMode mode, const QString& name, const QIcon& icon=QIcon());
};
/*! \brief class to plot an image from a QImage object
\ingroup jkqtplotter_imagelots
*/
class LIB_EXPORT JKQTPImage: public JKQTPImageBase {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPImage(JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPImage(JKQtPlotter* parent);
/** \brief class constructor */
JKQTPImage(double x, double y, double width, double height, QImage* image, JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPImage(double x, double y, double width, double height, QImage* image, JKQtPlotter* parent);
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw(JKQTPEnhancedPainter& painter);
/** \brief plots a key marker inside the specified rectangle \a rect */
virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect);
JKQTPGET_SET_MACRO(QImage*, image)
protected:
/** \brief the image to be plotted */
QImage* image;
void createImageActions();
protected:
QAction* actSaveImage;
QAction* actCopyImage;
public:
virtual void setParent(JKQtBasePlotter* parent);
virtual void set_title(const typedef_set_title& title);
public slots:
void saveImagePlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray());
void copyImagePlotAsImage();
};
/*! \brief class to plot an image from an 2-dimensional array of values
\ingroup jkqtplotter_imagelots
*/
class LIB_EXPORT JKQTPMathImage: public JKQTPMathImageBase {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPMathImage(double x, double y, double width, double height, DataType datatype, void* data, uint32_t Nx, uint32_t Ny, JKQTPMathImageColorPalette palette=JKQTPMathImageGRAY, JKQtBasePlotter* parent=NULL);
JKQTPMathImage(JKQtBasePlotter* parent=NULL);
JKQTPMathImage(double x, double y, double width, double height, DataType datatype, void* data, uint32_t Nx, uint32_t Ny, JKQTPMathImageColorPalette palette, JKQtPlotter* parent);
JKQTPMathImage(JKQtPlotter* parent);
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw(JKQTPEnhancedPainter& painter);
virtual void setParent(JKQtBasePlotter* parent);
/*! \brief get list with all available palettes */
static QStringList getPalettes() ;
/*! \brief get list with all available palettes */
static int getPalettesCount() ;
/*! \brief get QIcon representing the given palette */
static QIcon getPaletteIcon(int i) ;
/*! \brief get QIcon representing the given palette */
static QIcon getPaletteIcon(JKQTPMathImageColorPalette palette) ;
/*! \brief get QIcon representing the given palette */
static QImage getPaletteImage(int i, int width, int height=1) ;
/*! \brief get QIcon representing the given palette */
static QImage getPaletteImage(JKQTPMathImageColorPalette palette, int width, int height=1) ;
/*! \brief get QIcon representing the given palette */
static QIcon getPaletteKeyIcon(int i) ;
/*! \brief get QIcon representing the given palette */
static QIcon getPaletteKeyIcon(JKQTPMathImageColorPalette palette) ;
/*! \brief get QIcon representing the given palette */
static QImage getPaletteKeyImage(int i, int width, int height) ;
/*! \brief get QIcon representing the given palette */
static QImage getPaletteKeyImage(JKQTPMathImageColorPalette palette, int width, int height) ;
JKQTPGET_SET_MACRO(JKQTPMathImageColorPalette, palette)
JKQTPGET_SET_MACRO(JKQTPMathImageColorRangeFailAction, rangeMinFailAction)
JKQTPGET_SET_MACRO(JKQTPMathImageColorRangeFailAction, rangeMaxFailAction)
JKQTPGET_SET_MACRO(QColor, rangeMinFailColor)
JKQTPGET_SET_MACRO(QColor, rangeMaxFailColor)
JKQTPGET_SET_MACRO(QColor, nanColor)
JKQTPGET_SET_MACRO(QColor, infColor)
JKQTPGET_SET_MACRO(bool, showColorBar)
JKQTPGET_SET_MACRO(int, colorBarWidth)
JKQTPGET_SET_MACRO(int, colorBarModifiedWidth)
JKQTPGET_SET_MACRO(int, colorBarOffset)
JKQTPGET_SET_MACRO(double, colorBarRelativeHeight)
JKQTPGET_SET_MACRO(double, imageMin)
JKQTPGET_SET_MACRO(double, imageMax)
JKQTPGET_SET_MACRO(bool, autoImageRange)
JKQTPGET_SET_MACRO(QString, imageName)
JKQTPGET_SET_MACRO(QString, imageNameFontName)
JKQTPGET_SET_MACRO(double, imageNameFontSize)
JKQTPGET_MACRO(JKQTPverticalIndependentAxis*, colorBarRightAxis)
JKQTPGET_MACRO(JKQTPhorizontalIndependentAxis*, colorBarTopAxis)
JKQTPGET_MACRO(JKQTPverticalIndependentAxis*, modifierColorBarTopAxis)
JKQTPGET_MACRO(JKQTPhorizontalIndependentAxis*, modifierColorBarRightAxis )
JKQTPGET_SET_MACRO(bool, colorBarTopVisible)
JKQTPGET_SET_MACRO(bool, colorBarRightVisible)
JKQTPGET_SET_MACRO(bool, autoModifierRange)
JKQTPGET_SET_MACRO(double, modifierMin)
JKQTPGET_SET_MACRO(double, modifierMax)
void set_palette(int pal);
/*! \brief if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
\note If you want to draw outside, then you'll also have to implement drawOutside()
*/
virtual void getOutsideSize(JKQTPEnhancedPainter& painter, int& leftSpace, int& rightSpace, int& topSpace, int& bottomSpace);
/*! \brief plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
\note If you want to draw outside, then you'll also have to implement getOutsideSize(), so enough space is reserved
The four value supplied tell the method where to draw (inside one of the rectangles).
*/
virtual void drawOutside(JKQTPEnhancedPainter& painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace);
/*! \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. */
virtual QImage drawOutsidePalette(int steps=200);
/*! \brief return the plotted image only as a QImage */
virtual QImage drawImage();
/** \brief determine min/max data value of the image */
virtual void getDataMinMax(double& imin, double& imax);
/** \brief determine min/max data value of the image */
virtual void getModifierMinMax(double& imin, double& imax);
/** \brief return the value (raw data!) of the contained image at the given coordinate */
double getValueAt(double x, double y);
/** \brief plots a key marker inside the specified rectangle \a rect */
virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect);
protected:
void initJKQTPMathImage();
/** \brief top color bar visible */
bool colorBarTopVisible;
/** \brief right color bar visible */
bool colorBarRightVisible;
/** \brief name of the image displayed above color bar (may contain LaTeX markup!) */
QString imageName;
/** \brief font name when displaying imageName */
QString imageNameFontName;
/** \brief font size in points when displaying imageName */
double imageNameFontSize;
/** \brief palette for plotting an image */
JKQTPMathImageColorPalette palette;
/** \brief indicate whether to display a color bar */
bool showColorBar;
/** \brief width of the color bar */
int colorBarWidth;
/** \brief width of the color bar when modifier is on */
int colorBarModifiedWidth;
/** \brief height of the color bar, as multiple of plotHeight */
double colorBarRelativeHeight;
/** \brief indicates whether to estimate min/max of the image automatically */
bool autoImageRange;
/** \brief image value range minimum */
double imageMin;
/** \brief image value range maximum */
double imageMax;
/** \brief indicates whether to estimate min/max of the modifier automatically */
bool autoModifierRange;
/** \brief modifier value range minimum */
double modifierMin;
/** \brief modifier value range maximum */
double modifierMax;
/** \brief offset between outside space border and color bar */
int colorBarOffset;
/** \brief which action to take if a color is below \a imageMin and \a autoImageRange \c ==false */
JKQTPMathImageColorRangeFailAction rangeMinFailAction;
/** \brief which action to take if a color is above \a imageMax and \a autoImageRange \c ==false */
JKQTPMathImageColorRangeFailAction rangeMaxFailAction;
/** \brief color to use for some settings of \a rangeMinFailAction */
QColor rangeMinFailColor;
/** \brief color to use for some settings of \a rangeMaxFailAction */
QColor rangeMaxFailColor;
/** \brief color to use for a not-a-number value */
QColor nanColor;
/** \brief color to use for an infinity value */
QColor infColor;
/** \brief object used for color bar axes
*
* \note this axis has some kind of a special role. It is used to format color bar axes
*/
JKQTPverticalIndependentAxis* colorBarRightAxis;
JKQTPhorizontalIndependentAxis* colorBarTopAxis;
JKQTPverticalIndependentAxis* modifierColorBarTopAxis;
JKQTPhorizontalIndependentAxis* modifierColorBarRightAxis;
protected:
QAction* actSaveImage;
QAction* actCopyImage;
QAction* actSavePalette;
QAction* actCopyPalette;
public:
virtual void set_title(const typedef_set_title& title);
public slots:
void saveImagePlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray());
void copyImagePlotAsImage();
void saveColorbarPlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray());
void copyColorbarPlotAsImage();
};
/*! \brief class to plot an image from an 2-dimensional array of values
\ingroup jkqtplotter_imagelots
*/
class LIB_EXPORT JKQTPRGBMathImage: public JKQTPMathImageBase {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPRGBMathImage(double x, double y, double width, double height, DataType datatype, void* data, uint32_t Nx, uint32_t Ny, JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPRGBMathImage(double x, double y, double width, double height, DataType datatype, void* data, uint32_t Nx, uint32_t Ny, JKQtPlotter* parent);
/** \brief class constructor */
JKQTPRGBMathImage(JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPRGBMathImage(JKQtPlotter* parent);
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw(JKQTPEnhancedPainter& painter);
virtual void setParent(JKQtBasePlotter* parent);
virtual void set_data(void* data, void* dataG, void* dataB, uint32_t Nx, uint32_t Ny, DataType datatype);
virtual void set_data(void* data, void* dataG, void* dataB, uint32_t Nx, uint32_t Ny);
virtual void set_data(void* data, uint32_t Nx, uint32_t Ny, DataType datatype);
virtual void set_data(void* data, uint32_t Nx, uint32_t Ny);
/** \brief determine min/max data value of the image */
virtual void getDataMinMax(double& imin, double& imax);
JKQTPGET_SET_MACRO(void*, dataG)
JKQTPGET_SET_MACRO(DataType, datatypeG)
JKQTPGET_SET_MACRO(void*, dataB)
JKQTPGET_SET_MACRO(DataType, datatypeB)
JKQTPGET_SET_MACRO(bool, showColorBar)
JKQTPGET_SET_MACRO(int, colorBarWidth)
JKQTPGET_SET_MACRO(int, colorBarOffset)
JKQTPGET_SET_MACRO(double, colorBarRelativeHeight)
JKQTPGET_SET_MACRO(double, imageMin)
JKQTPGET_SET_MACRO(double, imageMax)
JKQTPGET_SET_MACRO(double, imageMinG)
JKQTPGET_SET_MACRO(double, imageMaxG)
JKQTPGET_SET_MACRO(double, imageMinB)
JKQTPGET_SET_MACRO(double, imageMaxB)
JKQTPGET_SET_MACRO(bool, autoImageRange)
JKQTPGET_SET_MACRO(QString, imageName)
JKQTPGET_SET_MACRO(QString, imageNameG)
JKQTPGET_SET_MACRO(QString, imageNameB)
JKQTPGET_SET_MACRO(QString, imageNameFontName)
JKQTPGET_SET_MACRO(double, imageNameFontSize)
JKQTPGET_MACRO(JKQTPverticalIndependentAxis*, colorBarRightAxis)
JKQTPGET_MACRO(JKQTPhorizontalIndependentAxis*, colorBarTopAxis)
JKQTPGET_MACRO(JKQTPverticalIndependentAxis*, colorBarRightAxisG)
JKQTPGET_MACRO(JKQTPhorizontalIndependentAxis*, colorBarTopAxisG)
JKQTPGET_MACRO(JKQTPverticalIndependentAxis*, colorBarRightAxisB)
JKQTPGET_MACRO(JKQTPhorizontalIndependentAxis*, colorBarTopAxisB)
JKQTPGET_SET_MACRO(bool, colorBarTopVisible)
JKQTPGET_SET_MACRO(bool, colorBarRightVisible)
JKQTPGET_SET_MACRO(bool, colorbarsSideBySide)
JKQTPGET_SET_MACRO(JKQTPRGBMathImageRGBMode, rgbMode)
QVector<double> getDataGAsDoubleVector() const;
QVector<double> getDataBAsDoubleVector() const;
/*! \brief if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
\note If you want to draw outside, then you'll also have to implement drawOutside()
*/
virtual void getOutsideSize(JKQTPEnhancedPainter& painter, int& leftSpace, int& rightSpace, int& topSpace, int& bottomSpace);
/*! \brief plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
\note If you want to draw outside, then you'll also have to implement getOutsideSize(), so enough space is reserved
The four value supplied tell the method where to draw (inside one of the rectangles).
*/
virtual void drawOutside(JKQTPEnhancedPainter& painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace);
/*! \brief return the plotted image only as a QImage */
virtual QImage drawImage();
/** \brief determine min/max data value of the image */
virtual void getDataMinMaxG(double& imin, double& imax);
/** \brief determine min/max data value of the image */
virtual void getDataMinMaxB(double& imin, double& imax);
/** \brief return the value (raw data!) of the contained image at the given coordinate */
double getValueAt(double x, double y, int channel=0) ;
/** \brief plots a key marker inside the specified rectangle \a rect */
virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect);
protected:
void initObject();
/** \brief points to the data array, holding the image */
void* dataG;
/** \brief datatype of the data array data */
DataType datatypeG;
/** \brief points to the data array, holding the image */
void* dataB;
/** \brief datatype of the data array data */
DataType datatypeB;
JKQTPRGBMathImageRGBMode rgbMode;
/** \brief top color bar visible */
bool colorBarTopVisible;
/** \brief right color bar visible */
bool colorBarRightVisible;
/** \brief name of the image displayed above color bar (may contain LaTeX markup!) */
QString imageName;
/** \brief name of the image displayed above color bar (may contain LaTeX markup!) */
QString imageNameG;
/** \brief name of the image displayed above color bar (may contain LaTeX markup!) */
QString imageNameB;
/** \brief font name when displaying imageName */
QString imageNameFontName;
/** \brief font size in points when displaying imageName */
double imageNameFontSize;
/** \brief indicate whether to display a color bar */
bool showColorBar;
/** \brief width of the color bar */
int colorBarWidth;
/** \brief height of the color bar, as multiple of plotHeight */
double colorBarRelativeHeight;
/** \brief indicates whether to estimate min/max of the image automatically */
bool autoImageRange;
/** \brief image value range minimum */
double imageMin;
/** \brief image value range maximum */
double imageMax;
/** \brief image value range minimum */
double imageMinG;
/** \brief image value range maximum */
double imageMaxG;
/** \brief image value range minimum */
double imageMinB;
/** \brief image value range maximum */
double imageMaxB;
/** \brief offset between outside space border and color bar */
int colorBarOffset;
/** \brief if \c true the different color bars share the space of a single color bar, if set \c false each colorbar uses the space of a single colorbar */
bool colorbarsSideBySide;
/** \brief object used for color bar axes
*
* \note this axis has some kind of a special role. It is used to format color bar axes
*/
JKQTPverticalIndependentAxis* colorBarRightAxis;
JKQTPhorizontalIndependentAxis* colorBarTopAxis;
JKQTPverticalIndependentAxis* colorBarRightAxisG;
JKQTPhorizontalIndependentAxis* colorBarTopAxisG;
JKQTPverticalIndependentAxis* colorBarRightAxisB;
JKQTPhorizontalIndependentAxis* colorBarTopAxisB;
double internalDataMinG;
double internalDataMaxG;
double internalDataMinB;
double internalDataMaxB;
protected:
QAction* actSaveImage;
QAction* actCopyImage;
public:
virtual void set_title(const typedef_set_title& title);
public slots:
void saveImagePlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray());
void copyImagePlotAsImage();
};
/*! \brief class to plot an image from an 2-dimensional array of values stored in a column of the datastore
\ingroup jkqtplotter_imagelots
*/
class LIB_EXPORT JKQTPColumnMathImage: public JKQTPMathImage {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPColumnMathImage(JKQtBasePlotter* parent=NULL);
JKQTPColumnMathImage(double x, double y, double width, double height, uint32_t Nx, uint32_t Ny, JKQtBasePlotter* parent=NULL);
JKQTPColumnMathImage(double x, double y, double width, double height, int imageColumn, uint32_t Nx, uint32_t Ny, JKQTPMathImageColorPalette palette=JKQTPMathImageGRAY, JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPColumnMathImage(JKQtPlotter* parent);
JKQTPColumnMathImage(double x, double y, double width, double height, uint32_t Nx, uint32_t Ny, JKQtPlotter* parent);
JKQTPColumnMathImage(double x, double y, double width, double height, int imageColumn, uint32_t Nx, uint32_t Ny, JKQTPMathImageColorPalette palette, JKQtPlotter* parent);
JKQTPColumnMathImage(double x, double y, double width, double height, int imageColumn, uint32_t Nx, uint32_t Ny, JKQtPlotter* parent);
JKQTPGET_SET_MACRO(int, imageColumn)
JKQTPGET_SET_MACRO(int, modifierColumn)
/** \copydoc JKQTPgraph::usesColumn() */
virtual bool usesColumn(int c);
protected:
/** \brief column containing the displayed image */
int imageColumn;
/** \brief column containing the modifier image */
int modifierColumn;
virtual void ensureImageData();
};
/*! \brief like JKQTPRGBMathImage but reads images from columns of the datastore
\ingroup jkqtplotter_imagelots
*/
class LIB_EXPORT JKQTPColumnRGBMathImage: public JKQTPRGBMathImage {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPColumnRGBMathImage(JKQtBasePlotter* parent=NULL);
JKQTPColumnRGBMathImage(double x, double y, double width, double height, uint32_t Nx, uint32_t Ny, JKQtBasePlotter* parent=NULL);
JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, uint32_t Nx, uint32_t Ny, JKQtBasePlotter* parent=NULL);
JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int imageGColumn, uint32_t Nx, uint32_t Ny, JKQtBasePlotter* parent=NULL);
JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int imageGColumn, int imageBColumn, uint32_t Nx, uint32_t Ny, JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPColumnRGBMathImage(JKQtPlotter* parent);
JKQTPColumnRGBMathImage(double x, double y, double width, double height, uint32_t Nx, uint32_t Ny, JKQtPlotter* parent);
JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, uint32_t Nx, uint32_t Ny, JKQtPlotter* parent);
JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int imageGColumn, uint32_t Nx, uint32_t Ny, JKQtPlotter* parent);
JKQTPColumnRGBMathImage(double x, double y, double width, double height, int imageRColumn, int imageGColumn, int imageBColumn, uint32_t Nx, uint32_t Ny, JKQtPlotter* parent);
JKQTPGET_SET_MACRO(int, imageRColumn)
JKQTPGET_SET_MACRO(int, imageGColumn)
JKQTPGET_SET_MACRO(int, imageBColumn)
JKQTPGET_SET_MACRO(int, modifierColumn)
/** \copydoc JKQTPgraph::usesColumn() */
virtual bool usesColumn(int c);
protected:
/** \brief image column for R channel */
int imageRColumn;
/** \brief image column for G channel */
int imageGColumn;
/** \brief image column for B channel */
int imageBColumn;
/** \brief column containing the modifier image */
int modifierColumn;
void ensureImageData();
};
/*! \brief class to plot an image from an 2-dimensional array of boolean values: alle \c true values are plotted in a given color, while the \c false pixels are drawn in another (default: transparent)
\ingroup jkqtplotter_imagelots
*/
class LIB_EXPORT JKQTPOverlayImage: public JKQTPImageBase {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPOverlayImage(double x, double y, double width, double height, bool* data, uint32_t Nx, uint32_t Ny, QColor colTrue, JKQtBasePlotter* parent=NULL);
JKQTPOverlayImage(JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPOverlayImage(double x, double y, double width, double height, bool* data, uint32_t Nx, uint32_t Ny, QColor colTrue, JKQtPlotter* parent);
JKQTPOverlayImage(JKQtPlotter* parent);
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw(JKQTPEnhancedPainter& painter);
/*! \brief return the plotted image only as a QImage */
virtual QImage drawImage();
/** \brief plots a key marker inside the specified rectangle \a rect */
virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect);
/** \brief returns the color to be used for the key label */
virtual QColor getKeyLabelColor();
JKQTPGET_SET_MACRO(QColor, trueColor)
JKQTPGET_SET_MACRO(QColor, falseColor)
JKQTPGET_SET_MACRO(uint32_t, Nx)
JKQTPGET_SET_MACRO(uint32_t, Ny)
JKQTPGET_SET_MACRO(bool*, data)
void set_data(bool* data, uint32_t Nx, uint32_t Ny);
QVector<double> getDataAsDoubleVector() const;
protected:
/** \brief points to the data array, holding the image */
bool* data;
/** \brief width of the data array data in pixels */
uint32_t Nx;
/** \brief height of the data array data in pixels */
uint32_t Ny;
/** \brief color for \c true pixels */
QColor trueColor;
/** \brief color for \c false pixels */
QColor falseColor;
protected:
QAction* actSaveImage;
QAction* actCopyImage;
public:
virtual void set_title(const typedef_set_title& title);
virtual void setParent(JKQtBasePlotter* parent);
public slots:
void saveImagePlotAsImage(const QString &filename=QString(""), const QByteArray &outputFormat=QByteArray());
void copyImagePlotAsImage();
};
/*! \brief class to plot an image from an 2-dimensional array of boolean values: alle \c true values are plotted in a given color, while the \c false pixels are drawn in another (default: transparent)
\ingroup jkqtplotter_imagelots
In contrast to JKQTPOverlayImage this class draws ist contents as rectangles, not as semi-transparent image. This may lead to nicer results,but could be slower.
Also it is possible to draw other types of markers (cross, circles, ...)
*/
class LIB_EXPORT JKQTPOverlayImageEnhanced: public JKQTPOverlayImage {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPOverlayImageEnhanced(double x, double y, double width, double height, bool* data, uint32_t Nx, uint32_t Ny, QColor colTrue, JKQtBasePlotter* parent=NULL);
JKQTPOverlayImageEnhanced(JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPOverlayImageEnhanced(double x, double y, double width, double height, bool* data, uint32_t Nx, uint32_t Ny, QColor colTrue, JKQtPlotter* parent);
JKQTPOverlayImageEnhanced(JKQtPlotter* parent);
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw(JKQTPEnhancedPainter& painter);
/** \brief plots a key marker inside the specified rectangle \a rect */
virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect);
JKQTPGET_SET_MACRO(JKQTPgraphSymbols, symbol)
JKQTPGET_SET_MACRO(double, symbolWidth)
JKQTPGET_SET_MACRO(bool, drawAsRectangles)
JKQTPGET_SET_MACRO(bool, rectanglesAsImageOverlay)
JKQTPGET_SET_MACRO(double, symbolSizeFactor)
protected:
/** \brief which symbol to use for the datapoints */
JKQTPgraphSymbols symbol;
/** \brief width (in pixels) of the lines used to plot the symbol for the data points */
double symbolWidth;
/** \brief indicates whether to draw filled rectangles (\c false, default) or symbols */
bool drawAsRectangles;
/** \brief a rescaling factor for the symbols */
double symbolSizeFactor;
/** \brief when \c drawAsRectangles==true this reactivates the drawing from JKQTPOverlayImage, i.e. the overlay is not drawn as separated rectangles, but as an overlay image */
bool rectanglesAsImageOverlay;
};
/*! \brief class to plot an image from an 2-dimensional array of boolean values: alle \c true values are plotted in a given color, while the \c false pixels are drawn in another (default: transparent)
\ingroup jkqtplotter_imagelots
In contrast to JKQTPOverlayImage this class draws ist contents as rectangles, not as semi-transparent image. This may lead to nicer results,but could be slower.
Also it is possible to draw other types of markers (cross, circles, ...)
*/
class LIB_EXPORT JKQTPColumnOverlayImageEnhanced: public JKQTPOverlayImageEnhanced {
Q_OBJECT
public:
JKQTPColumnOverlayImageEnhanced(JKQtBasePlotter* parent=NULL);
JKQTPColumnOverlayImageEnhanced(JKQtPlotter* parent);
JKQTPGET_SET_MACRO(int, imageColumn)
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw(JKQTPEnhancedPainter& painter);
/** \copydoc JKQTPgraph::usesColumn() */
virtual bool usesColumn(int c);
protected:
/** \brief top color bar visible */
int imageColumn;
};
/*! \brief class for a contour plot
* \ingroup jkqtplotter_imagelots
* calculates the contour of a given image using the CONREC algorithm
* \link http://paulbourke.net/papers/conrec/
* The implementation for Qt is adapted from Qwt
* \link http://qwt.sourceforge.net/
*
* The contour lines are calculated only once and then redrawn to save plotting time.
* Make sure you add a new graph when your data changes. The contour levels can be defined in
* contourLevels, each elemt in the list represents a contour plane. You can also create contour
* levels with createContourLevels(). The levels are linearly spaced between the maximum and minimum
* value in your data. For logarithmic data, use createContourLevelsLog() to create contour levels
* with logarithmic spacing.
*
* \author Sebastian Isbaner, 2013-2014
*/
class LIB_EXPORT JKQTPContour: public JKQTPMathImage {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPContour(JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPContour(double x, double y, double width, double height, void* data, uint32_t Nx, uint32_t Ny, JKQTPMathImageColorPalette palette=JKQTPMathImageGRAY, DataType datatype = JKQTPMathImageBase::DoubleArray, JKQtBasePlotter* parent=NULL);
/** \brief class constructor */
JKQTPContour(JKQtPlotter* parent);
/** \brief class constructor */
JKQTPContour(double x, double y, double width, double height, void* data, uint32_t Nx, uint32_t Ny, JKQTPMathImageColorPalette palette, DataType datatype , JKQtPlotter* parent);
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw(JKQTPEnhancedPainter& painter);
/** \brief creates at nLevels contour levels linearly spaced between the data's minimum and maximum values */
void createContourLevels(int nLevels=3);
/** \brief creates at least nLevels contour levels with logarithmic spacing. FIXME: Has not been tested yet */
void createContourLevelsLog(int nLevels=3,int m=2);
JKQTPGET_SET_MACRO(QColor, lineColor)
JKQTPGET_SET_MACRO(Qt::PenStyle, style)
JKQTPGET_SET_MACRO(double, lineWidth)
JKQTPGET_SET_MACRO(bool, ignoreOnPlane)
JKQTPGET_SET_MACRO(int, numberOfLevels)
JKQTPGET_SET_MACRO(bool, colorFromPalette)
JKQTPGET_SET_MACRO(QList<double>, contourLevels)
JKQTPGET_SET_MACRO(bool, relativeLevels)
/** convenience function to work with JKQTPdatastore */
void set_imageColumn(size_t columnID);
void addContourLevel(double &level);
protected:
/** \brief color of the contour lines */
QColor lineColor;
/** \brief linestyle of the contour lines */
Qt::PenStyle style;
/** \brief width (pixels) of the graph */
double lineWidth;
/** \brief if true, vertices that all lie on the contour plane will be ignored*/
bool ignoreOnPlane;
/** \brief if true, the colors of the \a palette are used for the contour lines */
bool colorFromPalette;
/** \brief the number of contour levels. Is only used if contourLevels is empty*/
int numberOfLevels;
/** \brief the list of contour levels */
QList<double> contourLevels;
// /** \brief indicates wether the contour levels are absolute values or relative to the maximum (max-min) */
bool relativeLevels;
virtual void ensureImageData();
private:
double value(int xIdx, int yIdx);
/// gives the intersection line of a plane defined by three vertices with a contour level in the x-y plane of heigth level
bool intersect(QLineF &line, const QVector3D &vertex1,const QVector3D &vertex2,const QVector3D &vertex3,const double &level);
/**
* @brief interpolatePoint linear interpolation of a line to the x-y plane using the z-value relative to level
* @param point1 start point of the line
* @param point2 end point of the line
* @param level the heigth for the interpolation (this z-value is projected onto the xy-plane)
* @return the interpolated point in the x-y plane
*/
QPointF interpolatePoint(const QVector3D &point1, const QVector3D &point2,const double &level);
/**
* @brief compare2level checks if the vertex lies above, under or on the contour plane level
* @param vertex
* @param level contour plane
* @return above (1), on the plane (0), below (-1);
*/
int compare2level(const QVector3D &vertex, const double &level);
/**
* @brief calcContourLines calculates the contour lines using the CONREC algorithm
*/
void calcContourLines(QList<QVector<QLineF > > &ContourLines);
/// the contour lines as vector of single lines (one for each triangle). the list index refers to the contour level.
QList<QVector<QLineF > > contourLines; // contour levels, squares on grid, line
};
#endif // JKQTPIMAGEELEMENTS_H