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