comparison layer/Colour3DPlotLayer.cpp @ 1105:ea5ae9dd10ba spectrogram-minor-refactor

Convert ColourScaleType into an enum class
author Chris Cannam
date Thu, 14 Jul 2016 16:52:16 +0100
parents 46cc4644206d
children 6d720fe1c8cc
comparison
equal deleted inserted replaced
1104:46cc4644206d 1105:ea5ae9dd10ba
50 m_model(0), 50 m_model(0),
51 m_cache(0), 51 m_cache(0),
52 m_peaksCache(0), 52 m_peaksCache(0),
53 m_cacheValidStart(0), 53 m_cacheValidStart(0),
54 m_cacheValidEnd(0), 54 m_cacheValidEnd(0),
55 m_colourScale(ColourScale::LinearColourScale), 55 m_colourScale(ColourScaleType::Linear),
56 m_colourScaleSet(false), 56 m_colourScaleSet(false),
57 m_colourMap(0), 57 m_colourMap(0),
58 m_gain(1.0), 58 m_gain(1.0),
59 m_binScale(BinScale::Linear), 59 m_binScale(BinScale::Linear),
60 m_normalization(ColumnNormalization::None), 60 m_normalization(ColumnNormalization::None),
82 delete m_peakCache; 82 delete m_peakCache;
83 83
84 cacheInvalid(); //!!! dup with above? 84 cacheInvalid(); //!!! dup with above?
85 } 85 }
86 86
87 ColourScale::Scale 87 ColourScaleType
88 Colour3DPlotLayer::convertToColourScale(int value) 88 Colour3DPlotLayer::convertToColourScale(int value)
89 { 89 {
90 switch (value) { 90 switch (value) {
91 default: 91 default:
92 case 0: return ColourScale::LinearColourScale; 92 case 0: return ColourScaleType::Linear;
93 case 1: return ColourScale::LogColourScale; 93 case 1: return ColourScaleType::Log;
94 case 2: return ColourScale::PlusMinusOneScale; 94 case 2: return ColourScaleType::PlusMinusOne;
95 case 3: return ColourScale::AbsoluteScale; 95 case 3: return ColourScaleType::Absolute;
96 } 96 }
97 } 97 }
98 98
99 int 99 int
100 Colour3DPlotLayer::convertFromColourScale(ColourScale::Scale scale) 100 Colour3DPlotLayer::convertFromColourScale(ColourScaleType scale)
101 { 101 {
102 switch (scale) { 102 switch (scale) {
103 case ColourScale::LinearColourScale: return 0; 103 case ColourScaleType::Linear: return 0;
104 case ColourScale::LogColourScale: return 1; 104 case ColourScaleType::Log: return 1;
105 case ColourScale::PlusMinusOneScale: return 2; 105 case ColourScaleType::PlusMinusOne: return 2;
106 case ColourScale::AbsoluteScale: return 3; 106 case ColourScaleType::Absolute: return 3;
107 107
108 case ColourScale::MeterColourScale: 108 case ColourScaleType::Meter:
109 case ColourScale::PhaseColourScale: 109 case ColourScaleType::Phase:
110 default: return 0; 110 default: return 0;
111 } 111 }
112 } 112 }
113 113
114 std::pair<ColumnNormalization, bool> 114 std::pair<ColumnNormalization, bool>
220 } 220 }
221 221
222 void 222 void
223 Colour3DPlotLayer::modelChanged() 223 Colour3DPlotLayer::modelChanged()
224 { 224 {
225 if (!m_colourScaleSet && m_colourScale == ColourScale::LinearColourScale) { 225 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) {
226 if (m_model) { 226 if (m_model) {
227 if (m_model->shouldUseLogValueScale()) { 227 if (m_model->shouldUseLogValueScale()) {
228 setColourScale(ColourScale::LogColourScale); 228 setColourScale(ColourScaleType::Log);
229 } else { 229 } else {
230 m_colourScaleSet = true; 230 m_colourScaleSet = true;
231 } 231 }
232 } 232 }
233 } 233 }
235 } 235 }
236 236
237 void 237 void
238 Colour3DPlotLayer::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) 238 Colour3DPlotLayer::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
239 { 239 {
240 if (!m_colourScaleSet && m_colourScale == ColourScale::LinearColourScale) { 240 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) {
241 if (m_model && m_model->getWidth() > 50) { 241 if (m_model && m_model->getWidth() > 50) {
242 if (m_model->shouldUseLogValueScale()) { 242 if (m_model->shouldUseLogValueScale()) {
243 setColourScale(ColourScale::LogColourScale); 243 setColourScale(ColourScaleType::Log);
244 } else { 244 } else {
245 m_colourScaleSet = true; 245 m_colourScaleSet = true;
246 } 246 }
247 } 247 }
248 } 248 }
470 setNormalizeVisibleArea(n.second); 470 setNormalizeVisibleArea(n.second);
471 } 471 }
472 } 472 }
473 473
474 void 474 void
475 Colour3DPlotLayer::setColourScale(ColourScale::Scale scale) 475 Colour3DPlotLayer::setColourScale(ColourScaleType scale)
476 { 476 {
477 if (m_colourScale == scale) return; 477 if (m_colourScale == scale) return;
478 m_colourScale = scale; 478 m_colourScale = scale;
479 m_colourScaleSet = true; 479 m_colourScaleSet = true;
480 cacheInvalid(); 480 cacheInvalid();
880 double max = m_model->getMaximumLevel(); 880 double max = m_model->getMaximumLevel();
881 881
882 double mmin = min; 882 double mmin = min;
883 double mmax = max; 883 double mmax = max;
884 884
885 if (m_colourScale == ColourScale::LogColourScale) { 885 if (m_colourScale == ColourScaleType::Log) {
886 LogRange::mapRange(mmin, mmax); 886 LogRange::mapRange(mmin, mmax);
887 } else if (m_colourScale == ColourScale::PlusMinusOneScale) { 887 } else if (m_colourScale == ColourScaleType::PlusMinusOne) {
888 mmin = -1.f; 888 mmin = -1.f;
889 mmax = 1.f; 889 mmax = 1.f;
890 } else if (m_colourScale == ColourScale::AbsoluteScale) { 890 } else if (m_colourScale == ColourScaleType::Absolute) {
891 if (mmin < 0) { 891 if (mmin < 0) {
892 if (fabs(mmin) > fabs(mmax)) mmax = fabs(mmin); 892 if (fabs(mmin) > fabs(mmax)) mmax = fabs(mmin);
893 else mmax = fabs(mmax); 893 else mmax = fabs(mmax);
894 mmin = 0; 894 mmin = 0;
895 } else { 895 } else {
904 paint.setPen(v->getForeground()); 904 paint.setPen(v->getForeground());
905 paint.drawRect(4, 10, cw - 8, ch+1); 905 paint.drawRect(4, 10, cw - 8, ch+1);
906 906
907 for (int y = 0; y < ch; ++y) { 907 for (int y = 0; y < ch; ++y) {
908 double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min; 908 double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min;
909 if (m_colourScale == ColourScale::LogColourScale) { 909 if (m_colourScale == ColourScaleType::Log) {
910 value = LogRange::map(value); 910 value = LogRange::map(value);
911 } 911 }
912 int pixel = int(((value - mmin) * 256) / (mmax - mmin)); 912 int pixel = int(((value - mmin) * 256) / (mmax - mmin));
913 if (pixel >= 0 && pixel < 256) { 913 if (pixel >= 0 && pixel < 256) {
914 QRgb c = m_cache->color(pixel); 914 QRgb c = m_cache->color(pixel);
1181 DenseThreeDimensionalModel::Column values; 1181 DenseThreeDimensionalModel::Column values;
1182 1182
1183 double min = m_model->getMinimumLevel(); 1183 double min = m_model->getMinimumLevel();
1184 double max = m_model->getMaximumLevel(); 1184 double max = m_model->getMaximumLevel();
1185 1185
1186 if (m_colourScale == ColourScale::LogColourScale) { 1186 if (m_colourScale == ColourScaleType::Log) {
1187 LogRange::mapRange(min, max); 1187 LogRange::mapRange(min, max);
1188 } else if (m_colourScale == ColourScale::PlusMinusOneScale) { 1188 } else if (m_colourScale == ColourScaleType::PlusMinusOne) {
1189 min = -1.f; 1189 min = -1.f;
1190 max = 1.f; 1190 max = 1.f;
1191 } else if (m_colourScale == ColourScale::AbsoluteScale) { 1191 } else if (m_colourScale == ColourScaleType::Absolute) {
1192 if (min < 0) { 1192 if (min < 0) {
1193 if (fabs(min) > fabs(max)) max = fabs(min); 1193 if (fabs(min) > fabs(max)) max = fabs(min);
1194 else max = fabs(max); 1194 else max = fabs(max);
1195 min = 0; 1195 min = 0;
1196 } else { 1196 } else {
1231 1231
1232 if (c == fillStart || colMax > visibleMax) visibleMax = colMax; 1232 if (c == fillStart || colMax > visibleMax) visibleMax = colMax;
1233 if (c == fillStart || colMin < visibleMin) visibleMin = colMin; 1233 if (c == fillStart || colMin < visibleMin) visibleMin = colMin;
1234 } 1234 }
1235 1235
1236 if (m_colourScale == ColourScale::LogColourScale) { 1236 if (m_colourScale == ColourScaleType::Log) {
1237 visibleMin = LogRange::map(visibleMin); 1237 visibleMin = LogRange::map(visibleMin);
1238 visibleMax = LogRange::map(visibleMax); 1238 visibleMax = LogRange::map(visibleMax);
1239 if (visibleMin > visibleMax) std::swap(visibleMin, visibleMax); 1239 if (visibleMin > visibleMax) std::swap(visibleMin, visibleMax);
1240 } else if (m_colourScale == ColourScale::AbsoluteScale) { 1240 } else if (m_colourScale == ColourScaleType::Absolute) {
1241 if (visibleMin < 0) { 1241 if (visibleMin < 0) {
1242 if (fabs(visibleMin) > fabs(visibleMax)) visibleMax = fabs(visibleMin); 1242 if (fabs(visibleMin) > fabs(visibleMax)) visibleMax = fabs(visibleMin);
1243 else visibleMax = fabs(visibleMax); 1243 else visibleMax = fabs(visibleMax);
1244 visibleMin = 0; 1244 visibleMin = 0;
1245 } else { 1245 } else {
1278 value = values.at(y); 1278 value = values.at(y);
1279 } 1279 }
1280 1280
1281 value = value * m_gain; 1281 value = value * m_gain;
1282 1282
1283 if (m_colourScale == ColourScale::LogColourScale) { 1283 if (m_colourScale == ColourScaleType::Log) {
1284 value = LogRange::map(value); 1284 value = LogRange::map(value);
1285 } else if (m_colourScale == ColourScale::AbsoluteScale) { 1285 } else if (m_colourScale == ColourScaleType::Absolute) {
1286 value = fabs(value); 1286 value = fabs(value);
1287 } 1287 }
1288 1288
1289 if (normalizeVisible) { 1289 if (normalizeVisible) {
1290 double norm = (value - visibleMin) / (visibleMax - visibleMin); 1290 double norm = (value - visibleMin) / (visibleMax - visibleMin);
1904 void 1904 void
1905 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes) 1905 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes)
1906 { 1906 {
1907 bool ok = false, alsoOk = false; 1907 bool ok = false, alsoOk = false;
1908 1908
1909 ColourScale::Scale colourScale = convertToColourScale 1909 ColourScaleType colourScale = convertToColourScale
1910 (attributes.value("colourScale").toInt(&ok)); 1910 (attributes.value("colourScale").toInt(&ok));
1911 if (ok) setColourScale(colourScale); 1911 if (ok) setColourScale(colourScale);
1912 1912
1913 int colourMap = attributes.value("colourScheme").toInt(&ok); 1913 int colourMap = attributes.value("colourScheme").toInt(&ok);
1914 if (ok) setColourMap(colourMap); 1914 if (ok) setColourMap(colourMap);