This repository has been archived by the owner on Sep 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwaterRemovalOperator.cpp
executable file
·56 lines (52 loc) · 1.75 KB
/
waterRemovalOperator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include"waterRemovalOperator.h"
void WaterRemovalOperator::
demLayer(RasterLayer<double> &layerD)
{
_pDEMLayer = &layerD;
_pDEMNbrhood = layerD.nbrhood();
cellSize = _pDEMLayer->_pMetaData->cellSize;
noData = _pDEMLayer->_pMetaData->noData;
Configure(_pDEMLayer, false); // false means not to send and receive the data of _pDEMLayer for each process after each round of iteration
}
void WaterRemovalOperator::wdemLayer(RasterLayer<double> &layerD)
{
_pwDEMLayer = &layerD;
Configure(_pwDEMLayer,true); // true means need to send and receive the data of _pwDEMLayer for each process after each round of iteration
}
// operator function for water-removal step
bool WaterRemovalOperator::Operator(const CellCoord &coord)
{
CellSpace<double> &dem = *(_pDEMLayer->cellSpace());
CellSpace<double> &wdem = *(_pwDEMLayer->cellSpace());
int xSize = _pDEMLayer->_pMetaData->row; //metadata of raster layer
int ySize = _pDEMLayer->_pMetaData->column;
int iRow = coord.iRow();
int iCol = coord.iCol();
Neighborhood<double>& nbrhoodD = *(_pDEMNbrhood);
int iNeighborCells = ((int)sqrt((double)nbrhoodD.size())) / 2; // assign the neighborhood window
int i, j;
int temp = 0;
if( wdem[iRow][iCol] > dem[iRow][iCol] )
{
for(i = iRow - iNeighborCells; i <= iRow + iNeighborCells; i++)
{
for(j = iCol - iNeighborCells; j <= iCol + iNeighborCells; j++)
{
if( dem[iRow][iCol] >= (wdem[i][j] + gap) )
{
wdem[iRow][iCol] = dem[iRow][iCol];
Termination = 0; // denote if the iterative processing will continue
}
else
{
if( wdem[iRow][iCol] > (wdem[i][j] + gap) )
{
wdem[iRow][iCol] = wdem[i][j] + gap;
Termination = 0;
}
}
}
}
}
return true;
}