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()))
696 int const TOOCLOSE = 1;
698 vector<bool> VbPossibleStartCellLHEdge;
699 vector<bool> VbTraced;
700 vector<int> VnSearchDirection;
701 vector<CGeom2DIPoint> V2DIPossibleStartCell;
704 for (
unsigned int n = 0; n <
m_VEdgeCell.size() - 1; n++)
724 bool const bThisCellIsSea =
m_pRasterGrid->m_Cell[nXThis][nYThis].bIsInContiguousSea();
725 bool const bNextCellIsSea =
m_pRasterGrid->m_Cell[nXNext][nYNext].bIsInContiguousSea();
728 if ((! bThisCellIsSea) && bNextCellIsSea)
731 if (
m_pRasterGrid->m_Cell[nXThis][nYThis].bIsPossibleCoastStartCell())
735 bool bTooClose =
false;
736 for (
int nn = 1; nn <= TOOCLOSE; nn++)
738 int const nTmp = n + nn;
745 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsPossibleCoastStartCell())
755 for (
int nn = 1; nn <= TOOCLOSE; nn++)
757 int const nTmp = n - nn;
764 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsPossibleCoastStartCell())
774 m_pRasterGrid->m_Cell[nXThis][nYThis].SetPossibleCoastStartCell();
780 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXThis, nYThis));
781 VbPossibleStartCellLHEdge.push_back(
true);
783 VbTraced.push_back(
false);
785 else if (bThisCellIsSea && (! bNextCellIsSea))
788 if (
m_pRasterGrid->m_Cell[nXNext][nYNext].bIsPossibleCoastStartCell())
792 bool bTooClose =
false;
793 for (
int nn = 1; nn <= TOOCLOSE; nn++)
795 int const nTmp = n + 1 + nn;
802 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsPossibleCoastStartCell())
812 for (
int nn = 1; nn <= TOOCLOSE; nn++)
814 int const nTmp = n + 1 - nn;
821 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsPossibleCoastStartCell())
831 m_pRasterGrid->m_Cell[nXNext][nYNext].SetPossibleCoastStartCell();
837 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXNext, nYNext));
838 VbPossibleStartCellLHEdge.push_back(
false);
840 VbTraced.push_back(
false);
845 if (V2DIPossibleStartCell.size() == 0)
847 LogStream <<
m_ulIter <<
": no coastline start/finish points found after grid edges searched.";
889 for (
int n =
static_cast<int>(V2DIPossibleStartCell.size())-1; n >= 0; n--)
895 if (VbPossibleStartCellLHEdge[n])
909 if (nValidCoast == 0)
912 for (
int n = 0; n < static_cast<int>(VbTraced.size()); n++)
915 for (
int n = 0; n < static_cast<int>(V2DIPossibleStartCell.size()); n++)
921 if (VbPossibleStartCellLHEdge[n])
936 if (nValidCoast == 0)
939 cerr <<
m_ulIter <<
": no valid coasts found, see " <<
m_strLogFile <<
" for more information" << endl;
949int CSimulation::nTraceCoastLine(
unsigned int const nTraceFromStartCellIndex,
int const nStartSearchDirection,
int const nHandedness, vector<bool>* pVbTraced, vector<CGeom2DIPoint>
const* pV2DIPossibleStartCell)
951 bool bHitStartCell =
false;
952 bool bAtCoast =
false;
953 bool bHasLeftStartEdge =
false;
954 bool bTooLong =
false;
955 bool bOffEdge =
false;
956 bool bRepeating =
false;
958 int const nStartX = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetX();
959 int const nStartY = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetY();
962 int nSearchDirection = nStartSearchDirection;
973 ILTempGridCRS.
Append(&PtiStart);
1001 if ((nRoundLoop > 10) && (ILTempGridCRS.
nGetSize() < 2))
1012 if (! bHasLeftStartEdge)
1015 if (((nStartSearchDirection ==
SOUTH) && (nY > nStartY)) || ((nStartSearchDirection ==
NORTH) && (nY < nStartY)) || ((nStartSearchDirection ==
EAST) && (nX > nStartX)) || ((nStartSearchDirection ==
WEST) && (nX < nStartX)))
1016 bHasLeftStartEdge =
true;
1025 if (bHasLeftStartEdge && bAtCoast)
1027 for (
unsigned int nn = 0; nn < pVbTraced->size(); nn++)
1029 bool const bTraced = pVbTraced->at(nn);
1030 if ((nn != nTraceFromStartCellIndex) && (! bTraced))
1032 int const nXPoss = pV2DIPossibleStartCell->at(nn).nGetX();
1033 int const nYPoss = pV2DIPossibleStartCell->at(nn).nGetY();
1037 if ((nX == nXPoss) && (nY == nYPoss))
1042 pVbTraced->at(nn) =
true;
1043 bHitStartCell =
true;
1056 int nSeawardNewDirection = 0;
1057 int nXStraightOn = 0;
1058 int nYStraightOn = 0;
1059 int nXAntiSeaward = 0;
1060 int nYAntiSeaward = 0;
1061 int nAntiSeawardNewDirection = 0;
1064 int nGoBackNewDirection = 0;
1069 switch (nHandedness)
1073 switch (nSearchDirection)
1079 nSeawardNewDirection =
EAST;
1083 nYStraightOn = nY - 1;
1086 nXAntiSeaward = nX - 1;
1088 nAntiSeawardNewDirection =
WEST;
1093 nGoBackNewDirection =
SOUTH;
1101 nSeawardNewDirection =
SOUTH;
1104 nXStraightOn = nX + 1;
1109 nYAntiSeaward = nY - 1;
1110 nAntiSeawardNewDirection =
NORTH;
1115 nGoBackNewDirection =
WEST;
1123 nSeawardNewDirection =
WEST;
1127 nYStraightOn = nY + 1;
1130 nXAntiSeaward = nX + 1;
1132 nAntiSeawardNewDirection =
EAST;
1137 nGoBackNewDirection =
NORTH;
1145 nSeawardNewDirection =
NORTH;
1148 nXStraightOn = nX - 1;
1153 nYAntiSeaward = nY + 1;
1154 nAntiSeawardNewDirection =
SOUTH;
1159 nGoBackNewDirection =
EAST;
1169 switch (nSearchDirection)
1175 nSeawardNewDirection =
WEST;
1179 nYStraightOn = nY - 1;
1182 nXAntiSeaward = nX + 1;
1184 nAntiSeawardNewDirection =
EAST;
1189 nGoBackNewDirection =
SOUTH;
1197 nSeawardNewDirection =
NORTH;
1200 nXStraightOn = nX + 1;
1205 nYAntiSeaward = nY + 1;
1206 nAntiSeawardNewDirection =
SOUTH;
1211 nGoBackNewDirection =
WEST;
1219 nSeawardNewDirection =
EAST;
1223 nYStraightOn = nY + 1;
1226 nXAntiSeaward = nX - 1;
1228 nAntiSeawardNewDirection =
WEST;
1233 nGoBackNewDirection =
NORTH;
1241 nSeawardNewDirection =
SOUTH;
1244 nXStraightOn = nX - 1;
1249 nYAntiSeaward = nY - 1;
1250 nAntiSeawardNewDirection =
NORTH;
1255 nGoBackNewDirection =
EAST;
1267 if (
m_pRasterGrid->m_Cell[nXSeaward][nYSeaward].bIsInContiguousSea())
1295 nSearchDirection = nSeawardNewDirection;
1304 if (
m_pRasterGrid->m_Cell[nXStraightOn][nYStraightOn].bIsInContiguousSea())
1340 if (
m_pRasterGrid->m_Cell[nXAntiSeaward][nYAntiSeaward].bIsInContiguousSea())
1368 nSearchDirection = nAntiSeawardNewDirection;
1380 nSearchDirection = nGoBackNewDirection;
1391 int nCoastSize = ILTempGridCRS.
nGetSize();
1409 LogStream <<
", ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
1424 LogStream <<
", it ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
1432 if (nCoastSize == 0)
1451 int const nEndX = nX;
1452 int const nEndY = nY;
1453 int const nCoastEndX = ILTempGridCRS[nCoastSize - 1].nGetX();
1454 int const nCoastEndY = ILTempGridCRS[nCoastSize - 1].nGetY();
1456 if ((nCoastEndX != nEndX) || (nCoastEndY != nEndY))
1459 if (!
m_pRasterGrid->m_Cell[nCoastEndX][nCoastEndY].bIsBoundingBoxEdge())
1468 int const nStartEdge =
m_pRasterGrid->m_Cell[nStartX][nStartY].nGetBoundingBoxEdge();
1469 int const nEndEdge =
m_pRasterGrid->m_Cell[nEndX][nEndY].nGetBoundingBoxEdge();
1474 for (
int j = 0; j < nCoastSize; j++)
1495 int const nCoast =
static_cast<int>(
m_VCoast.size()) - 1;
1498 for (
int n = 0; n < nCoastSize; n++)
1499 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsCoastline(nCoast);
1502 m_VCoast[nCoast].SetCoastlineExtCRS(<empExtCRS);
1505 m_VCoast[nCoast].SetCoastlineGridCRS(&ILTempGridCRS);
1523 m_VCoast[nCoast].SetSeaHandedness(nHandedness);
1524 m_VCoast[nCoast].SetStartEdge(nStartEdge);
1525 m_VCoast[nCoast].SetEndEdge(nEndEdge);
1531 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 ";
1533 if (nStartEdge ==
NORTH)
1535 else if (nStartEdge ==
SOUTH)
1537 else if (nStartEdge ==
WEST)
1539 else if (nStartEdge ==
EAST)
1543 if (nEndEdge ==
NORTH)
1545 else if (nEndEdge ==
SOUTH)
1547 else if (nEndEdge ==
WEST)
1549 else if (nEndEdge ==
EAST)
1566 m_VCoast[nCoast].CreateProfilesAtCoastPoints();
1630 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.