38using std::stringstream;
57===============================================================================================================================*/
72===============================================================================================================================*/
82 double const dElevLeft =
m_pRasterGrid->m_Cell[nX - 1][nY].dGetSedimentTopElev();
83 double const dElevRight =
m_pRasterGrid->m_Cell[nX + 1][nY].dGetSedimentTopElev();
84 double const dElevUp =
m_pRasterGrid->m_Cell[nX][nY - 1].dGetSedimentTopElev();
85 double const dElevDown =
m_pRasterGrid->m_Cell[nX][nY + 1].dGetSedimentTopElev();
88 double const dSlopeX = (dElevRight - dElevLeft) / (2.0 *
m_dCellSide);
89 double const dSlopeY = (dElevDown - dElevUp) / (2.0 *
m_dCellSide);
90 double const dSlope = sqrt(dSlopeX * dSlopeX + dSlopeY * dSlopeY);
99===============================================================================================================================*/
106 double const dSlope =
m_pRasterGrid->m_Cell[nX][nY].dGetSlope();
116===============================================================================================================================*/
123 vector<vector<bool>> bVisited(
static_cast<unsigned int>(
m_nXGridSize), vector<bool>(
static_cast<unsigned int>(
m_nYGridSize),
false));
126 vector<pair<int, int>> VSmallIslandCells;
129 for (
unsigned int nX = 0; nX < static_cast<unsigned int>(
m_nXGridSize); nX++)
131 for (
unsigned int nY = 0; nY < static_cast<unsigned int>(
m_nYGridSize); nY++)
134 if ((! bVisited[nX][nY]) &&
m_pRasterGrid->m_Cell[nX][nY].bIsCliff())
137 vector<pair<int, int>> VCurrentCliffRegion;
140 vector<pair<int, int>> VStack;
141 VStack.push_back(make_pair(nX, nY));
144 while (! VStack.empty())
146 pair<int, int>
const currentCell = VStack.back();
149 size_t const nCurX =
static_cast<size_t>(currentCell.first);
150 size_t const nCurY =
static_cast<size_t>(currentCell.second);
154 nCurY >=
static_cast<unsigned int>(
m_nYGridSize) || bVisited[nCurX][nCurY] ||
161 bVisited[nCurX][nCurY] =
true;
162 VCurrentCliffRegion.push_back(make_pair(nCurX, nCurY));
165 VStack.push_back(make_pair(nCurX - 1, nCurY));
166 VStack.push_back(make_pair(nCurX - 1, nCurY + 1));
167 VStack.push_back(make_pair(nCurX, nCurY + 1));
168 VStack.push_back(make_pair(nCurX + 1, nCurY + 1));
169 VStack.push_back(make_pair(nCurX + 1, nCurY));
170 VStack.push_back(make_pair(nCurX + 1, nCurY - 1));
171 VStack.push_back(make_pair(nCurX, nCurY - 1));
172 VStack.push_back(make_pair(nCurX - 1, nCurY - 1));
176 int const dCliffRegionArea =
static_cast<int>(VCurrentCliffRegion.size());
179 if (dCliffRegionArea < dMinCliffCellThreshold)
181 VSmallIslandCells.insert(VSmallIslandCells.end(), VCurrentCliffRegion.begin(), VCurrentCliffRegion.end());
188 for (
const auto &cell : VSmallIslandCells)
190 m_pRasterGrid->m_Cell[cell.first][cell.second].SetAsCliff(
false);
196===============================================================================================================================*/
203 vector<CGeom2DIPoint> V2DIPossibleStartCell;
204 vector<bool> VbPossibleStartCellHandedness;
205 vector<int> VnSearchDirection;
218 VbPossibleStartCellHandedness.push_back(
true);
219 VnSearchDirection.push_back(
EAST);
226 VbPossibleStartCellHandedness.push_back(
true);
227 VnSearchDirection.push_back(
SOUTH);
234 VbPossibleStartCellHandedness.push_back(
true);
235 VnSearchDirection.push_back(
WEST);
242 VbPossibleStartCellHandedness.push_back(
true);
243 VnSearchDirection.push_back(
NORTH);
252 int nCliffEdgesTraced = 0;
255 for (
size_t nStartPoint = 0; nStartPoint < V2DIPossibleStartCell.size(); nStartPoint++)
257 int const nXStart = V2DIPossibleStartCell[nStartPoint].nGetX();
258 int const nYStart = V2DIPossibleStartCell[nStartPoint].nGetY();
261 if (bUsedInCliffTrace[nXStart][nYStart])
267 vector<CGeom2DIPoint> VCliffEdge;
268 int nSearchDirection = VnSearchDirection[nStartPoint];
279 bUsedInCliffTrace[nX][nY] =
true;
287 int nXAntiSeaward, nYAntiSeaward, nXGoBack, nYGoBack;
290 switch (nSearchDirection)
296 nYStraightOn = nY - 1;
297 nXAntiSeaward = nX - 1;
307 nXStraightOn = nX + 1;
310 nYAntiSeaward = nY - 1;
320 nYStraightOn = nY + 1;
321 nXAntiSeaward = nX + 1;
331 nXStraightOn = nX - 1;
334 nYAntiSeaward = nY + 1;
341 nXSeaward = nXStraightOn = nXAntiSeaward = nXGoBack = nX;
342 nYSeaward = nYStraightOn = nYAntiSeaward = nYGoBack = nY;
348 bool bFoundNextCell =
false;
357 switch (nSearchDirection)
360 nSearchDirection =
EAST;
364 nSearchDirection =
SOUTH;
368 nSearchDirection =
WEST;
372 nSearchDirection =
NORTH;
376 bFoundNextCell =
true;
386 bFoundNextCell =
true;
396 switch (nSearchDirection)
399 nSearchDirection =
WEST;
403 nSearchDirection =
NORTH;
407 nSearchDirection =
EAST;
411 nSearchDirection =
SOUTH;
415 bFoundNextCell =
true;
426 bFoundNextCell =
true;
429 if (! bFoundNextCell)
434 }
while ((nX != nXStart || nY != nYStart) && nLength < nMaxLength);
437 if (VCliffEdge.size() > 2)
443 for (
const auto &point : VCliffEdge)
446 bUsedInCliffTrace[point.nGetX()][point.nGetY()] =
true;
464===============================================================================================================================*/
467 vector<CGeomLine> ValidatedCliffEdges;
470 for (
size_t nEdge = 0; nEdge <
m_VCliffEdge.size(); nEdge++)
488 BestValidated = ReverseValidated;
492 BestValidated = ForwardValidated;
498 ValidatedCliffEdges.push_back(BestValidated);
509===============================================================================================================================*/
514 int nConsecutiveFailures = 0;
515 int const nMaxConsecutiveFailures = 2;
516 int const nSize = CliffEdge.
nGetSize();
519 for (
int i = 0; i < nSize - 1; i++)
522 int const nPoint = bReverse ? (nSize - 1 - i) : i;
523 int const nNextPoint = bReverse ? (nSize - 2 - i) : (i + 1);
526 if (nNextPoint < 0 || nNextPoint >= nSize)
543 int const nDirX = nNextX - nX;
544 int const nDirY = nNextY - nY;
547 int const nLeftX = nX - nDirY;
548 int const nLeftY = nY + nDirX;
549 int const nRightX = nX + nDirY;
550 int const nRightY = nY - nDirX;
552 bool bIsValidToe =
true;
557 bool const bLeftIsCliff =
m_pRasterGrid->m_Cell[nLeftX][nLeftY].bIsCliff();
558 bool const bRightIsCliff =
m_pRasterGrid->m_Cell[nRightX][nRightY].bIsCliff();
561 if (bLeftIsCliff != bRightIsCliff)
564 double const dLeftElev =
m_pRasterGrid->m_Cell[nLeftX][nLeftY].dGetSedimentTopElev();
565 double const dRightElev =
m_pRasterGrid->m_Cell[nRightX][nRightY].dGetSedimentTopElev();
569 double dNonCliffElev;
572 dCliffElev = dLeftElev;
573 dNonCliffElev = dRightElev;
577 dCliffElev = dRightElev;
578 dNonCliffElev = dLeftElev;
582 if (dNonCliffElev > dCliffElev)
592 nConsecutiveFailures = 0;
600 nConsecutiveFailures++;
603 if (nConsecutiveFailures < nMaxConsecutiveFailures)
615 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)
vector< CGeomLine > m_VCliffEdge
The traced cliff edge lines (in external CRS)
void nTraceSeawardCliffEdge(void)
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...
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
double dGridCentroidXToExtCRSX(int const) const
double m_dCliffSlopeLimit
Slope limit for cliff toe detection.
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.