Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 444:e5800f4490c4
* Make Colour 3D Plot layer vertically zoomable and scrollable
Still need to save/restore these settings for this and the time/value
and note layers
author | Chris Cannam |
---|---|
date | Wed, 12 Nov 2008 15:17:16 +0000 |
parents | 5124d1494a59 |
children | 4a14499fb184 |
comparison
equal
deleted
inserted
replaced
443:5124d1494a59 | 444:e5800f4490c4 |
---|---|
16 #include "Colour3DPlotLayer.h" | 16 #include "Colour3DPlotLayer.h" |
17 | 17 |
18 #include "view/View.h" | 18 #include "view/View.h" |
19 #include "base/Profiler.h" | 19 #include "base/Profiler.h" |
20 #include "base/LogRange.h" | 20 #include "base/LogRange.h" |
21 #include "base/RangeMapper.h" | |
21 #include "ColourMapper.h" | 22 #include "ColourMapper.h" |
22 | 23 |
23 #include <QPainter> | 24 #include <QPainter> |
24 #include <QImage> | 25 #include <QImage> |
25 #include <QRect> | 26 #include <QRect> |
38 m_cacheStart(0), | 39 m_cacheStart(0), |
39 m_colourScale(LinearScale), | 40 m_colourScale(LinearScale), |
40 m_colourMap(0), | 41 m_colourMap(0), |
41 m_normalizeColumns(false), | 42 m_normalizeColumns(false), |
42 m_normalizeVisibleArea(false), | 43 m_normalizeVisibleArea(false), |
43 m_invertVertical(false) | 44 m_invertVertical(false), |
45 m_miny(0), | |
46 m_maxy(0) | |
44 { | 47 { |
45 | 48 |
46 } | 49 } |
47 | 50 |
48 Colour3DPlotLayer::~Colour3DPlotLayer() | 51 Colour3DPlotLayer::~Colour3DPlotLayer() |
288 if (m_normalizeVisibleArea) return false; | 291 if (m_normalizeVisibleArea) return false; |
289 QPoint discard; | 292 QPoint discard; |
290 return !v->shouldIlluminateLocalFeatures(this, discard); | 293 return !v->shouldIlluminateLocalFeatures(this, discard); |
291 } | 294 } |
292 | 295 |
296 bool | |
297 Colour3DPlotLayer::getValueExtents(float &min, float &max, | |
298 bool &logarithmic, QString &unit) const | |
299 { | |
300 if (!m_model) return false; | |
301 | |
302 min = 0; | |
303 max = m_model->getHeight(); | |
304 | |
305 logarithmic = false; | |
306 unit = ""; | |
307 | |
308 return true; | |
309 } | |
310 | |
311 bool | |
312 Colour3DPlotLayer::getDisplayExtents(float &min, float &max) const | |
313 { | |
314 if (!m_model) return false; | |
315 | |
316 min = m_miny; | |
317 max = m_maxy; | |
318 if (max <= min) { | |
319 min = 0; | |
320 max = m_model->getHeight(); | |
321 } | |
322 if (min < 0) min = 0; | |
323 if (max > m_model->getHeight()) max = m_model->getHeight(); | |
324 | |
325 return true; | |
326 } | |
327 | |
328 bool | |
329 Colour3DPlotLayer::setDisplayExtents(float min, float max) | |
330 { | |
331 if (!m_model) return false; | |
332 | |
333 m_miny = lrintf(min); | |
334 m_maxy = lrintf(max); | |
335 | |
336 emit layerParametersChanged(); | |
337 return true; | |
338 } | |
339 | |
340 int | |
341 Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const | |
342 { | |
343 if (!m_model) return 0; | |
344 | |
345 defaultStep = 0; | |
346 int h = m_model->getHeight(); | |
347 return h; | |
348 } | |
349 | |
350 int | |
351 Colour3DPlotLayer::getCurrentVerticalZoomStep() const | |
352 { | |
353 if (!m_model) return 0; | |
354 | |
355 float min, max; | |
356 getDisplayExtents(min, max); | |
357 return m_model->getHeight() - lrintf(max - min); | |
358 } | |
359 | |
360 void | |
361 Colour3DPlotLayer::setVerticalZoomStep(int step) | |
362 { | |
363 if (!m_model) return; | |
364 | |
365 std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << std::endl; | |
366 | |
367 int dist = m_model->getHeight() - step; | |
368 if (dist < 1) dist = 1; | |
369 float centre = m_miny + (float(m_maxy) - float(m_miny)) / 2.f; | |
370 m_miny = lrintf(centre - float(dist)/2); | |
371 if (m_miny < 0) m_miny = 0; | |
372 m_maxy = m_miny + dist; | |
373 if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight(); | |
374 | |
375 std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << std::endl; | |
376 | |
377 emit layerParametersChanged(); | |
378 } | |
379 | |
380 RangeMapper * | |
381 Colour3DPlotLayer::getNewVerticalZoomRangeMapper() const | |
382 { | |
383 if (!m_model) return 0; | |
384 | |
385 return new LinearRangeMapper(0, m_model->getHeight(), | |
386 0, m_model->getHeight(), ""); | |
387 } | |
388 | |
293 QString | 389 QString |
294 Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const | 390 Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const |
295 { | 391 { |
296 if (!m_model) return ""; | 392 if (!m_model) return ""; |
297 | 393 |
619 / long(modelResolution)); | 715 / long(modelResolution)); |
620 int sx1 = int((v->getFrameForX(x1) / srRatio - long(modelStart)) | 716 int sx1 = int((v->getFrameForX(x1) / srRatio - long(modelStart)) |
621 / long(modelResolution)); | 717 / long(modelResolution)); |
622 int sh = m_model->getHeight(); | 718 int sh = m_model->getHeight(); |
623 | 719 |
720 int symin = m_miny; | |
721 int symax = m_maxy; | |
722 if (symax <= symin) { | |
723 symin = 0; | |
724 symax = sh; | |
725 } | |
726 if (symin < 0) symin = 0; | |
727 if (symax > sh) symax = sh; | |
728 | |
624 if (sx0 > 0) --sx0; | 729 if (sx0 > 0) --sx0; |
625 fillCache(sx0 < 0 ? 0 : sx0, | 730 fillCache(sx0 < 0 ? 0 : sx0, |
626 sx1 < 0 ? 0 : sx1); | 731 sx1 < 0 ? 0 : sx1); |
627 | 732 |
628 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 733 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
665 | 770 |
666 bool showLabel = (rw > 10 && | 771 bool showLabel = (rw > 10 && |
667 paint.fontMetrics().width("0.000000") < rw - 3 && | 772 paint.fontMetrics().width("0.000000") < rw - 3 && |
668 paint.fontMetrics().height() < (h / sh)); | 773 paint.fontMetrics().height() < (h / sh)); |
669 | 774 |
670 for (int sy = 0; sy < sh; ++sy) { | 775 for (int sy = symin; sy < symax; ++sy) { |
671 | 776 |
672 int ry0 = h - (sy * h) / sh - 1; | 777 int ry0 = h - ((sy - symin) * h) / (symax - symin) - 1; |
673 QRgb pixel = qRgb(255, 255, 255); | 778 QRgb pixel = qRgb(255, 255, 255); |
674 if (scx >= 0 && scx < m_cache->width() && | 779 if (scx >= 0 && scx < m_cache->width() && |
675 sy >= 0 && sy < m_cache->height()) { | 780 sy >= 0 && sy < m_cache->height()) { |
676 pixel = m_cache->pixel(scx, sy); | 781 pixel = m_cache->pixel(scx, sy); |
677 } | 782 } |
678 | 783 |
679 QRect r(rx0, ry0 - h / sh - 1, rw, h / sh + 1); | 784 QRect r(rx0, ry0 - h / (symax - symin) - 1, |
785 rw, h / (symax - symin) + 1); | |
680 | 786 |
681 if (rw == 1) { | 787 if (rw == 1) { |
682 paint.setPen(pixel); | 788 paint.setPen(pixel); |
683 paint.setBrush(Qt::NoBrush); | 789 paint.setBrush(Qt::NoBrush); |
684 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1); | 790 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1); |
739 | 845 |
740 int w = x1 - x0; | 846 int w = x1 - x0; |
741 int h = v->height(); | 847 int h = v->height(); |
742 int sh = m_model->getHeight(); | 848 int sh = m_model->getHeight(); |
743 | 849 |
850 int symin = m_miny; | |
851 int symax = m_maxy; | |
852 if (symax <= symin) { | |
853 symin = 0; | |
854 symax = sh; | |
855 } | |
856 if (symin < 0) symin = 0; | |
857 if (symax > sh) symax = sh; | |
858 | |
744 QImage img(w, h, QImage::Format_RGB32); | 859 QImage img(w, h, QImage::Format_RGB32); |
745 | 860 |
746 for (int x = x0; x < x1; ++x) { | 861 for (int x = x0; x < x1; ++x) { |
747 | 862 |
748 long xf = long(v->getFrameForX(x)); | 863 long xf = long(v->getFrameForX(x)); |
761 int sx0i = int(sx0 + 0.001); | 876 int sx0i = int(sx0 + 0.001); |
762 int sx1i = int(sx1); | 877 int sx1i = int(sx1); |
763 | 878 |
764 for (int y = 0; y < h; ++y) { | 879 for (int y = 0; y < h; ++y) { |
765 | 880 |
766 float sy0 = (float(h - y - 1) * sh) / h; | 881 float sy0 = symin + (float(h - y - 1) * (symax - symin)) / h; |
767 float sy1 = (float(h - y) * sh) / h; | 882 float sy1 = symin + (float(h - y) * (symax - symin)) / h; |
768 | 883 |
769 int sy0i = int(sy0 + 0.001); | 884 int sy0i = int(sy0 + 0.001); |
770 int sy1i = int(sy1); | 885 int sy1i = int(sy1); |
771 | 886 |
772 float mag = 0.0, div = 0.0; | 887 float mag = 0.0, div = 0.0; |