Mercurial > hg > svgui
diff 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 |
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp Mon Feb 04 13:35:11 2008 +0000 +++ b/layer/Colour3DPlotLayer.cpp Mon Feb 04 13:35:43 2008 +0000 @@ -39,7 +39,8 @@ m_colourScale(LinearScale), m_colourMap(0), m_normalizeColumns(false), - m_normalizeVisibleArea(false) + m_normalizeVisibleArea(false), + m_invertVertical(false) { } @@ -87,6 +88,7 @@ list.push_back("Colour Scale"); list.push_back("Normalize Columns"); list.push_back("Normalize Visible Area"); + list.push_back("Invert Vertical Scale"); return list; } @@ -97,6 +99,7 @@ if (name == "Colour Scale") return tr("Scale"); if (name == "Normalize Columns") return tr("Normalize Columns"); if (name == "Normalize Visible Area") return tr("Normalize Visible Area"); + if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale"); return ""; } @@ -105,6 +108,7 @@ { if (name == "Normalize Columns") return "normalise-columns"; if (name == "Normalize Visible Area") return "normalise"; + if (name == "Invert Vertical Scale") return "invert-vertical"; return ""; } @@ -113,6 +117,7 @@ { if (name == "Normalize Columns") return ToggleProperty; if (name == "Normalize Visible Area") return ToggleProperty; + if (name == "Invert Vertical Scale") return ToggleProperty; return ValueProperty; } @@ -121,6 +126,7 @@ { if (name == "Normalize Columns" || name == "Normalize Visible Area" || + name == "Invert Vertical Scale" || name == "Colour Scale") return tr("Scale"); return QString(); } @@ -162,6 +168,11 @@ *deflt = 0; val = (m_normalizeVisibleArea ? 1 : 0); + } else if (name == "Invert Vertical Scale") { + + *deflt = 0; + val = (m_invertVertical ? 1 : 0); + } else { val = Layer::getPropertyRangeAndValue(name, min, max, deflt); } @@ -203,6 +214,8 @@ setNormalizeColumns(value ? true : false); } else if (name == "Normalize Visible Area") { setNormalizeVisibleArea(value ? true : false); + } else if (name == "Invert Vertical Scale") { + setInvertVertical(value ? true : false); } } @@ -254,6 +267,21 @@ return m_normalizeVisibleArea; } +void +Colour3DPlotLayer::setInvertVertical(bool n) +{ + if (m_invertVertical == n) return; + m_invertVertical = n; + cacheInvalid(); + emit layerParametersChanged(); +} + +bool +Colour3DPlotLayer::getInvertVertical() const +{ + return m_invertVertical; +} + bool Colour3DPlotLayer::isLayerScrollable(const View *v) const { @@ -286,6 +314,8 @@ float binHeight = float(v->height()) / m_model->getHeight(); int sy = int((v->height() - y) / binHeight); + if (m_invertVertical) sy = m_model->getHeight() - sy - 1; + float value = m_model->getValueAt(sx0, sy); // std::cerr << "bin value (" << sx0 << "," << sy << ") is " << value << std::endl; @@ -366,12 +396,15 @@ for (size_t i = 0; i < m_model->getHeight(); ++i) { - if ((i % step) != 0) continue; + size_t idx = i; + if (m_invertVertical) idx = m_model->getHeight() - idx - 1; + + if ((idx % step) != 0) continue; int y0 = int(v->height() - (i * binHeight) - 1); - QString text = m_model->getBinName(i); - if (text == "") text = QString("[%1]").arg(i + 1); + QString text = m_model->getBinName(idx); + if (text == "") text = QString("[%1]").arg(idx + 1); paint.drawLine(cw, y0, w, y0); @@ -526,7 +559,12 @@ if (pixel < 0) pixel = 0; if (pixel > 255) pixel = 255; - m_cache->setPixel(c - firstBin, y, pixel); + if (m_invertVertical) { + m_cache->setPixel(c - firstBin, m_model->getHeight() - y - 1, + pixel); + } else { + m_cache->setPixel(c - firstBin, y, pixel); + } } } }