34using std::stringstream;
53===============================================================================================================================*/
67===============================================================================================================================*/
77 double const dElevLeft =
m_pRasterGrid->m_Cell[nX - 1][nY].dGetAllSedTopElevOmitTalus();
78 double const dElevRight =
m_pRasterGrid->m_Cell[nX + 1][nY].dGetAllSedTopElevOmitTalus();
79 double const dElevUp =
m_pRasterGrid->m_Cell[nX][nY - 1].dGetAllSedTopElevOmitTalus();
80 double const dElevDown =
m_pRasterGrid->m_Cell[nX][nY + 1].dGetAllSedTopElevOmitTalus();
83 double const dSlopeX = (dElevRight - dElevLeft) / (2.0 *
m_dCellSide);
84 double const dSlopeY = (dElevDown - dElevUp) / (2.0 *
m_dCellSide);
85 double const dSlope = sqrt(dSlopeX * dSlopeX + dSlopeY * dSlopeY);
94===============================================================================================================================*/
101 double const dSlope =
m_pRasterGrid->m_Cell[nX][nY].dGetSlopeForCliffToe();
111===============================================================================================================================*/
115 vector<vector<bool>> bVisited(
static_cast<unsigned int>(
m_nXGridSize), vector<bool>(
static_cast<unsigned int>(
m_nYGridSize),
false));
118 vector<pair<int, int>> VSmallIslandCells;
121 for (
unsigned int nX = 0; nX < static_cast<unsigned int>(
m_nXGridSize); nX++)
123 for (
unsigned int nY = 0; nY < static_cast<unsigned int>(
m_nYGridSize); nY++)
126 if ((! bVisited[nX][nY]) &&
m_pRasterGrid->m_Cell[nX][nY].bIsCliffToe())
129 vector<pair<int, int>> VCurrentCliffRegion;
132 vector<pair<int, int>> VStack;
133 VStack.push_back(make_pair(nX, nY));
136 while (! VStack.empty())
138 pair<int, int>
const currentCell = VStack.back();
141 size_t const nCurX =
static_cast<size_t>(currentCell.first);
142 size_t const nCurY =
static_cast<size_t>(currentCell.second);
146 nCurY >=
static_cast<unsigned int>(
m_nYGridSize) || bVisited[nCurX][nCurY] ||
153 bVisited[nCurX][nCurY] =
true;
154 VCurrentCliffRegion.push_back(make_pair(nCurX, nCurY));
157 VStack.push_back(make_pair(nCurX - 1, nCurY));
158 VStack.push_back(make_pair(nCurX - 1, nCurY + 1));
159 VStack.push_back(make_pair(nCurX, nCurY + 1));
160 VStack.push_back(make_pair(nCurX + 1, nCurY + 1));
161 VStack.push_back(make_pair(nCurX + 1, nCurY));
162 VStack.push_back(make_pair(nCurX + 1, nCurY - 1));
163 VStack.push_back(make_pair(nCurX, nCurY - 1));
164 VStack.push_back(make_pair(nCurX - 1, nCurY - 1));
168 int const dCliffRegionArea =
static_cast<int>(VCurrentCliffRegion.size());
171 if (dCliffRegionArea < dMinCliffCellThreshold)
173 VSmallIslandCells.insert(VSmallIslandCells.end(), VCurrentCliffRegion.begin(), VCurrentCliffRegion.end());
180 for (
const auto &cell : VSmallIslandCells)
182 m_pRasterGrid->m_Cell[cell.first][cell.second].SetAsCliffToe(
false);
188===============================================================================================================================*/
195 vector<CGeom2DIPoint> V2DIPossibleStartCell;
196 vector<bool> VbPossibleStartCellHandedness;
197 vector<int> VnSearchDirection;
210 VbPossibleStartCellHandedness.push_back(
true);
211 VnSearchDirection.push_back(
EAST);
218 VbPossibleStartCellHandedness.push_back(
true);
219 VnSearchDirection.push_back(
SOUTH);
226 VbPossibleStartCellHandedness.push_back(
true);
227 VnSearchDirection.push_back(
WEST);
234 VbPossibleStartCellHandedness.push_back(
true);
235 VnSearchDirection.push_back(
NORTH);
244 int nCliffEdgesTraced = 0;
247 for (
size_t nStartPoint = 0; nStartPoint < V2DIPossibleStartCell.size(); nStartPoint++)
249 int const nXStart = V2DIPossibleStartCell[nStartPoint].nGetX();
250 int const nYStart = V2DIPossibleStartCell[nStartPoint].nGetY();
253 if (bUsedInCliffTrace[nXStart][nYStart])
259 vector<CGeom2DIPoint> VCliffEdge;
260 int nSearchDirection = VnSearchDirection[nStartPoint];
271 bUsedInCliffTrace[nX][nY] =
true;
279 int nXAntiSeaward, nYAntiSeaward, nXGoBack, nYGoBack;
282 switch (nSearchDirection)
288 nYStraightOn = nY - 1;
289 nXAntiSeaward = nX - 1;
299 nXStraightOn = nX + 1;
302 nYAntiSeaward = nY - 1;
312 nYStraightOn = nY + 1;
313 nXAntiSeaward = nX + 1;
323 nXStraightOn = nX - 1;
326 nYAntiSeaward = nY + 1;
333 nXSeaward = nXStraightOn = nXAntiSeaward = nXGoBack = nX;
334 nYSeaward = nYStraightOn = nYAntiSeaward = nYGoBack = nY;
340 bool bFoundNextCell =
false;
349 switch (nSearchDirection)
352 nSearchDirection =
EAST;
356 nSearchDirection =
SOUTH;
360 nSearchDirection =
WEST;
364 nSearchDirection =
NORTH;
368 bFoundNextCell =
true;
378 bFoundNextCell =
true;
388 switch (nSearchDirection)
391 nSearchDirection =
WEST;
395 nSearchDirection =
NORTH;
399 nSearchDirection =
EAST;
403 nSearchDirection =
SOUTH;
407 bFoundNextCell =
true;
418 bFoundNextCell =
true;
421 if (! bFoundNextCell)
426 }
while ((nX != nXStart || nY != nYStart) && nLength < nMaxLength);
429 if (VCliffEdge.size() > 2)
435 for (
const auto &point : VCliffEdge)
438 bUsedInCliffTrace[point.nGetX()][point.nGetY()] =
true;
456===============================================================================================================================*/
459 vector<CGeomLine> ValidatedCliffEdges;
462 for (
size_t nEdge = 0; nEdge <
m_VCliffToe.size(); nEdge++)
480 BestValidated = ReverseValidated;
484 BestValidated = ForwardValidated;
490 ValidatedCliffEdges.push_back(BestValidated);
501===============================================================================================================================*/
506 int nConsecutiveFailures = 0;
507 int const nMaxConsecutiveFailures = 2;
508 int const nSize = CliffEdge.
nGetSize();
511 for (
int i = 0; i < nSize - 1; i++)
514 int const nPoint = bReverse ? (nSize - 1 - i) : i;
515 int const nNextPoint = bReverse ? (nSize - 2 - i) : (i + 1);
518 if (nNextPoint < 0 || nNextPoint >= nSize)
535 int const nDirX = nNextX - nX;
536 int const nDirY = nNextY - nY;
539 int const nLeftX = nX - nDirY;
540 int const nLeftY = nY + nDirX;
541 int const nRightX = nX + nDirY;
542 int const nRightY = nY - nDirX;
544 bool bIsValidToe =
true;
549 bool const bLeftIsCliff =
m_pRasterGrid->m_Cell[nLeftX][nLeftY].bIsCliffToe();
550 bool const bRightIsCliff =
m_pRasterGrid->m_Cell[nRightX][nRightY].bIsCliffToe();
553 if (bLeftIsCliff != bRightIsCliff)
556 double const dLeftElev =
m_pRasterGrid->m_Cell[nLeftX][nLeftY].dGetAllSedTopElevOmitTalus();
557 double const dRightElev =
m_pRasterGrid->m_Cell[nRightX][nRightY].dGetAllSedTopElevOmitTalus();
561 double dNonCliffElev;
564 dCliffElev = dLeftElev;
565 dNonCliffElev = dRightElev;
569 dCliffElev = dRightElev;
570 dNonCliffElev = dLeftElev;
574 if (dNonCliffElev > dCliffElev)
584 nConsecutiveFailures = 0;
592 nConsecutiveFailures++;
595 if (nConsecutiveFailures < nMaxConsecutiveFailures)
607 return ValidatedEdge;
Contains CGeom2DIPoint definitions.
Contains CGeomCell definitions.
void Append(CGeom2DPoint const *)
Appends a point to this 2D shape.
Geometry class used to represent 2D point objects with integer coordinates.
Geometry class used to represent 2D vector line objects.
double dGetYAt(int const)
Returns the Y value at a given place in the line.
double dGetXAt(int const)
Returns the X value at a given place in the line.
CGeomLine LSmoothCoastRunningMean(CGeomLine *) const
Does running-mean smoothing of a CGeomLine coastline vector (is in external CRS coordinates)
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.
void nCalcSlopeAtAllCells(void)
int m_nYGridSize
The size of the grid in the y direction.
int nLocateCliffToe(void)
double m_dGeoTransform[6]
GDAL geotransformation info (see http://www.gdal.org/classGDALDataset.html)
void nTraceSeawardCliffEdge(void)
vector< CGeomLine > m_VCliffToe
The traced cliff toe lines (in external CRS)
int m_nCliffEdgeSmooth
Which method to use for cliff edge smoothing.
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...
double m_dSlopeThresholdForCliffToe
Slope limit for cliff toe detection.
void nLocateCliffCell(void)
CGeomLine nValidateCliffToeDirection(CGeomLine &CliffEdge, bool bReverse)
void nRemoveSmallCliffIslands(int const)
CGeomLine LSmoothCoastSavitzkyGolay(CGeomLine *, int const, int const) const
Does smoothing of a CGeomLine coastline vector (is in external CRS coordinates) using a Savitzky-Gola...
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,...
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...
double m_dCellSide
Length of a cell side (in external CRS units)
void nValidateCliffToeEdges(void)
This file contains global definitions for CoastalME.
int const SMOOTH_SAVITZKY_GOLAY
int const SMOOTH_RUNNING_MEAN
Contains CGeomLine definitions.
Contains CGeomRasterGrid definitions.
Contains CSimulation definitions.