Mercurial > hg > svgui
comparison layer/ColourMapper.cpp @ 197:6b023411087b
* Work on harmonising colour and scale ranges between types of layer
* Add normalize options to colour 3d plot layer
author | Chris Cannam |
---|---|
date | Thu, 01 Feb 2007 14:31:28 +0000 |
parents | 22c99c8aa1e0 |
children | 1ab31723825d |
comparison
equal
deleted
inserted
replaced
196:22c99c8aa1e0 | 197:6b023411087b |
---|---|
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #include "ColourMapper.h" | 16 #include "ColourMapper.h" |
17 | 17 |
18 #include <iostream> | |
19 | |
18 ColourMapper::ColourMapper(int map, float min, float max) : | 20 ColourMapper::ColourMapper(int map, float min, float max) : |
19 QObject(), | 21 QObject(), |
20 m_map(map), | 22 m_map(map), |
21 m_min(min), | 23 m_min(min), |
22 m_max(max) | 24 m_max(max) |
23 { | 25 { |
26 if (m_min == m_max) { | |
27 std::cerr << "WARNING: ColourMapper: min == max (== " << m_min | |
28 << "), adjusting" << std::endl; | |
29 m_max = m_min + 1; | |
30 } | |
24 } | 31 } |
25 | 32 |
26 ColourMapper::~ColourMapper() | 33 ColourMapper::~ColourMapper() |
27 { | 34 { |
28 } | 35 } |
29 | 36 |
30 int | 37 int |
31 ColourMapper::getColourMapCount() | 38 ColourMapper::getColourMapCount() |
32 { | 39 { |
33 return 8; | 40 return 10; |
34 } | 41 } |
35 | 42 |
36 QString | 43 QString |
37 ColourMapper::getColourMapName(int n) | 44 ColourMapper::getColourMapName(int n) |
38 { | 45 { |
39 if (n >= 8) return tr("<unknown>"); | 46 if (n >= getColourMapCount()) return tr("<unknown>"); |
40 StandardMap map = (StandardMap)n; | 47 StandardMap map = (StandardMap)n; |
41 | 48 |
42 switch (map) { | 49 switch (map) { |
43 case DefaultColours: return tr("Default"); | 50 case DefaultColours: return tr("Default"); |
44 case WhiteOnBlack: return tr("White on Black"); | 51 case WhiteOnBlack: return tr("White on Black"); |
46 case RedOnBlue: return tr("Red on Blue"); | 53 case RedOnBlue: return tr("Red on Blue"); |
47 case YellowOnBlack: return tr("Yellow on Black"); | 54 case YellowOnBlack: return tr("Yellow on Black"); |
48 case BlueOnBlack: return tr("Blue on Black"); | 55 case BlueOnBlack: return tr("Blue on Black"); |
49 case Sunset: return tr("Sunset"); | 56 case Sunset: return tr("Sunset"); |
50 case FruitSalad: return tr("Fruit Salad"); | 57 case FruitSalad: return tr("Fruit Salad"); |
58 case Banded: return tr("Banded"); | |
59 case Highlight: return tr("Highlight"); | |
51 } | 60 } |
52 | 61 |
53 return tr("<unknown>"); | 62 return tr("<unknown>"); |
54 } | 63 } |
55 | 64 |
63 float h = 0.f, s = 0.f, v = 0.f, r = 0.f, g = 0.f, b = 0.f; | 72 float h = 0.f, s = 0.f, v = 0.f, r = 0.f, g = 0.f, b = 0.f; |
64 bool hsv = true; | 73 bool hsv = true; |
65 | 74 |
66 float red = 0.f, green = 0.3333f, blue = 0.6666f, pieslice = 0.3333f; | 75 float red = 0.f, green = 0.3333f, blue = 0.6666f, pieslice = 0.3333f; |
67 | 76 |
68 if (m_map >= 8) return Qt::black; | 77 if (m_map >= getColourMapCount()) return Qt::black; |
69 StandardMap map = (StandardMap)m_map; | 78 StandardMap map = (StandardMap)m_map; |
70 | 79 |
71 switch (map) { | 80 switch (map) { |
72 | 81 |
73 case DefaultColours: | 82 case DefaultColours: |
97 s = 1.f; | 106 s = 1.f; |
98 v = norm; | 107 v = norm; |
99 break; | 108 break; |
100 | 109 |
101 case BlueOnBlack: | 110 case BlueOnBlack: |
102 h = blue / 1.f; | 111 h = blue; |
103 s = 1.f; | 112 s = 1.f; |
104 v = norm * 2.f; | 113 v = norm * 2.f; |
105 if (v > 1) { | 114 if (v > 1.f) { |
106 v = 1.f; | 115 v = 1.f; |
107 s = 1.f - (sqrtf(norm) - 0.707f) * 3.414f; | 116 s = 1.f - (sqrtf(norm) - 0.707f) * 3.413f; |
117 if (s < 0.f) s = 0.f; | |
118 if (s > 1.f) s = 1.f; | |
108 } | 119 } |
109 break; | 120 break; |
110 | 121 |
111 case Sunset: | 122 case Sunset: |
112 r = (norm - 0.24f) * 2.38f; | 123 r = (norm - 0.24f) * 2.38f; |
121 if (b < 0.f) b = 0.f; | 132 if (b < 0.f) b = 0.f; |
122 hsv = false; | 133 hsv = false; |
123 break; | 134 break; |
124 | 135 |
125 case FruitSalad: | 136 case FruitSalad: |
126 h = blue + (pieslice/2.f) - norm; | 137 h = blue + (pieslice/6.f) - norm; |
127 if (h < 0.f) h += 1.f; | 138 if (h < 0.f) h += 1.f; |
128 s = 1.f; | 139 s = 1.f; |
129 v = 1.f; | 140 v = 1.f; |
130 break; | 141 break; |
142 | |
143 case Banded: | |
144 if (norm < 0.125) return Qt::darkGreen; | |
145 else if (norm < 0.25) return Qt::green; | |
146 else if (norm < 0.375) return Qt::darkBlue; | |
147 else if (norm < 0.5) return Qt::blue; | |
148 else if (norm < 0.625) return Qt::darkYellow; | |
149 else if (norm < 0.75) return Qt::yellow; | |
150 else if (norm < 0.875) return Qt::darkRed; | |
151 else return Qt::red; | |
152 break; | |
153 | |
154 case Highlight: | |
155 if (norm > 0.99) return Qt::white; | |
156 else return Qt::darkBlue; | |
131 } | 157 } |
132 | 158 |
133 if (hsv) { | 159 if (hsv) { |
134 return QColor::fromHsvF(h, s, v); | 160 return QColor::fromHsvF(h, s, v); |
135 } else { | 161 } else { |
138 } | 164 } |
139 | 165 |
140 QColor | 166 QColor |
141 ColourMapper::getContrastingColour() const | 167 ColourMapper::getContrastingColour() const |
142 { | 168 { |
143 if (m_map >= 8) return Qt::white; | 169 if (m_map >= getColourMapCount()) return Qt::white; |
144 StandardMap map = (StandardMap)m_map; | 170 StandardMap map = (StandardMap)m_map; |
145 | 171 |
146 switch (map) { | 172 switch (map) { |
147 | 173 |
148 case DefaultColours: | 174 case DefaultColours: |
166 case Sunset: | 192 case Sunset: |
167 return Qt::white; | 193 return Qt::white; |
168 | 194 |
169 case FruitSalad: | 195 case FruitSalad: |
170 return Qt::white; | 196 return Qt::white; |
197 | |
198 case Banded: | |
199 return Qt::cyan; | |
200 | |
201 case Highlight: | |
202 return Qt::red; | |
171 } | 203 } |
172 | 204 |
173 return Qt::white; | 205 return Qt::white; |
174 } | 206 } |
175 | 207 |