comparison layer/Colour3DPlotLayer.cpp @ 1046:19bb1744518e

Fix confusion between model columns and painted columns, and document the difference
author Chris Cannam
date Fri, 04 Mar 2016 12:22:42 +0000
parents 08f20a23fb81
children 86a8145a1897
comparison
equal deleted inserted replaced
1034:44726e088590 1046:19bb1744518e
964 964
965 return values; 965 return values;
966 } 966 }
967 967
968 void 968 void
969 Colour3DPlotLayer::fillCache(int firstBin, int lastBin) const 969 Colour3DPlotLayer::fillCache(int firstColumn, int lastColumn) const
970 { 970 {
971 // This call requests a (perhaps partial) fill of the cache
972 // between model columns firstColumn and lastColumn inclusive.
973 // The cache itself always has size sufficient to contain the
974 // whole model, but its validity may be less, depending on which
975 // regions have been requested via calls to this function. Note
976 // that firstColumn and lastColumn are *model* column numbers. If
977 // the model starts at a frame > 0, a firstColumn of zero still
978 // corresponds to the first column in the model, not the first
979 // column on the resulting rendered layer.
980
971 Profiler profiler("Colour3DPlotLayer::fillCache", true); 981 Profiler profiler("Colour3DPlotLayer::fillCache", true);
972 982
973 sv_frame_t modelStart = m_model->getStartFrame(); 983 int cacheWidth = m_model->getWidth();
974 sv_frame_t modelEnd = m_model->getEndFrame(); 984 int cacheHeight = m_model->getHeight();
975 int modelResolution = m_model->getResolution();
976
977 int modelStartBin = int(modelStart / modelResolution);
978 int modelEndBin = int(modelEnd / modelResolution);
979 985
980 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 986 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
981 cerr << "Colour3DPlotLayer::fillCache: range " << firstBin << " -> " << lastBin << " of model range " << modelStartBin << " -> " << modelEndBin << " (model resolution " << modelResolution << ")" << endl; 987 cerr << "Colour3DPlotLayer::fillCache: range " << firstColumn << " -> " << lastColumn << " (cache size will be " << cacheWidth << " x " << cacheHeight << ")" << endl;
982 #endif 988 #endif
983
984 int cacheWidth = modelEndBin - modelStartBin + 1;
985 if (lastBin > modelEndBin) cacheWidth = lastBin - modelStartBin + 1;
986 int cacheHeight = m_model->getHeight();
987 989
988 if (m_cache && m_cache->height() != cacheHeight) { 990 if (m_cache && m_cache->height() != cacheHeight) {
989 // height has changed: delete everything rather than resizing 991 // height has changed: delete everything rather than resizing
990 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 992 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
991 cerr << "Colour3DPlotLayer::fillCache: Cache height has changed, recreating" << endl; 993 cerr << "Colour3DPlotLayer::fillCache: Cache height has changed, recreating" << endl;
1016 1018
1017 if (!m_cache) { 1019 if (!m_cache) {
1018 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1020 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1019 cerr << "Colour3DPlotLayer::fillCache: Have no cache, making one" << endl; 1021 cerr << "Colour3DPlotLayer::fillCache: Have no cache, making one" << endl;
1020 #endif 1022 #endif
1021 m_cache = new QImage 1023 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8);
1022 (cacheWidth, cacheHeight, QImage::Format_Indexed8);
1023 m_cache->setColorCount(256); 1024 m_cache->setColorCount(256);
1024 m_cache->fill(0); 1025 m_cache->fill(0);
1025 if (!m_normalizeVisibleArea) { 1026 if (!m_normalizeVisibleArea) {
1026 m_peaksCache = new QImage 1027 m_peaksCache = new QImage
1027 (cacheWidth / m_peakResolution + 1, cacheHeight, 1028 (cacheWidth / m_peakResolution + 1, cacheHeight,
1039 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1040 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1040 cerr << "cache size = " << m_cache->width() << "x" << m_cache->height() 1041 cerr << "cache size = " << m_cache->width() << "x" << m_cache->height()
1041 << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl; 1042 << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl;
1042 #endif 1043 #endif
1043 1044
1044 if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) { 1045 if (m_cacheValidStart <= firstColumn && m_cacheValidEnd >= lastColumn) {
1045 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1046 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1046 cerr << "Cache is valid in this region already" << endl; 1047 cerr << "Cache is valid in this region already" << endl;
1047 #endif 1048 #endif
1048 return; 1049 return;
1049 } 1050 }
1050 1051
1051 int fillStart = firstBin; 1052 int fillStart = firstColumn;
1052 int fillEnd = lastBin; 1053 int fillEnd = lastColumn;
1053 1054
1054 if (fillStart < modelStartBin) fillStart = modelStartBin; 1055 if (fillStart >= cacheWidth) fillStart = cacheWidth-1;
1055 if (fillStart > modelEndBin) fillStart = modelEndBin; 1056 if (fillStart < 0) fillStart = 0;
1056 if (fillEnd < modelStartBin) fillEnd = modelStartBin; 1057 if (fillEnd >= cacheWidth) fillEnd = cacheWidth-1;
1057 if (fillEnd > modelEndBin) fillEnd = modelEndBin; 1058 if (fillEnd < 0) fillEnd = 0;
1059 if (fillEnd < fillStart) fillEnd = fillStart;
1058 1060
1059 bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns); 1061 bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns);
1060 1062
1061 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) { 1063 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) {
1062 1064