Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 447:84ada1c89510
* Make scale bar more accurate (if no more helpful) in log scaled colour 3d plot
author | Chris Cannam |
---|---|
date | Wed, 12 Nov 2008 16:39:29 +0000 |
parents | ae51d4b73860 |
children | 035d62c4cddf |
comparison
equal
deleted
inserted
replaced
446:ae51d4b73860 | 447:84ada1c89510 |
---|---|
405 long(modelResolution)); | 405 long(modelResolution)); |
406 | 406 |
407 int f0 = sx0 * modelResolution; | 407 int f0 = sx0 * modelResolution; |
408 int f1 = f0 + modelResolution; | 408 int f1 = f0 + modelResolution; |
409 | 409 |
410 float binHeight = float(v->height()) / m_model->getHeight(); | 410 int sh = m_model->getHeight(); |
411 int sy = int((v->height() - y) / binHeight); | 411 |
412 int symin = m_miny; | |
413 int symax = m_maxy; | |
414 if (symax <= symin) { | |
415 symin = 0; | |
416 symax = sh; | |
417 } | |
418 if (symin < 0) symin = 0; | |
419 if (symax > sh) symax = sh; | |
420 | |
421 float binHeight = float(v->height()) / (symax - symin); | |
422 int sy = int((v->height() - y) / binHeight) + symin; | |
412 | 423 |
413 if (m_invertVertical) sy = m_model->getHeight() - sy - 1; | 424 if (m_invertVertical) sy = m_model->getHeight() - sy - 1; |
414 | 425 |
415 float value = m_model->getValueAt(sx0, sy); | 426 float value = m_model->getValueAt(sx0, sy); |
416 | 427 |
470 int cw = getColourScaleWidth(paint); | 481 int cw = getColourScaleWidth(paint); |
471 | 482 |
472 int ch = h - 20; | 483 int ch = h - 20; |
473 if (ch > 20 && m_cache) { | 484 if (ch > 20 && m_cache) { |
474 | 485 |
486 float min = m_model->getMinimumLevel(); | |
487 float max = m_model->getMaximumLevel(); | |
488 | |
489 float mmin = min; | |
490 float mmax = max; | |
491 | |
492 if (m_colourScale == LogScale) { | |
493 LogRange::mapRange(mmin, mmax); | |
494 } else if (m_colourScale == PlusMinusOneScale) { | |
495 mmin = -1.f; | |
496 mmax = 1.f; | |
497 } | |
498 | |
499 if (max == min) max = min + 1.0; | |
500 | |
475 paint.setPen(v->getForeground()); | 501 paint.setPen(v->getForeground()); |
476 paint.drawRect(4, 10, cw - 8, ch); | 502 paint.drawRect(4, 10, cw - 8, ch+1); |
477 | 503 |
478 for (int y = 0; y < ch; ++y) { | 504 for (int y = 0; y < ch; ++y) { |
479 QRgb c = m_cache->color(((ch - y) * 255) / ch); | 505 float value = ((max - min) * (ch - y - 1)) / ch + min; |
506 if (m_colourScale == LogScale) { | |
507 value = LogRange::map(value); | |
508 } | |
509 int pixel = int(((value - mmin) * 256) / (mmax - mmin)); | |
510 QRgb c = m_cache->color(pixel); | |
511 // QRgb c = m_cache->color(((ch - y) * 255) / ch); | |
480 paint.setPen(QColor(qRed(c), qGreen(c), qBlue(c))); | 512 paint.setPen(QColor(qRed(c), qGreen(c), qBlue(c))); |
481 paint.drawLine(5, 11 + y, cw - 5, 11 + y); | 513 paint.drawLine(5, 11 + y, cw - 5, 11 + y); |
482 } | 514 } |
483 | |
484 float min = m_model->getMinimumLevel(); | |
485 float max = m_model->getMaximumLevel(); | |
486 | 515 |
487 QString minstr = QString("%1").arg(min); | 516 QString minstr = QString("%1").arg(min); |
488 QString maxstr = QString("%1").arg(max); | 517 QString maxstr = QString("%1").arg(max); |
489 | 518 |
490 paint.save(); | 519 paint.save(); |
507 paint.setWorldMatrix(m); | 536 paint.setWorldMatrix(m); |
508 | 537 |
509 v->drawVisibleText(paint, 0, 0, maxstr, View::OutlinedText); | 538 v->drawVisibleText(paint, 0, 0, maxstr, View::OutlinedText); |
510 | 539 |
511 paint.restore(); | 540 paint.restore(); |
512 | |
513 } | 541 } |
514 | 542 |
515 paint.setPen(v->getForeground()); | 543 paint.setPen(v->getForeground()); |
516 | 544 |
517 int sh = m_model->getHeight(); | 545 int sh = m_model->getHeight(); |
956 if (mag > 255) mag = 255; | 984 if (mag > 255) mag = 255; |
957 if (max < 0) max = 0; | 985 if (max < 0) max = 0; |
958 if (max > 255) max = 255; | 986 if (max > 255) max = 255; |
959 | 987 |
960 img.setPixel(x - x0, y, m_cache->color(int(mag + 0.001))); | 988 img.setPixel(x - x0, y, m_cache->color(int(mag + 0.001))); |
961 // img.setPixel(x - x0, y, m_cache->color(max)); | |
962 } | 989 } |
963 } | 990 } |
964 | 991 |
965 paint.drawImage(x0, 0, img); | 992 paint.drawImage(x0, 0, img); |
966 } | 993 } |