Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 374:64e84e5efb76 spectrogram-cache-rejig
* Merge from trunk
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 11:59:42 +0000 |
parents | 984c1975f1ff |
children |
comparison
equal
deleted
inserted
replaced
332:6440e280122e | 374:64e84e5efb76 |
---|---|
37 m_cache(0), | 37 m_cache(0), |
38 m_cacheStart(0), | 38 m_cacheStart(0), |
39 m_colourScale(LinearScale), | 39 m_colourScale(LinearScale), |
40 m_colourMap(0), | 40 m_colourMap(0), |
41 m_normalizeColumns(false), | 41 m_normalizeColumns(false), |
42 m_normalizeVisibleArea(false) | 42 m_normalizeVisibleArea(false), |
43 m_invertVertical(false) | |
43 { | 44 { |
44 | 45 |
45 } | 46 } |
46 | 47 |
47 Colour3DPlotLayer::~Colour3DPlotLayer() | 48 Colour3DPlotLayer::~Colour3DPlotLayer() |
85 PropertyList list; | 86 PropertyList list; |
86 list.push_back("Colour"); | 87 list.push_back("Colour"); |
87 list.push_back("Colour Scale"); | 88 list.push_back("Colour Scale"); |
88 list.push_back("Normalize Columns"); | 89 list.push_back("Normalize Columns"); |
89 list.push_back("Normalize Visible Area"); | 90 list.push_back("Normalize Visible Area"); |
91 list.push_back("Invert Vertical Scale"); | |
90 return list; | 92 return list; |
91 } | 93 } |
92 | 94 |
93 QString | 95 QString |
94 Colour3DPlotLayer::getPropertyLabel(const PropertyName &name) const | 96 Colour3DPlotLayer::getPropertyLabel(const PropertyName &name) const |
95 { | 97 { |
96 if (name == "Colour") return tr("Colour"); | 98 if (name == "Colour") return tr("Colour"); |
97 if (name == "Colour Scale") return tr("Scale"); | 99 if (name == "Colour Scale") return tr("Scale"); |
98 if (name == "Normalize Columns") return tr("Normalize Columns"); | 100 if (name == "Normalize Columns") return tr("Normalize Columns"); |
99 if (name == "Normalize Visible Area") return tr("Normalize Visible Area"); | 101 if (name == "Normalize Visible Area") return tr("Normalize Visible Area"); |
102 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale"); | |
103 return ""; | |
104 } | |
105 | |
106 QString | |
107 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const | |
108 { | |
109 if (name == "Normalize Columns") return "normalise-columns"; | |
110 if (name == "Normalize Visible Area") return "normalise"; | |
111 if (name == "Invert Vertical Scale") return "invert-vertical"; | |
100 return ""; | 112 return ""; |
101 } | 113 } |
102 | 114 |
103 Layer::PropertyType | 115 Layer::PropertyType |
104 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const | 116 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const |
105 { | 117 { |
106 if (name == "Normalize Columns") return ToggleProperty; | 118 if (name == "Normalize Columns") return ToggleProperty; |
107 if (name == "Normalize Visible Area") return ToggleProperty; | 119 if (name == "Normalize Visible Area") return ToggleProperty; |
120 if (name == "Invert Vertical Scale") return ToggleProperty; | |
108 return ValueProperty; | 121 return ValueProperty; |
109 } | 122 } |
110 | 123 |
111 QString | 124 QString |
112 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const | 125 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const |
113 { | 126 { |
114 if (name == "Normalize Columns" || | 127 if (name == "Normalize Columns" || |
115 name == "Normalize Visible Area" || | 128 name == "Normalize Visible Area" || |
129 name == "Invert Vertical Scale" || | |
116 name == "Colour Scale") return tr("Scale"); | 130 name == "Colour Scale") return tr("Scale"); |
117 return QString(); | 131 return QString(); |
118 } | 132 } |
119 | 133 |
120 int | 134 int |
151 | 165 |
152 } else if (name == "Normalize Visible Area") { | 166 } else if (name == "Normalize Visible Area") { |
153 | 167 |
154 *deflt = 0; | 168 *deflt = 0; |
155 val = (m_normalizeVisibleArea ? 1 : 0); | 169 val = (m_normalizeVisibleArea ? 1 : 0); |
170 | |
171 } else if (name == "Invert Vertical Scale") { | |
172 | |
173 *deflt = 0; | |
174 val = (m_invertVertical ? 1 : 0); | |
156 | 175 |
157 } else { | 176 } else { |
158 val = Layer::getPropertyRangeAndValue(name, min, max, deflt); | 177 val = Layer::getPropertyRangeAndValue(name, min, max, deflt); |
159 } | 178 } |
160 | 179 |
193 setColourMap(value); | 212 setColourMap(value); |
194 } else if (name == "Normalize Columns") { | 213 } else if (name == "Normalize Columns") { |
195 setNormalizeColumns(value ? true : false); | 214 setNormalizeColumns(value ? true : false); |
196 } else if (name == "Normalize Visible Area") { | 215 } else if (name == "Normalize Visible Area") { |
197 setNormalizeVisibleArea(value ? true : false); | 216 setNormalizeVisibleArea(value ? true : false); |
217 } else if (name == "Invert Vertical Scale") { | |
218 setInvertVertical(value ? true : false); | |
198 } | 219 } |
199 } | 220 } |
200 | 221 |
201 void | 222 void |
202 Colour3DPlotLayer::setColourScale(ColourScale scale) | 223 Colour3DPlotLayer::setColourScale(ColourScale scale) |
244 Colour3DPlotLayer::getNormalizeVisibleArea() const | 265 Colour3DPlotLayer::getNormalizeVisibleArea() const |
245 { | 266 { |
246 return m_normalizeVisibleArea; | 267 return m_normalizeVisibleArea; |
247 } | 268 } |
248 | 269 |
270 void | |
271 Colour3DPlotLayer::setInvertVertical(bool n) | |
272 { | |
273 if (m_invertVertical == n) return; | |
274 m_invertVertical = n; | |
275 cacheInvalid(); | |
276 emit layerParametersChanged(); | |
277 } | |
278 | |
279 bool | |
280 Colour3DPlotLayer::getInvertVertical() const | |
281 { | |
282 return m_invertVertical; | |
283 } | |
284 | |
249 bool | 285 bool |
250 Colour3DPlotLayer::isLayerScrollable(const View *v) const | 286 Colour3DPlotLayer::isLayerScrollable(const View *v) const |
251 { | 287 { |
252 if (m_normalizeVisibleArea) return false; | 288 if (m_normalizeVisibleArea) return false; |
253 QPoint discard; | 289 QPoint discard; |
275 int f0 = sx0 * modelResolution; | 311 int f0 = sx0 * modelResolution; |
276 int f1 = f0 + modelResolution; | 312 int f1 = f0 + modelResolution; |
277 | 313 |
278 float binHeight = float(v->height()) / m_model->getHeight(); | 314 float binHeight = float(v->height()) / m_model->getHeight(); |
279 int sy = int((v->height() - y) / binHeight); | 315 int sy = int((v->height() - y) / binHeight); |
316 | |
317 if (m_invertVertical) sy = m_model->getHeight() - sy - 1; | |
280 | 318 |
281 float value = m_model->getValueAt(sx0, sy); | 319 float value = m_model->getValueAt(sx0, sy); |
282 | 320 |
283 // std::cerr << "bin value (" << sx0 << "," << sy << ") is " << value << std::endl; | 321 // std::cerr << "bin value (" << sx0 << "," << sy << ") is " << value << std::endl; |
284 | 322 |
356 int step = m_model->getHeight() / count; | 394 int step = m_model->getHeight() / count; |
357 if (step == 0) step = 1; | 395 if (step == 0) step = 1; |
358 | 396 |
359 for (size_t i = 0; i < m_model->getHeight(); ++i) { | 397 for (size_t i = 0; i < m_model->getHeight(); ++i) { |
360 | 398 |
361 if ((i % step) != 0) continue; | 399 size_t idx = i; |
400 if (m_invertVertical) idx = m_model->getHeight() - idx - 1; | |
401 | |
402 if ((idx % step) != 0) continue; | |
362 | 403 |
363 int y0 = int(v->height() - (i * binHeight) - 1); | 404 int y0 = int(v->height() - (i * binHeight) - 1); |
364 | 405 |
365 QString text = m_model->getBinName(i); | 406 QString text = m_model->getBinName(idx); |
366 if (text == "") text = QString("[%1]").arg(i + 1); | 407 if (text == "") text = QString("[%1]").arg(idx + 1); |
367 | 408 |
368 paint.drawLine(cw, y0, w, y0); | 409 paint.drawLine(cw, y0, w, y0); |
369 | 410 |
370 int cy = int(y0 - (step * binHeight)/2); | 411 int cy = int(y0 - (step * binHeight)/2); |
371 int ty = cy + paint.fontMetrics().ascent()/2; | 412 int ty = cy + paint.fontMetrics().ascent()/2; |
516 | 557 |
517 int pixel = int(((value - min) * 256) / (max - min)); | 558 int pixel = int(((value - min) * 256) / (max - min)); |
518 if (pixel < 0) pixel = 0; | 559 if (pixel < 0) pixel = 0; |
519 if (pixel > 255) pixel = 255; | 560 if (pixel > 255) pixel = 255; |
520 | 561 |
521 m_cache->setPixel(c - firstBin, y, pixel); | 562 if (m_invertVertical) { |
563 m_cache->setPixel(c - firstBin, m_model->getHeight() - y - 1, | |
564 pixel); | |
565 } else { | |
566 m_cache->setPixel(c - firstBin, y, pixel); | |
567 } | |
522 } | 568 } |
523 } | 569 } |
524 } | 570 } |
525 | 571 |
526 void | 572 void |
572 | 618 |
573 if (sx0 > 0) --sx0; | 619 if (sx0 > 0) --sx0; |
574 fillCache(sx0 < 0 ? 0 : sx0, | 620 fillCache(sx0 < 0 ? 0 : sx0, |
575 sx1 < 0 ? 0 : sx1); | 621 sx1 < 0 ? 0 : sx1); |
576 | 622 |
623 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | |
624 std::cerr << "Colour3DPlotLayer::paint: height = "<< m_model->getHeight() << ", modelStart = " << modelStart << ", resolution = " << modelResolution << ", model rate = " << m_model->getSampleRate() << std::endl; | |
625 #endif | |
626 | |
577 if (int(m_model->getHeight()) >= v->height() || | 627 if (int(m_model->getHeight()) >= v->height() || |
578 int(modelResolution) < v->getZoomLevel() / 2) { | 628 int(modelResolution * m_model->getSampleRate()) < v->getZoomLevel() / 2) { |
629 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | |
630 std::cerr << "calling paintDense" << std::endl; | |
631 #endif | |
579 paintDense(v, paint, rect); | 632 paintDense(v, paint, rect); |
580 return; | 633 return; |
581 } | 634 } |
582 | 635 |
583 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 636 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
584 std::cerr << "Colour3DPlotLayer::paint: w " << w << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sw << ", sh " << sh << std::endl; | 637 std::cerr << "Colour3DPlotLayer::paint: w " << x1-x0 << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sx1-sx0 << ", sh " << sh << std::endl; |
585 std::cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << std::endl; | 638 std::cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << std::endl; |
586 #endif | 639 #endif |
587 | 640 |
588 QPoint illuminatePos; | 641 QPoint illuminatePos; |
589 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos); | 642 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos); |
594 int scx = 0; | 647 int scx = 0; |
595 if (sx > int(m_cacheStart)) scx = sx - m_cacheStart; | 648 if (sx > int(m_cacheStart)) scx = sx - m_cacheStart; |
596 | 649 |
597 int fx = sx * int(modelResolution); | 650 int fx = sx * int(modelResolution); |
598 | 651 |
599 if (fx + int(modelResolution) < int(modelStart) || | 652 if (fx + int(modelResolution) <= int(modelStart) || |
600 fx > int(modelEnd)) continue; | 653 fx > int(modelEnd)) continue; |
601 | 654 |
602 int rx0 = v->getXForFrame(int((fx + int(modelStart)) * srRatio)); | 655 int rx0 = v->getXForFrame(int((fx + int(modelStart)) * srRatio)); |
603 int rx1 = v->getXForFrame(int((fx + int(modelStart) + int(modelResolution) + 1) * srRatio)); | 656 int rx1 = v->getXForFrame(int((fx + int(modelStart) + int(modelResolution) + 1) * srRatio)); |
604 | 657 |
685 | 738 |
686 QImage img(w, h, QImage::Format_RGB32); | 739 QImage img(w, h, QImage::Format_RGB32); |
687 | 740 |
688 for (int x = x0; x < x1; ++x) { | 741 for (int x = x0; x < x1; ++x) { |
689 | 742 |
690 long xf = long(v->getFrameForX(x) / srRatio); | 743 long xf = long(v->getFrameForX(x)); |
691 if (xf < 0) { | 744 if (xf < 0) { |
692 for (int y = 0; y < h; ++y) { | 745 for (int y = 0; y < h; ++y) { |
693 img.setPixel(x - x0, y, m_cache->color(0)); | 746 img.setPixel(x - x0, y, m_cache->color(0)); |
694 } | 747 } |
695 continue; | 748 continue; |
696 } | 749 } |
750 | |
751 xf /= srRatio; | |
697 | 752 |
698 float sx0 = (float(xf) - modelStart) / modelResolution; | 753 float sx0 = (float(xf) - modelStart) / modelResolution; |
699 float sx1 = (float(v->getFrameForX(x+1) / srRatio) - modelStart) / modelResolution; | 754 float sx1 = (float(v->getFrameForX(x+1) / srRatio) - modelStart) / modelResolution; |
700 | 755 |
701 int sx0i = int(sx0 + 0.001); | 756 int sx0i = int(sx0 + 0.001); |