From 1ef30d2e5e13c3f685fbee532edbd9369f277b5b Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 30 Nov 2023 20:22:15 +0100 Subject: [PATCH] update --- bin/CRITERIA3D/criteria3DProject.cpp | 79 +++++++++++++++++++++------- bin/CRITERIA3D/criteria3DProject.h | 2 + bin/CRITERIA3D/mainwindow.cpp | 8 ++- 3 files changed, 65 insertions(+), 24 deletions(-) diff --git a/bin/CRITERIA3D/criteria3DProject.cpp b/bin/CRITERIA3D/criteria3DProject.cpp index 0eb187a30..7ee476dc0 100644 --- a/bin/CRITERIA3D/criteria3DProject.cpp +++ b/bin/CRITERIA3D/criteria3DProject.cpp @@ -1392,35 +1392,47 @@ bool Crit3DProject::writeOutputPointsData() } -void Crit3DProject::shadowColor(const Crit3DColor &colorIn, Crit3DColor &colorOut, int row, int col) +bool Crit3DProject::writeMeteoPointsProperties(const QList &joinedPropertiesList, const QList &csvFields, + const QList> &csvData) { - colorOut.red = colorIn.red; - colorOut.green = colorIn.green; - colorOut.blue = colorIn.blue; + QList propertiesList; + QList posValues; - float aspect = radiationMaps->aspectMap->getValueFromRowCol(row, col); - if (! isEqual(aspect, radiationMaps->aspectMap->header->flag)) + for (int i = 0; i < joinedPropertiesList.size(); i++) { - float slopeDegree = radiationMaps->slopeMap->getValueFromRowCol(row, col); - if (! isEqual(slopeDegree, radiationMaps->slopeMap->header->flag)) + QList couple = joinedPropertiesList[i].split("-->"); + QString pragaProperty = couple[0]; + QString csvProperty = couple[1]; + int pos = csvFields.indexOf(csvProperty); + if (pos != -1) { - float slopeAmplification = 120.f / std::max(radiationMaps->slopeMap->maximum, 1.f); - float shadow = -cos(aspect * DEG_TO_RAD) * std::max(5.f, slopeDegree * slopeAmplification); + propertiesList << pragaProperty; + posValues << pos; + } + } - colorOut.red = std::min(255, std::max(0, int(colorOut.red + shadow))); - colorOut.green = std::min(255, std::max(0, int(colorOut.green + shadow))); - colorOut.blue = std::min(255, std::max(0, int(colorOut.blue + shadow))); - if (slope > openGlGeometry->artifactSlope()) - { - colorOut.red = std::min(255, std::max(0, int((colorOut.red + 256) / 2))); - colorOut.green = std::min(255, std::max(0, int((colorOut.green + 256) / 2))); - colorOut.blue = std::min(255, std::max(0, int((colorOut.blue + 256) / 2))); - } + for (int row = 0; row < csvData.size(); row++) + { + QList csvDataList; + + for (int j = 0; j < posValues.size(); j++) + { + csvDataList << csvData[row][posValues[j]]; + } + + if (! meteoPointsDbHandler->updatePointProperties(propertiesList, csvDataList)) + { + errorString = meteoPointsDbHandler->getErrorString(); + return false; } } + + return true; } +//------------------------------------- 3D geometry and color -------------------------------------- + void Crit3DProject::clearGeometry() { if (openGlGeometry != nullptr) @@ -1511,6 +1523,35 @@ bool Crit3DProject::initializeGeometry() } +void Crit3DProject::shadowColor(const Crit3DColor &colorIn, Crit3DColor &colorOut, int row, int col) +{ + colorOut.red = colorIn.red; + colorOut.green = colorIn.green; + colorOut.blue = colorIn.blue; + + float aspect = radiationMaps->aspectMap->getValueFromRowCol(row, col); + if (! isEqual(aspect, radiationMaps->aspectMap->header->flag)) + { + float slopeDegree = radiationMaps->slopeMap->getValueFromRowCol(row, col); + if (! isEqual(slopeDegree, radiationMaps->slopeMap->header->flag)) + { + float slopeAmplification = 120.f / std::max(radiationMaps->slopeMap->maximum, 1.f); + float shadow = -cos(aspect * DEG_TO_RAD) * std::max(5.f, slopeDegree * slopeAmplification); + + colorOut.red = std::min(255, std::max(0, int(colorOut.red + shadow))); + colorOut.green = std::min(255, std::max(0, int(colorOut.green + shadow))); + colorOut.blue = std::min(255, std::max(0, int(colorOut.blue + shadow))); + if (slope > openGlGeometry->artifactSlope()) + { + colorOut.red = std::min(255, std::max(0, int((colorOut.red + 256) / 2))); + colorOut.green = std::min(255, std::max(0, int((colorOut.green + 256) / 2))); + colorOut.blue = std::min(255, std::max(0, int((colorOut.blue + 256) / 2))); + } + } + } +} + + bool Crit3DProject::update3DColors() { if (openGlGeometry == nullptr) diff --git a/bin/CRITERIA3D/criteria3DProject.h b/bin/CRITERIA3D/criteria3DProject.h index bd14b488c..c08009721 100644 --- a/bin/CRITERIA3D/criteria3DProject.h +++ b/bin/CRITERIA3D/criteria3DProject.h @@ -102,6 +102,8 @@ bool writeOutputPointsTables(); bool writeOutputPointsData(); + bool writeMeteoPointsProperties(const QList &joinedPropertiesList, + const QList &csvFields, const QList> &csvData); void clearGeometry(); bool initializeGeometry(); diff --git a/bin/CRITERIA3D/mainwindow.cpp b/bin/CRITERIA3D/mainwindow.cpp index c64e6ca28..6a5ea6911 100644 --- a/bin/CRITERIA3D/mainwindow.cpp +++ b/bin/CRITERIA3D/mainwindow.cpp @@ -1762,13 +1762,12 @@ void MainWindow::on_actionNew_meteoPointsDB_from_csv_triggered() } else { - /*QList joinedList = dialogPointProp.getJoinedList(); - * TODO - if (! myProject.writeMeteoPointsProperties(joinedList)) + QList joinedPropertiesList = dialogPointProp.getJoinedList(); + if (! myProject.writeMeteoPointsProperties(joinedPropertiesList, csvFields, csvData)) { myProject.logError("Error in write points properties"); return; - }*/ + } } loadMeteoPointsDB_GUI(dbName); @@ -1925,7 +1924,6 @@ bool MainWindow::startModels(QDateTime firstTime, QDateTime lastTime) if (myProject.processes.computeCrop) { - // TODO: check on crop if (myProject.landUnitList.size() == 0) { myProject.logError("load land units map before.");