Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 534:7a560380b6e2
* Fixes to log bin scale; add colour scale gain
author | Chris Cannam |
---|---|
date | Thu, 21 May 2009 16:55:57 +0000 |
parents | a0e4176b0bf8 |
children | 78f9436195b1 |
comparison
equal
deleted
inserted
replaced
533:a0e4176b0bf8 | 534:7a560380b6e2 |
---|---|
41 m_cacheValidStart(0), | 41 m_cacheValidStart(0), |
42 m_cacheValidEnd(0), | 42 m_cacheValidEnd(0), |
43 m_colourScale(LinearScale), | 43 m_colourScale(LinearScale), |
44 m_colourScaleSet(false), | 44 m_colourScaleSet(false), |
45 m_colourMap(0), | 45 m_colourMap(0), |
46 m_gain(1.0), | |
46 m_binScale(LinearBinScale), | 47 m_binScale(LinearBinScale), |
47 m_normalizeColumns(false), | 48 m_normalizeColumns(false), |
48 m_normalizeVisibleArea(false), | 49 m_normalizeVisibleArea(false), |
49 m_invertVertical(false), | 50 m_invertVertical(false), |
50 m_opaque(false), | 51 m_opaque(false), |
148 PropertyList list; | 149 PropertyList list; |
149 list.push_back("Colour"); | 150 list.push_back("Colour"); |
150 list.push_back("Colour Scale"); | 151 list.push_back("Colour Scale"); |
151 list.push_back("Normalize Columns"); | 152 list.push_back("Normalize Columns"); |
152 list.push_back("Normalize Visible Area"); | 153 list.push_back("Normalize Visible Area"); |
154 list.push_back("Gain"); | |
153 list.push_back("Bin Scale"); | 155 list.push_back("Bin Scale"); |
154 list.push_back("Invert Vertical Scale"); | 156 list.push_back("Invert Vertical Scale"); |
155 list.push_back("Opaque"); | 157 list.push_back("Opaque"); |
156 return list; | 158 return list; |
157 } | 159 } |
162 if (name == "Colour") return tr("Colour"); | 164 if (name == "Colour") return tr("Colour"); |
163 if (name == "Colour Scale") return tr("Scale"); | 165 if (name == "Colour Scale") return tr("Scale"); |
164 if (name == "Normalize Columns") return tr("Normalize Columns"); | 166 if (name == "Normalize Columns") return tr("Normalize Columns"); |
165 if (name == "Normalize Visible Area") return tr("Normalize Visible Area"); | 167 if (name == "Normalize Visible Area") return tr("Normalize Visible Area"); |
166 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale"); | 168 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale"); |
169 if (name == "Gain") return tr("Gain"); | |
167 if (name == "Opaque") return tr("Always Opaque"); | 170 if (name == "Opaque") return tr("Always Opaque"); |
168 if (name == "Bin Scale") return tr("Bin Scale"); | 171 if (name == "Bin Scale") return tr("Bin Scale"); |
169 return ""; | 172 return ""; |
170 } | 173 } |
171 | 174 |
180 } | 183 } |
181 | 184 |
182 Layer::PropertyType | 185 Layer::PropertyType |
183 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const | 186 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const |
184 { | 187 { |
188 if (name == "Gain") return RangeProperty; | |
185 if (name == "Normalize Columns") return ToggleProperty; | 189 if (name == "Normalize Columns") return ToggleProperty; |
186 if (name == "Normalize Visible Area") return ToggleProperty; | 190 if (name == "Normalize Visible Area") return ToggleProperty; |
187 if (name == "Invert Vertical Scale") return ToggleProperty; | 191 if (name == "Invert Vertical Scale") return ToggleProperty; |
188 if (name == "Opaque") return ToggleProperty; | 192 if (name == "Opaque") return ToggleProperty; |
189 return ValueProperty; | 193 return ValueProperty; |
192 QString | 196 QString |
193 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const | 197 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const |
194 { | 198 { |
195 if (name == "Normalize Columns" || | 199 if (name == "Normalize Columns" || |
196 name == "Normalize Visible Area" || | 200 name == "Normalize Visible Area" || |
197 name == "Colour Scale") return tr("Scale"); | 201 name == "Colour Scale" || |
202 name == "Gain") return tr("Scale"); | |
198 if (name == "Bin Scale" || | 203 if (name == "Bin Scale" || |
199 name == "Invert Vertical Scale") return tr("Bins"); | 204 name == "Invert Vertical Scale") return tr("Bins"); |
200 if (name == "Opaque" || | 205 if (name == "Opaque" || |
201 name == "Colour") return tr("Colour"); | 206 name == "Colour") return tr("Colour"); |
202 return QString(); | 207 return QString(); |
211 int garbage0, garbage1, garbage2; | 216 int garbage0, garbage1, garbage2; |
212 if (!min) min = &garbage0; | 217 if (!min) min = &garbage0; |
213 if (!max) max = &garbage1; | 218 if (!max) max = &garbage1; |
214 if (!deflt) deflt = &garbage2; | 219 if (!deflt) deflt = &garbage2; |
215 | 220 |
216 if (name == "Colour Scale") { | 221 if (name == "Gain") { |
222 | |
223 *min = -50; | |
224 *max = 50; | |
225 | |
226 *deflt = lrintf(log10(1.f) * 20.0);; | |
227 if (*deflt < *min) *deflt = *min; | |
228 if (*deflt > *max) *deflt = *max; | |
229 | |
230 val = lrintf(log10(m_gain) * 20.0); | |
231 if (val < *min) val = *min; | |
232 if (val > *max) val = *max; | |
233 | |
234 } else if (name == "Colour Scale") { | |
217 | 235 |
218 *min = 0; | 236 *min = 0; |
219 *max = 3; | 237 *max = 3; |
220 *deflt = (int)LinearScale; | 238 *deflt = (int)LinearScale; |
221 | 239 |
287 } | 305 } |
288 } | 306 } |
289 return tr("<unknown>"); | 307 return tr("<unknown>"); |
290 } | 308 } |
291 | 309 |
310 RangeMapper * | |
311 Colour3DPlotLayer::getNewPropertyRangeMapper(const PropertyName &name) const | |
312 { | |
313 if (name == "Gain") { | |
314 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB")); | |
315 } | |
316 return 0; | |
317 } | |
318 | |
292 void | 319 void |
293 Colour3DPlotLayer::setProperty(const PropertyName &name, int value) | 320 Colour3DPlotLayer::setProperty(const PropertyName &name, int value) |
294 { | 321 { |
295 if (name == "Colour Scale") { | 322 if (name == "Gain") { |
323 setGain(pow(10, float(value)/20.0)); | |
324 } else if (name == "Colour Scale") { | |
296 switch (value) { | 325 switch (value) { |
297 default: | 326 default: |
298 case 0: setColourScale(LinearScale); break; | 327 case 0: setColourScale(LinearScale); break; |
299 case 1: setColourScale(LogScale); break; | 328 case 1: setColourScale(LogScale); break; |
300 case 2: setColourScale(PlusMinusOneScale); break; | 329 case 2: setColourScale(PlusMinusOneScale); break; |
337 cacheInvalid(); | 366 cacheInvalid(); |
338 emit layerParametersChanged(); | 367 emit layerParametersChanged(); |
339 } | 368 } |
340 | 369 |
341 void | 370 void |
371 Colour3DPlotLayer::setGain(float gain) | |
372 { | |
373 if (m_gain == gain) return; | |
374 m_gain = gain; | |
375 cacheInvalid(); | |
376 emit layerParametersChanged(); | |
377 } | |
378 | |
379 float | |
380 Colour3DPlotLayer::getGain() const | |
381 { | |
382 return m_gain; | |
383 } | |
384 | |
385 void | |
342 Colour3DPlotLayer::setBinScale(BinScale binScale) | 386 Colour3DPlotLayer::setBinScale(BinScale binScale) |
343 { | 387 { |
344 if (m_binScale == binScale) return; | 388 if (m_binScale == binScale) return; |
345 m_binScale = binScale; | 389 m_binScale = binScale; |
346 cacheInvalid(); | 390 cacheInvalid(); |
603 symax = sh; | 647 symax = sh; |
604 } | 648 } |
605 if (symin < 0) symin = 0; | 649 if (symin < 0) symin = 0; |
606 if (symax > sh) symax = sh; | 650 if (symax > sh) symax = sh; |
607 | 651 |
608 float binHeight = float(v->height()) / (symax - symin); | 652 // float binHeight = float(v->height()) / (symax - symin); |
609 int sy = int((v->height() - y) / binHeight) + symin; | 653 // int sy = int((v->height() - y) / binHeight) + symin; |
654 | |
655 int sy = getBinForY(v, y); | |
610 | 656 |
611 if (m_invertVertical) sy = m_model->getHeight() - sy - 1; | 657 if (m_invertVertical) sy = m_model->getHeight() - sy - 1; |
612 | 658 |
613 float value = m_model->getValueAt(sx0, sy); | 659 float value = m_model->getValueAt(sx0, sy); |
614 | 660 |
752 } | 798 } |
753 if (symin < 0) symin = 0; | 799 if (symin < 0) symin = 0; |
754 if (symax > sh) symax = sh; | 800 if (symax > sh) symax = sh; |
755 | 801 |
756 paint.save(); | 802 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 } | |
769 | |
770 QFont tf = paint.font(); | |
771 if (paint.fontMetrics().height() >= binHeight) { | |
772 tf.setPixelSize(binHeight > 7 ? binHeight - 2 : 5); | |
773 paint.setFont(tf); | |
774 } | |
775 */ | |
776 | 803 |
777 int py = h; | 804 int py = h; |
778 | 805 |
779 for (size_t i = symin; i < symax; ++i) { | 806 for (size_t i = symin; i <= symax; ++i) { |
780 | |
781 size_t idx = i; | |
782 if (m_invertVertical) idx = m_model->getHeight() - idx - 1; | |
783 | |
784 // if ((idx % step) != 0) continue; | |
785 | 807 |
786 int y0; | 808 int y0; |
787 /* | 809 |
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)); | 810 y0 = lrintf(getYForBin(v, i)); |
797 int h = py - y0; | 811 int h = py - y0; |
798 | 812 |
799 if (i > symin) { | 813 if (i > symin) { |
800 if (paint.fontMetrics().height() >= h) { | 814 if (paint.fontMetrics().height() >= h) { |
808 } | 822 } |
809 } | 823 } |
810 | 824 |
811 py = y0; | 825 py = y0; |
812 | 826 |
813 QString text = m_model->getBinName(idx); | 827 if (i < symax) { |
814 if (text == "") text = QString("[%1]").arg(idx + 1); | 828 paint.drawLine(cw, y0, w, y0); |
815 | 829 } |
816 paint.drawLine(cw, y0, w, y0); | 830 |
817 /*!!! | |
818 if (i > symin) { | 831 if (i > symin) { |
819 paint.drawLine(w - 1, y0 - (step * binHeight) + 1, | 832 |
820 w - 1, y0 - binHeight - 1); | 833 size_t idx = i - 1; |
821 paint.drawLine(w - 2, y0 - (step * binHeight) + 1, | 834 if (m_invertVertical) idx = m_model->getHeight() - idx - 1; |
822 w - 2, y0 - binHeight - 2); | 835 |
823 } | 836 QString text = m_model->getBinName(idx); |
824 */ | 837 if (text == "") text = QString("[%1]").arg(idx + 1); |
825 int cy = int(y0 - h/2); | 838 |
826 int ty = cy + paint.fontMetrics().ascent()/2; | 839 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) + |
827 | 840 paint.fontMetrics().ascent() + 1; |
828 paint.drawText(cw + 5, ty, text); | 841 |
842 paint.drawText(cw + 5, ty, text); | |
843 } | |
829 } | 844 } |
830 | 845 |
831 paint.restore(); | 846 paint.restore(); |
832 } | 847 } |
833 | 848 |
1052 | 1067 |
1053 float value = min; | 1068 float value = min; |
1054 if (y < values.size()) { | 1069 if (y < values.size()) { |
1055 value = values.at(y); | 1070 value = values.at(y); |
1056 } | 1071 } |
1072 | |
1073 value = value * m_gain; | |
1057 | 1074 |
1058 if (m_colourScale == LogScale) { | 1075 if (m_colourScale == LogScale) { |
1059 value = LogRange::map(value); | 1076 value = LogRange::map(value); |
1060 } else if (m_colourScale == AbsoluteScale) { | 1077 } else if (m_colourScale == AbsoluteScale) { |
1061 value = fabsf(value); | 1078 value = fabsf(value); |
1204 paint.fontMetrics().width("0.000000") < rw - 3 && | 1221 paint.fontMetrics().width("0.000000") < rw - 3 && |
1205 paint.fontMetrics().height() < (h / sh)); | 1222 paint.fontMetrics().height() < (h / sh)); |
1206 | 1223 |
1207 for (int sy = symin; sy < symax; ++sy) { | 1224 for (int sy = symin; sy < symax; ++sy) { |
1208 | 1225 |
1209 int ry0 = h - ((sy - symin) * h) / (symax - symin) - 1; | 1226 int ry0 = getYForBin(v, sy); |
1227 int ry1 = getYForBin(v, sy + 1); | |
1228 QRect r(rx0, ry1, rw, ry0 - ry1); | |
1229 | |
1210 QRgb pixel = qRgb(255, 255, 255); | 1230 QRgb pixel = qRgb(255, 255, 255); |
1211 if (sx >= 0 && sx < m_cache->width() && | 1231 if (sx >= 0 && sx < m_cache->width() && |
1212 sy >= 0 && sy < m_cache->height()) { | 1232 sy >= 0 && sy < m_cache->height()) { |
1213 pixel = m_cache->pixel(sx, sy); | 1233 pixel = m_cache->pixel(sx, sy); |
1214 } | 1234 } |
1215 | |
1216 QRect r(rx0, ry0 - h / (symax - symin), | |
1217 rw, h / (symax - symin) + 1); | |
1218 | 1235 |
1219 if (rw == 1) { | 1236 if (rw == 1) { |
1220 paint.setPen(pixel); | 1237 paint.setPen(pixel); |
1221 paint.setBrush(Qt::NoBrush); | 1238 paint.setBrush(Qt::NoBrush); |
1222 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1); | 1239 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1); |
1509 "normalizeColumns=\"%3\" " | 1526 "normalizeColumns=\"%3\" " |
1510 "normalizeVisibleArea=\"%4\" " | 1527 "normalizeVisibleArea=\"%4\" " |
1511 "minY=\"%5\" " | 1528 "minY=\"%5\" " |
1512 "maxY=\"%6\" " | 1529 "maxY=\"%6\" " |
1513 "invertVertical=\"%7\" " | 1530 "invertVertical=\"%7\" " |
1514 "opaque=\"%8\"") | 1531 "opaque=\"%8\" " |
1532 "binScale=\"%9\"") | |
1515 .arg((int)m_colourScale) | 1533 .arg((int)m_colourScale) |
1516 .arg(m_colourMap) | 1534 .arg(m_colourMap) |
1517 .arg(m_normalizeColumns ? "true" : "false") | 1535 .arg(m_normalizeColumns ? "true" : "false") |
1518 .arg(m_normalizeVisibleArea ? "true" : "false") | 1536 .arg(m_normalizeVisibleArea ? "true" : "false") |
1519 .arg(m_miny) | 1537 .arg(m_miny) |
1520 .arg(m_maxy) | 1538 .arg(m_maxy) |
1521 .arg(m_invertVertical ? "true" : "false") | 1539 .arg(m_invertVertical ? "true" : "false") |
1522 .arg(m_opaque ? "true" : "false"); | 1540 .arg(m_opaque ? "true" : "false") |
1541 .arg((int)m_binScale); | |
1523 | 1542 |
1524 Layer::toXml(stream, indent, extraAttributes + " " + s); | 1543 Layer::toXml(stream, indent, extraAttributes + " " + s); |
1525 } | 1544 } |
1526 | 1545 |
1527 void | 1546 void |
1532 ColourScale scale = (ColourScale)attributes.value("scale").toInt(&ok); | 1551 ColourScale scale = (ColourScale)attributes.value("scale").toInt(&ok); |
1533 if (ok) setColourScale(scale); | 1552 if (ok) setColourScale(scale); |
1534 | 1553 |
1535 int colourMap = attributes.value("colourScheme").toInt(&ok); | 1554 int colourMap = attributes.value("colourScheme").toInt(&ok); |
1536 if (ok) setColourMap(colourMap); | 1555 if (ok) setColourMap(colourMap); |
1556 | |
1557 BinScale binscale = (BinScale)attributes.value("binScale").toInt(&ok); | |
1558 if (ok) setBinScale(binscale); | |
1537 | 1559 |
1538 bool normalizeColumns = | 1560 bool normalizeColumns = |
1539 (attributes.value("normalizeColumns").trimmed() == "true"); | 1561 (attributes.value("normalizeColumns").trimmed() == "true"); |
1540 setNormalizeColumns(normalizeColumns); | 1562 setNormalizeColumns(normalizeColumns); |
1541 | 1563 |