Separate method for heatmap color scaling

I separated out the color scaling and slightly simplified the expressions.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2016-09-13 10:59:47 +02:00 committed by Dirk Hohndel
parent 1cae1255d7
commit 1b57b6cc17
2 changed files with 24 additions and 15 deletions

View file

@ -384,6 +384,27 @@ void DivePercentageItem::modelDataChanged(const QModelIndex &topLeft, const QMod
texts.last()->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
}
QColor DivePercentageItem::ColorScale(double value)
{
QColor color;
double scaledValue = value / (AMB_PERCENTAGE * N2_IN_AIR) * 1000.0;
if (scaledValue < 0.8) // grade from cyan to blue to purple
color.setHsvF(0.5 + 0.25 * scaledValue / 0.8, 1.0, 1.0);
else if (scaledValue < 1.0) // grade from magenta to black
color.setHsvF(0.75, 1.0, (1.0 - scaledValue) / 0.2);
else if (value < 55) // grade from black to green
color.setHsvF(0.333, 1.0, (value - AMB_PERCENTAGE * N2_IN_AIR / 1000.0) / (55.0 - AMB_PERCENTAGE * N2_IN_AIR / 1000.0));
else if (value < 100) // grade from green to yellow to red
color.setHsvF(0.333 * (100.0 - value) / 45.0, 1.0, 1.0);
else if (value < 120) // M value exceeded - grade from red to white
color.setHsvF(0.0, 1 - (value - 100.0) / 20.0, 1.0);
else // white
color.setHsvF(0.0, 0.0, 1.0);
return color;
}
void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
@ -392,7 +413,6 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
if (polygon().isEmpty())
return;
painter->save();
QColor color;
QPen mypen;
mypen.setCosmetic(false);
mypen.setWidth(5);
@ -400,20 +420,7 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
for (int i = 0, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) {
if (i < poly.count()) {
double value = dataModel->index(i, vDataColumn).data().toDouble();
if (value < 0.8 * AMB_PERCENTAGE * N2_IN_AIR / 1000.0) // grade from cyan to blue to purple
color.setHsvF(0.5 + 0.25 * value / (0.8 * AMB_PERCENTAGE * N2_IN_AIR / 1000.0), 1.0, 1.0);
else if (value < AMB_PERCENTAGE * N2_IN_AIR / 1000.0) // grade from magenta to black
color.setHsvF(0.75, 1.0, (AMB_PERCENTAGE * N2_IN_AIR / 1000.0 - value) / (0.2 * AMB_PERCENTAGE * N2_IN_AIR / 1000.0));
else if (value < 55) // grade from black to green
color.setHsvF(0.333, 1.0, (value - AMB_PERCENTAGE * N2_IN_AIR / 1000.0) / (55.0 - AMB_PERCENTAGE * N2_IN_AIR / 1000.0));
else if (value < 100) // grade from green to yellow to red
color.setHsvF(0.333 * (100.0 - value) / 45.0, 1.0, 1.0);
else if (value < 120) // M value exceeded - grade from red to white
color.setHsvF(0.0, 1 - (value - 100.0) / 20.0, 1.0);
else // white
color.setHsvF(0.0, 0.0, 1.0);
mypen.setBrush(QBrush(color));
mypen.setBrush(QBrush(ColorScale(value)));
painter->setPen(mypen);
painter->drawPoint(poly[i]);
}

View file

@ -133,6 +133,8 @@ public:
private:
QString visibilityKey;
int tissueIndex;
QColor ColorScale(double value);
};
class DiveAmbPressureItem : public AbstractProfilePolygonItem {