Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Nov 30, 2023
1 parent b5ca081 commit 1ef30d2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 24 deletions.
79 changes: 60 additions & 19 deletions bin/CRITERIA3D/criteria3DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,35 +1392,47 @@ bool Crit3DProject::writeOutputPointsData()
}


void Crit3DProject::shadowColor(const Crit3DColor &colorIn, Crit3DColor &colorOut, int row, int col)
bool Crit3DProject::writeMeteoPointsProperties(const QList<QString> &joinedPropertiesList, const QList<QString> &csvFields,
const QList<QList<QString>> &csvData)
{
colorOut.red = colorIn.red;
colorOut.green = colorIn.green;
colorOut.blue = colorIn.blue;
QList<QString> propertiesList;
QList<int> 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<QString> 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<QString> 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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions bin/CRITERIA3D/criteria3DProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@

bool writeOutputPointsTables();
bool writeOutputPointsData();
bool writeMeteoPointsProperties(const QList<QString> &joinedPropertiesList,
const QList<QString> &csvFields, const QList<QList<QString>> &csvData);

void clearGeometry();
bool initializeGeometry();
Expand Down
8 changes: 3 additions & 5 deletions bin/CRITERIA3D/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1762,13 +1762,12 @@ void MainWindow::on_actionNew_meteoPointsDB_from_csv_triggered()
}
else
{
/*QList<QString> joinedList = dialogPointProp.getJoinedList();
* TODO
if (! myProject.writeMeteoPointsProperties(joinedList))
QList<QString> joinedPropertiesList = dialogPointProp.getJoinedList();
if (! myProject.writeMeteoPointsProperties(joinedPropertiesList, csvFields, csvData))
{
myProject.logError("Error in write points properties");
return;
}*/
}
}

loadMeteoPointsDB_GUI(dbName);
Expand Down Expand Up @@ -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.");
Expand Down

0 comments on commit 1ef30d2

Please sign in to comment.