49 double dDiffTotWaterLevel = 0;
51 double dAuxWaterLevelDiff = 0;
57 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
59 int const nCoastSize =
m_VCoast[nCoast].pLGetCoastlineExtCRS()->nGetSize();
61 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
65 if (!isnan(dAuxWaterLevelDiff))
67 if (
tAbs(dAuxWaterLevelDiff) < 1)
70 dDiffTotWaterLevel += dAuxWaterLevelDiff;
77 dDiffTotWaterLevel /= pointCounter;
79 dDiffTotWaterLevel = 0;
83 for (
long unsigned int n = 0; n < nLocIDs; n++)
87 double dMinDiffTotWaterLevelAtCoast = 1e10;
89 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
91 int const nCoastSize =
m_VCoast[nCoast].pLGetCoastlineExtCRS()->nGetSize();
92 double dMinDistSquare = 1e10;
94 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
96 double const dCoastPointXExtCRS =
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nCoastPoint)->dGetX();
97 double const dCoastPointYExtCRS =
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nCoastPoint)->dGetY();
99 double const dDistSquare = (dCoastPointXExtCRS - dPointGridXExtCRS) * (dCoastPointXExtCRS - dPointGridXExtCRS) + (dCoastPointYExtCRS - dPointGridYExtCRS) * (dCoastPointYExtCRS - dPointGridYExtCRS);
101 if (dDistSquare < dMinDistSquare)
105 if (!isnan(dAuxWaterLevelDiff))
107 dMinDistSquare = dDistSquare;
108 dMinDiffTotWaterLevelAtCoast = dAuxWaterLevelDiff;
114 dDiffTotWaterLevel += dMinDiffTotWaterLevelAtCoast;
117 dDiffTotWaterLevel /=
static_cast<double>(nLocIDs);
134 stack<CGeom2DIPoint> PtiStackFlood;
140 while (! PtiStackFlood.empty())
145 int nX = Pti.
nGetX();
146 int const nY = Pti.
nGetY();
161 bool bSpanAbove =
false;
162 bool bSpanBelow =
false;
187 if ((! bSpanAbove) && (nY > 0) && (
m_pRasterGrid->m_Cell[nX][nY - 1].bElevLessThanSWL()) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bIsCellFloodCheck()))
193 else if (bSpanAbove && (nY > 0) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bElevLessThanSWL()))
219 vector<bool> VbPossibleStartCellLHEdge;
220 vector<bool> VbTraced;
221 vector<int> VnSearchDirection;
222 vector<CGeom2DIPoint> V2DIPossibleStartCell;
225 for (
unsigned int n = 0; n <
m_VEdgeCell.size() - 1; n++)
245 bool const bThisCellIsSea =
m_pRasterGrid->m_Cell[nXThis][nYThis].bIsInContiguousSeaFlood();
246 bool const bNextCellIsSea =
m_pRasterGrid->m_Cell[nXNext][nYNext].bIsInContiguousSeaFlood();
249 if ((! bThisCellIsSea) && bNextCellIsSea)
255 m_pRasterGrid->m_Cell[nXThis][nYThis].SetPossibleFloodStartCell();
258 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXThis, nYThis));
259 VbPossibleStartCellLHEdge.push_back(
true);
261 VbTraced.push_back(
false);
265 else if (bThisCellIsSea && (! bNextCellIsSea))
271 m_pRasterGrid->m_Cell[nXNext][nYNext].SetPossibleFloodStartCell();
274 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXNext, nYNext));
275 VbPossibleStartCellLHEdge.push_back(
false);
277 VbTraced.push_back(
false);
282 bool bAtLeastOneCoastTraced =
false;
284 for (
unsigned int n = 0; n < V2DIPossibleStartCell.size(); n++)
290 if (VbPossibleStartCellLHEdge[n])
304 bAtLeastOneCoastTraced =
true;
309 if (bAtLeastOneCoastTraced)
318int CSimulation::nTraceFloodCoastLine(
unsigned int const nTraceFromStartCellIndex,
int const nStartSearchDirection,
int const nHandedness, vector<bool>* pVbTraced, vector<CGeom2DIPoint>
const* pV2DIPossibleStartCell)
320 bool bHitStartCell =
false;
321 bool bAtCoast =
false;
322 bool bHasLeftStartEdge =
false;
323 bool bTooLong =
false;
324 bool bOffEdge =
false;
325 bool bRepeating =
false;
327 int const nStartX = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetX();
328 int const nStartY = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetY();
331 int nSearchDirection = nStartSearchDirection;
341 m_pRasterGrid->m_Cell[nStartX][nStartY].SetAsFloodline(
true);
343 ILTempGridCRS.
Append(&PtiStart);
371 if ((nRoundLoop > 10) && (ILTempGridCRS.
nGetSize() < 2))
380 if (! bHasLeftStartEdge)
383 if (((nStartSearchDirection ==
SOUTH) && (nY > nStartY)) || ((nStartSearchDirection ==
NORTH) && (nY < nStartY)) ||
384 ((nStartSearchDirection ==
EAST) && (nX > nStartX)) || ((nStartSearchDirection ==
WEST) && (nX < nStartX)))
385 bHasLeftStartEdge =
true;
395 for (
unsigned int nn = 0; nn < pVbTraced->size(); nn++)
397 if ((nn != nTraceFromStartCellIndex) && (! pVbTraced->at(nn)))
401 if (bAtCoast && (nX == pV2DIPossibleStartCell->at(nn).nGetX()) && (nY == pV2DIPossibleStartCell->at(nn).nGetY()))
404 LogStream <<
m_ulIter <<
": Possible flood coastline found, traced from [" << nStartX <<
"][" << nStartY <<
"] and hit another possible flood coast start cell at [" << nX <<
"][" << nY <<
"]" << endl;
406 pVbTraced->at(nn) =
true;
407 bHitStartCell =
true;
422 int nSeawardNewDirection = 0;
423 int nXStraightOn = 0;
424 int nYStraightOn = 0;
425 int nXAntiSeaward = 0;
426 int nYAntiSeaward = 0;
427 int nAntiSeawardNewDirection = 0;
430 int nGoBackNewDirection = 0;
440 switch (nSearchDirection)
446 nSeawardNewDirection =
EAST;
450 nYStraightOn = nY - 1;
453 nXAntiSeaward = nX - 1;
455 nAntiSeawardNewDirection =
WEST;
460 nGoBackNewDirection =
SOUTH;
468 nSeawardNewDirection =
SOUTH;
471 nXStraightOn = nX + 1;
476 nYAntiSeaward = nY - 1;
477 nAntiSeawardNewDirection =
NORTH;
482 nGoBackNewDirection =
WEST;
490 nSeawardNewDirection =
WEST;
494 nYStraightOn = nY + 1;
497 nXAntiSeaward = nX + 1;
499 nAntiSeawardNewDirection =
EAST;
504 nGoBackNewDirection =
NORTH;
512 nSeawardNewDirection =
NORTH;
515 nXStraightOn = nX - 1;
520 nYAntiSeaward = nY + 1;
521 nAntiSeawardNewDirection =
SOUTH;
526 nGoBackNewDirection =
EAST;
536 switch (nSearchDirection)
542 nSeawardNewDirection =
WEST;
546 nYStraightOn = nY - 1;
549 nXAntiSeaward = nX + 1;
551 nAntiSeawardNewDirection =
EAST;
556 nGoBackNewDirection =
SOUTH;
564 nSeawardNewDirection =
NORTH;
567 nXStraightOn = nX + 1;
572 nYAntiSeaward = nY + 1;
573 nAntiSeawardNewDirection =
SOUTH;
578 nGoBackNewDirection =
WEST;
586 nSeawardNewDirection =
EAST;
590 nYStraightOn = nY + 1;
593 nXAntiSeaward = nX - 1;
595 nAntiSeawardNewDirection =
WEST;
600 nGoBackNewDirection =
NORTH;
608 nSeawardNewDirection =
SOUTH;
611 nXStraightOn = nX - 1;
616 nYAntiSeaward = nY - 1;
617 nAntiSeawardNewDirection =
NORTH;
622 nGoBackNewDirection =
EAST;
634 if (
m_pRasterGrid->m_Cell[nXSeaward][nYSeaward].bIsInContiguousSeaFlood())
647 ILTempGridCRS.
Append(&Pti);
654 ILTempGridCRS.
Append(&Pti);
666 nSearchDirection = nSeawardNewDirection;
675 if (
m_pRasterGrid->m_Cell[nXStraightOn][nYStraightOn].bIsInContiguousSeaFlood())
688 ILTempGridCRS.
Append(&Pti);
695 ILTempGridCRS.
Append(&Pti);
715 if (
m_pRasterGrid->m_Cell[nXAntiSeaward][nYAntiSeaward].bIsInContiguousSeaFlood())
728 ILTempGridCRS.
Append(&Pti);
735 ILTempGridCRS.
Append(&Pti);
747 nSearchDirection = nAntiSeawardNewDirection;
759 nSearchDirection = nGoBackNewDirection;
771 int nCoastSize = ILTempGridCRS.
nGetSize();
779 for (
int n = 0; n < nCoastSize; n++)
780 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodline(
false);
793 LogStream <<
", it ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
799 for (
int n = 0; n < nCoastSize; n++)
800 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodline(
false);
812 LogStream <<
", it ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
818 for (
int n = 0; n < nCoastSize; n++)
819 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodline(
false);
840 for (
int n = 0; n < nCoastSize; n++)
841 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsFloodline(
false);
847 int const nEndX = nX;
848 int const nEndY = nY;
849 int const nCoastEndX = ILTempGridCRS[nCoastSize - 1].nGetX();
850 int const nCoastEndY = ILTempGridCRS[nCoastSize - 1].nGetY();
852 if ((nCoastEndX != nEndX) || (nCoastEndY != nEndY))
855 if (!
m_pRasterGrid->m_Cell[nCoastEndX][nCoastEndY].bIsBoundingBoxEdge())
858 ILTempGridCRS.
Append(nEndX, nEndY);
873 for (
int j = 0; j < nCoastSize; j++)