Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 1057:218be6cf2d4f spectrogram-minor-refactor
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 13 Jun 2016 12:46:36 +0100 |
parents | 38a53c7b81f6 |
children | 5144d7185fb5 |
comparison
equal
deleted
inserted
replaced
1040:25b035362c44 | 1057:218be6cf2d4f |
---|---|
847 QString maxstr = QString("%1").arg(max); | 847 QString maxstr = QString("%1").arg(max); |
848 | 848 |
849 paint.save(); | 849 paint.save(); |
850 | 850 |
851 QFont font = paint.font(); | 851 QFont font = paint.font(); |
852 font.setPixelSize(int(font.pixelSize() * 0.65)); | 852 if (font.pixelSize() > 0) { |
853 paint.setFont(font); | 853 int newSize = int(font.pixelSize() * 0.65); |
854 if (newSize < 6) newSize = 6; | |
855 font.setPixelSize(newSize); | |
856 paint.setFont(font); | |
857 } | |
854 | 858 |
855 int msw = paint.fontMetrics().width(maxstr); | 859 int msw = paint.fontMetrics().width(maxstr); |
856 | 860 |
857 QMatrix m; | 861 QMatrix m; |
858 m.translate(cw - 6, ch + 10); | 862 m.translate(cw - 6, ch + 10); |
973 | 977 |
974 return values; | 978 return values; |
975 } | 979 } |
976 | 980 |
977 void | 981 void |
978 Colour3DPlotLayer::fillCache(int firstBin, int lastBin) const | 982 Colour3DPlotLayer::fillCache(int firstColumn, int lastColumn) const |
979 { | 983 { |
984 // This call requests a (perhaps partial) fill of the cache | |
985 // between model columns firstColumn and lastColumn inclusive. | |
986 // The cache itself always has size sufficient to contain the | |
987 // whole model, but its validity may be less, depending on which | |
988 // regions have been requested via calls to this function. Note | |
989 // that firstColumn and lastColumn are *model* column numbers. If | |
990 // the model starts at a frame > 0, a firstColumn of zero still | |
991 // corresponds to the first column in the model, not the first | |
992 // column on the resulting rendered layer. | |
993 | |
980 Profiler profiler("Colour3DPlotLayer::fillCache", true); | 994 Profiler profiler("Colour3DPlotLayer::fillCache", true); |
981 | 995 |
982 sv_frame_t modelStart = m_model->getStartFrame(); | 996 int cacheWidth = m_model->getWidth(); |
983 sv_frame_t modelEnd = m_model->getEndFrame(); | 997 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 | 998 |
989 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 999 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
990 cerr << "Colour3DPlotLayer::fillCache: range " << firstBin << " -> " << lastBin << " of model range " << modelStartBin << " -> " << modelEndBin << " (model resolution " << modelResolution << ")" << endl; | 1000 cerr << "Colour3DPlotLayer::fillCache: range " << firstColumn << " -> " << lastColumn << " (cache size will be " << cacheWidth << " x " << cacheHeight << ")" << endl; |
991 #endif | 1001 #endif |
992 | |
993 int cacheWidth = modelEndBin - modelStartBin + 1; | |
994 if (lastBin > modelEndBin) cacheWidth = lastBin - modelStartBin + 1; | |
995 int cacheHeight = m_model->getHeight(); | |
996 | 1002 |
997 if (m_cache && m_cache->height() != cacheHeight) { | 1003 if (m_cache && m_cache->height() != cacheHeight) { |
998 // height has changed: delete everything rather than resizing | 1004 // height has changed: delete everything rather than resizing |
999 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 1005 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
1000 cerr << "Colour3DPlotLayer::fillCache: Cache height has changed, recreating" << endl; | 1006 cerr << "Colour3DPlotLayer::fillCache: Cache height has changed, recreating" << endl; |
1025 | 1031 |
1026 if (!m_cache) { | 1032 if (!m_cache) { |
1027 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 1033 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
1028 cerr << "Colour3DPlotLayer::fillCache: Have no cache, making one" << endl; | 1034 cerr << "Colour3DPlotLayer::fillCache: Have no cache, making one" << endl; |
1029 #endif | 1035 #endif |
1030 m_cache = new QImage | 1036 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8); |
1031 (cacheWidth, cacheHeight, QImage::Format_Indexed8); | |
1032 m_cache->setColorCount(256); | 1037 m_cache->setColorCount(256); |
1033 m_cache->fill(0); | 1038 m_cache->fill(0); |
1034 if (!m_normalizeVisibleArea) { | 1039 if (!m_normalizeVisibleArea) { |
1035 m_peaksCache = new QImage | 1040 m_peaksCache = new QImage |
1036 (cacheWidth / m_peakResolution + 1, cacheHeight, | 1041 (cacheWidth / m_peakResolution + 1, cacheHeight, |
1048 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 1053 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
1049 cerr << "cache size = " << m_cache->width() << "x" << m_cache->height() | 1054 cerr << "cache size = " << m_cache->width() << "x" << m_cache->height() |
1050 << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl; | 1055 << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl; |
1051 #endif | 1056 #endif |
1052 | 1057 |
1053 if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) { | 1058 if (m_cacheValidStart <= firstColumn && m_cacheValidEnd >= lastColumn) { |
1054 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 1059 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
1055 cerr << "Cache is valid in this region already" << endl; | 1060 cerr << "Cache is valid in this region already" << endl; |
1056 #endif | 1061 #endif |
1057 return; | 1062 return; |
1058 } | 1063 } |
1059 | 1064 |
1060 int fillStart = firstBin; | 1065 int fillStart = firstColumn; |
1061 int fillEnd = lastBin; | 1066 int fillEnd = lastColumn; |
1062 | 1067 |
1063 if (fillStart < modelStartBin) fillStart = modelStartBin; | 1068 if (fillStart >= cacheWidth) fillStart = cacheWidth-1; |
1064 if (fillStart > modelEndBin) fillStart = modelEndBin; | 1069 if (fillStart < 0) fillStart = 0; |
1065 if (fillEnd < modelStartBin) fillEnd = modelStartBin; | 1070 if (fillEnd >= cacheWidth) fillEnd = cacheWidth-1; |
1066 if (fillEnd > modelEndBin) fillEnd = modelEndBin; | 1071 if (fillEnd < 0) fillEnd = 0; |
1072 if (fillEnd < fillStart) fillEnd = fillStart; | |
1067 | 1073 |
1068 bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns); | 1074 bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns); |
1069 | 1075 |
1070 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) { | 1076 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) { |
1071 | 1077 |
1291 10, QColor(120, 120, 120)); | 1297 10, QColor(120, 120, 120)); |
1292 } | 1298 } |
1293 return; | 1299 return; |
1294 } | 1300 } |
1295 | 1301 |
1302 if (m_model->getWidth() == 0) { | |
1303 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | |
1304 cerr << "Colour3DPlotLayer::paint(): model width == 0, " | |
1305 << "nothing to paint (yet)" << endl; | |
1306 #endif | |
1307 return; | |
1308 } | |
1309 | |
1296 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->getPaintRect(); | 1310 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->getPaintRect(); |
1297 | 1311 |
1298 sv_frame_t modelStart = m_model->getStartFrame(); | 1312 sv_frame_t modelStart = m_model->getStartFrame(); |
1299 sv_frame_t modelEnd = m_model->getEndFrame(); | 1313 sv_frame_t modelEnd = m_model->getEndFrame(); |
1300 int modelResolution = m_model->getResolution(); | 1314 int modelResolution = m_model->getResolution(); |
1314 int h = v->getPaintHeight(); | 1328 int h = v->getPaintHeight(); |
1315 | 1329 |
1316 double srRatio = | 1330 double srRatio = |
1317 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); | 1331 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); |
1318 | 1332 |
1333 // the s-prefix values are source, i.e. model, column and bin numbers | |
1319 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart)) | 1334 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart)) |
1320 / modelResolution); | 1335 / modelResolution); |
1321 int sx1 = int((double(v->getFrameForX(x1)) / srRatio - double(modelStart)) | 1336 int sx1 = int((double(v->getFrameForX(x1)) / srRatio - double(modelStart)) |
1322 / modelResolution); | 1337 / modelResolution); |
1323 int sh = m_model->getHeight(); | 1338 int sh = m_model->getHeight(); |
1358 const int buflen = 40; | 1373 const int buflen = 40; |
1359 char labelbuf[buflen]; | 1374 char labelbuf[buflen]; |
1360 | 1375 |
1361 for (int sx = sx0; sx <= sx1; ++sx) { | 1376 for (int sx = sx0; sx <= sx1; ++sx) { |
1362 | 1377 |
1363 sv_frame_t fx = sx * modelResolution; | 1378 sv_frame_t fx = sx * modelResolution + modelStart; |
1364 | 1379 |
1365 if (fx + modelResolution <= modelStart || fx > modelEnd) continue; | 1380 if (fx + modelResolution <= modelStart || fx > modelEnd) continue; |
1366 | 1381 |
1367 int rx0 = v->getXForFrame(int(double(fx + modelStart) * srRatio)); | 1382 int rx0 = v->getXForFrame(int(double(fx) * srRatio)); |
1368 int rx1 = v->getXForFrame(int(double(fx + modelStart + modelResolution + 1) * srRatio)); | 1383 int rx1 = v->getXForFrame(int(double(fx + modelResolution + 1) * srRatio)); |
1369 | 1384 |
1370 int rw = rx1 - rx0; | 1385 int rw = rx1 - rx0; |
1371 if (rw < 1) rw = 1; | 1386 if (rw < 1) rw = 1; |
1372 | 1387 |
1373 bool showLabel = (rw > 10 && | 1388 bool showLabel = (rw > 10 && |
1420 if (sx >= 0 && sx < m_cache->width() && | 1435 if (sx >= 0 && sx < m_cache->width() && |
1421 sy >= 0 && sy < m_cache->height()) { | 1436 sy >= 0 && sy < m_cache->height()) { |
1422 double value = m_model->getValueAt(sx, sy); | 1437 double value = m_model->getValueAt(sx, sy); |
1423 snprintf(labelbuf, buflen, "%06f", value); | 1438 snprintf(labelbuf, buflen, "%06f", value); |
1424 QString text(labelbuf); | 1439 QString text(labelbuf); |
1425 paint.setPen(v->getBackground()); | 1440 v->drawVisibleText |
1426 paint.drawText(rx0 + 2, | 1441 (paint, |
1427 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(), | 1442 rx0 + 2, |
1428 text); | 1443 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(), |
1444 text, | |
1445 View::OutlinedText); | |
1429 } | 1446 } |
1430 } | 1447 } |
1431 } | 1448 } |
1432 } | 1449 } |
1433 } | 1450 } |