Incompatible change: fix method PLQualitativeHue() to have configurable divergence.
[gencolormap.git] / colormapwidgets.hpp
1 /*
2  * Copyright (C) 2015, 2016, 2017, 2018, 2019
3  * Computer Graphics Group, University of Siegen
4  * Written by Martin Lambers <martin.lambers@uni-siegen.de>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24
25 #ifndef COLORMAPWIDGETS_HPP
26 #define COLORMAPWIDGETS_HPP
27
28 #include <QVector>
29 #include <QWidget>
30
31 class QSpinBox;
32 class QSlider;
33 class QDoubleSpinBox;
34 class QPushButton;
35
36
37 // Internal helper class for a slider/spinbox combination
38 class ColorMapCombinedSliderSpinBox : public QObject
39 {
40 Q_OBJECT
41
42 private:
43     bool _update_lock;
44
45 public:
46     float minval, maxval, step;
47     QSlider* slider;
48     QDoubleSpinBox* spinbox;
49
50     ColorMapCombinedSliderSpinBox(float minval, float maxval, float step);
51     float value() const;
52     void setValue(float v);
53
54 private slots:
55     void sliderChanged();
56     void spinboxChanged();
57
58 signals:
59     void valueChanged(float);
60 };
61
62 /* The ColorMapWidget interface, implemented by all color map method widgets */
63 class ColorMapWidget : public QWidget
64 {
65 Q_OBJECT
66
67 public:
68     ColorMapWidget();
69     ~ColorMapWidget();
70
71     /* Reset all values to their method-specific defaults */
72     virtual void reset() = 0;
73
74     /* Get the color map corresponding to the current values as a vector of colors.
75      * Also return the number of clipped colors unless 'clipped' is NULL. */
76     virtual QVector<QColor> colorMap(int* clipped = NULL) const = 0;
77
78     /* Transform a color map to an image of the specified size. If width or
79      * height is zero, then it will be set to the number of colors in the
80      * color map. */
81     static QImage colorMapImage(const QVector<QColor>& colormap, int width, int height);
82
83     /* Get a rich text string containing the relevant literature reference for this method */
84     virtual QString reference() const = 0;
85
86 signals:
87     void colorMapChanged();
88 };
89
90 class ColorMapBrewerSequentialWidget : public ColorMapWidget
91 {
92 Q_OBJECT
93 private:
94     bool _update_lock;
95     QSpinBox* _n_spinbox;
96     ColorMapCombinedSliderSpinBox* _hue_changer;
97     ColorMapCombinedSliderSpinBox* _warmth_changer;
98     ColorMapCombinedSliderSpinBox* _contrast_changer;
99     ColorMapCombinedSliderSpinBox* _saturation_changer;
100     ColorMapCombinedSliderSpinBox* _brightness_changer;
101 private slots:
102     void update();
103
104 public:
105     ColorMapBrewerSequentialWidget();
106     ~ColorMapBrewerSequentialWidget();
107
108     void reset() override;
109     QVector<QColor> colorMap(int* clipped = NULL) const override;
110     QString reference() const override;
111     void parameters(int& n, float& hue,
112             float& contrast, float& saturation, float& brightness, float& warmth) const;
113 };
114
115 class ColorMapBrewerDivergingWidget : public ColorMapWidget
116 {
117 Q_OBJECT
118 private:
119     bool _update_lock;
120     QSpinBox* _n_spinbox;
121     ColorMapCombinedSliderSpinBox* _hue_changer;
122     ColorMapCombinedSliderSpinBox* _divergence_changer;
123     ColorMapCombinedSliderSpinBox* _warmth_changer;
124     ColorMapCombinedSliderSpinBox* _contrast_changer;
125     ColorMapCombinedSliderSpinBox* _saturation_changer;
126     ColorMapCombinedSliderSpinBox* _brightness_changer;
127 private slots:
128     void update();
129
130 public:
131     ColorMapBrewerDivergingWidget();
132     ~ColorMapBrewerDivergingWidget();
133
134     void reset() override;
135     QVector<QColor> colorMap(int* clipped = NULL) const override;
136     QString reference() const override;
137     void parameters(int& n, float& hue, float& divergence,
138             float& contrast, float& saturation, float& brightness, float& warmth) const;
139 };
140
141 class ColorMapBrewerQualitativeWidget : public ColorMapWidget
142 {
143 Q_OBJECT
144 private:
145     bool _update_lock;
146     QSpinBox* _n_spinbox;
147     ColorMapCombinedSliderSpinBox* _hue_changer;
148     ColorMapCombinedSliderSpinBox* _divergence_changer;
149     ColorMapCombinedSliderSpinBox* _contrast_changer;
150     ColorMapCombinedSliderSpinBox* _saturation_changer;
151     ColorMapCombinedSliderSpinBox* _brightness_changer;
152 private slots:
153     void update();
154
155 public:
156     ColorMapBrewerQualitativeWidget();
157     ~ColorMapBrewerQualitativeWidget();
158
159     void reset() override;
160     QVector<QColor> colorMap(int* clipped = NULL) const override;
161     QString reference() const override;
162     void parameters(int& n, float& hue, float& divergence,
163             float& contrast, float& saturation, float& brightness) const;
164 };
165
166 class ColorMapPLSequentialLightnessWidget : public ColorMapWidget
167 {
168 Q_OBJECT
169 private:
170     bool _update_lock;
171     QSpinBox* _n_spinbox;
172     ColorMapCombinedSliderSpinBox* _saturation_changer;
173     ColorMapCombinedSliderSpinBox* _hue_changer;
174 private slots:
175     void update();
176
177 public:
178     ColorMapPLSequentialLightnessWidget();
179     ~ColorMapPLSequentialLightnessWidget();
180
181     void reset() override;
182     QVector<QColor> colorMap(int* clipped = NULL) const override;
183     QString reference() const override;
184     void parameters(int& n, float& saturation, float& hue) const;
185 };
186
187 class ColorMapPLSequentialSaturationWidget : public ColorMapWidget
188 {
189 Q_OBJECT
190 private:
191     bool _update_lock;
192     QSpinBox* _n_spinbox;
193     ColorMapCombinedSliderSpinBox* _lightness_changer;
194     ColorMapCombinedSliderSpinBox* _saturation_changer;
195     ColorMapCombinedSliderSpinBox* _hue_changer;
196 private slots:
197     void update();
198
199 public:
200     ColorMapPLSequentialSaturationWidget();
201     ~ColorMapPLSequentialSaturationWidget();
202
203     void reset() override;
204     QVector<QColor> colorMap(int* clipped = NULL) const override;
205     QString reference() const override;
206     void parameters(int& n, float& lightness, float& saturation, float& hue) const;
207 };
208
209 class ColorMapPLSequentialRainbowWidget : public ColorMapWidget
210 {
211 Q_OBJECT
212 private:
213     bool _update_lock;
214     QSpinBox* _n_spinbox;
215     ColorMapCombinedSliderSpinBox* _hue_changer;
216     ColorMapCombinedSliderSpinBox* _rotations_changer;
217     ColorMapCombinedSliderSpinBox* _saturation_changer;
218 private slots:
219     void update();
220
221 public:
222     ColorMapPLSequentialRainbowWidget();
223     ~ColorMapPLSequentialRainbowWidget();
224
225     void reset() override;
226     QVector<QColor> colorMap(int* clipped = NULL) const override;
227     QString reference() const override;
228     void parameters(int& n, float& hue, float& rotations, float& saturation) const;
229 };
230
231 class ColorMapPLSequentialBlackBodyWidget : public ColorMapWidget
232 {
233 Q_OBJECT
234 private:
235     bool _update_lock;
236     QSpinBox* _n_spinbox;
237     ColorMapCombinedSliderSpinBox* _temperature_changer;
238     ColorMapCombinedSliderSpinBox* _range_changer;
239     ColorMapCombinedSliderSpinBox* _saturation_changer;
240 private slots:
241     void update();
242
243 public:
244     ColorMapPLSequentialBlackBodyWidget();
245     ~ColorMapPLSequentialBlackBodyWidget();
246
247     void reset() override;
248     QVector<QColor> colorMap(int* clipped = NULL) const override;
249     QString reference() const override;
250     void parameters(int& n, float& temperature, float& range, float& saturation) const;
251 };
252
253 class ColorMapPLDivergingLightnessWidget : public ColorMapWidget
254 {
255 Q_OBJECT
256 private:
257     bool _update_lock;
258     QSpinBox* _n_spinbox;
259     ColorMapCombinedSliderSpinBox* _lightness_changer;
260     ColorMapCombinedSliderSpinBox* _saturation_changer;
261     ColorMapCombinedSliderSpinBox* _hue_changer;
262     ColorMapCombinedSliderSpinBox* _divergence_changer;
263 private slots:
264     void update();
265
266 public:
267     ColorMapPLDivergingLightnessWidget();
268     ~ColorMapPLDivergingLightnessWidget();
269
270     void reset() override;
271     QVector<QColor> colorMap(int* clipped = NULL) const override;
272     QString reference() const override;
273     void parameters(int& n, float& lightness, float& saturation, float& hue, float& divergence) const;
274 };
275
276 class ColorMapPLDivergingSaturationWidget : public ColorMapWidget
277 {
278 Q_OBJECT
279 private:
280     bool _update_lock;
281     QSpinBox* _n_spinbox;
282     ColorMapCombinedSliderSpinBox* _lightness_changer;
283     ColorMapCombinedSliderSpinBox* _saturation_changer;
284     ColorMapCombinedSliderSpinBox* _hue_changer;
285     ColorMapCombinedSliderSpinBox* _divergence_changer;
286 private slots:
287     void update();
288
289 public:
290     ColorMapPLDivergingSaturationWidget();
291     ~ColorMapPLDivergingSaturationWidget();
292
293     void reset() override;
294     QVector<QColor> colorMap(int* clipped = NULL) const override;
295     QString reference() const override;
296     void parameters(int& n, float& lightness, float& saturation, float& hue, float& divergence) const;
297 };
298
299 class ColorMapPLQualitativeHueWidget : public ColorMapWidget
300 {
301 Q_OBJECT
302 private:
303     bool _update_lock;
304     QSpinBox* _n_spinbox;
305     ColorMapCombinedSliderSpinBox* _hue_changer;
306     ColorMapCombinedSliderSpinBox* _divergence_changer;
307     ColorMapCombinedSliderSpinBox* _lightness_changer;
308     ColorMapCombinedSliderSpinBox* _saturation_changer;
309 private slots:
310     void update();
311
312 public:
313     ColorMapPLQualitativeHueWidget();
314     ~ColorMapPLQualitativeHueWidget();
315
316     void reset() override;
317     QVector<QColor> colorMap(int* clipped = NULL) const override;
318     QString reference() const override;
319     void parameters(int& n, float& hue, float& divergence, float& lightness, float& saturation) const;
320 };
321
322 class ColorMapCubeHelixWidget : public ColorMapWidget
323 {
324 Q_OBJECT
325 private:
326     bool _update_lock;
327     QSpinBox* _n_spinbox;
328     ColorMapCombinedSliderSpinBox* _hue_changer;
329     ColorMapCombinedSliderSpinBox* _rotations_changer;
330     ColorMapCombinedSliderSpinBox* _saturation_changer;
331     ColorMapCombinedSliderSpinBox* _gamma_changer;
332 private slots:
333     void update();
334
335 public:
336     ColorMapCubeHelixWidget();
337     ~ColorMapCubeHelixWidget();
338
339     void reset() override;
340     QVector<QColor> colorMap(int* clipped = NULL) const override;
341     QString reference() const override;
342     void parameters(int& n, float& hue, float& rotations,
343             float& saturation, float& gamma) const;
344 };
345
346 class ColorMapMorelandWidget : public ColorMapWidget
347 {
348 Q_OBJECT
349 private:
350     bool _update_lock;
351     QSpinBox* _n_spinbox;
352     QPushButton* _color0_button;
353     QPushButton* _color1_button;
354 private slots:
355     void chooseColor0();
356     void chooseColor1();
357     void update();
358
359 public:
360     ColorMapMorelandWidget();
361     ~ColorMapMorelandWidget();
362
363     void reset() override;
364     QVector<QColor> colorMap(int* clipped = NULL) const override;
365     QString reference() const override;
366     void parameters(int& n,
367             unsigned char& r0, unsigned char& g0, unsigned char& b0,
368             unsigned char& r1, unsigned char& g1, unsigned char& b1) const;
369 };
370
371 class ColorMapMcNamesWidget : public ColorMapWidget
372 {
373 Q_OBJECT
374 private:
375     bool _update_lock;
376     QSpinBox* _n_spinbox;
377     ColorMapCombinedSliderSpinBox* _periods_changer;
378 private slots:
379     void update();
380
381 public:
382     ColorMapMcNamesWidget();
383     ~ColorMapMcNamesWidget();
384
385     void reset() override;
386     QVector<QColor> colorMap(int* clipped = NULL) const override;
387     QString reference() const override;
388     void parameters(int& n, float& p) const;
389 };
390
391 #endif