comparison layer/Colour3DPlotLayer.cpp @ 1103:d84a0033b305 spectrogram-minor-refactor

Turn BinDisplay and BinScale into enum classes
author Chris Cannam
date Thu, 14 Jul 2016 15:13:37 +0100
parents 36a981a0fa31
children 46cc4644206d
comparison
equal deleted inserted replaced
1102:36a981a0fa31 1103:d84a0033b305
54 m_cacheValidEnd(0), 54 m_cacheValidEnd(0),
55 m_colourScale(ColourScale::LinearColourScale), 55 m_colourScale(ColourScale::LinearColourScale),
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(Colour3DPlotRenderer::LinearBinScale), 59 m_binScale(BinScale::Linear),
60 m_normalization(ColumnOp::NoNormalization), 60 m_normalization(ColumnOp::NoNormalization),
61 m_invertVertical(false), 61 m_invertVertical(false),
62 m_opaque(false), 62 m_opaque(false),
63 m_smooth(false), 63 m_smooth(false),
64 m_peakResolution(256), 64 m_peakResolution(256),
319 319
320 } else if (name == "Bin Scale") { 320 } else if (name == "Bin Scale") {
321 321
322 *min = 0; 322 *min = 0;
323 *max = 1; 323 *max = 1;
324 *deflt = int(Colour3DPlotRenderer::LinearBinScale); 324 *deflt = int(BinScale::Linear);
325 val = (int)m_binScale; 325 val = (int)m_binScale;
326 326
327 } else if (name == "Opaque") { 327 } else if (name == "Opaque") {
328 328
329 *deflt = 0; 329 *deflt = 0;
418 } else if (name == "Smooth") { 418 } else if (name == "Smooth") {
419 setSmooth(value ? true : false); 419 setSmooth(value ? true : false);
420 } else if (name == "Bin Scale") { 420 } else if (name == "Bin Scale") {
421 switch (value) { 421 switch (value) {
422 default: 422 default:
423 case 0: setBinScale(Colour3DPlotRenderer::LinearBinScale); break; 423 case 0: setBinScale(BinScale::Linear); break;
424 case 1: setBinScale(Colour3DPlotRenderer::LogBinScale); break; 424 case 1: setBinScale(BinScale::Log); break;
425 } 425 }
426 } else if (name == "Normalization") { 426 } else if (name == "Normalization") {
427 switch (value) { 427 switch (value) {
428 default: 428 default:
429 case 0: setNormalization(ColumnOp::NoNormalization); break; 429 case 0: setNormalization(ColumnOp::NoNormalization); break;
467 { 467 {
468 return m_gain; 468 return m_gain;
469 } 469 }
470 470
471 void 471 void
472 Colour3DPlotLayer::setBinScale(Colour3DPlotRenderer::BinScale binScale) 472 Colour3DPlotLayer::setBinScale(BinScale binScale)
473 { 473 {
474 if (m_binScale == binScale) return; 474 if (m_binScale == binScale) return;
475 m_binScale = binScale; 475 m_binScale = binScale;
476 cacheInvalid(); 476 cacheInvalid();
477 emit layerParametersChanged(); 477 emit layerParametersChanged();
478 } 478 }
479 479
480 Colour3DPlotRenderer::BinScale 480 BinScale
481 Colour3DPlotLayer::getBinScale() const 481 Colour3DPlotLayer::getBinScale() const
482 { 482 {
483 return m_binScale; 483 return m_binScale;
484 } 484 }
485 485
688 double y = bin; 688 double y = bin;
689 if (!m_model) return y; 689 if (!m_model) return y;
690 double mn = 0, mx = m_model->getHeight(); 690 double mn = 0, mx = m_model->getHeight();
691 getDisplayExtents(mn, mx); 691 getDisplayExtents(mn, mx);
692 double h = v->getPaintHeight(); 692 double h = v->getPaintHeight();
693 if (m_binScale == Colour3DPlotRenderer::LinearBinScale) { 693 if (m_binScale == BinScale::Linear) {
694 y = h - (((bin - mn) * h) / (mx - mn)); 694 y = h - (((bin - mn) * h) / (mx - mn));
695 } else { 695 } else {
696 double logmin = mn + 1, logmax = mx + 1; 696 double logmin = mn + 1, logmax = mx + 1;
697 LogRange::mapRange(logmin, logmax); 697 LogRange::mapRange(logmin, logmax);
698 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin)); 698 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin));
706 double bin = y; 706 double bin = y;
707 if (!m_model) return bin; 707 if (!m_model) return bin;
708 double mn = 0, mx = m_model->getHeight(); 708 double mn = 0, mx = m_model->getHeight();
709 getDisplayExtents(mn, mx); 709 getDisplayExtents(mn, mx);
710 double h = v->getPaintHeight(); 710 double h = v->getPaintHeight();
711 if (m_binScale == Colour3DPlotRenderer::LinearBinScale) { 711 if (m_binScale == BinScale::Linear) {
712 bin = mn + ((h - y) * (mx - mn)) / h; 712 bin = mn + ((h - y) * (mx - mn)) / h;
713 } else { 713 } else {
714 double logmin = mn + 1, logmax = mx + 1; 714 double logmin = mn + 1, logmax = mx + 1;
715 LogRange::mapRange(logmin, logmax); 715 LogRange::mapRange(logmin, logmax);
716 bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1; 716 bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1;
1849 .arg(m_miny) 1849 .arg(m_miny)
1850 .arg(m_maxy) 1850 .arg(m_maxy)
1851 .arg(m_invertVertical ? "true" : "false") 1851 .arg(m_invertVertical ? "true" : "false")
1852 .arg(m_opaque ? "true" : "false") 1852 .arg(m_opaque ? "true" : "false")
1853 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ") 1853 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ")
1854 .arg((int)m_binScale) 1854 .arg(int(m_binScale))
1855 .arg(m_smooth ? "true" : "false") 1855 .arg(m_smooth ? "true" : "false")
1856 .arg(m_gain)); 1856 .arg(m_gain));
1857 1857
1858 // New-style normalization attributes, allowing for more types of 1858 // New-style normalization attributes, allowing for more types of
1859 // normalization in future: write out the column normalization 1859 // normalization in future: write out the column normalization
1887 if (ok) setColourScale(colourScale); 1887 if (ok) setColourScale(colourScale);
1888 1888
1889 int colourMap = attributes.value("colourScheme").toInt(&ok); 1889 int colourMap = attributes.value("colourScheme").toInt(&ok);
1890 if (ok) setColourMap(colourMap); 1890 if (ok) setColourMap(colourMap);
1891 1891
1892 Colour3DPlotRenderer::BinScale binScale = (Colour3DPlotRenderer::BinScale) 1892 BinScale binScale = (BinScale)
1893 attributes.value("binScale").toInt(&ok); 1893 attributes.value("binScale").toInt(&ok);
1894 if (ok) setBinScale(binScale); 1894 if (ok) setBinScale(binScale);
1895 1895
1896 bool invertVertical = 1896 bool invertVertical =
1897 (attributes.value("invertVertical").trimmed() == "true"); 1897 (attributes.value("invertVertical").trimmed() == "true");