Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 1131:ee98d587cd1a spectrogram-minor-refactor
Sensible vertical scale and hybrid normalisation range in colour 3d plot
author | Chris Cannam |
---|---|
date | Tue, 02 Aug 2016 09:58:41 +0100 |
parents | 343887ac6766 |
children | b4b155cfd8b4 |
comparison
equal
deleted
inserted
replaced
1130:dc4b8fd3fcb7 | 1131:ee98d587cd1a |
---|---|
864 int cw = getColourScaleWidth(paint); | 864 int cw = getColourScaleWidth(paint); |
865 | 865 |
866 int ch = h - 20; | 866 int ch = h - 20; |
867 if (ch > 20) { | 867 if (ch > 20) { |
868 | 868 |
869 double min = m_model->getMinimumLevel(); | 869 double min = m_viewMags[v->getId()].getMin(); |
870 double max = m_model->getMaximumLevel(); | 870 double max = m_viewMags[v->getId()].getMax(); |
871 | 871 |
872 double mmin = min; | 872 if (max <= min) max = min + 0.1; |
873 double mmax = max; | 873 |
874 | |
875 if (m_colourScale == ColourScaleType::Log) { | |
876 LogRange::mapRange(mmin, mmax); | |
877 } else if (m_colourScale == ColourScaleType::PlusMinusOne) { | |
878 mmin = -1.f; | |
879 mmax = 1.f; | |
880 } else if (m_colourScale == ColourScaleType::Absolute) { | |
881 if (mmin < 0) { | |
882 if (fabs(mmin) > fabs(mmax)) mmax = fabs(mmin); | |
883 else mmax = fabs(mmax); | |
884 mmin = 0; | |
885 } else { | |
886 mmin = fabs(mmin); | |
887 mmax = fabs(mmax); | |
888 } | |
889 } | |
890 | |
891 if (max == min) max = min + 1.f; | |
892 if (mmax == mmin) mmax = mmin + 1.f; | |
893 | |
894 paint.setPen(v->getForeground()); | 874 paint.setPen(v->getForeground()); |
895 paint.drawRect(4, 10, cw - 8, ch+1); | 875 paint.drawRect(4, 10, cw - 8, ch+1); |
896 | 876 |
897 for (int y = 0; y < ch; ++y) { | 877 for (int y = 0; y < ch; ++y) { |
898 double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min; | 878 double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min; |
899 if (m_colourScale == ColourScaleType::Log) { | 879 paint.setPen(getRenderer(v)->getColour(value)); |
900 value = LogRange::map(value); | 880 paint.drawLine(5, 11 + y, cw - 5, 11 + y); |
901 } | |
902 int pixel = int(((value - mmin) * 256) / (mmax - mmin)); | |
903 if (pixel >= 0 && pixel < 256) { | |
904 //!!! replace this | |
905 // QRgb c = m_cache->color(pixel); | |
906 // paint.setPen(QColor(qRed(c), qGreen(c), qBlue(c))); | |
907 paint.drawLine(5, 11 + y, cw - 5, 11 + y); | |
908 } else { | |
909 cerr << "WARNING: Colour3DPlotLayer::paintVerticalScale: value " << value << ", mmin " << mmin << ", mmax " << mmax << " leads to invalid pixel " << pixel << endl; | |
910 } | |
911 } | 881 } |
912 | 882 |
913 QString minstr = QString("%1").arg(min); | 883 QString minstr = QString("%1").arg(min); |
914 QString maxstr = QString("%1").arg(max); | 884 QString maxstr = QString("%1").arg(max); |
915 | 885 |
1063 ColourScale::Parameters cparams; | 1033 ColourScale::Parameters cparams; |
1064 cparams.colourMap = m_colourMap; | 1034 cparams.colourMap = m_colourMap; |
1065 cparams.scale = m_colourScale; | 1035 cparams.scale = m_colourScale; |
1066 cparams.gain = m_gain; | 1036 cparams.gain = m_gain; |
1067 | 1037 |
1038 if (m_normalization == ColumnNormalization::None) { | |
1039 cparams.minValue = m_model->getMinimumLevel(); | |
1040 cparams.maxValue = m_model->getMaximumLevel(); | |
1041 } else if (m_normalization == ColumnNormalization::Hybrid) { | |
1042 cparams.minValue = 0; | |
1043 cparams.maxValue = log10(m_model->getMaximumLevel() + 1.0); | |
1044 } | |
1045 | |
1046 if (cparams.maxValue <= cparams.minValue) { | |
1047 cparams.maxValue = cparams.minValue + 0.1; | |
1048 } | |
1049 | |
1068 Colour3DPlotRenderer::Parameters params; | 1050 Colour3DPlotRenderer::Parameters params; |
1069 params.colourScale = ColourScale(cparams); | 1051 params.colourScale = ColourScale(cparams); |
1070 params.normalization = m_normalization; | 1052 params.normalization = m_normalization; |
1071 params.binScale = m_binScale; | 1053 params.binScale = m_binScale; |
1072 params.alwaysOpaque = m_opaque; | 1054 params.alwaysOpaque = m_opaque; |