Skip to content

Commit

Permalink
update 3D viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jul 9, 2024
1 parent 3c96518 commit 1a27e8e
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 87 deletions.
10 changes: 0 additions & 10 deletions agrolib/graphics/mapGraphicsRasterObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ void RasterObject::clear()
}


void RasterObject::setRaster(gis::Crit3DRasterGrid* rasterPtr)
{
rasterPointer = rasterPtr;
}

gis::Crit3DRasterGrid* RasterObject::getRaster()
{
return rasterPointer;
}

void RasterObject::setDrawing(bool value)
{
isDrawing = value;
Expand Down
6 changes: 4 additions & 2 deletions agrolib/graphics/mapGraphicsRasterObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@
const gis::Crit3DLatLonHeader& latLonHeader, bool isGrid_);
float getRasterMaxSize();
gis::Crit3DGeoPoint* getRasterCenter();
void setRaster(gis::Crit3DRasterGrid* rasterPtr);
gis::Crit3DRasterGrid* getRaster();

void setRaster(gis::Crit3DRasterGrid* rasterPtr) { rasterPointer = rasterPtr; }
gis::Crit3DRasterGrid* getRasterPointer() { return rasterPointer; }

void updateCenter();
Position getCurrentCenter();

Expand Down
2 changes: 1 addition & 1 deletion agrolib/graphics/mapGraphicsRasterUtm.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
void setColorLegend(ColorLegend* colorLegendPtr) {_colorLegendPointer = colorLegendPtr;}
void setRaster(gis::Crit3DRasterGrid* rasterPtr) {_rasterPointer = rasterPtr;}

gis::Crit3DRasterGrid* getRaster() {return _rasterPointer;}
gis::Crit3DRasterGrid* getRasterPointer() {return _rasterPointer;}

float getValue(Position& pos);
float getRasterMaxSize();
Expand Down
36 changes: 32 additions & 4 deletions bin/CRITERIA3D/criteria3DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,17 +1939,18 @@ void Crit3DProject::shadowColor(const Crit3DColor &colorIn, Crit3DColor &colorOu
}


