comparison layer/Colour3DPlotLayer.cpp @ 1049:40480e4bab6a 3.0-integration

Merge from default branch
author Chris Cannam
date Fri, 04 Mar 2016 12:38:29 +0000
parents 25ec2390fad3 e8102ff5573b
children 38a53c7b81f6
comparison
equal deleted inserted replaced
1044:4e5c1c326794 1049:40480e4bab6a
973 973
974 return values; 974 return values;
975 } 975 }
976 976
977 void 977 void
978 Colour3DPlotLayer::fillCache(int firstBin, int lastBin) const 978 Colour3DPlotLayer::fillCache(int firstColumn, int lastColumn) const
979 { 979 {
980 // This call requests a (perhaps partial) fill of the cache
981 // between model columns firstColumn and lastColumn inclusive.
982 // The cache itself always has size sufficient to contain the
983 // whole model, but its validity may be less, depending on which
984 // regions have been requested via calls to this function. Note
985 // that firstColumn and lastColumn are *model* column numbers. If
986 // the model starts at a frame > 0, a firstColumn of zero still
987 // corresponds to the first column in the model, not the first
988 // column on the resulting rendered layer.
989
980 Profiler profiler("Colour3DPlotLayer::fillCache", true); 990 Profiler profiler("Colour3DPlotLayer::fillCache", true);
981 991
982 sv_frame_t modelStart = m_model->getStartFrame(); 992 int cacheWidth = m_model->getWidth();
983 sv_frame_t modelEnd = m_model->getEndFrame(); 993 int cacheHeight = m_model->getHeight();
984 int modelResolution = m_model->getResolution();
985
986 int modelStartBin = int(modelStart / modelResolution);
987 int modelEndBin = int(modelEnd / modelResolution);
988 994
989 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 995 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
990 cerr << "Colour3DPlotLayer::fillCache: range " << firstBin << " -> " << lastBin << " of model range " << modelStartBin << " -> " << modelEndBin << " (model resolution " << modelResolution << ")" << endl; 996 cerr << "Colour3DPlotLayer::fillCache: range " << firstColumn << " -> " << lastColumn << " (cache size will be " << cacheWidth << " x " << cacheHeight << ")" << endl;
991 #endif 997 #endif
992
993 int cacheWidth = modelEndBin - modelStartBin + 1;
994 if (lastBin > modelEndBin) cacheWidth = lastBin - modelStartBin + 1;
995 int cacheHeight = m_model->getHeight();
996 998
997 if (m_cache && m_cache->height() != cacheHeight) { 999 if (m_cache && m_cache->height() != cacheHeight) {
998 // height has changed: delete everything rather than resizing 1000 // height has changed: delete everything rather than resizing
999 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1001 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1000 cerr << "Colour3DPlotLayer::fillCache: Cache height has changed, recreating" << endl; 1002 cerr << "Colour3DPlotLayer::fillCache: Cache height has changed, recreating" << endl;
1025 1027
1026 if (!m_cache) { 1028 if (!m_cache) {
1027 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1029 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1028 cerr << "Colour3DPlotLayer::fillCache: Have no cache, making one" << endl; 1030 cerr << "Colour3DPlotLayer::fillCache: Have no cache, making one" << endl;
1029 #endif 1031 #endif
1030 m_cache = new QImage 1032 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8);
1031 (cacheWidth, cacheHeight, QImage::Format_Indexed8);
1032 m_cache->setColorCount(256); 1033 m_cache->setColorCount(256);
1033 m_cache->fill(0); 1034 m_cache->fill(0);
1034 if (!m_normalizeVisibleArea) { 1035 if (!m_normalizeVisibleArea) {
1035 m_peaksCache = new QImage 1036 m_peaksCache = new QImage
1036 (cacheWidth / m_peakResolution + 1, cacheHeight, 1037 (cacheWidth / m_peakResolution + 1, cacheHeight,
1048 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1049 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1049 cerr << "cache size = " << m_cache->width() << "x" << m_cache->height() 1050 cerr << "cache size = " << m_cache->width() << "x" << m_cache->height()
1050 << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl; 1051 << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl;
1051 #endif 1052 #endif
1052 1053
1053 if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) { 1054 if (m_cacheValidStart <= firstColumn && m_cacheValidEnd >= lastColumn) {
1054 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1055 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1055 cerr << "Cache is valid in this region already" << endl; 1056 cerr << "Cache is valid in this region already" << endl;
1056 #endif 1057 #endif
1057 return; 1058 return;
1058 } 1059 }
1059 1060
1060 int fillStart = firstBin; 1061 int fillStart = firstColumn;
1061 int fillEnd = lastBin; 1062 int fillEnd = lastColumn;
1062 1063
1063 if (fillStart < modelStartBin) fillStart = modelStartBin; 1064 if (fillStart >= cacheWidth) fillStart = cacheWidth-1;
1064 if (fillStart > modelEndBin) fillStart = modelEndBin; 1065 if (fillStart < 0) fillStart = 0;
1065 if (fillEnd < modelStartBin) fillEnd = modelStartBin; 1066 if (fillEnd >= cacheWidth) fillEnd = cacheWidth-1;
1066 if (fillEnd > modelEndBin) fillEnd = modelEndBin; 1067 if (fillEnd < 0) fillEnd = 0;
1068 if (fillEnd < fillStart) fillEnd = fillStart;
1067 1069
1068 bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns); 1070 bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns);
1069 1071
1070 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) { 1072 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) {
1071 1073
1314 int h = v->getPaintHeight(); 1316 int h = v->getPaintHeight();
1315 1317
1316 double srRatio = 1318 double srRatio =
1317 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); 1319 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate();
1318 1320
1321 // the s-prefix values are source, i.e. model, column and bin numbers
1319 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart)) 1322 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart))
1320 / modelResolution); 1323 / modelResolution);
1321 int sx1 = int((double(v->getFrameForX(x1)) / srRatio - double(modelStart)) 1324 int sx1 = int((double(v->getFrameForX(x1)) / srRatio - double(modelStart))
1322 / modelResolution); 1325 / modelResolution);
1323 int sh = m_model->getHeight(); 1326 int sh = m_model->getHeight();
1358 const int buflen = 40; 1361 const int buflen = 40;
1359 char labelbuf[buflen]; 1362 char labelbuf[buflen];
1360 1363
1361 for (int sx = sx0; sx <= sx1; ++sx) { 1364 for (int sx = sx0; sx <= sx1; ++sx) {
1362 1365
1363 sv_frame_t fx = sx * modelResolution; 1366 sv_frame_t fx = sx * modelResolution + modelStart;
1364 1367
1365 if (fx + modelResolution <= modelStart || fx > modelEnd) continue; 1368 if (fx + modelResolution <= modelStart || fx > modelEnd) continue;
1366 1369
1367 int rx0 = v->getXForFrame(int(double(fx + modelStart) * srRatio)); 1370 int rx0 = v->getXForFrame(int(double(fx) * srRatio));
1368 int rx1 = v->getXForFrame(int(double(fx + modelStart + modelResolution + 1) * srRatio)); 1371 int rx1 = v->getXForFrame(int(double(fx + modelResolution + 1) * srRatio));
1369 1372
1370 int rw = rx1 - rx0; 1373 int rw = rx1 - rx0;
1371 if (rw < 1) rw = 1; 1374 if (rw < 1) rw = 1;
1372 1375
1373 bool showLabel = (rw > 10 && 1376 bool showLabel = (rw > 10 &&
1420 if (sx >= 0 && sx < m_cache->width() && 1423 if (sx >= 0 && sx < m_cache->width() &&
1421 sy >= 0 && sy < m_cache->height()) { 1424 sy >= 0 && sy < m_cache->height()) {
1422 double value = m_model->getValueAt(sx, sy); 1425 double value = m_model->getValueAt(sx, sy);
1423 snprintf(labelbuf, buflen, "%06f", value); 1426 snprintf(labelbuf, buflen, "%06f", value);
1424 QString text(labelbuf); 1427 QString text(labelbuf);
1425 paint.setPen(v->getBackground()); 1428 v->drawVisibleText
1426 paint.drawText(rx0 + 2, 1429 (paint,
1427 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(), 1430 rx0 + 2,
1428 text); 1431 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(),
1432 text,
1433 View::OutlinedText);
1429 } 1434 }
1430 } 1435 }
1431 } 1436 }
1432 } 1437 }
1433 } 1438 }