Mercurial > hg > svgui
comparison layer/Colour3DPlotRenderer.cpp @ 1135:628cd329c241 spectrogram-minor-refactor
Use a count of bins rather than min and max bins (because the name maxbin tells us nothing about whether the range is inclusive or not)
author | Chris Cannam |
---|---|
date | Wed, 03 Aug 2016 14:20:27 +0100 |
parents | b4b155cfd8b4 |
children | 9ff838a64461 |
comparison
equal
deleted
inserted
replaced
1134:199049012fc6 | 1135:628cd329c241 |
---|---|
329 | 329 |
330 const int buflen = 40; | 330 const int buflen = 40; |
331 char labelbuf[buflen]; | 331 char labelbuf[buflen]; |
332 | 332 |
333 int minbin = m_sources.verticalBinLayer->getIBinForY(v, h); | 333 int minbin = m_sources.verticalBinLayer->getIBinForY(v, h); |
334 int maxbin = m_sources.verticalBinLayer->getIBinForY(v, 0) + 1; | 334 if (minbin >= sh) minbin = sh - 1; |
335 if (minbin < 0) minbin = 0; | |
336 | |
337 int nbins = m_sources.verticalBinLayer->getIBinForY(v, 0) - minbin + 1; | |
338 if (minbin + nbins > sh) nbins = sh - minbin; | |
335 | 339 |
336 int psx = -1; | 340 int psx = -1; |
337 | 341 |
338 vector<float> preparedColumn; | 342 vector<float> preparedColumn; |
339 | 343 |
355 | 359 |
356 ColumnOp::Column fullColumn = model->getColumn(sx); | 360 ColumnOp::Column fullColumn = model->getColumn(sx); |
357 | 361 |
358 ColumnOp::Column column = | 362 ColumnOp::Column column = |
359 vector<float>(fullColumn.data() + minbin, | 363 vector<float>(fullColumn.data() + minbin, |
360 fullColumn.data() + maxbin + 1); | 364 fullColumn.data() + minbin + nbins); |
361 | 365 |
362 column = ColumnOp::applyGain(column, m_params.scaleFactor); | 366 column = ColumnOp::applyGain(column, m_params.scaleFactor); |
363 | 367 |
364 // if (m_colourScale != ColourScaleType::Phase) { | 368 // if (m_colourScale != ColourScaleType::Phase) { |
365 preparedColumn = ColumnOp::normalize(column, m_params.normalization); | 369 preparedColumn = ColumnOp::normalize(column, m_params.normalization); |
389 | 393 |
390 bool showLabel = (rw > 10 && | 394 bool showLabel = (rw > 10 && |
391 paint.fontMetrics().width("0.000000") < rw - 3 && | 395 paint.fontMetrics().width("0.000000") < rw - 3 && |
392 paint.fontMetrics().height() < (h / sh)); | 396 paint.fontMetrics().height() < (h / sh)); |
393 | 397 |
394 for (int sy = minbin; sy <= maxbin; ++sy) { | 398 for (int sy = minbin; sy < minbin + nbins; ++sy) { |
395 | 399 |
396 int ry0 = m_sources.verticalBinLayer->getIYForBin(v, sy); | 400 int ry0 = m_sources.verticalBinLayer->getIYForBin(v, sy); |
397 int ry1 = m_sources.verticalBinLayer->getIYForBin(v, sy + 1); | 401 int ry1 = m_sources.verticalBinLayer->getIYForBin(v, sy + 1); |
398 | 402 |
399 if (m_params.invertVertical) { | 403 if (m_params.invertVertical) { |
702 // peaks model exists if usePeaksCache) | 706 // peaks model exists if usePeaksCache) |
703 | 707 |
704 RenderTimer timer(timeConstrained ? | 708 RenderTimer timer(timeConstrained ? |
705 RenderTimer::FastRender : | 709 RenderTimer::FastRender : |
706 RenderTimer::NoTimeout); | 710 RenderTimer::NoTimeout); |
707 | |
708 int minbin = int(binfory[0] + 0.0001); | |
709 int maxbin = int(binfory[h-1]); | |
710 if (minbin < 0) minbin = 0; | |
711 if (maxbin < 0) maxbin = minbin+1; | |
712 | 711 |
713 int divisor = 1; | 712 int divisor = 1; |
714 const DenseThreeDimensionalModel *sourceModel = m_sources.source; | 713 const DenseThreeDimensionalModel *sourceModel = m_sources.source; |
715 if (usePeaksCache) { | 714 if (usePeaksCache) { |
716 divisor = m_sources.peaks->getColumnsPerPeak(); | 715 divisor = m_sources.peaks->getColumnsPerPeak(); |
717 sourceModel = m_sources.peaks; | 716 sourceModel = m_sources.peaks; |
718 } | 717 } |
719 | 718 |
719 int sh = sourceModel->getHeight(); | |
720 | |
721 int minbin = int(binfory[0] + 0.0001); | |
722 if (minbin >= sh) minbin = sh - 1; | |
723 if (minbin < 0) minbin = 0; | |
724 | |
725 int nbins = int(binfory[h-1]) - minbin + 1; | |
726 if (minbin + nbins > sh) nbins = sh - minbin; | |
727 | |
720 int psx = -1; | 728 int psx = -1; |
721 | 729 |
722 int start = 0; | 730 int start = 0; |
723 int finish = w; | 731 int finish = w; |
724 int step = 1; | 732 int step = 1; |
777 // normalise -> peak pick -> distribute/interpolate -> | 785 // normalise -> peak pick -> distribute/interpolate -> |
778 // apply display gain | 786 // apply display gain |
779 | 787 |
780 ColumnOp::Column fullColumn = sourceModel->getColumn(sx); | 788 ColumnOp::Column fullColumn = sourceModel->getColumn(sx); |
781 | 789 |
782 // cerr << "x " << x << ", sx " << sx << ", col height " << fullColumn.size() | 790 cerr << "x " << x << ", sx " << sx << ", col height " << fullColumn.size() |
783 // << ", minbin " << minbin << ", maxbin " << maxbin << endl; | 791 << ", minbin " << minbin << ", nbins " << nbins << endl; |
784 | 792 |
785 ColumnOp::Column column = | 793 ColumnOp::Column column = |
786 vector<float>(fullColumn.data() + minbin, | 794 vector<float>(fullColumn.data() + minbin, |
787 fullColumn.data() + maxbin + 1); | 795 fullColumn.data() + minbin + nbins); |
788 | 796 |
789 column = ColumnOp::applyGain(column, m_params.scaleFactor); | 797 column = ColumnOp::applyGain(column, m_params.scaleFactor); |
790 | 798 |
791 // if (m_colourScale != ColourScaleType::Phase) { | 799 // if (m_colourScale != ColourScaleType::Phase) { |
792 column = ColumnOp::normalize(column, m_params.normalization); | 800 column = ColumnOp::normalize(column, m_params.normalization); |
863 | 871 |
864 RenderTimer timer(timeConstrained ? | 872 RenderTimer timer(timeConstrained ? |
865 RenderTimer::FastRender : | 873 RenderTimer::FastRender : |
866 RenderTimer::NoTimeout); | 874 RenderTimer::NoTimeout); |
867 | 875 |
876 const FFTModel *fft = m_sources.fft; | |
877 | |
878 int sh = fft->getHeight(); | |
879 | |
868 int minbin = int(binfory[0] + 0.0001); | 880 int minbin = int(binfory[0] + 0.0001); |
869 int maxbin = int(binfory[h-1]); | 881 if (minbin >= sh) minbin = sh - 1; |
870 if (minbin < 0) minbin = 0; | 882 if (minbin < 0) minbin = 0; |
871 if (maxbin < 0) maxbin = minbin+1; | 883 |
872 | 884 int nbins = int(binfory[h-1]) - minbin + 1; |
873 const FFTModel *fft = m_sources.fft; | 885 if (minbin + nbins > sh) nbins = sh - minbin; |
874 | 886 |
875 FFTModel::PeakSet peakfreqs; | 887 FFTModel::PeakSet peakfreqs; |
876 | 888 |
877 int psx = -1; | 889 int psx = -1; |
878 | 890 |
891 vector<float> preparedColumn; | 903 vector<float> preparedColumn; |
892 | 904 |
893 int modelWidth = fft->getWidth(); | 905 int modelWidth = fft->getWidth(); |
894 cerr << "modelWidth " << modelWidth << endl; | 906 cerr << "modelWidth " << modelWidth << endl; |
895 | 907 |
896 double minFreq = (double(minbin) * fft->getSampleRate()) / fft->getFFTSize(); | 908 double minFreq = |
897 double maxFreq = (double(maxbin) * fft->getSampleRate()) / fft->getFFTSize(); | 909 (double(minbin) * fft->getSampleRate()) / fft->getFFTSize(); |
910 double maxFreq = | |
911 (double(minbin + nbins - 1) * fft->getSampleRate()) / fft->getFFTSize(); | |
898 | 912 |
899 bool logarithmic = (m_params.binScale == BinScale::Log); | 913 bool logarithmic = (m_params.binScale == BinScale::Log); |
900 | 914 |
901 for (int x = start; x != finish; x += step) { | 915 for (int x = start; x != finish; x += step) { |
902 | 916 |
927 | 941 |
928 ColumnOp::Column fullColumn = fft->getColumn(sx); | 942 ColumnOp::Column fullColumn = fft->getColumn(sx); |
929 | 943 |
930 ColumnOp::Column column = | 944 ColumnOp::Column column = |
931 vector<float>(fullColumn.data() + minbin, | 945 vector<float>(fullColumn.data() + minbin, |
932 fullColumn.data() + maxbin + 1); | 946 fullColumn.data() + minbin + nbins + 1); |
933 | 947 |
934 column = ColumnOp::applyGain(column, m_params.scaleFactor); | 948 column = ColumnOp::applyGain(column, m_params.scaleFactor); |
935 | 949 |
936 //!!! if (m_colourScale != ColourScaleType::Phase) { | 950 //!!! if (m_colourScale != ColourScaleType::Phase) { |
937 preparedColumn = ColumnOp::normalize | 951 preparedColumn = ColumnOp::normalize |
944 } | 958 } |
945 | 959 |
946 if (sx == sx0) { | 960 if (sx == sx0) { |
947 pixelPeakColumn = preparedColumn; | 961 pixelPeakColumn = preparedColumn; |
948 peakfreqs = fft->getPeakFrequencies(FFTModel::AllPeaks, sx, | 962 peakfreqs = fft->getPeakFrequencies(FFTModel::AllPeaks, sx, |
949 minbin, maxbin - 1); | 963 minbin, minbin + nbins - 1); |
950 } else { | 964 } else { |
951 for (int i = 0; in_range_for(pixelPeakColumn, i); ++i) { | 965 for (int i = 0; in_range_for(pixelPeakColumn, i); ++i) { |
952 pixelPeakColumn[i] = std::max(pixelPeakColumn[i], | 966 pixelPeakColumn[i] = std::max(pixelPeakColumn[i], |
953 preparedColumn[i]); | 967 preparedColumn[i]); |
954 } | 968 } |
962 | 976 |
963 int bin = pi->first; | 977 int bin = pi->first; |
964 double freq = pi->second; | 978 double freq = pi->second; |
965 | 979 |
966 if (bin < minbin) continue; | 980 if (bin < minbin) continue; |
967 if (bin > maxbin) break; | 981 if (bin >= minbin + nbins) break; |
968 | 982 |
969 double value = pixelPeakColumn[bin - minbin]; | 983 double value = pixelPeakColumn[bin - minbin]; |
970 | 984 |
971 double y = v->getYForFrequency | 985 double y = v->getYForFrequency |
972 (freq, minFreq, maxFreq, logarithmic); | 986 (freq, minFreq, maxFreq, logarithmic); |