Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 742:d7e8cefedbbc
Diagnostics and fix for peaks cache sizing (need +1 to avoid null cache)
author | Chris Cannam |
---|---|
date | Tue, 11 Mar 2014 17:29:02 +0000 |
parents | c27a3604fe6f |
children | 1d526ba11a24 |
comparison
equal
deleted
inserted
replaced
736:88a16eed3338 | 742:d7e8cefedbbc |
---|---|
957 size_t cacheWidth = modelEndBin - modelStartBin + 1; | 957 size_t cacheWidth = modelEndBin - modelStartBin + 1; |
958 if (lastBin > modelEndBin) cacheWidth = lastBin - modelStartBin + 1; | 958 if (lastBin > modelEndBin) cacheWidth = lastBin - modelStartBin + 1; |
959 size_t cacheHeight = m_model->getHeight(); | 959 size_t cacheHeight = m_model->getHeight(); |
960 | 960 |
961 if (m_cache && (m_cache->height() != int(cacheHeight))) { | 961 if (m_cache && (m_cache->height() != int(cacheHeight))) { |
962 // height has changed: delete everything rather than resizing | |
962 delete m_cache; | 963 delete m_cache; |
963 delete m_peaksCache; | 964 delete m_peaksCache; |
964 m_cache = 0; | 965 m_cache = 0; |
965 m_peaksCache = 0; | 966 m_peaksCache = 0; |
966 } | 967 } |
967 | 968 |
968 if (m_cache && (m_cache->width() != int(cacheWidth))) { | 969 if (m_cache && (m_cache->width() != int(cacheWidth))) { |
970 // width has changed and we have an existing cache: resize it | |
969 QImage *newCache = | 971 QImage *newCache = |
970 new QImage(m_cache->copy(0, 0, cacheWidth, cacheHeight)); | 972 new QImage(m_cache->copy(0, 0, cacheWidth, cacheHeight)); |
971 delete m_cache; | 973 delete m_cache; |
972 m_cache = newCache; | 974 m_cache = newCache; |
973 if (m_peaksCache) { | 975 if (m_peaksCache) { |
974 QImage *newPeaksCache = | 976 QImage *newPeaksCache = |
975 new QImage(m_peaksCache->copy | 977 new QImage(m_peaksCache->copy |
976 (0, 0, cacheWidth / m_peakResolution, cacheHeight)); | 978 (0, 0, cacheWidth / m_peakResolution + 1, cacheHeight)); |
977 delete m_peaksCache; | 979 delete m_peaksCache; |
978 m_peaksCache = newPeaksCache; | 980 m_peaksCache = newPeaksCache; |
979 } | 981 } |
980 } | 982 } |
981 | 983 |
996 } | 998 } |
997 m_cacheValidStart = 0; | 999 m_cacheValidStart = 0; |
998 m_cacheValidEnd = 0; | 1000 m_cacheValidEnd = 0; |
999 } | 1001 } |
1000 | 1002 |
1003 // cerr << "cache size = " << m_cache->width() << "x" << m_cache->height() | |
1004 // << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl; | |
1005 | |
1001 if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) { | 1006 if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) { |
1002 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 1007 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
1003 cerr << "Cache is valid in this region already" << endl; | 1008 cerr << "Cache is valid in this region already" << endl; |
1004 #endif | 1009 #endif |
1005 return; | 1010 return; |
1122 | 1127 |
1123 for (size_t c = fillStart; c <= fillEnd; ++c) { | 1128 for (size_t c = fillStart; c <= fillEnd; ++c) { |
1124 | 1129 |
1125 values = getColumn(c); | 1130 values = getColumn(c); |
1126 | 1131 |
1132 if (c >= m_cache->width()) { | |
1133 cerr << "ERROR: column " << c << " >= cache width " | |
1134 << m_cache->width() << endl; | |
1135 continue; | |
1136 } | |
1137 | |
1127 for (size_t y = 0; y < cacheHeight; ++y) { | 1138 for (size_t y = 0; y < cacheHeight; ++y) { |
1128 | 1139 |
1129 float value = min; | 1140 float value = min; |
1130 if (y < values.size()) { | 1141 if (y < values.size()) { |
1131 value = values.at(y); | 1142 value = values.at(y); |
1150 if (peaks && (pixel > peaks[y])) peaks[y] = pixel; | 1161 if (peaks && (pixel > peaks[y])) peaks[y] = pixel; |
1151 | 1162 |
1152 if (m_invertVertical) { | 1163 if (m_invertVertical) { |
1153 m_cache->setPixel(c, cacheHeight - y - 1, pixel); | 1164 m_cache->setPixel(c, cacheHeight - y - 1, pixel); |
1154 } else { | 1165 } else { |
1155 m_cache->setPixel(c, y, pixel); | 1166 if (y >= m_cache->height()) { |
1167 cerr << "ERROR: row " << y << " >= cache height " << m_cache->height() << endl; | |
1168 } else { | |
1169 m_cache->setPixel(c, y, pixel); | |
1170 } | |
1156 } | 1171 } |
1157 } | 1172 } |
1158 | 1173 |
1159 if (peaks) { | 1174 if (peaks) { |
1160 size_t notch = (c % m_peakResolution); | 1175 size_t notch = (c % m_peakResolution); |
1161 if (notch == m_peakResolution-1 || c == fillEnd) { | 1176 if (notch == m_peakResolution-1 || c == fillEnd) { |
1162 size_t pc = c / m_peakResolution; | 1177 size_t pc = c / m_peakResolution; |
1178 if (pc >= m_peaksCache->width()) { | |
1179 cerr << "ERROR: peak column " << pc | |
1180 << " (from col " << c << ") >= peaks cache width " | |
1181 << m_peaksCache->width() << endl; | |
1182 continue; | |
1183 } | |
1163 for (size_t y = 0; y < cacheHeight; ++y) { | 1184 for (size_t y = 0; y < cacheHeight; ++y) { |
1164 if (m_invertVertical) { | 1185 if (m_invertVertical) { |
1165 m_peaksCache->setPixel(pc, cacheHeight - y - 1, peaks[y]); | 1186 m_peaksCache->setPixel(pc, cacheHeight - y - 1, peaks[y]); |
1166 } else { | 1187 } else { |
1167 m_peaksCache->setPixel(pc, y, peaks[y]); | 1188 if (y >= m_peaksCache->height()) { |
1189 cerr << "ERROR: row " << y | |
1190 << " >= peaks cache height " | |
1191 << m_peaksCache->height() << endl; | |
1192 } else { | |
1193 m_peaksCache->setPixel(pc, y, peaks[y]); | |
1194 } | |
1168 } | 1195 } |
1169 } | 1196 } |
1170 for (int y = 0; y < cacheHeight; ++y) { | 1197 for (int y = 0; y < cacheHeight; ++y) { |
1171 peaks[y] = 0; | 1198 peaks[y] = 0; |
1172 } | 1199 } |