60 double dDiffTotWaterLevel = 0;
62 double dAuxWaterLevelDiff = 0;
68 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
70 int nCoastSize =
m_VCoast[nCoast].pLGetCoastlineExtCRS()->nGetSize();
72 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
76 if (! isnan(dAuxWaterLevelDiff))
78 if (
tAbs(dAuxWaterLevelDiff) < 1)
81 dDiffTotWaterLevel += dAuxWaterLevelDiff;
88 dDiffTotWaterLevel /= pointCounter;
91 dDiffTotWaterLevel = 0;
96 for (
long unsigned int n = 0; n < nLocIDs; n++)
100 double dMinDiffTotWaterLevelAtCoast = 1e10;
102 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
104 int nCoastSize =
m_VCoast[nCoast].pLGetCoastlineExtCRS()->nGetSize();
105 double dMinDistSquare = 1e10;
107 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
109 double dCoastPointXExtCRS =
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nCoastPoint)->dGetX();
110 double dCoastPointYExtCRS =
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nCoastPoint)->dGetY();
112 double dDistSquare = (dCoastPointXExtCRS - dPointGridXExtCRS) * (dCoastPointXExtCRS - dPointGridXExtCRS) + (dCoastPointYExtCRS - dPointGridYExtCRS) * (dCoastPointYExtCRS - dPointGridYExtCRS);
114 if (dDistSquare < dMinDistSquare)
118 if (! isnan(dAuxWaterLevelDiff))
120 dMinDistSquare = dDistSquare;
121 dMinDiffTotWaterLevelAtCoast = dAuxWaterLevelDiff;
127 dDiffTotWaterLevel += dMinDiffTotWaterLevelAtCoast;
130 dDiffTotWaterLevel /=
static_cast<double>(nLocIDs);
147 stack<CGeom2DIPoint> PtiStackFlood;
153 while (! PtiStackFlood.empty())
158 int nX = Pti.
nGetX();
159 int nY = Pti.
nGetY();
166 if (!
m_pRasterGrid->m_Cell[nX][nY].bIsElevLessThanWaterLevel())
174 bool bSpanAbove =
false;
175 bool bSpanBelow =
false;
182 if (!
m_pRasterGrid->m_Cell[nX][nY].bIsElevLessThanWaterLevel())
200 if ((! bSpanAbove) && (nY > 0) && (
m_pRasterGrid->m_Cell[nX][nY - 1].bIsElevLessThanWaterLevel()) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bIsCellFloodCheck()))
206 else if (bSpanAbove && (nY > 0) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bIsElevLessThanWaterLevel()))
232 vector<bool> VbPossibleStartCellLHEdge;
233 vector<bool> VbTraced;
234 vector<int> VnSearchDirection;
235 vector<CGeom2DIPoint> V2DIPossibleStartCell;
238 for (
unsigned int n = 0; n <
m_VEdgeCell.size() - 1; n++)
258 bool bThisCellIsSea =
m_pRasterGrid->m_Cell[nXThis][nYThis].bIsInContiguousSeaArea();
259 bool bNextCellIsSea =
m_pRasterGrid->m_Cell[nXNext][nYNext].bIsInContiguousSeaArea();
262 if ((! bThisCellIsSea) && bNextCellIsSea)
268 m_pRasterGrid->m_Cell[nXThis][nYThis].SetPossibleFloodStartCell();
271 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXThis, nYThis));
272 VbPossibleStartCellLHEdge.push_back(
true);
274 VbTraced.push_back(
false);
278 else if (bThisCellIsSea && (! bNextCellIsSea))
284 m_pRasterGrid->m_Cell[nXNext][nYNext].SetPossibleFloodStartCell();
287 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXNext, nYNext));
288 VbPossibleStartCellLHEdge.push_back(
false);
290 VbTraced.push_back(
false);
295 bool bAtLeastOneCoastTraced =
false;
297 for (
unsigned int n = 0; n < V2DIPossibleStartCell.size(); n++)
303 if (VbPossibleStartCellLHEdge[n])
317 bAtLeastOneCoastTraced =
true;
322 if (bAtLeastOneCoastTraced)
332int CSimulation::nTraceFloodCoastLine(
unsigned int const nTraceFromStartCellIndex,
int const nStartSearchDirection,
int const nHandedness, vector<bool>*pVbTraced, vector<CGeom2DIPoint>
const* pV2DIPossibleStartCell)
334 bool bHitStartCell =
false;
335 bool bAtCoast =
false;
336 bool bHasLeftStartEdge =
false;
337 bool bTooLong =
false;
338 bool bOffEdge =
false;
339 bool bRepeating =
false;
341 int nStartX = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetX();
342 int nStartY = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetY();
345 int nSearchDirection = nStartSearchDirection;
355 m_pRasterGrid->m_Cell[nStartX][nStartY].SetAsFloodLine(
true);
357 ILTempGridCRS.
Append(&PtiStart);
385 if ((nRoundLoop > 10) && (ILTempGridCRS.
nGetSize() < 2))
394 if (! bHasLeftStartEdge)
397 if (((nStartSearchDirection ==
SOUTH) && (nY > nStartY)) || ((nStartSearchDirection ==
NORTH) && (nY < nStartY)) ||
398 ((nStartSearchDirection ==
EAST) && (nX > nStartX)) || ((nStartSearchDirection ==
WEST) && (nX < nStartX)))
399 bHasLeftStartEdge =
true;
409 for (
unsigned int nn = 0; nn < pVbTraced->size(); nn++)
411 if ((nn != nTraceFromStartCellIndex) && (! pVbTraced->at(nn)))
415 if (bAtCoast && (nX == pV2DIPossibleStartCell->at(nn).nGetX()) && (nY == pV2DIPossibleStartCell->at(nn).nGetY()))
418 LogStream <<
m_ulIter <<
": Possible flood coastline found, traced from [" << nStartX <<
"][" << nStartY <<
"] and hit another coast start cell at [" << nX <<
"][" << nY <<
"]" << endl;
420 pVbTraced->at(nn) =
true;
421 bHitStartCell =
true;
436 int nSeawardNewDirection = 0;
437 int nXStraightOn = 0;
438 int nYStraightOn = 0;
439 int nXAntiSeaward = 0;
440 int nYAntiSeaward = 0;
441 int nAntiSeawardNewDirection = 0;
444 int nGoBackNewDirection = 0;
454 switch (nSearchDirection)
460 nSeawardNewDirection =
EAST;
464 nYStraightOn = nY - 1;
467 nXAntiSeaward = nX - 1;
469 nAntiSeawardNewDirection =
WEST;
474 nGoBackNewDirection =
SOUTH;
482 nSeawardNewDirection =
SOUTH;
485 nXStraightOn = nX + 1;
490 nYAntiSeaward = nY - 1;
491 nAntiSeawardNewDirection =
NORTH;
496 nGoBackNewDirection =
WEST;
504 nSeawardNewDirection =
WEST;
508 nYStraightOn = nY + 1;
511 nXAntiSeaward = nX + 1;
513 nAntiSeawardNewDirection =
EAST;
518 nGoBackNewDirection =
NORTH;
526 nSeawardNewDirection =
NORTH;
529 nXStraightOn = nX - 1;
534 nYAntiSeaward = nY + 1;
535 nAntiSeawardNewDirection =
SOUTH;
540 nGoBackNewDirection =
EAST;
550 switch (nSearchDirection)
556 nSeawardNewDirection =
WEST;
560 nYStraightOn = nY - 1;
563 nXAntiSeaward = nX + 1;
565 nAntiSeawardNewDirection =
EAST;
570 nGoBackNewDirection =
SOUTH;
578 nSeawardNewDirection =
NORTH;
581 nXStraightOn = nX + 1;
586 nYAntiSeaward = nY + 1;
587 nAntiSeawardNewDirection =
SOUTH;
592 nGoBackNewDirection =
WEST;
600 nSeawardNewDirection =
EAST;
604 nYStraightOn = nY + 1;
607 nXAntiSeaward = nX - 1;
609 nAntiSeawardNewDirection =
WEST;
614 nGoBackNewDirection =
NORTH;
622 nSeawardNewDirection =
SOUTH;
625 nXStraightOn = nX - 1;
630 nYAntiSeaward = nY - 1;
631 nAntiSeawardNewDirection =
NORTH;
636 nGoBackNewDirection =
EAST;
648 if (
m_pRasterGrid->m_Cell[nXSeaward][nYSeaward].bIsInContiguousSeaArea())
661 ILTempGridCRS.
Append(&Pti);
664 else if (!
m_pRasterGrid->m_Cell[nX][nY].bIsElevLessThanWaterLevel())
668 ILTempGridCRS.
Append(&Pti);
680 nSearchDirection = nSeawardNewDirection;
689 if (
m_pRasterGrid->m_Cell[nXStraightOn][nYStraightOn].bIsInContiguousSeaArea())
702 ILTempGridCRS.
Append(&Pti);
705 else if (!
m_pRasterGrid->m_Cell[nX][nY].bIsElevLessThanWaterLevel())
709 ILTempGridCRS.
Append(&Pti);
729 if (
m_pRasterGrid->m_Cell[nXAntiSeaward][nYAntiSeaward].bIsInContiguousSeaArea())
742 ILTempGridCRS.
Append(&Pti);
745 else if (!
m_pRasterGrid->m_Cell[nX][nY].bIsElevLessThanWaterLevel())
749 ILTempGridCRS.
Append(&Pti);
761 nSearchDirection = nAntiSeawardNewDirection;
773 nSearchDirection = nGoBackNewDirection;
785 int nCoastSize = ILTempGridCRS.
nGetSize();
793 for (
int n = 0; n < nCoastSize; n++)
794 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodLine(
false);
807 LogStream <<
", it ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
813 for (
int n = 0; n < nCoastSize; n++)
814 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodLine(
false);
826 LogStream <<
", it ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
832 for (
int n = 0; n < nCoastSize; n++)
833 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodLine(
false);
854 for (
int n = 0; n < nCoastSize; n++)
855 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodLine(
false);
863 int nCoastEndX = ILTempGridCRS[nCoastSize - 1].nGetX();
864 int nCoastEndY = ILTempGridCRS[nCoastSize - 1].nGetY();
866 if ((nCoastEndX != nEndX) || (nCoastEndY != nEndY))
869 if (!
m_pRasterGrid->m_Cell[nCoastEndX][nCoastEndY].bIsBoundingBoxEdge())
872 ILTempGridCRS.
Append(nEndX, nEndY);
887 for (
int j = 0; j < nCoastSize; j++)