Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 903:1757933ce5a7 cxx11
More conversion fixes
author | Chris Cannam |
---|---|
date | Mon, 09 Mar 2015 08:43:20 +0000 |
parents | a1226b3b7925 |
children | e0f08e108064 |
comparison
equal
deleted
inserted
replaced
902:a1226b3b7925 | 903:1757933ce5a7 |
---|---|
31 #include <cassert> | 31 #include <cassert> |
32 | 32 |
33 #ifndef __GNUC__ | 33 #ifndef __GNUC__ |
34 #include <alloca.h> | 34 #include <alloca.h> |
35 #endif | 35 #endif |
36 | |
37 using std::vector; | |
36 | 38 |
37 //#define DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1 | 39 //#define DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1 |
38 | 40 |
39 | 41 |
40 Colour3DPlotLayer::Colour3DPlotLayer() : | 42 Colour3DPlotLayer::Colour3DPlotLayer() : |
658 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin)); | 660 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin)); |
659 } | 661 } |
660 return y; | 662 return y; |
661 } | 663 } |
662 | 664 |
665 int | |
666 Colour3DPlotLayer::getIYForBin(View *v, int bin) const | |
667 { | |
668 return int(roundf(getYForBin(v, float(bin)))); | |
669 } | |
670 | |
663 float | 671 float |
664 Colour3DPlotLayer::getBinForY(View *v, float y) const | 672 Colour3DPlotLayer::getBinForY(View *v, float y) const |
665 { | 673 { |
666 float bin = y; | 674 float bin = y; |
667 if (!m_model) return bin; | 675 if (!m_model) return bin; |
676 bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1; | 684 bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1; |
677 } | 685 } |
678 return bin; | 686 return bin; |
679 } | 687 } |
680 | 688 |
689 int | |
690 Colour3DPlotLayer::getIBinForY(View *v, int y) const | |
691 { | |
692 return int(floorf(getBinForY(v, float(y)))); | |
693 } | |
694 | |
681 QString | 695 QString |
682 Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const | 696 Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const |
683 { | 697 { |
684 if (!m_model) return ""; | 698 if (!m_model) return ""; |
685 | 699 |
711 if (symax > sh) symax = sh; | 725 if (symax > sh) symax = sh; |
712 | 726 |
713 // float binHeight = float(v->height()) / (symax - symin); | 727 // float binHeight = float(v->height()) / (symax - symin); |
714 // int sy = int((v->height() - y) / binHeight) + symin; | 728 // int sy = int((v->height() - y) / binHeight) + symin; |
715 | 729 |
716 int sy = int(getBinForY(v, float(y))); | 730 int sy = getIBinForY(v, y); |
717 | 731 |
718 if (sy < 0 || sy >= m_model->getHeight()) { | 732 if (sy < 0 || sy >= m_model->getHeight()) { |
719 return ""; | 733 return ""; |
720 } | 734 } |
721 | 735 |
870 | 884 |
871 for (int i = symin; i <= symax; ++i) { | 885 for (int i = symin; i <= symax; ++i) { |
872 | 886 |
873 int y0; | 887 int y0; |
874 | 888 |
875 y0 = int(lrint(getYForBin(v, float(i)))); | 889 y0 = getIYForBin(v, i); |
876 int h = py - y0; | 890 int h = py - y0; |
877 | 891 |
878 if (i > symin) { | 892 if (i > symin) { |
879 if (paint.fontMetrics().height() >= h) { | 893 if (paint.fontMetrics().height() >= h) { |
880 if (h >= 8) { | 894 if (h >= 8) { |
1351 paint.fontMetrics().width("0.000000") < rw - 3 && | 1365 paint.fontMetrics().width("0.000000") < rw - 3 && |
1352 paint.fontMetrics().height() < (h / sh)); | 1366 paint.fontMetrics().height() < (h / sh)); |
1353 | 1367 |
1354 for (int sy = symin; sy < symax; ++sy) { | 1368 for (int sy = symin; sy < symax; ++sy) { |
1355 | 1369 |
1356 int ry0 = getYForBin(v, sy); | 1370 int ry0 = getIYForBin(v, sy); |
1357 int ry1 = getYForBin(v, sy + 1); | 1371 int ry1 = getIYForBin(v, sy + 1); |
1358 QRect r(rx0, ry1, rw, ry0 - ry1); | 1372 QRect r(rx0, ry1, rw, ry0 - ry1); |
1359 | 1373 |
1360 QRgb pixel = qRgb(255, 255, 255); | 1374 QRgb pixel = qRgb(255, 255, 255); |
1361 if (sx >= 0 && sx < m_cache->width() && | 1375 if (sx >= 0 && sx < m_cache->width() && |
1362 sy >= 0 && sy < m_cache->height()) { | 1376 sy >= 0 && sy < m_cache->height()) { |
1413 Colour3DPlotLayer::paintDense(View *v, QPainter &paint, QRect rect) const | 1427 Colour3DPlotLayer::paintDense(View *v, QPainter &paint, QRect rect) const |
1414 { | 1428 { |
1415 Profiler profiler("Colour3DPlotLayer::paintDense", true); | 1429 Profiler profiler("Colour3DPlotLayer::paintDense", true); |
1416 if (!m_cache) return; | 1430 if (!m_cache) return; |
1417 | 1431 |
1418 float modelStart = m_model->getStartFrame(); | 1432 double modelStart = double(m_model->getStartFrame()); |
1419 float modelResolution = m_model->getResolution(); | 1433 double modelResolution = double(m_model->getResolution()); |
1420 | 1434 |
1421 int mmsr = v->getViewManager()->getMainModelSampleRate(); | 1435 sv_samplerate_t mmsr = v->getViewManager()->getMainModelSampleRate(); |
1422 int msr = m_model->getSampleRate(); | 1436 sv_samplerate_t msr = m_model->getSampleRate(); |
1423 float srRatio = float(mmsr) / float(msr); | 1437 double srRatio = mmsr / msr; |
1424 | 1438 |
1425 int x0 = rect.left(); | 1439 int x0 = rect.left(); |
1426 int x1 = rect.right() + 1; | 1440 int x1 = rect.right() + 1; |
1427 | 1441 |
1428 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 |
1474 #endif | 1488 #endif |
1475 } | 1489 } |
1476 | 1490 |
1477 int sw = source->width(); | 1491 int sw = source->width(); |
1478 | 1492 |
1479 int xf = -1; | 1493 sv_frame_t xf = -1; |
1480 int nxf = v->getFrameForX(x0); | 1494 sv_frame_t nxf = v->getFrameForX(x0); |
1481 | 1495 |
1482 float epsilon = 0.000001; | 1496 double epsilon = 0.000001; |
1483 | 1497 |
1484 #ifdef __GNUC__ | 1498 vector<double> sxa(w*2); |
1485 float sxa[w * 2]; | 1499 |
1486 #else | |
1487 float *sxa = (float *)alloca(w * 2 * sizeof(float)); | |
1488 #endif | |
1489 for (int x = 0; x < w; ++x) { | 1500 for (int x = 0; x < w; ++x) { |
1490 | 1501 |
1491 xf = nxf; | 1502 xf = nxf; |
1492 nxf = xf + zoomLevel; | 1503 nxf = xf + zoomLevel; |
1493 | 1504 |
1494 float sx0 = (float(xf) / srRatio - modelStart) / modelResolution; | 1505 double sx0 = (double(xf) / srRatio - modelStart) / modelResolution; |
1495 float sx1 = (float(nxf) / srRatio - modelStart) / modelResolution; | 1506 double sx1 = (double(nxf) / srRatio - modelStart) / modelResolution; |
1496 | 1507 |
1497 sxa[x*2] = sx0; | 1508 sxa[x*2] = sx0; |
1498 sxa[x*2 + 1] = sx1; | 1509 sxa[x*2 + 1] = sx1; |
1499 } | 1510 } |
1500 | 1511 |
1501 float logmin = symin+1, logmax = symax+1; | 1512 float logmin = float(symin+1), logmax = float(symax+1); |
1502 LogRange::mapRange(logmin, logmax); | 1513 LogRange::mapRange(logmin, logmax); |
1503 | 1514 |
1504 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 1515 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
1505 cerr << "m_smooth = " << m_smooth << ", w = " << w << ", h = " << h << endl; | 1516 cerr << "m_smooth = " << m_smooth << ", w = " << w << ", h = " << h << endl; |
1506 #endif | 1517 #endif |
1507 | 1518 |
1508 if (m_smooth) { | 1519 if (m_smooth) { |
1509 | 1520 |
1510 for (int y = 0; y < h; ++y) { | 1521 for (int y = 0; y < h; ++y) { |
1511 | 1522 |
1512 float sy = getBinForY(v, y) - 0.5; | 1523 double sy = getBinForY(v, float(y)) - 0.5; |
1513 int syi = int(sy + epsilon); | 1524 int syi = int(sy + epsilon); |
1514 if (syi < 0 || syi >= source->height()) continue; | 1525 if (syi < 0 || syi >= source->height()) continue; |
1515 | 1526 |
1516 uchar *targetLine = img.scanLine(y); | 1527 uchar *targetLine = img.scanLine(y); |
1517 uchar *sourceLine = source->scanLine(syi); | 1528 uchar *sourceLine = source->scanLine(syi); |
1524 | 1535 |
1525 for (int x = 0; x < w; ++x) { | 1536 for (int x = 0; x < w; ++x) { |
1526 | 1537 |
1527 targetLine[x] = 0; | 1538 targetLine[x] = 0; |
1528 | 1539 |
1529 float sx0 = sxa[x*2]; | 1540 double sx0 = sxa[x*2]; |
1530 if (sx0 < 0) continue; | 1541 if (sx0 < 0) continue; |
1531 int sx0i = int(sx0 + epsilon); | 1542 int sx0i = int(sx0 + epsilon); |
1532 if (sx0i >= sw) break; | 1543 if (sx0i >= sw) break; |
1533 | 1544 |
1534 float a = float(sourceLine[sx0i]); | 1545 double a = sourceLine[sx0i]; |
1535 float b = a; | 1546 double b = a; |
1536 float value; | 1547 double value; |
1537 | 1548 |
1538 float sx1 = sxa[x*2+1]; | 1549 double sx1 = sxa[x*2+1]; |
1539 if (sx1 > sx0 + 1.f) { | 1550 if (sx1 > sx0 + 1.f) { |
1540 int sx1i = int(sx1); | 1551 int sx1i = int(sx1); |
1541 bool have = false; | 1552 bool have = false; |
1542 for (int sx = sx0i; sx <= sx1i; ++sx) { | 1553 for (int sx = sx0i; sx <= sx1i; ++sx) { |
1543 if (sx < 0 || sx >= sw) continue; | 1554 if (sx < 0 || sx >= sw) continue; |
1544 if (!have) { | 1555 if (!have) { |
1545 a = float(sourceLine[sx]); | 1556 a = sourceLine[sx]; |
1546 b = float(nextSource[sx]); | 1557 b = nextSource[sx]; |
1547 have = true; | 1558 have = true; |
1548 } else { | 1559 } else { |
1549 a = std::max(a, float(sourceLine[sx])); | 1560 a = std::max(a, double(sourceLine[sx])); |
1550 b = std::max(b, float(nextSource[sx])); | 1561 b = std::max(b, double(nextSource[sx])); |
1551 } | 1562 } |
1552 } | 1563 } |
1553 float yprop = sy - syi; | 1564 double yprop = sy - syi; |
1554 value = (a * (1.f - yprop) + b * yprop); | 1565 value = (a * (1.f - yprop) + b * yprop); |
1555 } else { | 1566 } else { |
1556 a = float(sourceLine[sx0i]); | 1567 a = sourceLine[sx0i]; |
1557 b = float(nextSource[sx0i]); | 1568 b = nextSource[sx0i]; |
1558 float yprop = sy - syi; | 1569 double yprop = sy - syi; |
1559 value = (a * (1.f - yprop) + b * yprop); | 1570 value = (a * (1.f - yprop) + b * yprop); |
1560 int oi = sx0i + 1; | 1571 int oi = sx0i + 1; |
1561 float xprop = sx0 - sx0i; | 1572 double xprop = sx0 - sx0i; |
1562 xprop -= 0.5; | 1573 xprop -= 0.5; |
1563 if (xprop < 0) { | 1574 if (xprop < 0) { |
1564 oi = sx0i - 1; | 1575 oi = sx0i - 1; |
1565 xprop = -xprop; | 1576 xprop = -xprop; |
1566 } | 1577 } |
1567 if (oi < 0 || oi >= sw) oi = sx0i; | 1578 if (oi < 0 || oi >= sw) oi = sx0i; |
1568 a = float(sourceLine[oi]); | 1579 a = sourceLine[oi]; |
1569 b = float(nextSource[oi]); | 1580 b = nextSource[oi]; |
1570 value = (value * (1.f - xprop) + | 1581 value = (value * (1.f - xprop) + |
1571 (a * (1.f - yprop) + b * yprop) * xprop); | 1582 (a * (1.f - yprop) + b * yprop) * xprop); |
1572 } | 1583 } |
1573 | 1584 |
1574 int vi = lrintf(value); | 1585 int vi = int(lrint(value)); |
1575 if (vi > 255) vi = 255; | 1586 if (vi > 255) vi = 255; |
1576 if (vi < 0) vi = 0; | 1587 if (vi < 0) vi = 0; |
1577 targetLine[x] = uchar(vi); | 1588 targetLine[x] = uchar(vi); |
1578 } | 1589 } |
1579 } | 1590 } |
1584 int psy0i = -1, psy1i = -1; | 1595 int psy0i = -1, psy1i = -1; |
1585 | 1596 |
1586 for (int y = 0; y < h; ++y) { | 1597 for (int y = 0; y < h; ++y) { |
1587 | 1598 |
1588 float sy1 = sy0; | 1599 float sy1 = sy0; |
1589 sy0 = getBinForY(v, y + 1); | 1600 sy0 = getBinForY(v, float(y + 1)); |
1590 | 1601 |
1591 int sy0i = int(sy0 + epsilon); | 1602 int sy0i = int(sy0 + epsilon); |
1592 int sy1i = int(sy1); | 1603 int sy1i = int(sy1); |
1593 | 1604 |
1594 uchar *targetLine = img.scanLine(y); | 1605 uchar *targetLine = img.scanLine(y); |
1611 | 1622 |
1612 uchar *sourceLine = source->scanLine(sy); | 1623 uchar *sourceLine = source->scanLine(sy); |
1613 | 1624 |
1614 for (int x = 0; x < w; ++x) { | 1625 for (int x = 0; x < w; ++x) { |
1615 | 1626 |
1616 float sx1 = sxa[x*2 + 1]; | 1627 double sx1 = sxa[x*2 + 1]; |
1617 if (sx1 < 0) continue; | 1628 if (sx1 < 0) continue; |
1618 int sx1i = int(sx1); | 1629 int sx1i = int(sx1); |
1619 | 1630 |
1620 float sx0 = sxa[x*2]; | 1631 double sx0 = sxa[x*2]; |
1621 if (sx0 < 0) continue; | 1632 if (sx0 < 0) continue; |
1622 int sx0i = int(sx0 + epsilon); | 1633 int sx0i = int(sx0 + epsilon); |
1623 if (sx0i >= sw) break; | 1634 if (sx0i >= sw) break; |
1624 | 1635 |
1625 uchar peak = 0; | 1636 uchar peak = 0; |