comparison layer/Colour3DPlotLayer.cpp @ 902:a1226b3b7925 cxx11

Toward building with new sv types
author Chris Cannam
date Wed, 04 Mar 2015 19:11:32 +0000
parents 3ca3b8fbbcee
children 1757933ce5a7
comparison
equal deleted inserted replaced
901:0fe1f4407261 902:a1226b3b7925
232 if (name == "Gain") { 232 if (name == "Gain") {
233 233
234 *min = -50; 234 *min = -50;
235 *max = 50; 235 *max = 50;
236 236
237 *deflt = lrintf(log10(1.f) * 20.0);; 237 *deflt = int(lrint(log10(1.0) * 20.0));
238 if (*deflt < *min) *deflt = *min; 238 if (*deflt < *min) *deflt = *min;
239 if (*deflt > *max) *deflt = *max; 239 if (*deflt > *max) *deflt = *max;
240 240
241 val = lrintf(log10(m_gain) * 20.0); 241 val = int(lrint(log10(m_gain) * 20.0));
242 if (val < *min) val = *min; 242 if (val < *min) val = *min;
243 if (val > *max) val = *max; 243 if (val > *max) val = *max;
244 244
245 } else if (name == "Colour Scale") { 245 } else if (name == "Colour Scale") {
246 246
334 334
335 void 335 void
336 Colour3DPlotLayer::setProperty(const PropertyName &name, int value) 336 Colour3DPlotLayer::setProperty(const PropertyName &name, int value)
337 { 337 {
338 if (name == "Gain") { 338 if (name == "Gain") {
339 setGain(pow(10, float(value)/20.0)); 339 setGain(float(pow(10, value/20.0)));
340 } else if (name == "Colour Scale") { 340 } else if (name == "Colour Scale") {
341 switch (value) { 341 switch (value) {
342 default: 342 default:
343 case 0: setColourScale(LinearScale); break; 343 case 0: setColourScale(LinearScale); break;
344 case 1: setColourScale(LogScale); break; 344 case 1: setColourScale(LogScale); break;
545 bool &logarithmic, QString &unit) const 545 bool &logarithmic, QString &unit) const
546 { 546 {
547 if (!m_model) return false; 547 if (!m_model) return false;
548 548
549 min = 0; 549 min = 0;
550 max = m_model->getHeight(); 550 max = float(m_model->getHeight());
551 551
552 logarithmic = false; 552 logarithmic = false;
553 unit = ""; 553 unit = "";
554 554
555 return true; 555 return true;
558 bool 558 bool
559 Colour3DPlotLayer::getDisplayExtents(float &min, float &max) const 559 Colour3DPlotLayer::getDisplayExtents(float &min, float &max) const
560 { 560 {
561 if (!m_model) return false; 561 if (!m_model) return false;
562 562
563 min = m_miny; 563 float hmax = float(m_model->getHeight());
564 max = m_maxy; 564
565 min = float(m_miny);
566 max = float(m_maxy);
565 if (max <= min) { 567 if (max <= min) {
566 min = 0; 568 min = 0;
567 max = m_model->getHeight(); 569 max = hmax;
568 } 570 }
569 if (min < 0) min = 0; 571 if (min < 0) min = 0;
570 if (max > m_model->getHeight()) max = m_model->getHeight(); 572 if (max > hmax) max = hmax;
571 573
572 return true; 574 return true;
573 } 575 }
574 576
575 bool 577 bool
576 Colour3DPlotLayer::setDisplayExtents(float min, float max) 578 Colour3DPlotLayer::setDisplayExtents(float min, float max)
577 { 579 {
578 if (!m_model) return false; 580 if (!m_model) return false;
579 581
580 m_miny = lrintf(min); 582 m_miny = int(lrintf(min));
581 m_maxy = lrintf(max); 583 m_maxy = int(lrintf(max));
582 584
583 emit layerParametersChanged(); 585 emit layerParametersChanged();
584 return true; 586 return true;
585 } 587 }
586 588
606 { 608 {
607 if (!m_model) return 0; 609 if (!m_model) return 0;
608 610
609 float min, max; 611 float min, max;
610 getDisplayExtents(min, max); 612 getDisplayExtents(min, max);
611 return m_model->getHeight() - lrintf(max - min); 613 return m_model->getHeight() - int(lrintf(max - min));
612 } 614 }
613 615
614 void 616 void
615 Colour3DPlotLayer::setVerticalZoomStep(int step) 617 Colour3DPlotLayer::setVerticalZoomStep(int step)
616 { 618 {
618 620
619 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << endl; 621 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << endl;
620 622
621 int dist = m_model->getHeight() - step; 623 int dist = m_model->getHeight() - step;
622 if (dist < 1) dist = 1; 624 if (dist < 1) dist = 1;
623 float centre = m_miny + (float(m_maxy) - float(m_miny)) / 2.f; 625 float centre = float(m_miny) + (float(m_maxy) - float(m_miny)) / 2.f;
624 m_miny = lrintf(centre - float(dist)/2); 626 m_miny = int(lrintf(centre - float(dist)/2));
625 if (m_miny < 0) m_miny = 0; 627 if (m_miny < 0) m_miny = 0;
626 m_maxy = m_miny + dist; 628 m_maxy = m_miny + dist;
627 if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight(); 629 if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight();
628 630
629 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << endl; 631 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << endl;
643 float 645 float
644 Colour3DPlotLayer::getYForBin(View *v, float bin) const 646 Colour3DPlotLayer::getYForBin(View *v, float bin) const
645 { 647 {
646 float y = bin; 648 float y = bin;
647 if (!m_model) return y; 649 if (!m_model) return y;
648 float mn = 0, mx = m_model->getHeight(); 650 float mn = 0, mx = float(m_model->getHeight());
649 getDisplayExtents(mn, mx); 651 getDisplayExtents(mn, mx);
650 float h = v->height(); 652 float h = float(v->height());
651 if (m_binScale == LinearBinScale) { 653 if (m_binScale == LinearBinScale) {
652 y = h - (((bin - mn) * h) / (mx - mn)); 654 y = h - (((bin - mn) * h) / (mx - mn));
653 } else { 655 } else {
654 float logmin = mn + 1, logmax = mx + 1; 656 float logmin = mn + 1, logmax = mx + 1;
655 LogRange::mapRange(logmin, logmax); 657 LogRange::mapRange(logmin, logmax);
661 float 663 float
662 Colour3DPlotLayer::getBinForY(View *v, float y) const 664 Colour3DPlotLayer::getBinForY(View *v, float y) const
663 { 665 {
664 float bin = y; 666 float bin = y;
665 if (!m_model) return bin; 667 if (!m_model) return bin;
666 float mn = 0, mx = m_model->getHeight(); 668 float mn = 0, mx = float(m_model->getHeight());
667 getDisplayExtents(mn, mx); 669 getDisplayExtents(mn, mx);
668 float h = v->height(); 670 float h = float(v->height());
669 if (m_binScale == LinearBinScale) { 671 if (m_binScale == LinearBinScale) {
670 bin = mn + ((h - y) * (mx - mn)) / h; 672 bin = mn + ((h - y) * (mx - mn)) / h;
671 } else { 673 } else {
672 float logmin = mn + 1, logmax = mx + 1; 674 float logmin = mn + 1, logmax = mx + 1;
673 LogRange::mapRange(logmin, logmax); 675 LogRange::mapRange(logmin, logmax);
682 if (!m_model) return ""; 684 if (!m_model) return "";
683 685
684 int x = pos.x(); 686 int x = pos.x();
685 int y = pos.y(); 687 int y = pos.y();
686 688
687 int modelStart = m_model->getStartFrame(); 689 sv_frame_t modelStart = m_model->getStartFrame();
688 int modelResolution = m_model->getResolution(); 690 int modelResolution = m_model->getResolution();
689 691
690 float srRatio = 692 double srRatio =
691 float(v->getViewManager()->getMainModelSampleRate()) / 693 v->getViewManager()->getMainModelSampleRate() /
692 float(m_model->getSampleRate()); 694 m_model->getSampleRate();
693 695
694 int sx0 = int((v->getFrameForX(x) / srRatio - modelStart) / 696 int sx0 = int((double(v->getFrameForX(x)) / srRatio - double(modelStart)) /
695 modelResolution); 697 modelResolution);
696 698
697 int f0 = sx0 * modelResolution; 699 int f0 = sx0 * modelResolution;
698 int f1 = f0 + modelResolution; 700 int f1 = f0 + modelResolution;
699 701
709 if (symax > sh) symax = sh; 711 if (symax > sh) symax = sh;
710 712
711 // float binHeight = float(v->height()) / (symax - symin); 713 // float binHeight = float(v->height()) / (symax - symin);
712 // int sy = int((v->height() - y) / binHeight) + symin; 714 // int sy = int((v->height() - y) / binHeight) + symin;
713 715
714 int sy = getBinForY(v, y); 716 int sy = int(getBinForY(v, float(y)));
715 717
716 if (sy < 0 || sy >= m_model->getHeight()) { 718 if (sy < 0 || sy >= m_model->getHeight()) {
717 return ""; 719 return "";
718 } 720 }
719 721
799 mmin = fabsf(mmin); 801 mmin = fabsf(mmin);
800 mmax = fabsf(mmax); 802 mmax = fabsf(mmax);
801 } 803 }
802 } 804 }
803 805
804 if (max == min) max = min + 1.0; 806 if (max == min) max = min + 1.f;
805 if (mmax == mmin) mmax = mmin + 1.0; 807 if (mmax == mmin) mmax = mmin + 1.f;
806 808
807 paint.setPen(v->getForeground()); 809 paint.setPen(v->getForeground());
808 paint.drawRect(4, 10, cw - 8, ch+1); 810 paint.drawRect(4, 10, cw - 8, ch+1);
809 811
810 for (int y = 0; y < ch; ++y) { 812 for (int y = 0; y < ch; ++y) {
811 float value = ((max - min) * (ch - y - 1)) / ch + min; 813 float value = ((max - min) * (float(ch-y) - 1.f)) / float(ch) + min;
812 if (m_colourScale == LogScale) { 814 if (m_colourScale == LogScale) {
813 value = LogRange::map(value); 815 value = LogRange::map(value);
814 } 816 }
815 int pixel = int(((value - mmin) * 256) / (mmax - mmin)); 817 int pixel = int(((value - mmin) * 256) / (mmax - mmin));
816 if (pixel >= 0 && pixel < 256) { 818 if (pixel >= 0 && pixel < 256) {
868 870
869 for (int i = symin; i <= symax; ++i) { 871 for (int i = symin; i <= symax; ++i) {
870 872
871 int y0; 873 int y0;
872 874
873 y0 = lrintf(getYForBin(v, i)); 875 y0 = int(lrint(getYForBin(v, float(i))));
874 int h = py - y0; 876 int h = py - y0;
875 877
876 if (i > symin) { 878 if (i > symin) {
877 if (paint.fontMetrics().height() >= h) { 879 if (paint.fontMetrics().height() >= h) {
878 if (h >= 8) { 880 if (h >= 8) {
938 940
939 if (value != newvalue) values[y] = newvalue; 941 if (value != newvalue) values[y] = newvalue;
940 } 942 }
941 943
942 if (m_normalizeHybrid && (colMax > 0.0)) { 944 if (m_normalizeHybrid && (colMax > 0.0)) {
943 float logmax = log10(colMax); 945 float logmax = log10f(colMax);
944 for (int y = 0; y < values.size(); ++y) { 946 for (int y = 0; y < values.size(); ++y) {
945 values[y] *= logmax; 947 values[y] *= logmax;
946 } 948 }
947 } 949 }
948 950
952 void 954 void
953 Colour3DPlotLayer::fillCache(int firstBin, int lastBin) const 955 Colour3DPlotLayer::fillCache(int firstBin, int lastBin) const
954 { 956 {
955 Profiler profiler("Colour3DPlotLayer::fillCache", true); 957 Profiler profiler("Colour3DPlotLayer::fillCache", true);
956 958
957 int modelStart = m_model->getStartFrame(); 959 sv_frame_t modelStart = m_model->getStartFrame();
958 int modelEnd = m_model->getEndFrame(); 960 sv_frame_t modelEnd = m_model->getEndFrame();
959 int modelResolution = m_model->getResolution(); 961 int modelResolution = m_model->getResolution();
960 962
961 int modelStartBin = modelStart / modelResolution; 963 int modelStartBin = int(modelStart / modelResolution);
962 int modelEndBin = modelEnd / modelResolution; 964 int modelEndBin = int(modelEnd / modelResolution);
963 965
964 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 966 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
965 cerr << "Colour3DPlotLayer::fillCache: range " << firstBin << " -> " << lastBin << " of model range " << modelStartBin << " -> " << modelEndBin << " (model resolution " << modelResolution << ")" << endl; 967 cerr << "Colour3DPlotLayer::fillCache: range " << firstBin << " -> " << lastBin << " of model range " << modelStartBin << " -> " << modelEndBin << " (model resolution " << modelResolution << ")" << endl;
966 #endif 968 #endif
967 969
1086 min = fabsf(min); 1088 min = fabsf(min);
1087 max = fabsf(max); 1089 max = fabsf(max);
1088 } 1090 }
1089 } 1091 }
1090 1092
1091 if (max == min) max = min + 1.0; 1093 if (max == min) max = min + 1.f;
1092 1094
1093 ColourMapper mapper(m_colourMap, 0.f, 255.f); 1095 ColourMapper mapper(m_colourMap, 0.f, 255.f);
1094 1096
1095 for (int index = 0; index < 256; ++index) { 1097 for (int index = 0; index < 256; ++index) {
1096 QColor colour = mapper.map(index); 1098 QColor colour = mapper.map(index);
1233 Colour3DPlotLayer::shouldPaintDenseIn(const View *v) const 1235 Colour3DPlotLayer::shouldPaintDenseIn(const View *v) const
1234 { 1236 {
1235 if (!m_model || !v || !(v->getViewManager())) { 1237 if (!m_model || !v || !(v->getViewManager())) {
1236 return false; 1238 return false;
1237 } 1239 }
1238 float srRatio = 1240 double srRatio =
1239 float(v->getViewManager()->getMainModelSampleRate()) / 1241 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate();
1240 float(m_model->getSampleRate());
1241 if (m_opaque || 1242 if (m_opaque ||
1242 m_smooth || 1243 m_smooth ||
1243 m_model->getHeight() >= v->height() || 1244 m_model->getHeight() >= v->height() ||
1244 ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) { 1245 ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) {
1245 return true; 1246 return true;
1269 return; 1270 return;
1270 } 1271 }
1271 1272
1272 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->rect(); 1273 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->rect();
1273 1274
1274 int modelStart = m_model->getStartFrame(); 1275 sv_frame_t modelStart = m_model->getStartFrame();
1275 int modelEnd = m_model->getEndFrame(); 1276 sv_frame_t modelEnd = m_model->getEndFrame();
1276 int modelResolution = m_model->getResolution(); 1277 int modelResolution = m_model->getResolution();
1277 1278
1278 // The cache is from the model's start frame to the model's end 1279 // The cache is from the model's start frame to the model's end
1279 // frame at the model's window increment frames per pixel. We 1280 // frame at the model's window increment frames per pixel. We
1280 // want to draw from our start frame + x0 * zoomLevel to our start 1281 // want to draw from our start frame + x0 * zoomLevel to our start
1287 int x0 = rect.left(); 1288 int x0 = rect.left();
1288 int x1 = rect.right() + 1; 1289 int x1 = rect.right() + 1;
1289 1290
1290 int h = v->height(); 1291 int h = v->height();
1291 1292
1292 float srRatio = 1293 double srRatio =
1293 float(v->getViewManager()->getMainModelSampleRate()) / 1294 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate();
1294 float(m_model->getSampleRate()); 1295
1295 1296 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart))
1296 int sx0 = int((v->getFrameForX(x0) / srRatio - modelStart)
1297 / modelResolution); 1297 / modelResolution);
1298 int sx1 = int((v->getFrameForX(x1) / srRatio - modelStart) 1298 int sx1 = int((double(v->getFrameForX(x1)) / srRatio - double(modelStart))
1299 / modelResolution); 1299 / modelResolution);
1300 int sh = m_model->getHeight(); 1300 int sh = m_model->getHeight();
1301 1301
1302 int symin = m_miny; 1302 int symin = m_miny;
1303 int symax = m_maxy; 1303 int symax = m_maxy;
1335 const int buflen = 40; 1335 const int buflen = 40;
1336 char labelbuf[buflen]; 1336 char labelbuf[buflen];
1337 1337
1338 for (int sx = sx0; sx <= sx1; ++sx) { 1338 for (int sx = sx0; sx <= sx1; ++sx) {
1339 1339
1340 int fx = sx * modelResolution; 1340 sv_frame_t fx = sx * modelResolution;
1341 1341
1342 if (fx + modelResolution <= modelStart || fx > modelEnd) continue; 1342 if (fx + modelResolution <= modelStart || fx > modelEnd) continue;
1343 1343
1344 int rx0 = v->getXForFrame(int((fx + modelStart) * srRatio)); 1344 int rx0 = v->getXForFrame(int(double(fx + modelStart) * srRatio));
1345 int rx1 = v->getXForFrame(int((fx + modelStart + modelResolution + 1) * srRatio)); 1345 int rx1 = v->getXForFrame(int(double(fx + modelStart + modelResolution + 1) * srRatio));
1346 1346
1347 int rw = rx1 - rx0; 1347 int rw = rx1 - rx0;
1348 if (rw < 1) rw = 1; 1348 if (rw < 1) rw = 1;
1349 1349
1350 bool showLabel = (rw > 10 && 1350 bool showLabel = (rw > 10 &&