comparison layer/Colour3DPlotLayer.cpp @ 532:188049db73fa

* some improvements to log scale in colour 3d plot (still only in dense mode though)
author Chris Cannam
date Tue, 19 May 2009 13:03:36 +0000
parents 0bd0b517e795
children a0e4176b0bf8
comparison
equal deleted inserted replaced
531:0bd0b517e795 532:188049db73fa
535 535
536 return new LinearRangeMapper(0, m_model->getHeight(), 536 return new LinearRangeMapper(0, m_model->getHeight(),
537 0, m_model->getHeight(), ""); 537 0, m_model->getHeight(), "");
538 } 538 }
539 539
540 float
541 Colour3DPlotLayer::getYForBin(View *v, float bin) const
542 {
543 float y = bin;
544 if (!m_model) return y;
545 float mn = 0, mx = m_model->getHeight();
546 getDisplayExtents(mn, mx);
547 float h = v->height();
548 if (m_binScale == LinearBinScale) {
549 y = h - (((bin - mn) * h) / (mx - mn));
550 } else {
551 float logmin = mn + 1, logmax = mx + 1;
552 LogRange::mapRange(logmin, logmax);
553 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin));
554 }
555 return y;
556 }
557
558 float
559 Colour3DPlotLayer::getBinForY(View *v, float y) const
560 {
561 float bin = y;
562 if (!m_model) return bin;
563 float mn = 0, mx = m_model->getHeight();
564 getDisplayExtents(mn, mx);
565 float h = v->height();
566 if (m_binScale == LinearBinScale) {
567 bin = mn + ((h - y) * (mx - mn)) / h;
568 } else {
569 float logmin = mn + 1, logmax = mx + 1;
570 LogRange::mapRange(logmin, logmax);
571 bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1;
572 }
573 return bin;
574 }
575
540 QString 576 QString
541 Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const 577 Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const
542 { 578 {
543 if (!m_model) return ""; 579 if (!m_model) return "";
544 580
715 symax = sh; 751 symax = sh;
716 } 752 }
717 if (symin < 0) symin = 0; 753 if (symin < 0) symin = 0;
718 if (symax > sh) symax = sh; 754 if (symax > sh) symax = sh;
719 755
720 float binHeight = float(v->height()) / (symax - symin);
721
722 paint.save(); 756 paint.save();
757 /*
758 int count = v->height() / paint.fontMetrics().height();
759 int step = (symax - symin) / count;
760 if (step == 0) step = 1;
761
762 float logmin = symin+1, logmax = symax+1;
763 LogRange::mapRange(logmin, logmax);
764
765 float binHeight = float(v->height()) / (symax - symin); //!!!
766 if (m_binScale == LogBinScale) {
767 binHeight = float(v->height()) / (logmax - logmin);
768 }
723 769
724 QFont tf = paint.font(); 770 QFont tf = paint.font();
725 if (paint.fontMetrics().height() >= binHeight) { 771 if (paint.fontMetrics().height() >= binHeight) {
726 tf.setPixelSize(binHeight > 7 ? binHeight - 2 : 5); 772 tf.setPixelSize(binHeight > 7 ? binHeight - 2 : 5);
727 paint.setFont(tf); 773 paint.setFont(tf);
728 } 774 }
729 775 */
730 int count = v->height() / paint.fontMetrics().height(); 776
731 int step = (symax - symin) / count; 777 int py = 0;
732 if (step == 0) step = 1;
733 778
734 for (size_t i = symin; i < symax; ++i) { 779 for (size_t i = symin; i < symax; ++i) {
735 780
736 size_t idx = i; 781 size_t idx = i;
737 if (m_invertVertical) idx = m_model->getHeight() - idx - 1; 782 if (m_invertVertical) idx = m_model->getHeight() - idx - 1;
738 783
739 if ((idx % step) != 0) continue; 784 // if ((idx % step) != 0) continue;
740 785
741 int y0 = int(v->height() - ((i - symin) * binHeight) - 1); 786 int y0;
787 /*
788 if (m_binScale == LinearBinScale) {
789 y0 = int(v->height() - ((i - symin) * binHeight) - 1);
790 } else {
791 //!!! garbage
792 float yy = LogRange::unmap(LogRange::map(i+1) - logmin);
793 y0 = int(v->height() - (yy * binHeight) - 1);
794 }
795 */
796 y0 = lrintf(getYForBin(v, i));
797 int h = py - y0;
798
799 if (i > symin) {
800 if (paint.fontMetrics().height() >= h) {
801 if (h >= 7) {
802 QFont tf = paint.font();
803 tf.setPixelSize(h > 7 ? h-2 : 5);
804 paint.setFont(tf);
805 } else {
806 continue;
807 }
808 }
809 }
742 810
811 py = y0;
812
743 QString text = m_model->getBinName(idx); 813 QString text = m_model->getBinName(idx);
744 if (text == "") text = QString("[%1]").arg(idx + 1); 814 if (text == "") text = QString("[%1]").arg(idx + 1);
745 815
746 paint.drawLine(cw, y0, w, y0); 816 paint.drawLine(cw, y0, w, y0);
747 817 /*!!!
748 if (step > 1) { 818 if (i > symin) {
749 paint.drawLine(w - 1, y0 - (step * binHeight) + 1, 819 paint.drawLine(w - 1, y0 - (step * binHeight) + 1,
750 w - 1, y0 - binHeight - 1); 820 w - 1, y0 - binHeight - 1);
751 paint.drawLine(w - 2, y0 - (step * binHeight) + 1, 821 paint.drawLine(w - 2, y0 - (step * binHeight) + 1,
752 w - 2, y0 - binHeight - 2); 822 w - 2, y0 - binHeight - 2);
753 } 823 }
754 824 */
755 int cy = int(y0 - (step * binHeight)/2); 825 int cy = int(y0 - h/2);
756 int ty = cy + paint.fontMetrics().ascent()/2; 826 int ty = cy + paint.fontMetrics().ascent()/2;
757 827
758 paint.drawText(cw + 5, ty, text); 828 paint.drawText(cw + 5, ty, text);
759 } 829 }
760 830
1269 1339
1270 sxa[x*2] = sx0i; 1340 sxa[x*2] = sx0i;
1271 sxa[x*2 + 1] = sx1i; 1341 sxa[x*2 + 1] = sx1i;
1272 } 1342 }
1273 1343
1344 float logmin = symin+1, logmax = symax+1;
1345 LogRange::mapRange(logmin, logmax);
1346
1274 for (int y = 0; y < h; ++y) { 1347 for (int y = 0; y < h; ++y) {
1275 1348
1276 float sy0, sy1; 1349 float sy0, sy1;
1277 1350
1351 sy0 = getBinForY(v, y + 1);
1352 sy1 = getBinForY(v, y);
1353 /*
1278 if (m_binScale == LinearBinScale) { 1354 if (m_binScale == LinearBinScale) {
1279 sy0 = symin + (float(h - y - 1) * (symax - symin)) / h; 1355 sy0 = symin + (float(h - y - 1) * (symax - symin)) / h;
1280 sy1 = symin + (float(h - y) * (symax - symin)) / h; 1356 sy1 = symin + (float(h - y) * (symax - symin)) / h;
1281 } else { 1357 } else {
1282 float logmin = LogRange::map(symin); 1358 // float logmin = LogRange::map(symin);
1283 float logmax = LogRange::map(symax); 1359 // float logmax = LogRange::map(symax);
1284 sy0 = logmin + (float(h - y - 1) * (logmax - logmin)) / h; 1360 sy0 = logmin + (float(h - y - 1) * (logmax - logmin)) / h;
1285 sy1 = logmin + (float(h - y) * (logmax - logmin)) / h; 1361 sy1 = logmin + (float(h - y) * (logmax - logmin)) / h;
1286 sy0 = pow10f(sy0); 1362 sy0 = LogRange::unmap(sy0)-1;
1287 sy1 = pow10f(sy1); 1363 sy1 = LogRange::unmap(sy1)-1;
1288 } 1364 // sy0 = pow10f(sy0);
1289 1365 // sy1 = pow10f(sy1);
1366 }
1367 */
1290 int sy0i = int(sy0 + 0.001); 1368 int sy0i = int(sy0 + 0.001);
1291 int sy1i = int(sy1); 1369 int sy1i = int(sy1);
1292 1370
1293 uchar *targetLine = img.scanLine(y); 1371 uchar *targetLine = img.scanLine(y);
1294 1372