Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 1099:5c6271734790 spectrogram-minor-refactor
Switch in "standard" colour scale, bin scale, normalisation -- not quite handled elegantly or correctly yet
author | Chris Cannam |
---|---|
date | Wed, 13 Jul 2016 10:00:21 +0100 |
parents | 179ea8a2f650 |
children | 102f986ec032 |
comparison
equal
deleted
inserted
replaced
1098:d9f1d2756b59 | 1099:5c6271734790 |
---|---|
48 m_model(0), | 48 m_model(0), |
49 m_cache(0), | 49 m_cache(0), |
50 m_peaksCache(0), | 50 m_peaksCache(0), |
51 m_cacheValidStart(0), | 51 m_cacheValidStart(0), |
52 m_cacheValidEnd(0), | 52 m_cacheValidEnd(0), |
53 m_colourScale(LinearScale), | 53 m_colourScale(ColourScale::LinearColourScale), |
54 m_colourScaleSet(false), | 54 m_colourScaleSet(false), |
55 m_colourMap(0), | 55 m_colourMap(0), |
56 m_gain(1.0), | 56 m_gain(1.0), |
57 m_binScale(LinearBinScale), | 57 m_binScale(Colour3DPlotRenderer::LinearBinScale), |
58 m_normalizeColumns(false), | 58 m_normalization(ColumnOp::NoNormalization), |
59 m_normalizeVisibleArea(false), | |
60 m_normalizeHybrid(false), | |
61 m_invertVertical(false), | 59 m_invertVertical(false), |
62 m_opaque(false), | 60 m_opaque(false), |
63 m_smooth(false), | 61 m_smooth(false), |
64 m_peakResolution(256), | 62 m_peakResolution(256), |
65 m_miny(0), | 63 m_miny(0), |
130 } | 128 } |
131 | 129 |
132 void | 130 void |
133 Colour3DPlotLayer::modelChanged() | 131 Colour3DPlotLayer::modelChanged() |
134 { | 132 { |
135 if (!m_colourScaleSet && m_colourScale == LinearScale) { | 133 if (!m_colourScaleSet && m_colourScale == ColourScale::LinearColourScale) { |
136 if (m_model) { | 134 if (m_model) { |
137 if (m_model->shouldUseLogValueScale()) { | 135 if (m_model->shouldUseLogValueScale()) { |
138 setColourScale(LogScale); | 136 setColourScale(ColourScale::LogColourScale); |
139 } else { | 137 } else { |
140 m_colourScaleSet = true; | 138 m_colourScaleSet = true; |
141 } | 139 } |
142 } | 140 } |
143 } | 141 } |
145 } | 143 } |
146 | 144 |
147 void | 145 void |
148 Colour3DPlotLayer::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) | 146 Colour3DPlotLayer::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) |
149 { | 147 { |
150 if (!m_colourScaleSet && m_colourScale == LinearScale) { | 148 if (!m_colourScaleSet && m_colourScale == ColourScale::LinearColourScale) { |
151 if (m_model && m_model->getWidth() > 50) { | 149 if (m_model && m_model->getWidth() > 50) { |
152 if (m_model->shouldUseLogValueScale()) { | 150 if (m_model->shouldUseLogValueScale()) { |
153 setColourScale(LogScale); | 151 setColourScale(ColourScale::LogColourScale); |
154 } else { | 152 } else { |
155 m_colourScaleSet = true; | 153 m_colourScaleSet = true; |
156 } | 154 } |
157 } | 155 } |
158 } | 156 } |
252 if (val < *min) val = *min; | 250 if (val < *min) val = *min; |
253 if (val > *max) val = *max; | 251 if (val > *max) val = *max; |
254 | 252 |
255 } else if (name == "Colour Scale") { | 253 } else if (name == "Colour Scale") { |
256 | 254 |
255 // linear, log, +/-1, abs | |
257 *min = 0; | 256 *min = 0; |
258 *max = 3; | 257 *max = 3; |
259 *deflt = (int)LinearScale; | 258 *deflt = 0; |
260 | 259 |
261 val = (int)m_colourScale; | 260 val = (int)m_colourScale; |
262 | 261 |
263 } else if (name == "Colour") { | 262 } else if (name == "Colour") { |
264 | 263 |
266 *max = ColourMapper::getColourMapCount() - 1; | 265 *max = ColourMapper::getColourMapCount() - 1; |
267 *deflt = 0; | 266 *deflt = 0; |
268 | 267 |
269 val = m_colourMap; | 268 val = m_colourMap; |
270 | 269 |
271 } else if (name == "Normalize Columns") { | 270 } else if (name == "Normalization") { |
272 | 271 |
273 *deflt = 0; | 272 *min = 0; |
274 val = (m_normalizeColumns ? 1 : 0); | 273 *max = 3; |
275 | 274 *deflt = int(ColumnOp::NoNormalization); |
276 } else if (name == "Normalize Visible Area") { | 275 val = (int)m_normalization; |
277 | |
278 *deflt = 0; | |
279 val = (m_normalizeVisibleArea ? 1 : 0); | |
280 | 276 |
281 } else if (name == "Invert Vertical Scale") { | 277 } else if (name == "Invert Vertical Scale") { |
282 | 278 |
283 *deflt = 0; | 279 *deflt = 0; |
284 val = (m_invertVertical ? 1 : 0); | 280 val = (m_invertVertical ? 1 : 0); |
285 | 281 |
286 } else if (name == "Bin Scale") { | 282 } else if (name == "Bin Scale") { |
287 | 283 |
288 *min = 0; | 284 *min = 0; |
289 *max = 1; | 285 *max = 1; |
290 *deflt = int(LinearBinScale); | 286 *deflt = int(Colour3DPlotRenderer::LinearBinScale); |
291 val = (int)m_binScale; | 287 val = (int)m_binScale; |
292 | 288 |
293 } else if (name == "Opaque") { | 289 } else if (name == "Opaque") { |
294 | 290 |
295 *deflt = 0; | 291 *deflt = 0; |
315 return ColourMapper::getColourMapName(value); | 311 return ColourMapper::getColourMapName(value); |
316 } | 312 } |
317 if (name == "Colour Scale") { | 313 if (name == "Colour Scale") { |
318 switch (value) { | 314 switch (value) { |
319 default: | 315 default: |
316 //!!! yuck | |
320 case 0: return tr("Linear"); | 317 case 0: return tr("Linear"); |
321 case 1: return tr("Log"); | 318 case 1: return tr("Log"); |
322 case 2: return tr("+/-1"); | 319 case 2: return tr("+/-1"); |
323 case 3: return tr("Absolute"); | 320 case 3: return tr("Absolute"); |
324 } | 321 } |
322 } | |
323 if (name == "Normalization") { | |
324 return ""; // icon only | |
325 } | 325 } |
326 if (name == "Bin Scale") { | 326 if (name == "Bin Scale") { |
327 switch (value) { | 327 switch (value) { |
328 default: | 328 default: |
329 case 0: return tr("Linear"); | 329 case 0: return tr("Linear"); |
331 } | 331 } |
332 } | 332 } |
333 return tr("<unknown>"); | 333 return tr("<unknown>"); |
334 } | 334 } |
335 | 335 |
336 QString | |
337 Colour3DPlotLayer::getPropertyValueIconName(const PropertyName &name, | |
338 int value) const | |
339 { | |
340 if (name == "Normalization") { | |
341 switch(value) { | |
342 default: | |
343 case 0: return "normalise-none"; | |
344 case 1: return "normalise-columns"; | |
345 case 2: return "normalise"; | |
346 case 3: return "normalise-hybrid"; | |
347 } | |
348 } | |
349 return ""; | |
350 } | |
351 | |
336 RangeMapper * | 352 RangeMapper * |
337 Colour3DPlotLayer::getNewPropertyRangeMapper(const PropertyName &name) const | 353 Colour3DPlotLayer::getNewPropertyRangeMapper(const PropertyName &name) const |
338 { | 354 { |
339 if (name == "Gain") { | 355 if (name == "Gain") { |
340 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB")); | 356 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB")); |
348 if (name == "Gain") { | 364 if (name == "Gain") { |
349 setGain(float(pow(10, value/20.0))); | 365 setGain(float(pow(10, value/20.0))); |
350 } else if (name == "Colour Scale") { | 366 } else if (name == "Colour Scale") { |
351 switch (value) { | 367 switch (value) { |
352 default: | 368 default: |
353 case 0: setColourScale(LinearScale); break; | 369 case 0: setColourScale(ColourScale::LinearColourScale); break; |
354 case 1: setColourScale(LogScale); break; | 370 case 1: setColourScale(ColourScale::LogColourScale); break; |
355 case 2: setColourScale(PlusMinusOneScale); break; | 371 case 2: setColourScale(ColourScale::PlusMinusOneScale); break; |
356 case 3: setColourScale(AbsoluteScale); break; | 372 case 3: setColourScale(ColourScale::AbsoluteScale); break; |
357 } | 373 } |
358 } else if (name == "Colour") { | 374 } else if (name == "Colour") { |
359 setColourMap(value); | 375 setColourMap(value); |
360 } else if (name == "Normalize Columns") { | |
361 setNormalizeColumns(value ? true : false); | |
362 } else if (name == "Normalize Visible Area") { | |
363 setNormalizeVisibleArea(value ? true : false); | |
364 } else if (name == "Invert Vertical Scale") { | 376 } else if (name == "Invert Vertical Scale") { |
365 setInvertVertical(value ? true : false); | 377 setInvertVertical(value ? true : false); |
366 } else if (name == "Opaque") { | 378 } else if (name == "Opaque") { |
367 setOpaque(value ? true : false); | 379 setOpaque(value ? true : false); |
368 } else if (name == "Smooth") { | 380 } else if (name == "Smooth") { |
369 setSmooth(value ? true : false); | 381 setSmooth(value ? true : false); |
370 } else if (name == "Bin Scale") { | 382 } else if (name == "Bin Scale") { |
371 switch (value) { | 383 switch (value) { |
372 default: | 384 default: |
373 case 0: setBinScale(LinearBinScale); break; | 385 case 0: setBinScale(Colour3DPlotRenderer::LinearBinScale); break; |
374 case 1: setBinScale(LogBinScale); break; | 386 case 1: setBinScale(Colour3DPlotRenderer::LogBinScale); break; |
375 } | 387 } |
376 } | 388 } else if (name == "Normalization") { |
377 } | 389 switch (value) { |
378 | 390 default: |
379 void | 391 case 0: setNormalization(ColumnOp::NoNormalization); break; |
380 Colour3DPlotLayer::setColourScale(ColourScale scale) | 392 case 1: setNormalization(ColumnOp::NormalizeColumns); break; |
393 case 2: setNormalization(ColumnOp::NormalizeVisibleArea); break; | |
394 case 3: setNormalization(ColumnOp::NormalizeHybrid); break; | |
395 } | |
396 } | |
397 } | |
398 | |
399 void | |
400 Colour3DPlotLayer::setColourScale(ColourScale::Scale scale) | |
381 { | 401 { |
382 if (m_colourScale == scale) return; | 402 if (m_colourScale == scale) return; |
383 m_colourScale = scale; | 403 m_colourScale = scale; |
384 m_colourScaleSet = true; | 404 m_colourScaleSet = true; |
385 cacheInvalid(); | 405 cacheInvalid(); |
409 { | 429 { |
410 return m_gain; | 430 return m_gain; |
411 } | 431 } |
412 | 432 |
413 void | 433 void |
414 Colour3DPlotLayer::setBinScale(BinScale binScale) | 434 Colour3DPlotLayer::setBinScale(Colour3DPlotRenderer::BinScale binScale) |
415 { | 435 { |
416 if (m_binScale == binScale) return; | 436 if (m_binScale == binScale) return; |
417 m_binScale = binScale; | 437 m_binScale = binScale; |
418 cacheInvalid(); | 438 cacheInvalid(); |
419 emit layerParametersChanged(); | 439 emit layerParametersChanged(); |
420 } | 440 } |
421 | 441 |
422 Colour3DPlotLayer::BinScale | 442 Colour3DPlotRenderer::BinScale |
423 Colour3DPlotLayer::getBinScale() const | 443 Colour3DPlotLayer::getBinScale() const |
424 { | 444 { |
425 return m_binScale; | 445 return m_binScale; |
426 } | 446 } |
427 | 447 |
428 void | 448 void |
429 Colour3DPlotLayer::setNormalizeColumns(bool n) | 449 Colour3DPlotLayer::setNormalization(ColumnOp::Normalization n) |
430 { | 450 { |
431 if (m_normalizeColumns == n) return; | 451 if (m_normalization == n) return; |
432 m_normalizeColumns = n; | 452 |
453 m_normalization = n; | |
433 cacheInvalid(); | 454 cacheInvalid(); |
455 | |
434 emit layerParametersChanged(); | 456 emit layerParametersChanged(); |
435 } | 457 } |
436 | 458 |
437 bool | 459 ColumnOp::Normalization |
438 Colour3DPlotLayer::getNormalizeColumns() const | 460 Colour3DPlotLayer::getNormalization() const |
439 { | 461 { |
440 return m_normalizeColumns; | 462 return m_normalization; |
441 } | |
442 | |
443 void | |
444 Colour3DPlotLayer::setNormalizeHybrid(bool n) | |
445 { | |
446 if (m_normalizeHybrid == n) return; | |
447 m_normalizeHybrid = n; | |
448 cacheInvalid(); | |
449 emit layerParametersChanged(); | |
450 } | |
451 | |
452 bool | |
453 Colour3DPlotLayer::getNormalizeHybrid() const | |
454 { | |
455 return m_normalizeHybrid; | |
456 } | |
457 | |
458 void | |
459 Colour3DPlotLayer::setNormalizeVisibleArea(bool n) | |
460 { | |
461 if (m_normalizeVisibleArea == n) return; | |
462 m_normalizeVisibleArea = n; | |
463 cacheInvalid(); | |
464 emit layerParametersChanged(); | |
465 } | |
466 | |
467 bool | |
468 Colour3DPlotLayer::getNormalizeVisibleArea() const | |
469 { | |
470 return m_normalizeVisibleArea; | |
471 } | 463 } |
472 | 464 |
473 void | 465 void |
474 Colour3DPlotLayer::setInvertVertical(bool n) | 466 Colour3DPlotLayer::setInvertVertical(bool n) |
475 { | 467 { |
538 } | 530 } |
539 | 531 |
540 bool | 532 bool |
541 Colour3DPlotLayer::isLayerScrollable(const LayerGeometryProvider *v) const | 533 Colour3DPlotLayer::isLayerScrollable(const LayerGeometryProvider *v) const |
542 { | 534 { |
543 if (m_normalizeVisibleArea) { | 535 if (m_normalization == ColumnOp::NormalizeVisibleArea) { |
544 return false; | 536 return false; |
545 } | 537 } |
546 if (shouldPaintDenseIn(v)) { | 538 if (shouldPaintDenseIn(v)) { |
547 return true; | 539 return true; |
548 } | 540 } |
658 double y = bin; | 650 double y = bin; |
659 if (!m_model) return y; | 651 if (!m_model) return y; |
660 double mn = 0, mx = m_model->getHeight(); | 652 double mn = 0, mx = m_model->getHeight(); |
661 getDisplayExtents(mn, mx); | 653 getDisplayExtents(mn, mx); |
662 double h = v->getPaintHeight(); | 654 double h = v->getPaintHeight(); |
663 if (m_binScale == LinearBinScale) { | 655 if (m_binScale == Colour3DPlotRenderer::LinearBinScale) { |
664 y = h - (((bin - mn) * h) / (mx - mn)); | 656 y = h - (((bin - mn) * h) / (mx - mn)); |
665 } else { | 657 } else { |
666 double logmin = mn + 1, logmax = mx + 1; | 658 double logmin = mn + 1, logmax = mx + 1; |
667 LogRange::mapRange(logmin, logmax); | 659 LogRange::mapRange(logmin, logmax); |
668 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin)); | 660 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin)); |
676 double bin = y; | 668 double bin = y; |
677 if (!m_model) return bin; | 669 if (!m_model) return bin; |
678 double mn = 0, mx = m_model->getHeight(); | 670 double mn = 0, mx = m_model->getHeight(); |
679 getDisplayExtents(mn, mx); | 671 getDisplayExtents(mn, mx); |
680 double h = v->getPaintHeight(); | 672 double h = v->getPaintHeight(); |
681 if (m_binScale == LinearBinScale) { | 673 if (m_binScale == Colour3DPlotRenderer::LinearBinScale) { |
682 bin = mn + ((h - y) * (mx - mn)) / h; | 674 bin = mn + ((h - y) * (mx - mn)) / h; |
683 } else { | 675 } else { |
684 double logmin = mn + 1, logmax = mx + 1; | 676 double logmin = mn + 1, logmax = mx + 1; |
685 LogRange::mapRange(logmin, logmax); | 677 LogRange::mapRange(logmin, logmax); |
686 bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1; | 678 bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1; |
796 double max = m_model->getMaximumLevel(); | 788 double max = m_model->getMaximumLevel(); |
797 | 789 |
798 double mmin = min; | 790 double mmin = min; |
799 double mmax = max; | 791 double mmax = max; |
800 | 792 |
801 if (m_colourScale == LogScale) { | 793 if (m_colourScale == ColourScale::LogColourScale) { |
802 LogRange::mapRange(mmin, mmax); | 794 LogRange::mapRange(mmin, mmax); |
803 } else if (m_colourScale == PlusMinusOneScale) { | 795 } else if (m_colourScale == ColourScale::PlusMinusOneScale) { |
804 mmin = -1.f; | 796 mmin = -1.f; |
805 mmax = 1.f; | 797 mmax = 1.f; |
806 } else if (m_colourScale == AbsoluteScale) { | 798 } else if (m_colourScale == ColourScale::AbsoluteScale) { |
807 if (mmin < 0) { | 799 if (mmin < 0) { |
808 if (fabs(mmin) > fabs(mmax)) mmax = fabs(mmin); | 800 if (fabs(mmin) > fabs(mmax)) mmax = fabs(mmin); |
809 else mmax = fabs(mmax); | 801 else mmax = fabs(mmax); |
810 mmin = 0; | 802 mmin = 0; |
811 } else { | 803 } else { |
820 paint.setPen(v->getForeground()); | 812 paint.setPen(v->getForeground()); |
821 paint.drawRect(4, 10, cw - 8, ch+1); | 813 paint.drawRect(4, 10, cw - 8, ch+1); |
822 | 814 |
823 for (int y = 0; y < ch; ++y) { | 815 for (int y = 0; y < ch; ++y) { |
824 double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min; | 816 double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min; |
825 if (m_colourScale == LogScale) { | 817 if (m_colourScale == ColourScale::LogColourScale) { |
826 value = LogRange::map(value); | 818 value = LogRange::map(value); |
827 } | 819 } |
828 int pixel = int(((value - mmin) * 256) / (mmax - mmin)); | 820 int pixel = int(((value - mmin) * 256) / (mmax - mmin)); |
829 if (pixel >= 0 && pixel < 256) { | 821 if (pixel >= 0 && pixel < 256) { |
830 QRgb c = m_cache->color(pixel); | 822 QRgb c = m_cache->color(pixel); |
933 { | 925 { |
934 Profiler profiler("Colour3DPlotLayer::getColumn"); | 926 Profiler profiler("Colour3DPlotLayer::getColumn"); |
935 | 927 |
936 DenseThreeDimensionalModel::Column values = m_model->getColumn(col); | 928 DenseThreeDimensionalModel::Column values = m_model->getColumn(col); |
937 values.resize(m_model->getHeight(), 0.f); | 929 values.resize(m_model->getHeight(), 0.f); |
938 if (!m_normalizeColumns && !m_normalizeHybrid) return values; | 930 if (m_normalization != ColumnOp::NormalizeColumns && |
931 m_normalization != ColumnOp::NormalizeHybrid) { | |
932 return values; | |
933 } | |
939 | 934 |
940 double colMax = 0.f, colMin = 0.f; | 935 double colMax = 0.f, colMin = 0.f; |
941 double min = 0.f, max = 0.f; | 936 double min = 0.f, max = 0.f; |
942 | 937 |
943 int nv = int(values.size()); | 938 int nv = int(values.size()); |
958 double newvalue = min + (max - min) * norm; | 953 double newvalue = min + (max - min) * norm; |
959 | 954 |
960 if (value != newvalue) values[y] = float(newvalue); | 955 if (value != newvalue) values[y] = float(newvalue); |
961 } | 956 } |
962 | 957 |
963 if (m_normalizeHybrid && (colMax > 0.0)) { | 958 if (m_normalization == ColumnOp::NormalizeHybrid |
959 && (colMax > 0.0)) { | |
964 double logmax = log10(colMax); | 960 double logmax = log10(colMax); |
965 for (int y = 0; y < nv; ++y) { | 961 for (int y = 0; y < nv; ++y) { |
966 values[y] = float(values[y] * logmax); | 962 values[y] = float(values[y] * logmax); |
967 } | 963 } |
968 } | 964 } |
1026 cerr << "Colour3DPlotLayer::fillCache: Have no cache, making one" << endl; | 1022 cerr << "Colour3DPlotLayer::fillCache: Have no cache, making one" << endl; |
1027 #endif | 1023 #endif |
1028 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8); | 1024 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8); |
1029 m_cache->setColorCount(256); | 1025 m_cache->setColorCount(256); |
1030 m_cache->fill(0); | 1026 m_cache->fill(0); |
1031 if (!m_normalizeVisibleArea) { | 1027 if (m_normalization != ColumnOp::NormalizeVisibleArea) { |
1032 m_peaksCache = new QImage | 1028 m_peaksCache = new QImage |
1033 (cacheWidth / m_peakResolution + 1, cacheHeight, | 1029 (cacheWidth / m_peakResolution + 1, cacheHeight, |
1034 QImage::Format_Indexed8); | 1030 QImage::Format_Indexed8); |
1035 m_peaksCache->setColorCount(256); | 1031 m_peaksCache->setColorCount(256); |
1036 m_peaksCache->fill(0); | 1032 m_peaksCache->fill(0); |
1061 if (fillStart < 0) fillStart = 0; | 1057 if (fillStart < 0) fillStart = 0; |
1062 if (fillEnd >= cacheWidth) fillEnd = cacheWidth-1; | 1058 if (fillEnd >= cacheWidth) fillEnd = cacheWidth-1; |
1063 if (fillEnd < 0) fillEnd = 0; | 1059 if (fillEnd < 0) fillEnd = 0; |
1064 if (fillEnd < fillStart) fillEnd = fillStart; | 1060 if (fillEnd < fillStart) fillEnd = fillStart; |
1065 | 1061 |
1066 bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns); | 1062 bool normalizeVisible = (m_normalization == ColumnOp::NormalizeVisibleArea); |
1067 | 1063 |
1068 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) { | 1064 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) { |
1069 | 1065 |
1070 if (m_cacheValidEnd < fillStart) { | 1066 if (m_cacheValidEnd < fillStart) { |
1071 fillStart = m_cacheValidEnd + 1; | 1067 fillStart = m_cacheValidEnd + 1; |
1093 DenseThreeDimensionalModel::Column values; | 1089 DenseThreeDimensionalModel::Column values; |
1094 | 1090 |
1095 double min = m_model->getMinimumLevel(); | 1091 double min = m_model->getMinimumLevel(); |
1096 double max = m_model->getMaximumLevel(); | 1092 double max = m_model->getMaximumLevel(); |
1097 | 1093 |
1098 if (m_colourScale == LogScale) { | 1094 if (m_colourScale == ColourScale::LogColourScale) { |
1099 LogRange::mapRange(min, max); | 1095 LogRange::mapRange(min, max); |
1100 } else if (m_colourScale == PlusMinusOneScale) { | 1096 } else if (m_colourScale == ColourScale::PlusMinusOneScale) { |
1101 min = -1.f; | 1097 min = -1.f; |
1102 max = 1.f; | 1098 max = 1.f; |
1103 } else if (m_colourScale == AbsoluteScale) { | 1099 } else if (m_colourScale == ColourScale::AbsoluteScale) { |
1104 if (min < 0) { | 1100 if (min < 0) { |
1105 if (fabs(min) > fabs(max)) max = fabs(min); | 1101 if (fabs(min) > fabs(max)) max = fabs(min); |
1106 else max = fabs(max); | 1102 else max = fabs(max); |
1107 min = 0; | 1103 min = 0; |
1108 } else { | 1104 } else { |
1143 | 1139 |
1144 if (c == fillStart || colMax > visibleMax) visibleMax = colMax; | 1140 if (c == fillStart || colMax > visibleMax) visibleMax = colMax; |
1145 if (c == fillStart || colMin < visibleMin) visibleMin = colMin; | 1141 if (c == fillStart || colMin < visibleMin) visibleMin = colMin; |
1146 } | 1142 } |
1147 | 1143 |
1148 if (m_colourScale == LogScale) { | 1144 if (m_colourScale == ColourScale::LogColourScale) { |
1149 visibleMin = LogRange::map(visibleMin); | 1145 visibleMin = LogRange::map(visibleMin); |
1150 visibleMax = LogRange::map(visibleMax); | 1146 visibleMax = LogRange::map(visibleMax); |
1151 if (visibleMin > visibleMax) std::swap(visibleMin, visibleMax); | 1147 if (visibleMin > visibleMax) std::swap(visibleMin, visibleMax); |
1152 } else if (m_colourScale == AbsoluteScale) { | 1148 } else if (m_colourScale == ColourScale::AbsoluteScale) { |
1153 if (visibleMin < 0) { | 1149 if (visibleMin < 0) { |
1154 if (fabs(visibleMin) > fabs(visibleMax)) visibleMax = fabs(visibleMin); | 1150 if (fabs(visibleMin) > fabs(visibleMax)) visibleMax = fabs(visibleMin); |
1155 else visibleMax = fabs(visibleMax); | 1151 else visibleMax = fabs(visibleMax); |
1156 visibleMin = 0; | 1152 visibleMin = 0; |
1157 } else { | 1153 } else { |
1190 value = values.at(y); | 1186 value = values.at(y); |
1191 } | 1187 } |
1192 | 1188 |
1193 value = value * m_gain; | 1189 value = value * m_gain; |
1194 | 1190 |
1195 if (m_colourScale == LogScale) { | 1191 if (m_colourScale == ColourScale::LogColourScale) { |
1196 value = LogRange::map(value); | 1192 value = LogRange::map(value); |
1197 } else if (m_colourScale == AbsoluteScale) { | 1193 } else if (m_colourScale == ColourScale::AbsoluteScale) { |
1198 value = fabs(value); | 1194 value = fabs(value); |
1199 } | 1195 } |
1200 | 1196 |
1201 if (normalizeVisible) { | 1197 if (normalizeVisible) { |
1202 double norm = (value - visibleMin) / (visibleMax - visibleMin); | 1198 double norm = (value - visibleMin) / (visibleMax - visibleMin); |
1297 << "nothing to paint (yet)" << endl; | 1293 << "nothing to paint (yet)" << endl; |
1298 #endif | 1294 #endif |
1299 return; | 1295 return; |
1300 } | 1296 } |
1301 | 1297 |
1302 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->getPaintRect(); | 1298 if (m_normalization == ColumnOp::NormalizeVisibleArea) { |
1299 rect = v->getPaintRect(); | |
1300 } | |
1303 | 1301 |
1304 sv_frame_t modelStart = m_model->getStartFrame(); | 1302 sv_frame_t modelStart = m_model->getStartFrame(); |
1305 sv_frame_t modelEnd = m_model->getEndFrame(); | 1303 sv_frame_t modelEnd = m_model->getEndFrame(); |
1306 int modelResolution = m_model->getResolution(); | 1304 int modelResolution = m_model->getResolution(); |
1307 | 1305 |
1697 } | 1695 } |
1698 | 1696 |
1699 return true; | 1697 return true; |
1700 } | 1698 } |
1701 | 1699 |
1700 static ColourScale::Scale | |
1701 convertInColourScale(int fileScale) | |
1702 { | |
1703 //!!! this is very badly handled, switching the enum directly for | |
1704 //!!! the ColourScale one did not work out well! | |
1705 | |
1706 switch (fileScale) { | |
1707 default: | |
1708 case 0: return ColourScale::LinearColourScale; | |
1709 case 1: return ColourScale::LogColourScale; | |
1710 case 2: return ColourScale::PlusMinusOneScale; | |
1711 case 3: return ColourScale::AbsoluteScale; | |
1712 } | |
1713 } | |
1714 | |
1715 static int | |
1716 convertOutColourScale(ColourScale::Scale scale) | |
1717 { | |
1718 switch (scale) { | |
1719 case ColourScale::LinearColourScale: return 0; | |
1720 case ColourScale::LogColourScale: return 1; | |
1721 case ColourScale::PlusMinusOneScale: return 2; | |
1722 case ColourScale::AbsoluteScale: return 3; | |
1723 | |
1724 case ColourScale::MeterColourScale: | |
1725 case ColourScale::PhaseColourScale: | |
1726 default: return 0; | |
1727 } | |
1728 } | |
1729 | |
1702 void | 1730 void |
1703 Colour3DPlotLayer::toXml(QTextStream &stream, | 1731 Colour3DPlotLayer::toXml(QTextStream &stream, |
1704 QString indent, QString extraAttributes) const | 1732 QString indent, QString extraAttributes) const |
1705 { | 1733 { |
1706 QString s = QString("scale=\"%1\" " | 1734 QString s = QString("scale=\"%1\" " |
1707 "colourScheme=\"%2\" " | 1735 "colourScheme=\"%2\" " |
1708 "normalizeColumns=\"%3\" " | 1736 "minY=\"%3\" " |
1709 "normalizeVisibleArea=\"%4\" " | 1737 "maxY=\"%4\" " |
1710 "minY=\"%5\" " | 1738 "invertVertical=\"%5\" " |
1711 "maxY=\"%6\" " | 1739 "opaque=\"%6\" %7") |
1712 "invertVertical=\"%7\" " | 1740 .arg(convertOutColourScale(m_colourScale)) |
1713 "opaque=\"%8\" %9") | |
1714 .arg((int)m_colourScale) | |
1715 .arg(m_colourMap) | 1741 .arg(m_colourMap) |
1716 .arg(m_normalizeColumns ? "true" : "false") | |
1717 .arg(m_normalizeVisibleArea ? "true" : "false") | |
1718 .arg(m_miny) | 1742 .arg(m_miny) |
1719 .arg(m_maxy) | 1743 .arg(m_maxy) |
1720 .arg(m_invertVertical ? "true" : "false") | 1744 .arg(m_invertVertical ? "true" : "false") |
1721 .arg(m_opaque ? "true" : "false") | 1745 .arg(m_opaque ? "true" : "false") |
1722 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ") | 1746 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ") |
1723 .arg((int)m_binScale) | 1747 .arg((int)m_binScale) |
1724 .arg(m_smooth ? "true" : "false") | 1748 .arg(m_smooth ? "true" : "false") |
1725 .arg(m_gain)); | 1749 .arg(m_gain)); |
1726 | 1750 |
1751 // New-style normalization attributes, allowing for more types of | |
1752 // normalization in future: write out the column normalization | |
1753 // type separately, and then whether we are normalizing visible | |
1754 // area as well afterwards | |
1755 | |
1756 s += QString("columnNormalization=\"%1\" ") | |
1757 .arg(m_normalization == ColumnOp::NormalizeColumns ? "peak" : | |
1758 m_normalization == ColumnOp::NormalizeHybrid ? "hybrid" : "none"); | |
1759 | |
1760 // Old-style normalization attribute, for backward compatibility | |
1761 | |
1762 s += QString("normalizeColumns=\"%1\" ") | |
1763 .arg(m_normalization == ColumnOp::NormalizeColumns ? "true" : "false"); | |
1764 | |
1765 // And this applies to both old- and new-style attributes | |
1766 | |
1767 s += QString("normalizeVisibleArea=\"%1\" ") | |
1768 .arg(m_normalization == ColumnOp::NormalizeVisibleArea ? "true" : "false"); | |
1769 | |
1727 Layer::toXml(stream, indent, extraAttributes + " " + s); | 1770 Layer::toXml(stream, indent, extraAttributes + " " + s); |
1728 } | 1771 } |
1729 | 1772 |
1730 void | 1773 void |
1731 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes) | 1774 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes) |
1732 { | 1775 { |
1733 bool ok = false, alsoOk = false; | 1776 bool ok = false, alsoOk = false; |
1734 | 1777 |
1735 ColourScale scale = (ColourScale)attributes.value("scale").toInt(&ok); | 1778 ColourScale::Scale colourScale = convertInColourScale |
1736 if (ok) setColourScale(scale); | 1779 (attributes.value("colourScale").toInt(&ok)); |
1780 if (ok) setColourScale(colourScale); | |
1737 | 1781 |
1738 int colourMap = attributes.value("colourScheme").toInt(&ok); | 1782 int colourMap = attributes.value("colourScheme").toInt(&ok); |
1739 if (ok) setColourMap(colourMap); | 1783 if (ok) setColourMap(colourMap); |
1740 | 1784 |
1741 BinScale binscale = (BinScale)attributes.value("binScale").toInt(&ok); | 1785 Colour3DPlotRenderer::BinScale binScale = (Colour3DPlotRenderer::BinScale) |
1742 if (ok) setBinScale(binscale); | 1786 attributes.value("binScale").toInt(&ok); |
1743 | 1787 if (ok) setBinScale(binScale); |
1744 bool normalizeColumns = | |
1745 (attributes.value("normalizeColumns").trimmed() == "true"); | |
1746 setNormalizeColumns(normalizeColumns); | |
1747 | |
1748 bool normalizeVisibleArea = | |
1749 (attributes.value("normalizeVisibleArea").trimmed() == "true"); | |
1750 setNormalizeVisibleArea(normalizeVisibleArea); | |
1751 | 1788 |
1752 bool invertVertical = | 1789 bool invertVertical = |
1753 (attributes.value("invertVertical").trimmed() == "true"); | 1790 (attributes.value("invertVertical").trimmed() == "true"); |
1754 setInvertVertical(invertVertical); | 1791 setInvertVertical(invertVertical); |
1755 | 1792 |
1765 if (ok) setGain(gain); | 1802 if (ok) setGain(gain); |
1766 | 1803 |
1767 float min = attributes.value("minY").toFloat(&ok); | 1804 float min = attributes.value("minY").toFloat(&ok); |
1768 float max = attributes.value("maxY").toFloat(&alsoOk); | 1805 float max = attributes.value("maxY").toFloat(&alsoOk); |
1769 if (ok && alsoOk) setDisplayExtents(min, max); | 1806 if (ok && alsoOk) setDisplayExtents(min, max); |
1770 } | 1807 |
1771 | 1808 bool haveNewStyleNormalization = false; |
1809 | |
1810 QString columnNormalization = attributes.value("columnNormalization"); | |
1811 | |
1812 if (columnNormalization != "") { | |
1813 | |
1814 haveNewStyleNormalization = true; | |
1815 | |
1816 if (columnNormalization == "peak") { | |
1817 setNormalization(ColumnOp::NormalizeColumns); | |
1818 } else if (columnNormalization == "hybrid") { | |
1819 setNormalization(ColumnOp::NormalizeHybrid); | |
1820 } else if (columnNormalization == "none") { | |
1821 // do nothing | |
1822 } else { | |
1823 cerr << "NOTE: Unknown or unsupported columnNormalization attribute \"" | |
1824 << columnNormalization << "\"" << endl; | |
1825 } | |
1826 } | |
1827 | |
1828 if (!haveNewStyleNormalization) { | |
1829 | |
1830 bool normalizeColumns = | |
1831 (attributes.value("normalizeColumns").trimmed() == "true"); | |
1832 if (normalizeColumns) { | |
1833 setNormalization(ColumnOp::NormalizeColumns); | |
1834 } | |
1835 | |
1836 bool normalizeHybrid = | |
1837 (attributes.value("normalizeHybrid").trimmed() == "true"); | |
1838 if (normalizeHybrid) { | |
1839 setNormalization(ColumnOp::NormalizeHybrid); | |
1840 } | |
1841 } | |
1842 | |
1843 bool normalizeVisibleArea = | |
1844 (attributes.value("normalizeVisibleArea").trimmed() == "true"); | |
1845 if (normalizeVisibleArea) { | |
1846 setNormalization(ColumnOp::NormalizeVisibleArea); | |
1847 } | |
1848 | |
1849 //!!! todo: check save/reload scaling, compare with | |
1850 //!!! SpectrogramLayer, compare with prior SV versions, compare | |
1851 //!!! with Tony v1 and v2 and their save files | |
1852 } | |
1853 |