31using std::setprecision;
70 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
74 LCoast = *
m_VCoast[nCoast].pLGetCoastlineExtCRS();
84 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
88 LCoast = *
m_VCoast[nCoast].pLGetCoastlineExtCRS();
102 for (
unsigned int n = 0; n <
m_VEdgeCell.size(); n++)
134 stack<CGeom2DIPoint> PtiStack;
142 while (! PtiStack.empty())
145 if (nRoundLoop++ > nRoundLoopMax)
151 int nX = Pti.
nGetX();
152 int const nY = Pti.
nGetY();
154 while ((nX >= 0) && (!
m_pRasterGrid->m_Cell[nX][nY].bBasementElevIsMissingValue()) && (
m_pRasterGrid->m_Cell[nX][nY].bIsInundated()))
159 bool bSpanAbove =
false;
160 bool bSpanBelow =
false;
178 m_pRasterGrid->m_Cell[nX][nY].SetWaveValuesToDeepWaterWaveValues();
188 m_pRasterGrid->m_Cell[nX][nY].SetWaveValuesToDeepWaterWaveValues();
207 if ((! bSpanAbove) && (nY > 0) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bBasementElevIsMissingValue()) && (
m_pRasterGrid->m_Cell[nX][nY - 1].bIsInundated()))
212 else if (bSpanAbove && (nY > 0) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bBasementElevIsMissingValue()) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bIsInundated()))
648 int const TOOCLOSE = 1;
650 vector<bool> VbPossibleStartCellLHEdge;
651 vector<bool> VbTraced;
652 vector<int> VnSearchDirection;
653 vector<CGeom2DIPoint> V2DIPossibleStartCell;
656 for (
unsigned int n = 0; n <
m_VEdgeCell.size() - 1; n++)
676 bool const bThisCellIsSea =
m_pRasterGrid->m_Cell[nXThis][nYThis].bIsInContiguousSea();
677 bool const bNextCellIsSea =
m_pRasterGrid->m_Cell[nXNext][nYNext].bIsInContiguousSea();
680 if ((! bThisCellIsSea) && bNextCellIsSea)
683 if (
m_pRasterGrid->m_Cell[nXThis][nYThis].bIsPossibleCoastStartCell())
687 bool bTooClose =
false;
688 for (
int nn = 1; nn <= TOOCLOSE; nn++)
690 int const nTmp = n + nn;
697 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsPossibleCoastStartCell())
707 for (
int nn = 1; nn <= TOOCLOSE; nn++)
709 int const nTmp = n - nn;
716 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsPossibleCoastStartCell())
726 m_pRasterGrid->m_Cell[nXThis][nYThis].SetPossibleCoastStartCell();
732 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXThis, nYThis));
733 VbPossibleStartCellLHEdge.push_back(
true);
735 VbTraced.push_back(
false);
737 else if (bThisCellIsSea && (! bNextCellIsSea))
740 if (
m_pRasterGrid->m_Cell[nXNext][nYNext].bIsPossibleCoastStartCell())
744 bool bTooClose =
false;
745 for (
int nn = 1; nn <= TOOCLOSE; nn++)
747 int const nTmp = n + 1 + nn;
754 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsPossibleCoastStartCell())
764 for (
int nn = 1; nn <= TOOCLOSE; nn++)
766 int const nTmp = n + 1 - nn;
773 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsPossibleCoastStartCell())
783 m_pRasterGrid->m_Cell[nXNext][nYNext].SetPossibleCoastStartCell();
789 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXNext, nYNext));
790 VbPossibleStartCellLHEdge.push_back(
false);
792 VbTraced.push_back(
false);
797 if (V2DIPossibleStartCell.size() == 0)
799 LogStream <<
m_ulIter <<
": no coastline start/finish points found after grid edges searched.";
841 for (
int n =
static_cast<int>(V2DIPossibleStartCell.size())-1; n >= 0; n--)
847 if (VbPossibleStartCellLHEdge[n])
861 if (nValidCoast == 0)
864 for (
int n = 0; n < static_cast<int>(VbTraced.size()); n++)
867 for (
int n = 0; n < static_cast<int>(V2DIPossibleStartCell.size()); n++)
873 if (VbPossibleStartCellLHEdge[n])
888 if (nValidCoast == 0)
891 cerr <<
m_ulIter <<
": no valid coasts found, see " <<
m_strLogFile <<
" for more information" << endl;
901int CSimulation::nTraceCoastLine(
unsigned int const nTraceFromStartCellIndex,
int const nStartSearchDirection,
int const nHandedness, vector<bool>* pVbTraced, vector<CGeom2DIPoint>
const* pV2DIPossibleStartCell)
903 bool bHitStartCell =
false;
904 bool bAtCoast =
false;
905 bool bHasLeftStartEdge =
false;
906 bool bTooLong =
false;
907 bool bOffEdge =
false;
908 bool bRepeating =
false;
910 int const nStartX = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetX();
911 int const nStartY = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetY();
914 int nSearchDirection = nStartSearchDirection;
925 ILTempGridCRS.
Append(&PtiStart);
953 if ((nRoundLoop > 10) && (ILTempGridCRS.
nGetSize() < 2))
964 if (! bHasLeftStartEdge)
967 if (((nStartSearchDirection ==
SOUTH) && (nY > nStartY)) || ((nStartSearchDirection ==
NORTH) && (nY < nStartY)) || ((nStartSearchDirection ==
EAST) && (nX > nStartX)) || ((nStartSearchDirection ==
WEST) && (nX < nStartX)))
968 bHasLeftStartEdge =
true;
977 if (bHasLeftStartEdge && bAtCoast)
979 for (
unsigned int nn = 0; nn < pVbTraced->size(); nn++)
981 bool const bTraced = pVbTraced->at(nn);
982 if ((nn != nTraceFromStartCellIndex) && (! bTraced))
984 int const nXPoss = pV2DIPossibleStartCell->at(nn).nGetX();
985 int const nYPoss = pV2DIPossibleStartCell->at(nn).nGetY();
989 if ((nX == nXPoss) && (nY == nYPoss))
994 pVbTraced->at(nn) =
true;
995 bHitStartCell =
true;
1008 int nSeawardNewDirection = 0;
1009 int nXStraightOn = 0;
1010 int nYStraightOn = 0;
1011 int nXAntiSeaward = 0;
1012 int nYAntiSeaward = 0;
1013 int nAntiSeawardNewDirection = 0;
1016 int nGoBackNewDirection = 0;
1021 switch (nHandedness)
1025 switch (nSearchDirection)
1031 nSeawardNewDirection =
EAST;
1035 nYStraightOn = nY - 1;
1038 nXAntiSeaward = nX - 1;
1040 nAntiSeawardNewDirection =
WEST;
1045 nGoBackNewDirection =
SOUTH;
1053 nSeawardNewDirection =
SOUTH;
1056 nXStraightOn = nX + 1;
1061 nYAntiSeaward = nY - 1;
1062 nAntiSeawardNewDirection =
NORTH;
1067 nGoBackNewDirection =
WEST;
1075 nSeawardNewDirection =
WEST;
1079 nYStraightOn = nY + 1;
1082 nXAntiSeaward = nX + 1;
1084 nAntiSeawardNewDirection =
EAST;
1089 nGoBackNewDirection =
NORTH;
1097 nSeawardNewDirection =
NORTH;
1100 nXStraightOn = nX - 1;
1105 nYAntiSeaward = nY + 1;
1106 nAntiSeawardNewDirection =
SOUTH;
1111 nGoBackNewDirection =
EAST;
1121 switch (nSearchDirection)
1127 nSeawardNewDirection =
WEST;
1131 nYStraightOn = nY - 1;
1134 nXAntiSeaward = nX + 1;
1136 nAntiSeawardNewDirection =
EAST;
1141 nGoBackNewDirection =
SOUTH;
1149 nSeawardNewDirection =
NORTH;
1152 nXStraightOn = nX + 1;
1157 nYAntiSeaward = nY + 1;
1158 nAntiSeawardNewDirection =
SOUTH;
1163 nGoBackNewDirection =
WEST;
1171 nSeawardNewDirection =
EAST;
1175 nYStraightOn = nY + 1;
1178 nXAntiSeaward = nX - 1;
1180 nAntiSeawardNewDirection =
WEST;
1185 nGoBackNewDirection =
NORTH;
1193 nSeawardNewDirection =
SOUTH;
1196 nXStraightOn = nX - 1;
1201 nYAntiSeaward = nY - 1;
1202 nAntiSeawardNewDirection =
NORTH;
1207 nGoBackNewDirection =
EAST;
1219 if (
m_pRasterGrid->m_Cell[nXSeaward][nYSeaward].bIsInContiguousSea())
1247 nSearchDirection = nSeawardNewDirection;
1256 if (
m_pRasterGrid->m_Cell[nXStraightOn][nYStraightOn].bIsInContiguousSea())
1292 if (
m_pRasterGrid->m_Cell[nXAntiSeaward][nYAntiSeaward].bIsInContiguousSea())
1320 nSearchDirection = nAntiSeawardNewDirection;
1332 nSearchDirection = nGoBackNewDirection;
1343 int nCoastSize = ILTempGridCRS.
nGetSize();
1361 LogStream <<
", ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
1376 LogStream <<
", it ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
1384 if (nCoastSize == 0)
1403 int const nEndX = nX;
1404 int const nEndY = nY;
1405 int const nCoastEndX = ILTempGridCRS[nCoastSize - 1].nGetX();
1406 int const nCoastEndY = ILTempGridCRS[nCoastSize - 1].nGetY();
1408 if ((nCoastEndX != nEndX) || (nCoastEndY != nEndY))
1411 if (!
m_pRasterGrid->m_Cell[nCoastEndX][nCoastEndY].bIsBoundingBoxEdge())
1420 int const nStartEdge =
m_pRasterGrid->m_Cell[nStartX][nStartY].nGetBoundingBoxEdge();
1421 int const nEndEdge =
m_pRasterGrid->m_Cell[nEndX][nEndY].nGetBoundingBoxEdge();
1426 for (
int j = 0; j < nCoastSize; j++)
1447 int const nCoast =
static_cast<int>(
m_VCoast.size()) - 1;
1450 for (
int n = 0; n < nCoastSize; n++)
1451 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsCoastline(nCoast);
1454 m_VCoast[nCoast].SetCoastlineExtCRS(<empExtCRS);
1457 m_VCoast[nCoast].SetCoastlineGridCRS(&ILTempGridCRS);
1475 m_VCoast[nCoast].SetSeaHandedness(nHandedness);
1476 m_VCoast[nCoast].SetStartEdge(nStartEdge);
1477 m_VCoast[nCoast].SetEndEdge(nEndEdge);
1483 LogStream <<
m_ulIter <<
": \tsmoothed coastline " << nCoast <<
" runs from {" << LTempExtCRS[0].dGetX() <<
", " << LTempExtCRS[0].dGetY() <<
"} to {" << LTempExtCRS[nCoastSize - 1].dGetX() <<
", " << LTempExtCRS[nCoastSize - 1].dGetY() <<
"} i.e. from the ";
1485 if (nStartEdge ==
NORTH)
1487 else if (nStartEdge ==
SOUTH)
1489 else if (nStartEdge ==
WEST)
1491 else if (nStartEdge ==
EAST)
1495 if (nEndEdge ==
NORTH)
1497 else if (nEndEdge ==
SOUTH)
1499 else if (nEndEdge ==
WEST)
1501 else if (nEndEdge ==
EAST)
1518 m_VCoast[nCoast].CreateProfilesAtCoastPoints();
1582 for (
unsigned int n = 0; n <
m_VEdgeCell.size(); n++)
Contains CGeom2DIPoint definitions.
int nGetSize(void) const
Returns the number of integer point in the vector which represents this 2D shape.
void AppendIfNotPrevious(int const, int const)
Appends a new integer point to the vector which represents this 2D shape, but only if the point is no...
void Append(CGeom2DIPoint const *)
Appends a new integer point to the vector which represents this 2D shape.
void Append(CGeom2DPoint const *)
Appends a point to this 2D shape.
Geometry class used to represent 2D point objects with integer coordinates.
int nGetY(void) const
Returns the CGeom2DIPoint object's integer Y coordinate.
int nGetX(void) const
Returns the CGeom2DIPoint object's integer X coordinate.
Geometry class used to represent 2D vector integer line objects.
Geometry class used to represent 2D vector line objects.
Real-world class used to represent coastline objects.
int m_nLogFileDetail
The level of detail in the log file output. Can be LOG_FILE_LOW_DETAIL, LOG_FILE_MIDDLE_DETAIL,...
int m_nYMinBoundingBox
The minimum y value of the bounding box.
void FindAllSeaCells(void)
Finds and flags all sea areas which have at least one cell at a grid edge (i.e. does not flag 'inland...
CGeomLine LSmoothCoastRunningMean(CGeomLine *) const
Does running-mean smoothing of a CGeomLine coastline vector (is in external CRS coordinates)
double m_dThisIterSWL
The still water level for this timestep (this includes tidal changes and any long-term SWL change)
CGeomRasterGrid * m_pRasterGrid
Pointer to the raster grid object.
int m_nXGridSize
The size of the grid in the x direction.
static int nGetOppositeDirection(int const)
Returns the opposite direction.
vector< CRWCoast > m_VFloodWaveSetupSurgeRunup
TODO 007 Finish surge and runup stuff.
vector< CRWCoast > m_VCoast
The coastline objects.
int nLocateFloodAndCoasts(void)
First find all connected sea areas, then locate the vector coastline(s), then put these onto the rast...
int nTraceCoastLine(unsigned int const, int const, int const, vector< bool > *, vector< CGeom2DIPoint > const *)
Traces a coastline (which is defined to be just above still water level) on the grid using the 'wall ...
int nTraceAllFloodCoasts(void)
Locates all the potential coastline start points on the edges of the raster grid, then traces vector ...
void FloodFillLand(int const, int const)
Use the sealevel, wave set-up and run-up to evaluate flood hydraulically connected TODO 007 Finish su...
int m_nYGridSize
The size of the grid in the y direction.
double m_dThisIterTopElevMin
This-iteration lowest elevation of DEM.
void CalcCoastTangents(int const)
Calculates tangents to a coastline: the tangent is assumed to be the orientation of energy/sediment f...
vector< CGeomLine > m_VLowestSWLCoastLine
Coastline (external CRS) at the lowest SWL so far during this simulation.
vector< CRWCoast > m_VFloodWaveSetupSurge
TODO 007 Finish surge and runup stuff.
int m_nCoastMax
Maximum valid coast length when searching for coasts.
int m_nXMaxBoundingBox
The maximum x value of the bounding box.
bool m_bLowestSWLSoFar
Do we have the lowest SWL so far?
vector< CGeomLine > m_VHighestSWLCoastLine
Coastline (external CRS) at the highest SWL so far during this simulation.
string m_strLogFile
Name of output log file.
bool m_bOmitSearchWestEdge
Omit the west edge of the grid from coast-end searches?
double dGridCentroidYToExtCRSY(int const) const
Given the integer Y-axis ordinate of a cell in the raster grid CRS, returns the external CRS Y-axis o...
int m_nCoastMin
Minimum valid coast length when searching for coasts.
bool m_bOmitSearchNorthEdge
Omit the north edge of the grid from coast-end searches?
vector< CGeom2DIPoint > m_VEdgeCell
Edge cells.
bool m_bHighestSWLSoFar
Do we have the highest SWL so far?
int m_nYMaxBoundingBox
The maximum y value of the bounding box.
unsigned long m_ulThisIterNumSeaCells
The number of grid cells which are marked as sea, for this iteration.
CGeomLine LSmoothCoastSavitzkyGolay(CGeomLine *, int const, int const) const
Does smoothing of a CGeomLine coastline vector (is in external CRS coordinates) using a Savitzky-Gola...
int nLocateSeaAndCoasts(void)
First find all connected sea areas, then locate the vector coastline(s), then put these onto the rast...
int m_nXMinBoundingBox
The minimum x value of the bounding box.
bool bIsWithinValidGrid(int const, int const) const
Checks whether the supplied point (an x-y pair, in the grid CRS) is within the raster grid,...
int m_nCoastSmooth
Which method to use for coast smoothing.
void DoCoastCurvature(int const, int const)
Calculates both detailed and smoothed curvature for every point on a coastline.
int nTraceAllCoasts(void)
Locates all the potential coastline start/finish points on the edges of the raster grid,...
bool m_bOmitSearchSouthEdge
Omit the south edge of the grid from coast-end searches?
unsigned long m_ulIter
The number of the current iteration (time step)
double dGridCentroidXToExtCRSX(int const) const
Given the integer X-axis ordinate of a cell in the raster grid CRS, returns the external CRS X-axis o...
void CellByCellFillSea(int const, int const)
Cell-by-cell fills all sea cells starting from a given cell. The cell-by-cell fill (aka 'floodfill') ...
bool bIsInterventionCell(int const, int const) const
Returns true if the cell is an intervention.
double m_dThisIterTopElevMax
This-iteration highest elevation of DEM.
int FindAllInundatedCells(void)
Finds and flags all sea areas which have at least one cell at a grid edge (i.e. does not flag 'inland...
int m_nLevel
TODO 007 Used in WAVESETUP + SURGE + RUNUP Finish surge and runup stuff.
bool m_bOmitSearchEastEdge
Omit the east edge of the grid from coast-end searches?
vector< int > m_VEdgeCellEdge
The grid edge that each edge cell belongs to.
This file contains global definitions for CoastalME.
int const RTN_ERR_NO_COAST
int const LF_SEDIMENT_INPUT_CONSOLIDATED
int const RTN_ERR_TOO_LONG_TRACING_COAST
int const LOG_FILE_MIDDLE_DETAIL
bool bFPIsEqual(const T d1, const T d2, const T dEpsilon)
int const LOG_FILE_HIGH_DETAIL
int const RTN_ERR_NO_START_FINISH_POINTS_TRACING_COAST
int const SMOOTH_SAVITZKY_GOLAY
int const LF_SEDIMENT_INPUT_UNCONSOLIDATED
int const SMOOTH_RUNNING_MEAN
int const RTN_ERR_COAST_TOO_SMALL
int const RTN_ERR_NO_VALID_COAST
int const RTN_ERR_ZERO_LENGTH_COAST
int const RTN_ERR_REPEATING_WHEN_TRACING_COAST
Contains CRWCoast definitions.
Contains CGeomILine definitions.
Contains CGeomLine definitions.
Contains CGeomRasterGrid definitions.
Contains CSimulation definitions.