55 double dDiffTotWaterLevel = 0;
57 double dAuxWaterLevelDiff = 0;
63 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
65 int const nCoastSize =
m_VCoast[nCoast].pLGetCoastlineExtCRS()->nGetSize();
67 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
71 if (!isnan(dAuxWaterLevelDiff))
73 if (
tAbs(dAuxWaterLevelDiff) < 1)
76 dDiffTotWaterLevel += dAuxWaterLevelDiff;
83 dDiffTotWaterLevel /= pointCounter;
86 dDiffTotWaterLevel = 0;
91 for (
long unsigned int n = 0; n < nLocIDs; n++)
95 double dMinDiffTotWaterLevelAtCoast = 1e10;
97 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
99 int const nCoastSize =
m_VCoast[nCoast].pLGetCoastlineExtCRS()->nGetSize();
100 double dMinDistSquare = 1e10;
102 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
104 double const dCoastPointXExtCRS =
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nCoastPoint)->dGetX();
105 double const dCoastPointYExtCRS =
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nCoastPoint)->dGetY();
107 double const dDistSquare = (dCoastPointXExtCRS - dPointGridXExtCRS) * (dCoastPointXExtCRS - dPointGridXExtCRS) + (dCoastPointYExtCRS - dPointGridYExtCRS) * (dCoastPointYExtCRS - dPointGridYExtCRS);
109 if (dDistSquare < dMinDistSquare)
113 if (!isnan(dAuxWaterLevelDiff))
115 dMinDistSquare = dDistSquare;
116 dMinDiffTotWaterLevelAtCoast = dAuxWaterLevelDiff;
122 dDiffTotWaterLevel += dMinDiffTotWaterLevelAtCoast;
125 dDiffTotWaterLevel /=
static_cast<double>(nLocIDs);
142 stack<CGeom2DIPoint> PtiStackFlood;
148 while (! PtiStackFlood.empty())
153 int nX = Pti.
nGetX();
154 int const nY = Pti.
nGetY();
161 if (!
m_pRasterGrid->m_Cell[nX][nY].bIsElevLessThanWaterLevel())
169 bool bSpanAbove =
false;
170 bool bSpanBelow =
false;
177 if (!
m_pRasterGrid->m_Cell[nX][nY].bIsElevLessThanWaterLevel())
195 if ((! bSpanAbove) && (nY > 0) && (
m_pRasterGrid->m_Cell[nX][nY - 1].bIsElevLessThanWaterLevel()) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bIsCellFloodCheck()))
201 else if (bSpanAbove && (nY > 0) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bIsElevLessThanWaterLevel()))
227 vector<bool> VbPossibleStartCellLHEdge;
228 vector<bool> VbTraced;
229 vector<int> VnSearchDirection;
230 vector<CGeom2DIPoint> V2DIPossibleStartCell;
233 for (
unsigned int n = 0; n <
m_VEdgeCell.size() - 1; n++)
253 bool const bThisCellIsSea =
m_pRasterGrid->m_Cell[nXThis][nYThis].bIsInContiguousSeaArea();
254 bool const bNextCellIsSea =
m_pRasterGrid->m_Cell[nXNext][nYNext].bIsInContiguousSeaArea();
257 if ((! bThisCellIsSea) && bNextCellIsSea)
263 m_pRasterGrid->m_Cell[nXThis][nYThis].SetPossibleFloodStartCell();
266 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXThis, nYThis));
267 VbPossibleStartCellLHEdge.push_back(
true);
269 VbTraced.push_back(
false);
273 else if (bThisCellIsSea && (! bNextCellIsSea))
279 m_pRasterGrid->m_Cell[nXNext][nYNext].SetPossibleFloodStartCell();
282 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXNext, nYNext));
283 VbPossibleStartCellLHEdge.push_back(
false);
285 VbTraced.push_back(
false);
290 bool bAtLeastOneCoastTraced =
false;
292 for (
unsigned int n = 0; n < V2DIPossibleStartCell.size(); n++)
298 if (VbPossibleStartCellLHEdge[n])
312 bAtLeastOneCoastTraced =
true;
317 if (bAtLeastOneCoastTraced)
326int CSimulation::nTraceFloodCoastLine(
unsigned int const nTraceFromStartCellIndex,
int const nStartSearchDirection,
int const nHandedness, vector<bool>* pVbTraced, vector<CGeom2DIPoint>
const* pV2DIPossibleStartCell)
328 bool bHitStartCell =
false;
329 bool bAtCoast =
false;
330 bool bHasLeftStartEdge =
false;
331 bool bTooLong =
false;
332 bool bOffEdge =
false;
333 bool bRepeating =
false;
335 int const nStartX = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetX();
336 int const nStartY = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetY();
339 int nSearchDirection = nStartSearchDirection;
349 m_pRasterGrid->m_Cell[nStartX][nStartY].SetAsFloodline(
true);
351 ILTempGridCRS.
Append(&PtiStart);
379 if ((nRoundLoop > 10) && (ILTempGridCRS.
nGetSize() < 2))
388 if (! bHasLeftStartEdge)
391 if (((nStartSearchDirection ==
SOUTH) && (nY > nStartY)) || ((nStartSearchDirection ==
NORTH) && (nY < nStartY)) ||
392 ((nStartSearchDirection ==
EAST) && (nX > nStartX)) || ((nStartSearchDirection ==
WEST) && (nX < nStartX)))
393 bHasLeftStartEdge =
true;
403 for (
unsigned int nn = 0; nn < pVbTraced->size(); nn++)
405 if ((nn != nTraceFromStartCellIndex) && (! pVbTraced->at(nn)))
409 if (bAtCoast && (nX == pV2DIPossibleStartCell->at(nn).nGetX()) && (nY == pV2DIPossibleStartCell->at(nn).nGetY()))
412 LogStream <<
m_ulIter <<
": Possible flood coastline found, traced from [" << nStartX <<
"][" << nStartY <<
"] and hit another possible flood coast start cell at [" << nX <<
"][" << nY <<
"]" << endl;
414 pVbTraced->at(nn) =
true;
415 bHitStartCell =
true;
430 int nSeawardNewDirection = 0;
431 int nXStraightOn = 0;
432 int nYStraightOn = 0;
433 int nXAntiSeaward = 0;
434 int nYAntiSeaward = 0;
435 int nAntiSeawardNewDirection = 0;
438 int nGoBackNewDirection = 0;
448 switch (nSearchDirection)
454 nSeawardNewDirection =
EAST;
458 nYStraightOn = nY - 1;
461 nXAntiSeaward = nX - 1;
463 nAntiSeawardNewDirection =
WEST;
468 nGoBackNewDirection =
SOUTH;
476 nSeawardNewDirection =
SOUTH;
479 nXStraightOn = nX + 1;
484 nYAntiSeaward = nY - 1;
485 nAntiSeawardNewDirection =
NORTH;
490 nGoBackNewDirection =
WEST;
498 nSeawardNewDirection =
WEST;
502 nYStraightOn = nY + 1;
505 nXAntiSeaward = nX + 1;
507 nAntiSeawardNewDirection =
EAST;
512 nGoBackNewDirection =
NORTH;
520 nSeawardNewDirection =
NORTH;
523 nXStraightOn = nX - 1;
528 nYAntiSeaward = nY + 1;
529 nAntiSeawardNewDirection =
SOUTH;
534 nGoBackNewDirection =
EAST;
544 switch (nSearchDirection)
550 nSeawardNewDirection =
WEST;
554 nYStraightOn = nY - 1;
557 nXAntiSeaward = nX + 1;
559 nAntiSeawardNewDirection =
EAST;
564 nGoBackNewDirection =
SOUTH;
572 nSeawardNewDirection =
NORTH;
575 nXStraightOn = nX + 1;
580 nYAntiSeaward = nY + 1;
581 nAntiSeawardNewDirection =
SOUTH;
586 nGoBackNewDirection =
WEST;
594 nSeawardNewDirection =
EAST;
598 nYStraightOn = nY + 1;
601 nXAntiSeaward = nX - 1;
603 nAntiSeawardNewDirection =
WEST;
608 nGoBackNewDirection =
NORTH;
616 nSeawardNewDirection =
SOUTH;
619 nXStraightOn = nX - 1;
624 nYAntiSeaward = nY - 1;
625 nAntiSeawardNewDirection =
NORTH;
630 nGoBackNewDirection =
EAST;
642 if (
m_pRasterGrid->m_Cell[nXSeaward][nYSeaward].bIsInContiguousSeaArea())
655 ILTempGridCRS.
Append(&Pti);
658 else if (!
m_pRasterGrid->m_Cell[nX][nY].bIsElevLessThanWaterLevel())
662 ILTempGridCRS.
Append(&Pti);
674 nSearchDirection = nSeawardNewDirection;
683 if (
m_pRasterGrid->m_Cell[nXStraightOn][nYStraightOn].bIsInContiguousSeaArea())
696 ILTempGridCRS.
Append(&Pti);
699 else if (!
m_pRasterGrid->m_Cell[nX][nY].bIsElevLessThanWaterLevel())
703 ILTempGridCRS.
Append(&Pti);
723 if (
m_pRasterGrid->m_Cell[nXAntiSeaward][nYAntiSeaward].bIsInContiguousSeaArea())
736 ILTempGridCRS.
Append(&Pti);
739 else if (!
m_pRasterGrid->m_Cell[nX][nY].bIsElevLessThanWaterLevel())
743 ILTempGridCRS.
Append(&Pti);
755 nSearchDirection = nAntiSeawardNewDirection;
767 nSearchDirection = nGoBackNewDirection;
779 int nCoastSize = ILTempGridCRS.
nGetSize();
787 for (
int n = 0; n < nCoastSize; n++)
788 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodline(
false);
801 LogStream <<
", it ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
807 for (
int n = 0; n < nCoastSize; n++)
808 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodline(
false);
820 LogStream <<
", it ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
826 for (
int n = 0; n < nCoastSize; n++)
827 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodline(
false);
848 for (
int n = 0; n < nCoastSize; n++)
849 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodline(
false);
855 int const nEndX = nX;
856 int const nEndY = nY;
857 int const nCoastEndX = ILTempGridCRS[nCoastSize - 1].nGetX();
858 int const nCoastEndY = ILTempGridCRS[nCoastSize - 1].nGetY();
860 if ((nCoastEndX != nEndX) || (nCoastEndY != nEndY))
863 if (!
m_pRasterGrid->m_Cell[nCoastEndX][nCoastEndY].bIsBoundingBoxEdge())
866 ILTempGridCRS.
Append(nEndX, nEndY);
881 for (
int j = 0; j < nCoastSize; j++)