comparison layer/Colour3DPlotLayer.cpp @ 357:3e538a90e9b8

* Add ability to invert a colour 3d plot in the vertical axis
author Chris Cannam
date Mon, 04 Feb 2008 13:35:43 +0000
parents de4db9b5dcf1
children e1a9e478b7f2
comparison
equal deleted inserted replaced
356:bff85425228c 357:3e538a90e9b8
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");
100 return ""; 103 return "";
101 } 104 }
102 105
103 QString 106 QString
104 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const 107 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const
105 { 108 {
106 if (name == "Normalize Columns") return "normalise-columns"; 109 if (name == "Normalize Columns") return "normalise-columns";
107 if (name == "Normalize Visible Area") return "normalise"; 110 if (name == "Normalize Visible Area") return "normalise";
111 if (name == "Invert Vertical Scale") return "invert-vertical";
108 return ""; 112 return "";
109 } 113 }
110 114
111 Layer::PropertyType 115 Layer::PropertyType
112 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const 116 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const
113 { 117 {
114 if (name == "Normalize Columns") return ToggleProperty; 118 if (name == "Normalize Columns") return ToggleProperty;
115 if (name == "Normalize Visible Area") return ToggleProperty; 119 if (name == "Normalize Visible Area") return ToggleProperty;
120 if (name == "Invert Vertical Scale") return ToggleProperty;
116 return ValueProperty; 121 return ValueProperty;
117 } 122 }
118 123
119 QString 124 QString
120 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const 125 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const
121 { 126 {
122 if (name == "Normalize Columns" || 127 if (name == "Normalize Columns" ||
123 name == "Normalize Visible Area" || 128 name == "Normalize Visible Area" ||
129 name == "Invert Vertical Scale" ||
124 name == "Colour Scale") return tr("Scale"); 130 name == "Colour Scale") return tr("Scale");
125 return QString(); 131 return QString();
126 } 132 }
127 133
128 int 134 int
159 165
160 } else if (name == "Normalize Visible Area") { 166 } else if (name == "Normalize Visible Area") {
161 167
162 *deflt = 0; 168 *deflt = 0;
163 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);
164 175
165 } else { 176 } else {
166 val = Layer::getPropertyRangeAndValue(name, min, max, deflt); 177 val = Layer::getPropertyRangeAndValue(name, min, max, deflt);
167 } 178 }
168 179
201 setColourMap(value); 212 setColourMap(value);
202 } else if (name == "Normalize Columns") { 213 } else if (name == "Normalize Columns") {
203 setNormalizeColumns(value ? true : false); 214 setNormalizeColumns(value ? true : false);
204 } else if (name == "Normalize Visible Area") { 215 } else if (name == "Normalize Visible Area") {
205 setNormalizeVisibleArea(value ? true : false); 216 setNormalizeVisibleArea(value ? true : false);
217 } else if (name == "Invert Vertical Scale") {
218 setInvertVertical(value ? true : false);
206 } 219 }
207 } 220 }
208 221
209 void 222 void
210 Colour3DPlotLayer::setColourScale(ColourScale scale) 223 Colour3DPlotLayer::setColourScale(ColourScale scale)
252 Colour3DPlotLayer::getNormalizeVisibleArea() const 265 Colour3DPlotLayer::getNormalizeVisibleArea() const
253 { 266 {
254 return m_normalizeVisibleArea; 267 return m_normalizeVisibleArea;
255 } 268 }
256 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
257 bool 285 bool
258 Colour3DPlotLayer::isLayerScrollable(const View *v) const 286 Colour3DPlotLayer::isLayerScrollable(const View *v) const
259 { 287 {
260 if (m_normalizeVisibleArea) return false; 288 if (m_normalizeVisibleArea) return false;
261 QPoint discard; 289 QPoint discard;
283 int f0 = sx0 * modelResolution; 311 int f0 = sx0 * modelResolution;
284 int f1 = f0 + modelResolution; 312 int f1 = f0 + modelResolution;
285 313
286 float binHeight = float(v->height()) / m_model->getHeight(); 314 float binHeight = float(v->height()) / m_model->getHeight();
287 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;
288 318
289 float value = m_model->getValueAt(sx0, sy); 319 float value = m_model->getValueAt(sx0, sy);
290 320
291 // std::cerr << "bin value (" << sx0 << "," << sy << ") is " << value << std::endl; 321 // std::cerr << "bin value (" << sx0 << "," << sy << ") is " << value << std::endl;
292 322
364 int step = m_model->getHeight() / count; 394 int step = m_model->getHeight() / count;
365 if (step == 0) step = 1; 395 if (step == 0) step = 1;
366 396
367 for (size_t i = 0; i < m_model->getHeight(); ++i) { 397 for (size_t i = 0; i < m_model->getHeight(); ++i) {
368 398
369 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;
370 403
371 int y0 = int(v->height() - (i * binHeight) - 1); 404 int y0 = int(v->height() - (i * binHeight) - 1);
372 405
373 QString text = m_model->getBinName(i); 406 QString text = m_model->getBinName(idx);
374 if (text == "") text = QString("[%1]").arg(i + 1); 407 if (text == "") text = QString("[%1]").arg(idx + 1);
375 408
376 paint.drawLine(cw, y0, w, y0); 409 paint.drawLine(cw, y0, w, y0);
377 410
378 int cy = int(y0 - (step * binHeight)/2); 411 int cy = int(y0 - (step * binHeight)/2);
379 int ty = cy + paint.fontMetrics().ascent()/2; 412 int ty = cy + paint.fontMetrics().ascent()/2;
524 557
525 int pixel = int(((value - min) * 256) / (max - min)); 558 int pixel = int(((value - min) * 256) / (max - min));
526 if (pixel < 0) pixel = 0; 559 if (pixel < 0) pixel = 0;
527 if (pixel > 255) pixel = 255; 560 if (pixel > 255) pixel = 255;
528 561
529 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 }
530 } 568 }
531 } 569 }
532 } 570 }
533 571
534 void 572 void