Skip to content

Commit

Permalink
feat: different color of isocontour lines
Browse files Browse the repository at this point in the history
  • Loading branch information
iffse committed May 16, 2023
1 parent 7cf7768 commit a677752
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
14 changes: 13 additions & 1 deletion src-qml/OutputConf.qml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,22 @@ ScrollView {
decimals: false
}

ComboBox {
id: isocontourColor
objectName: "isocontourColor"
width: parent.width
currentIndex: 0
model: [
"5 colors",
"2 colors",
"black and white"
]
}

Button {
text: "Redraw"
onClicked: {
actions.redrawIsocontourLines(isocontourSize.input, numIsocontourLines.input);
actions.redrawIsocontourLines(isocontourSize.input, numIsocontourLines.input, isocontourColor.currentIndex);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/headers/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ inline double diffusiveWeight;
inline uint diffusiveMethod;
inline uint numIsocontourLines;
inline uint isocontourSize;
inline uint isocontourColor;
inline std::map<uint, std::vector<double>> boundaryDataDict;
2 changes: 1 addition & 1 deletion src/headers/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ public slots:
QString getRecession();
QString getRecession(QString filepath);
void drawIsocontourLines(uint maxSize, uint numLines);
void redrawIsocontourLines(uint maxSize, uint numLines);
void redrawIsocontourLines(uint maxSize, uint numLines, uint numIndex);
};
36 changes: 23 additions & 13 deletions src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void Actions::worker() {
errorIter.clear();
}
emit newOutput("--> Starting subiteration loop");
if (errorIter.size() < maxIter)
if (currentIter < maxIter)
errorIter.resize(maxIter);

double error = tolerance + 1;
Expand Down Expand Up @@ -286,7 +286,10 @@ void Actions::afterWorker() {
double &burningAreaMax = *max_element(burningArea.begin(), burningArea.end());

emit graphBurningArea(plotData::burningAreaData(), burningWayMax, burningAreaMax);
emit graphErrorIter(errorIter, *max_element(errorIter.begin(), errorIter.end()));
emit graphErrorIter(
vector<double>(errorIter.begin(), errorIter.begin() + currentIter),
*max_element(errorIter.begin(), errorIter.end())
);
drawIsocontourLines(isocontourSize, numIsocontourLines);
}

Expand Down Expand Up @@ -450,24 +453,30 @@ void Actions::drawIsocontourLines(uint maxSize, uint numLines) {

auto value = step;
for (uint line = 1; line < numLines; ++line) {

auto pickColor = [](double region) {
if (region < 0.25) {
return QString("rgb(%1, %2, %3)").arg(255).arg(255*region*4).arg(0);
} else if (region < 0.5) {
return QString("rgb(%1, %2, %3)").arg(255*(1-(region-0.25)*4)).arg(255).arg(0);
} else if (region < 0.75) {
return QString("rgb(%1, %2, %3)").arg(0).arg(255).arg(255*(region-0.5)*4);
} else {
return QString("rgb(%1, %2, %3)").arg(0).arg(255*(1-(region-0.75)*4)).arg(255);
switch (isocontourColor) {
case 0: { // 5 colors
auto hue = (1 - region) * 240;
return QString("hsl(") + QString::number(hue) + ", 100%, 50%)";
}
case 1: { // 2 colors
auto hue = 240 + 120 * region;
return QString("hsl(") + QString::number(hue) + ", 100%, 50%)";
}
case 2: { // black and white
auto lightness = 100 * region;
return QString("hsl(0, 0%, ") + QString::number(lightness) + "%)";
}
default:
return QString("#000000");
}
};

// paintCanvas(plotData::isocolourData(value), color);
emit paintCanvas(plotData::isocolourData(value, shiftX, shiftY, scale), pickColor(double(line-1)/(numLines-1)));
value += step;

}
emit newOutput("Isocontour lines drawn with a step of " + QString::number(step) + " from " + QString::number(uVertexMin) + " to " + QString::number(uVertexMax));
} catch (const std::exception &e) {
emit newOutput("Error while drawing isocontour lines: " + QString(e.what()));
} catch (...) {
Expand All @@ -476,7 +485,8 @@ void Actions::drawIsocontourLines(uint maxSize, uint numLines) {
return;
}

void Actions::redrawIsocontourLines(uint maxSize, uint numLines) {
void Actions::redrawIsocontourLines(uint maxSize, uint numLines, uint colorIndex) {
isocontourColor = colorIndex;
std::thread thread(&Actions::drawIsocontourLines, this, maxSize, numLines);
thread.detach();
}
Expand Down
1 change: 1 addition & 0 deletions src/iosystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void Reader::readInput() {//{{{
diffusiveMethod = root->findChild<QObject*>("diffusiveMethod")->property("currentIndex").toInt();
numIsocontourLines = root->findChild<QObject*>("numIsocontourLines")->property("text").toInt();
isocontourSize = root->findChild<QObject*>("isocontourSize")->property("text").toInt();
isocontourColor = root->findChild<QObject*>("isocontourColor")->property("currentIndex").toInt();
}
//}}}

Expand Down

0 comments on commit a677752

Please sign in to comment.