bool Crit3DProject::update3DColors()
bool Crit3DProject::update3DColors(gis::Crit3DRasterGrid *rasterPointer)
{
if (openGlGeometry == nullptr)
{
errorString = "Initialize 3D openGlGeometry before.";
return false;
}

float z1, z2, z3;
float z1, z2, z3, value;
Crit3DColor *c1, *c2, *c3;
Crit3DColor sc1, sc2, sc3;

long i = 0;
for (long row = 0; row < DEM.header->nrRows; row++)
{
Expand All @@ -1958,18 +1959,38 @@ bool Crit3DProject::update3DColors()
z1 = DEM.getValueFromRowCol(row, col);
if (! isEqual(z1, DEM.header->flag))
{
c1 = DEM.colorScale->getColor(z1);
shadowColor(*c1, sc1, row, col);
z3 = DEM.getValueFromRowCol(row+1, col+1);
if (! isEqual(z3, DEM.header->flag))
{
c1 = DEM.colorScale->getColor(z1);
c3 = DEM.colorScale->getColor(z3);

if (rasterPointer != nullptr)
{
value = rasterPointer->getValueFromRowCol(row, col);
if (! isEqual(value, rasterPointer->header->flag))
c1 = rasterPointer->colorScale->getColor(value);

value = rasterPointer->getValueFromRowCol(row+1, col+1);
if (! isEqual(value, rasterPointer->header->flag))
c3 = rasterPointer->colorScale->getColor(value);
}

shadowColor(*c1, sc1, row, col);
shadowColor(*c3, sc3, row+1, col+1);

z2 = DEM.getValueFromRowCol(row+1, col);
if (! isEqual(z2, DEM.header->flag))
{
c2 = DEM.colorScale->getColor(z2);
if (rasterPointer != nullptr)
{
value = rasterPointer->getValueFromRowCol(row+1, col);
if (! isEqual(value, rasterPointer->header->flag))
c2 = rasterPointer->colorScale->getColor(value);
}
shadowColor(*c2, sc2, row+1, col);

openGlGeometry->setVertexColor(i++, sc1);
openGlGeometry->setVertexColor(i++, sc2);
openGlGeometry->setVertexColor(i++, sc3);
Expand All @@ -1979,7 +2000,14 @@ bool Crit3DProject::update3DColors()
if (! isEqual(z2, DEM.header->flag))
{
c2 = DEM.colorScale->getColor(z2);
if (rasterPointer != nullptr)
{
value = rasterPointer->getValueFromRowCol(row, col+1);
if (! isEqual(value, rasterPointer->header->flag))
c2 = rasterPointer->colorScale->getColor(value);
}
shadowColor(*c2, sc2, row, col+1);

openGlGeometry->setVertexColor(i++, sc3);
openGlGeometry->setVertexColor(i++, sc2);
openGlGeometry->setVertexColor(i++, sc1);
Expand Down
2 changes: 1 addition & 1 deletion bin/CRITERIA3D/criteria3DProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
void clearGeometry();
bool initializeGeometry();
void shadowColor(const Crit3DColor &colorIn, Crit3DColor &colorOut, int row, int col);
bool update3DColors();
bool update3DColors(gis::Crit3DRasterGrid *rasterPointer = nullptr);

};

Expand Down
86 changes: 62 additions & 24 deletions bin/CRITERIA3D/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ void MainWindow::updateOutputMap()

emit rasterOutput->redrawRequested();
outputRasterColorLegend->update();

refreshViewer3D();

qApp->processEvents();
}

Expand Down Expand Up @@ -1111,18 +1114,18 @@ void MainWindow::on_variableButton_clicked()
this->updateCurrentVariable();
}

void MainWindow::setInputRasterVisible(bool value)
void MainWindow::setInputRasterVisible(bool isVisible)
{
inputRasterColorLegend->setVisible(value);
ui->labelInputRaster->setVisible(value);
rasterDEM->setVisible(value);
inputRasterColorLegend->setVisible(isVisible);
ui->labelInputRaster->setVisible(isVisible);
rasterDEM->setVisible(isVisible);
}

void MainWindow::setOutputRasterVisible(bool value)
void MainWindow::setOutputRasterVisible(bool isVisible)
{
outputRasterColorLegend->setVisible(value);
ui->labelOutputRaster->setVisible(value);
rasterOutput->setVisible(value);
outputRasterColorLegend->setVisible(isVisible);
ui->labelOutputRaster->setVisible(isVisible);
rasterOutput->setVisible(isVisible);
}

void MainWindow::setCurrentRasterInput(gis::Crit3DRasterGrid *myRaster)
Expand All @@ -1136,18 +1139,39 @@ void MainWindow::setCurrentRasterInput(gis::Crit3DRasterGrid *myRaster)
emit rasterDEM->redrawRequested();
}

void MainWindow::setCurrentRasterOutput(gis::Crit3DRasterGrid *myRaster)

void MainWindow::refreshViewer3D()
{
if (viewer3D != nullptr)
{
if (rasterOutput->visible())
{
myProject.update3DColors(rasterOutput->getRasterPointer());
}
else
{
myProject.update3DColors();
}

viewer3D->glWidget->update();
}
}


void MainWindow::setCurrentRasterOutput(gis::Crit3DRasterGrid *rasterPointer)
{
setOutputRasterVisible(true);

rasterOutput->initialize(myRaster, myProject.gisSettings);
outputRasterColorLegend->colorScale = myRaster->colorScale;
rasterOutput->initialize(rasterPointer, myProject.gisSettings);
outputRasterColorLegend->colorScale = rasterPointer->colorScale;

emit rasterOutput->redrawRequested();
outputRasterColorLegend->update();

rasterOutput->updateCenter();
view3DVariable = (myRaster == &(myProject.criteria3DMap));

refreshViewer3D();

view3DVariable = (rasterPointer == &(myProject.criteria3DMap));
}


Expand Down Expand Up @@ -1248,11 +1272,12 @@ void MainWindow::on_actionView_SoilMap_triggered()
}


void MainWindow::on_actionHide_soil_map_triggered()
void MainWindow::on_actionHide_Soil_map_triggered()
{
if (ui->labelOutputRaster->text() == "Soil")
{
setOutputRasterVisible(false);
refreshViewer3D();
}
}

Expand Down Expand Up @@ -1356,9 +1381,16 @@ void MainWindow::showMeteoVariable(meteoVariable var)
}
}

