Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 916:94e4952a6774 osx-retina
Start trying to introduce LayerGeometryProvider as proxyable interface for View methods that the Layer wants to use
| author | Chris Cannam |
|---|---|
| date | Tue, 17 Mar 2015 15:05:25 +0000 |
| parents | 4a578a360011 |
| children | 0aac065f09f9 |
comparison
equal
deleted
inserted
replaced
| 915:f6d9f28f37cb | 916:94e4952a6774 |
|---|---|
| 504 { | 504 { |
| 505 return m_smooth; | 505 return m_smooth; |
| 506 } | 506 } |
| 507 | 507 |
| 508 void | 508 void |
| 509 Colour3DPlotLayer::setLayerDormant(const View *v, bool dormant) | 509 Colour3DPlotLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) |
| 510 { | 510 { |
| 511 if (dormant) { | 511 if (dormant) { |
| 512 | 512 |
| 513 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 513 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
| 514 cerr << "Colour3DPlotLayer::setLayerDormant(" << dormant << ")" | 514 cerr << "Colour3DPlotLayer::setLayerDormant(" << dormant << ")" |
| 528 Layer::setLayerDormant(v, false); | 528 Layer::setLayerDormant(v, false); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 bool | 532 bool |
| 533 Colour3DPlotLayer::isLayerScrollable(const View *v) const | 533 Colour3DPlotLayer::isLayerScrollable(const LayerGeometryProvider *v) const |
| 534 { | 534 { |
| 535 if (m_normalizeVisibleArea) { | 535 if (m_normalizeVisibleArea) { |
| 536 return false; | 536 return false; |
| 537 } | 537 } |
| 538 if (shouldPaintDenseIn(v)) { | 538 if (shouldPaintDenseIn(v)) { |
| 587 emit layerParametersChanged(); | 587 emit layerParametersChanged(); |
| 588 return true; | 588 return true; |
| 589 } | 589 } |
| 590 | 590 |
| 591 bool | 591 bool |
| 592 Colour3DPlotLayer::getYScaleValue(const View *, int, | 592 Colour3DPlotLayer::getYScaleValue(const LayerGeometryProvider *, int, |
| 593 double &, QString &) const | 593 double &, QString &) const |
| 594 { | 594 { |
| 595 return false;//!!! | 595 return false;//!!! |
| 596 } | 596 } |
| 597 | 597 |
| 643 return new LinearRangeMapper(0, m_model->getHeight(), | 643 return new LinearRangeMapper(0, m_model->getHeight(), |
| 644 0, m_model->getHeight(), ""); | 644 0, m_model->getHeight(), ""); |
| 645 } | 645 } |
| 646 | 646 |
| 647 double | 647 double |
| 648 Colour3DPlotLayer::getYForBin(View *v, double bin) const | 648 Colour3DPlotLayer::getYForBin(LayerGeometryProvider *v, double bin) const |
| 649 { | 649 { |
| 650 double y = bin; | 650 double y = bin; |
| 651 if (!m_model) return y; | 651 if (!m_model) return y; |
| 652 double mn = 0, mx = m_model->getHeight(); | 652 double mn = 0, mx = m_model->getHeight(); |
| 653 getDisplayExtents(mn, mx); | 653 getDisplayExtents(mn, mx); |
| 654 double h = v->height(); | 654 double h = v->getPaintHeight(); |
| 655 if (m_binScale == LinearBinScale) { | 655 if (m_binScale == LinearBinScale) { |
| 656 y = h - (((bin - mn) * h) / (mx - mn)); | 656 y = h - (((bin - mn) * h) / (mx - mn)); |
| 657 } else { | 657 } else { |
| 658 double logmin = mn + 1, logmax = mx + 1; | 658 double logmin = mn + 1, logmax = mx + 1; |
| 659 LogRange::mapRange(logmin, logmax); | 659 LogRange::mapRange(logmin, logmax); |
| 661 } | 661 } |
| 662 return y; | 662 return y; |
| 663 } | 663 } |
| 664 | 664 |
| 665 int | 665 int |
| 666 Colour3DPlotLayer::getIYForBin(View *v, int bin) const | 666 Colour3DPlotLayer::getIYForBin(LayerGeometryProvider *v, int bin) const |
| 667 { | 667 { |
| 668 return int(round(getYForBin(v, bin))); | 668 return int(round(getYForBin(v, bin))); |
| 669 } | 669 } |
| 670 | 670 |
| 671 double | 671 double |
| 672 Colour3DPlotLayer::getBinForY(View *v, double y) const | 672 Colour3DPlotLayer::getBinForY(LayerGeometryProvider *v, double y) const |
| 673 { | 673 { |
| 674 double bin = y; | 674 double bin = y; |
| 675 if (!m_model) return bin; | 675 if (!m_model) return bin; |
| 676 double mn = 0, mx = m_model->getHeight(); | 676 double mn = 0, mx = m_model->getHeight(); |
| 677 getDisplayExtents(mn, mx); | 677 getDisplayExtents(mn, mx); |
| 678 double h = v->height(); | 678 double h = v->getPaintHeight(); |
| 679 if (m_binScale == LinearBinScale) { | 679 if (m_binScale == LinearBinScale) { |
| 680 bin = mn + ((h - y) * (mx - mn)) / h; | 680 bin = mn + ((h - y) * (mx - mn)) / h; |
| 681 } else { | 681 } else { |
| 682 double logmin = mn + 1, logmax = mx + 1; | 682 double logmin = mn + 1, logmax = mx + 1; |
| 683 LogRange::mapRange(logmin, logmax); | 683 LogRange::mapRange(logmin, logmax); |
| 685 } | 685 } |
| 686 return bin; | 686 return bin; |
| 687 } | 687 } |
| 688 | 688 |
| 689 int | 689 int |
| 690 Colour3DPlotLayer::getIBinForY(View *v, int y) const | 690 Colour3DPlotLayer::getIBinForY(LayerGeometryProvider *v, int y) const |
| 691 { | 691 { |
| 692 return int(floor(getBinForY(v, y))); | 692 return int(floor(getBinForY(v, y))); |
| 693 } | 693 } |
| 694 | 694 |
| 695 QString | 695 QString |
| 696 Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const | 696 Colour3DPlotLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const |
| 697 { | 697 { |
| 698 if (!m_model) return ""; | 698 if (!m_model) return ""; |
| 699 | 699 |
| 700 int x = pos.x(); | 700 int x = pos.x(); |
| 701 int y = pos.y(); | 701 int y = pos.y(); |
| 722 symax = sh; | 722 symax = sh; |
| 723 } | 723 } |
| 724 if (symin < 0) symin = 0; | 724 if (symin < 0) symin = 0; |
| 725 if (symax > sh) symax = sh; | 725 if (symax > sh) symax = sh; |
| 726 | 726 |
| 727 // double binHeight = double(v->height()) / (symax - symin); | 727 // double binHeight = double(v->getPaintHeight()) / (symax - symin); |
| 728 // int sy = int((v->height() - y) / binHeight) + symin; | 728 // int sy = int((v->getPaintHeight() - y) / binHeight) + symin; |
| 729 | 729 |
| 730 int sy = getIBinForY(v, y); | 730 int sy = getIBinForY(v, y); |
| 731 | 731 |
| 732 if (sy < 0 || sy >= m_model->getHeight()) { | 732 if (sy < 0 || sy >= m_model->getHeight()) { |
| 733 return ""; | 733 return ""; |
| 760 int cw = 20; | 760 int cw = 20; |
| 761 return cw; | 761 return cw; |
| 762 } | 762 } |
| 763 | 763 |
| 764 int | 764 int |
| 765 Colour3DPlotLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const | 765 Colour3DPlotLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const |
| 766 { | 766 { |
| 767 if (!m_model) return 0; | 767 if (!m_model) return 0; |
| 768 | 768 |
| 769 QString sampleText = QString("[%1]").arg(m_model->getHeight()); | 769 QString sampleText = QString("[%1]").arg(m_model->getHeight()); |
| 770 int tw = paint.fontMetrics().width(sampleText); | 770 int tw = paint.fontMetrics().width(sampleText); |
| 782 | 782 |
| 783 return tw + 13 + getColourScaleWidth(paint); | 783 return tw + 13 + getColourScaleWidth(paint); |
| 784 } | 784 } |
| 785 | 785 |
| 786 void | 786 void |
| 787 Colour3DPlotLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const | 787 Colour3DPlotLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const |
| 788 { | 788 { |
| 789 if (!m_model) return; | 789 if (!m_model) return; |
| 790 | 790 |
| 791 int h = rect.height(), w = rect.width(); | 791 int h = rect.height(), w = rect.width(); |
| 792 | 792 |
| 1244 | 1244 |
| 1245 delete[] peaks; | 1245 delete[] peaks; |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 bool | 1248 bool |
| 1249 Colour3DPlotLayer::shouldPaintDenseIn(const View *v) const | 1249 Colour3DPlotLayer::shouldPaintDenseIn(const LayerGeometryProvider *v) const |
| 1250 { | 1250 { |
| 1251 if (!m_model || !v || !(v->getViewManager())) { | 1251 if (!m_model || !v || !(v->getViewManager())) { |
| 1252 return false; | 1252 return false; |
| 1253 } | 1253 } |
| 1254 double srRatio = | 1254 double srRatio = |
| 1255 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); | 1255 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); |
| 1256 if (m_opaque || | 1256 if (m_opaque || |
| 1257 m_smooth || | 1257 m_smooth || |
| 1258 m_model->getHeight() >= v->height() || | 1258 m_model->getHeight() >= v->getPaintHeight() || |
| 1259 ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) { | 1259 ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) { |
| 1260 return true; | 1260 return true; |
| 1261 } | 1261 } |
| 1262 return false; | 1262 return false; |
| 1263 } | 1263 } |
| 1264 | 1264 |
| 1265 void | 1265 void |
| 1266 Colour3DPlotLayer::paint(View *v, QPainter &paint, QRect rect) const | 1266 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const |
| 1267 { | 1267 { |
| 1268 /* | 1268 /* |
| 1269 if (m_model) { | 1269 if (m_model) { |
| 1270 SVDEBUG << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << m_model->shouldUseLogValueScale() << endl; | 1270 SVDEBUG << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << m_model->shouldUseLogValueScale() << endl; |
| 1271 } | 1271 } |
| 1276 #endif | 1276 #endif |
| 1277 | 1277 |
| 1278 int completion = 0; | 1278 int completion = 0; |
| 1279 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) { | 1279 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) { |
| 1280 if (completion > 0) { | 1280 if (completion > 0) { |
| 1281 paint.fillRect(0, 10, v->width() * completion / 100, | 1281 paint.fillRect(0, 10, v->getPaintWidth() * completion / 100, |
| 1282 10, QColor(120, 120, 120)); | 1282 10, QColor(120, 120, 120)); |
| 1283 } | 1283 } |
| 1284 return; | 1284 return; |
| 1285 } | 1285 } |
| 1286 | 1286 |
| 1287 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->rect(); | 1287 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->getPaintRect(); |
| 1288 | 1288 |
| 1289 sv_frame_t modelStart = m_model->getStartFrame(); | 1289 sv_frame_t modelStart = m_model->getStartFrame(); |
| 1290 sv_frame_t modelEnd = m_model->getEndFrame(); | 1290 sv_frame_t modelEnd = m_model->getEndFrame(); |
| 1291 int modelResolution = m_model->getResolution(); | 1291 int modelResolution = m_model->getResolution(); |
| 1292 | 1292 |
| 1300 // "small". This is "large"; see paintDense below for "small". | 1300 // "small". This is "large"; see paintDense below for "small". |
| 1301 | 1301 |
| 1302 int x0 = rect.left(); | 1302 int x0 = rect.left(); |
| 1303 int x1 = rect.right() + 1; | 1303 int x1 = rect.right() + 1; |
| 1304 | 1304 |
| 1305 int h = v->height(); | 1305 int h = v->getPaintHeight(); |
| 1306 | 1306 |
| 1307 double srRatio = | 1307 double srRatio = |
| 1308 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); | 1308 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); |
| 1309 | 1309 |
| 1310 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart)) | 1310 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart)) |
| 1422 } | 1422 } |
| 1423 } | 1423 } |
| 1424 } | 1424 } |
| 1425 | 1425 |
| 1426 void | 1426 void |
| 1427 Colour3DPlotLayer::paintDense(View *v, QPainter &paint, QRect rect) const | 1427 Colour3DPlotLayer::paintDense(LayerGeometryProvider *v, QPainter &paint, QRect rect) const |
| 1428 { | 1428 { |
| 1429 Profiler profiler("Colour3DPlotLayer::paintDense", true); | 1429 Profiler profiler("Colour3DPlotLayer::paintDense", true); |
| 1430 if (!m_cache) return; | 1430 if (!m_cache) return; |
| 1431 | 1431 |
| 1432 double modelStart = double(m_model->getStartFrame()); | 1432 double modelStart = double(m_model->getStartFrame()); |
| 1438 | 1438 |
| 1439 int x0 = rect.left(); | 1439 int x0 = rect.left(); |
| 1440 int x1 = rect.right() + 1; | 1440 int x1 = rect.right() + 1; |
| 1441 | 1441 |
| 1442 const int w = x1 - x0; // const so it can be used as array size below | 1442 const int w = x1 - x0; // const so it can be used as array size below |
| 1443 int h = v->height(); // we always paint full height | 1443 int h = v->getPaintHeight(); // we always paint full height |
| 1444 int sh = m_model->getHeight(); | 1444 int sh = m_model->getHeight(); |
| 1445 | 1445 |
| 1446 int symin = m_miny; | 1446 int symin = m_miny; |
| 1447 int symax = m_maxy; | 1447 int symax = m_maxy; |
| 1448 if (symax <= symin) { | 1448 if (symax <= symin) { |
| 1653 | 1653 |
| 1654 paint.drawImage(x0, 0, img); | 1654 paint.drawImage(x0, 0, img); |
| 1655 } | 1655 } |
| 1656 | 1656 |
| 1657 bool | 1657 bool |
| 1658 Colour3DPlotLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, | 1658 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
| 1659 int &resolution, | 1659 int &resolution, |
| 1660 SnapType snap) const | 1660 SnapType snap) const |
| 1661 { | 1661 { |
| 1662 if (!m_model) { | 1662 if (!m_model) { |
| 1663 return Layer::snapToFeatureFrame(v, frame, resolution, snap); | 1663 return Layer::snapToFeatureFrame(v, frame, resolution, snap); |
