comparison layer/Colour3DPlotLayer.cpp @ 465:b77b79413cdb

* fix some warnings, remove debug
author Chris Cannam
date Fri, 16 Jan 2009 15:12:23 +0000
parents 1461cfc7e446
children b13dfc443e71
comparison
equal deleted inserted replaced
464:69089c9dc42e 465:b77b79413cdb
42 m_colourScaleSet(false), 42 m_colourScaleSet(false),
43 m_colourMap(0), 43 m_colourMap(0),
44 m_normalizeColumns(false), 44 m_normalizeColumns(false),
45 m_normalizeVisibleArea(false), 45 m_normalizeVisibleArea(false),
46 m_invertVertical(false), 46 m_invertVertical(false),
47 m_opaque(false),
47 m_miny(0), 48 m_miny(0),
48 m_maxy(0) 49 m_maxy(0)
49 { 50 {
50 51
51 } 52 }
132 list.push_back("Colour"); 133 list.push_back("Colour");
133 list.push_back("Colour Scale"); 134 list.push_back("Colour Scale");
134 list.push_back("Normalize Columns"); 135 list.push_back("Normalize Columns");
135 list.push_back("Normalize Visible Area"); 136 list.push_back("Normalize Visible Area");
136 list.push_back("Invert Vertical Scale"); 137 list.push_back("Invert Vertical Scale");
138 list.push_back("Opaque");
137 return list; 139 return list;
138 } 140 }
139 141
140 QString 142 QString
141 Colour3DPlotLayer::getPropertyLabel(const PropertyName &name) const 143 Colour3DPlotLayer::getPropertyLabel(const PropertyName &name) const
143 if (name == "Colour") return tr("Colour"); 145 if (name == "Colour") return tr("Colour");
144 if (name == "Colour Scale") return tr("Scale"); 146 if (name == "Colour Scale") return tr("Scale");
145 if (name == "Normalize Columns") return tr("Normalize Columns"); 147 if (name == "Normalize Columns") return tr("Normalize Columns");
146 if (name == "Normalize Visible Area") return tr("Normalize Visible Area"); 148 if (name == "Normalize Visible Area") return tr("Normalize Visible Area");
147 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale"); 149 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale");
150 if (name == "Opaque") return tr("Always Opaque");
148 return ""; 151 return "";
149 } 152 }
150 153
151 QString 154 QString
152 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const 155 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const
153 { 156 {
154 if (name == "Normalize Columns") return "normalise-columns"; 157 if (name == "Normalize Columns") return "normalise-columns";
155 if (name == "Normalize Visible Area") return "normalise"; 158 if (name == "Normalize Visible Area") return "normalise";
156 if (name == "Invert Vertical Scale") return "invert-vertical"; 159 if (name == "Invert Vertical Scale") return "invert-vertical";
160 if (name == "Opaque") return "opaque";
157 return ""; 161 return "";
158 } 162 }
159 163
160 Layer::PropertyType 164 Layer::PropertyType
161 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const 165 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const
162 { 166 {
163 if (name == "Normalize Columns") return ToggleProperty; 167 if (name == "Normalize Columns") return ToggleProperty;
164 if (name == "Normalize Visible Area") return ToggleProperty; 168 if (name == "Normalize Visible Area") return ToggleProperty;
165 if (name == "Invert Vertical Scale") return ToggleProperty; 169 if (name == "Invert Vertical Scale") return ToggleProperty;
170 if (name == "Opaque") return ToggleProperty;
166 return ValueProperty; 171 return ValueProperty;
167 } 172 }
168 173
169 QString 174 QString
170 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const 175 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const
171 { 176 {
172 if (name == "Normalize Columns" || 177 if (name == "Normalize Columns" ||
173 name == "Normalize Visible Area" || 178 name == "Normalize Visible Area" ||
174 name == "Invert Vertical Scale" || 179 name == "Invert Vertical Scale" ||
175 name == "Colour Scale") return tr("Scale"); 180 name == "Colour Scale") return tr("Scale");
181 if (name == "Opaque" ||
182 name == "Colour") return tr("Colour");
176 return QString(); 183 return QString();
177 } 184 }
178 185
179 int 186 int
180 Colour3DPlotLayer::getPropertyRangeAndValue(const PropertyName &name, 187 Colour3DPlotLayer::getPropertyRangeAndValue(const PropertyName &name,
216 } else if (name == "Invert Vertical Scale") { 223 } else if (name == "Invert Vertical Scale") {
217 224
218 *deflt = 0; 225 *deflt = 0;
219 val = (m_invertVertical ? 1 : 0); 226 val = (m_invertVertical ? 1 : 0);
220 227
228 } else if (name == "Opaque") {
229
230 *deflt = 0;
231 val = (m_opaque ? 1 : 0);
232
221 } else { 233 } else {
222 val = Layer::getPropertyRangeAndValue(name, min, max, deflt); 234 val = Layer::getPropertyRangeAndValue(name, min, max, deflt);
223 } 235 }
224 236
225 return val; 237 return val;
259 setNormalizeColumns(value ? true : false); 271 setNormalizeColumns(value ? true : false);
260 } else if (name == "Normalize Visible Area") { 272 } else if (name == "Normalize Visible Area") {
261 setNormalizeVisibleArea(value ? true : false); 273 setNormalizeVisibleArea(value ? true : false);
262 } else if (name == "Invert Vertical Scale") { 274 } else if (name == "Invert Vertical Scale") {
263 setInvertVertical(value ? true : false); 275 setInvertVertical(value ? true : false);
276 } else if (name == "Opaque") {
277 setOpaque(value ? true : false);
264 } 278 }
265 } 279 }
266 280
267 void 281 void
268 Colour3DPlotLayer::setColourScale(ColourScale scale) 282 Colour3DPlotLayer::setColourScale(ColourScale scale)
320 m_invertVertical = n; 334 m_invertVertical = n;
321 cacheInvalid(); 335 cacheInvalid();
322 emit layerParametersChanged(); 336 emit layerParametersChanged();
323 } 337 }
324 338
339 void
340 Colour3DPlotLayer::setOpaque(bool n)
341 {
342 if (m_opaque == n) return;
343 m_opaque = n;
344 emit layerParametersChanged();
345 }
346
325 bool 347 bool
326 Colour3DPlotLayer::getInvertVertical() const 348 Colour3DPlotLayer::getInvertVertical() const
327 { 349 {
328 return m_invertVertical; 350 return m_invertVertical;
351 }
352
353 bool
354 Colour3DPlotLayer::getOpaque() const
355 {
356 return m_opaque;
329 } 357 }
330 358
331 bool 359 bool
332 Colour3DPlotLayer::isLayerScrollable(const View *v) const 360 Colour3DPlotLayer::isLayerScrollable(const View *v) const
333 { 361 {
538 mmin = -1.f; 566 mmin = -1.f;
539 mmax = 1.f; 567 mmax = 1.f;
540 } 568 }
541 569
542 if (max == min) max = min + 1.0; 570 if (max == min) max = min + 1.0;
571 if (mmax == mmin) mmax = mmin + 1.0;
543 572
544 paint.setPen(v->getForeground()); 573 paint.setPen(v->getForeground());
545 paint.drawRect(4, 10, cw - 8, ch+1); 574 paint.drawRect(4, 10, cw - 8, ch+1);
546 575
547 for (int y = 0; y < ch; ++y) { 576 for (int y = 0; y < ch; ++y) {
548 float value = ((max - min) * (ch - y - 1)) / ch + min; 577 float value = ((max - min) * (ch - y - 1)) / ch + min;
549 if (m_colourScale == LogScale) { 578 if (m_colourScale == LogScale) {
550 value = LogRange::map(value); 579 value = LogRange::map(value);
551 } 580 }
552 int pixel = int(((value - mmin) * 256) / (mmax - mmin)); 581 int pixel = int(((value - mmin) * 256) / (mmax - mmin));
553 QRgb c = m_cache->color(pixel); 582 if (pixel >= 0 && pixel < 256) {
554 // QRgb c = m_cache->color(((ch - y) * 255) / ch); 583 QRgb c = m_cache->color(pixel);
555 paint.setPen(QColor(qRed(c), qGreen(c), qBlue(c))); 584 paint.setPen(QColor(qRed(c), qGreen(c), qBlue(c)));
556 paint.drawLine(5, 11 + y, cw - 5, 11 + y); 585 paint.drawLine(5, 11 + y, cw - 5, 11 + y);
586 } else {
587 std::cerr << "WARNING: Colour3DPlotLayer::paintVerticalScale: value " << value << ", mmin " << mmin << ", mmax " << mmax << " leads to invalid pixel " << pixel << std::endl;
588 }
557 } 589 }
558 590
559 QString minstr = QString("%1").arg(min); 591 QString minstr = QString("%1").arg(min);
560 QString maxstr = QString("%1").arg(max); 592 QString maxstr = QString("%1").arg(max);
561 593
894 926
895 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 927 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
896 std::cerr << "Colour3DPlotLayer::paint: height = "<< m_model->getHeight() << ", modelStart = " << modelStart << ", resolution = " << modelResolution << ", model rate = " << m_model->getSampleRate() << std::endl; 928 std::cerr << "Colour3DPlotLayer::paint: height = "<< m_model->getHeight() << ", modelStart = " << modelStart << ", resolution = " << modelResolution << ", model rate = " << m_model->getSampleRate() << std::endl;
897 #endif 929 #endif
898 930
899 if (int(m_model->getHeight()) >= v->height() || 931 if (m_opaque ||
932 int(m_model->getHeight()) >= v->height() ||
900 int(modelResolution * m_model->getSampleRate()) < v->getZoomLevel() / 2) { 933 int(modelResolution * m_model->getSampleRate()) < v->getZoomLevel() / 2) {
901 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 934 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
902 std::cerr << "calling paintDense" << std::endl; 935 std::cerr << "calling paintDense" << std::endl;
903 #endif 936 #endif
904 paintDense(v, paint, rect); 937 paintDense(v, paint, rect);
1114 QString s = QString("scale=\"%1\" " 1147 QString s = QString("scale=\"%1\" "
1115 "colourScheme=\"%2\" " 1148 "colourScheme=\"%2\" "
1116 "normalizeColumns=\"%3\" " 1149 "normalizeColumns=\"%3\" "
1117 "normalizeVisibleArea=\"%4\" " 1150 "normalizeVisibleArea=\"%4\" "
1118 "minY=\"%5\" " 1151 "minY=\"%5\" "
1119 "maxY=\"%6\" ") 1152 "maxY=\"%6\" "
1153 "invertVertical=\"%7\" "
1154 "opaque=\"%8\"")
1120 .arg((int)m_colourScale) 1155 .arg((int)m_colourScale)
1121 .arg(m_colourMap) 1156 .arg(m_colourMap)
1122 .arg(m_normalizeColumns ? "true" : "false") 1157 .arg(m_normalizeColumns ? "true" : "false")
1123 .arg(m_normalizeVisibleArea ? "true" : "false") 1158 .arg(m_normalizeVisibleArea ? "true" : "false")
1124 .arg(m_miny) 1159 .arg(m_miny)
1125 .arg(m_maxy); 1160 .arg(m_maxy)
1161 .arg(m_invertVertical ? "true" : "false")
1162 .arg(m_opaque ? "true" : "false");
1126 1163
1127 Layer::toXml(stream, indent, extraAttributes + " " + s); 1164 Layer::toXml(stream, indent, extraAttributes + " " + s);
1128 } 1165 }
1129 1166
1130 void 1167 void
1144 1181
1145 bool normalizeVisibleArea = 1182 bool normalizeVisibleArea =
1146 (attributes.value("normalizeVisibleArea").trimmed() == "true"); 1183 (attributes.value("normalizeVisibleArea").trimmed() == "true");
1147 setNormalizeVisibleArea(normalizeVisibleArea); 1184 setNormalizeVisibleArea(normalizeVisibleArea);
1148 1185
1186 bool invertVertical =
1187 (attributes.value("invertVertical").trimmed() == "true");
1188 setInvertVertical(invertVertical);
1189
1190 bool opaque =
1191 (attributes.value("opaque").trimmed() == "true");
1192 setNormalizeVisibleArea(opaque);
1193
1149 float min = attributes.value("minY").toFloat(&ok); 1194 float min = attributes.value("minY").toFloat(&ok);
1150 float max = attributes.value("maxY").toFloat(&alsoOk); 1195 float max = attributes.value("maxY").toFloat(&alsoOk);
1151 if (ok && alsoOk) setDisplayExtents(min, max); 1196 if (ok && alsoOk) setDisplayExtents(min, max);
1152 } 1197 }
1153 1198