void MainWindow::on_actionViewMeteoVariable_None_triggered()
void MainWindow::on_actionView_Radiation_None_triggered()
{
setOutputRasterVisible(false);
refreshViewer3D();
}

void MainWindow::on_actionView_MeteoVariable_None_triggered()
{
setOutputRasterVisible(false);
refreshViewer3D();
}

void MainWindow::on_actionView_Air_temperature_triggered()
Expand Down Expand Up @@ -1521,7 +1553,8 @@ void MainWindow::on_actionView_Snow_latent_heat_triggered()


// ------------- CROP MAPS ---------------------------------------------------
void MainWindow::on_actionView_degree_days_triggered()

void MainWindow::on_actionView_Crop_degreeDays_triggered()
{
if (! myProject.isCropInitialized)
{
Expand Down Expand Up @@ -3135,6 +3168,8 @@ void MainWindow::on_actionShow_3D_viewer_triggered()

connect (viewer3D, SIGNAL(destroyed()), this, SLOT(on_viewer3DClosed()));
connect (viewer3D, SIGNAL(slopeChanged()), this, SLOT(on_slopeChanged()));

refreshViewer3D();
}


Expand Down Expand Up @@ -3175,25 +3210,27 @@ void MainWindow::on_actionHide_LandUseMap_triggered()
if (ui->labelOutputRaster->text() == "Land use")
{
setOutputRasterVisible(false);
refreshViewer3D();
}
}


void MainWindow::on_actionHide_Geomap_triggered()
{
setOutputRasterVisible(false);
refreshViewer3D();
}


//------------------- MENU VIEW SOIL FLUXES OUTPUT ------------------

void MainWindow::on_actionView_surfaceWaterContent_automatic_range_triggered()
void MainWindow::on_actionView_SurfaceWaterContent_automatic_range_triggered()
{
showCriteria3DVariable(volumetricWaterContent, 0, false, 0.1, NODATA);
}


void MainWindow::on_actionView_surfaceWaterContent_fixed_range_triggered()
void MainWindow::on_actionView_SurfaceWaterContent_fixed_range_triggered()
{
// choose minimum
float minimum = 0;
Expand All @@ -3218,28 +3255,28 @@ void MainWindow::on_actionView_SoilMoisture_triggered()
}


void MainWindow::on_actionView_degreeOfSaturation_automatic_range_triggered()
void MainWindow::on_actionView_DegreeOfSaturation_automatic_range_triggered()
{
int layerIndex = ui->layerNrEdit->value();
showCriteria3DVariable(degreeOfSaturation, layerIndex, false, NODATA, NODATA);
}


void MainWindow::on_actionView_degreeOfSaturation_fixed_range_triggered()
void MainWindow::on_actionView_DegreeOfSaturation_fixed_range_triggered()
{
int layerIndex = ui->layerNrEdit->value();
showCriteria3DVariable(degreeOfSaturation, layerIndex, true, 0.2, 1.0);
}


void MainWindow::on_actionView_factor_of_safety_triggered()
void MainWindow::on_actionView_Factor_of_safety_triggered()
{
int layerIndex = std::max(1, ui->layerNrEdit->value());
showCriteria3DVariable(factorOfSafety, layerIndex, true, 0, 4);
}


void MainWindow::on_actionView_factor_of_safety_minimum_triggered()
void MainWindow::on_actionView_Factor_of_safety_minimum_triggered()
{
showCriteria3DVariable(minimumFactorOfSafety, NODATA, true, 0, 4);
}
Expand Down Expand Up @@ -3319,11 +3356,11 @@ void MainWindow::on_actionCriteria3D_load_state_triggered()
return;
}

updateDateTime();
initializeCriteria3DInterface();
updateOutputMap();

loadMeteoPointsDataSingleDay(myProject.getCurrentDate(), true);
redrawMeteoPoints(currentPointsVisualization, true);
updateOutputMap();
}


Expand Down Expand Up @@ -3367,3 +3404,4 @@ void MainWindow::on_actionCriteria3D_save_state_triggered()
}



Loading

0 comments on commit 1a27e8e

Please sign in to comment.