44 int const nCoastSize =
static_cast<int>(
m_VCoast.size());
47 LogStream << endl <<
m_ulIter <<
": " << nCoastSize <<
" coastlines found, checking coast-coast intersections" << endl;
50 vector<int> VnCoastID(nCoastSize);
51 for (
int nn = 0; nn < nCoastSize; nn++)
53 shuffle(VnCoastID.begin(), VnCoastID.end(),
m_Rand[1]);
56 for (
int nn = 0; nn < nCoastSize; nn++)
59 int const nCoast = VnCoastID[nn];
62 vector<int> VnProfileID(
m_VCoast[nCoast].nGetNumProfiles());
63 for (
int m = 0; m <
m_VCoast[nCoast].nGetNumProfiles(); m++)
65 shuffle(VnProfileID.begin(), VnProfileID.end(),
m_Rand[1]);
68 for (
int n = 0; n <
m_VCoast[nCoast].nGetNumProfiles(); n++)
78 int const nX = pCell->
nGetX();
79 int const nY = pCell->
nGetY();
85 int const nHitCoast =
m_pRasterGrid->m_Cell[nX][nY].nGetCoastline();
86 if (nHitCoast != nCoast)
104 int const nHitCoast =
m_pRasterGrid->m_Cell[nX][nYTmp].nGetCoastline();
105 if (nHitCoast != nCoast)
119 int nHitProfileCoast =
m_pRasterGrid->m_Cell[nX][nY].nGetProfileCoastID();
120 if ((nHitProfileCoast !=
INT_NODATA) && (nHitProfileCoast != nCoast))
123 int const nHitProfile =
m_pRasterGrid->m_Cell[nX][nY].nGetProfileID();
141 nHitProfileCoast =
m_pRasterGrid->m_Cell[nX][nYTmp].nGetProfileCoastID();
142 if ((nHitProfileCoast !=
INT_NODATA) && (nHitProfileCoast != nCoast))
145 int const nHitProfile =
m_pRasterGrid->m_Cell[nX][nYTmp].nGetProfileID();
197 double const dXThisProfileStart = pPtiThisProfileStart->
nGetX();
198 double const dYThisProfileStart = pPtiThisProfileStart->
nGetY();
199 double const dXHitProfileStart = pPtiHitProfileStart->
nGetX();
200 double const dYHitProfileStart = pPtiHitProfileStart->
nGetY();
205 FindClosestPointOnStraightLine(dXThisProfileStart, dYThisProfileStart, dXHitProfileStart, dYHitProfileStart, nXIntersect, nYIntersect, dClosestX, dClosestY);
210 double const dTotDist = dThisDist + dHitDist;
213 double const dThisPropToRetain = dThisDist / dTotDist;
214 double const dHitPropToRetain = dHitDist / dTotDist;
225 int const nXThisProfileEndPoint = pVThisProfileCells->at(nThisProfileEndpointIndex).nGetX();
226 int const nYThisProfileEndPoint = pVThisProfileCells->at(nThisProfileEndpointIndex).nGetY();
227 int const nXHitProfileEndPoint = pVHitProfileCells->at(nHitProfileEndpointIndex).nGetX();
228 int const nYHitProfileEndPoint = pVHitProfileCells->at(nHitProfileEndpointIndex).nGetY();
239 for (
int nn = nThisProfileEndpointIndex+1; nn < nThisProfileLen; nn++)
241 int const nXTmp = pVThisProfileCells->at(nn).nGetX();
242 int const nYTmp = pVThisProfileCells->at(nn).nGetY();
244 if ((
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetProfileID() == nThisProfile) && (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetProfileCoastID() == nThisProfileCoast))
251 for (
int nn = nHitProfileEndpointIndex+1; nn < nHitProfileLen; nn++)
253 int const nXTmp = pVHitProfileCells->at(nn).nGetX();
254 int const nYTmp = pVHitProfileCells->at(nn).nGetY();
256 if ((
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetProfileID() == nHitProfile) && (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetProfileCoastID() == nHitProfileCoast))
273 pVThisProfileCells->resize(nThisProfileEndpointIndex);
277 pVHitProfileCells->resize(nHitProfileEndpointIndex);
291 strTmp +=
" grid-edge ";
300 LogStream <<
m_ulIter <<
": coast " << nThisProfileCoast << strTmp <<
" profile " << nThisProfile <<
" hit by coast " << nHitProfileCoast <<
" profile " << nHitProfile <<
" at [" << nXIntersect <<
"][" << nYIntersect <<
"] = {" <<
dGridCentroidXToExtCRSX(nXIntersect) <<
", " <<
dGridCentroidYToExtCRSY(nYIntersect) <<
"}. Profile truncated, new endpoint is [" << nXThisProfileEndPoint <<
"][" << nYThisProfileEndPoint <<
"] = {" <<
dGridCentroidXToExtCRSX(nXThisProfileEndPoint) <<
", " <<
dGridCentroidYToExtCRSY(nYThisProfileEndPoint) <<
"}. Length was " << nThisProfileLen <<
" cells, length is now " << nThisProfileEndpointIndex <<
" cells (" << 100 * nThisProfileEndpointIndex / nThisProfileLen <<
"%)" << endl;
304 strTmp =
" grid-edge ";
313 LogStream <<
m_ulIter <<
": coast " << nHitProfileCoast << strTmp <<
" profile " << nHitProfile <<
" hit by coast " << nThisProfileCoast <<
" profile " << nThisProfile <<
" at [" << nXIntersect <<
"][" << nYIntersect <<
"] = {" <<
dGridCentroidXToExtCRSX(nXIntersect) <<
", " <<
dGridCentroidYToExtCRSY(nYIntersect) <<
"}. Profile truncated, new endpoint is [" << nXHitProfileEndPoint <<
"][" << nYHitProfileEndPoint <<
"] = {" <<
dGridCentroidXToExtCRSX(nXHitProfileEndPoint) <<
", " <<
dGridCentroidYToExtCRSY(nYHitProfileEndPoint) <<
"}. Length was " << nHitProfileLen <<
" cells, length is now " << nHitProfileEndpointIndex <<
" cells (" << 100 * nHitProfileEndpointIndex / nHitProfileLen <<
"%)" << endl;
338 int const nProfileLen =
static_cast<int>(pVProfileCells->size());
341 for (
int nn = nNewLenProfile-1; nn < nProfileLen; nn++)
343 int const nXThis = pVProfileCells->at(nn).nGetX();
344 int const nYThis = pVProfileCells->at(nn).nGetY();
346 if ((
m_pRasterGrid->m_Cell[nXThis][nYThis].nGetProfileID() == nProfile) && (
m_pRasterGrid->m_Cell[nXThis][nYThis].nGetProfileCoastID() == nCoast))
351 pVProfileCells->resize(nNewLenProfile);
371 strTmp +=
" grid-edge ";
380 LogStream <<
m_ulIter <<
": coast " << nCoast << strTmp <<
" profile " << nProfile <<
" hit another coast at [" << nXHitCoast <<
"][" << nYHitCoast <<
"] = {" <<
dGridCentroidXToExtCRSX(nXHitCoast) <<
", " <<
dGridCentroidYToExtCRSY(nYHitCoast) <<
"}. Profile truncated, length of profile " << nProfile <<
" was " << nProfileLen <<
" cells, is now " << nNewLenProfile <<
" cells (" << 100 * nNewLenProfile / nProfileLen <<
"%)" << endl;
408 int const nProfileLineSegments = pProfile->CGeomMultiLine::nGetNumLineSegments();
409 for (
int nSeg = 0; nSeg < nProfileLineSegments; nSeg++)
412 int const nNumCoinc = pProfile->CGeomMultiLine::nGetNumCoincidentProfilesInLineSegment(nSeg);
413 for (
int nCoinc = 0; nCoinc < nNumCoinc; nCoinc++)
415 vector<CGeom2DPoint>& pVPt = pProfile->CGeomMultiLine::pGetPoints();
417 for (
int nLin = 0; nLin < static_cast<int>(pVPt.size())-1; nLin++)
419 double const dX1 = pVPt[nLin].dGetX();
420 double const dY1 = pVPt[nLin].dGetY();
421 double const dX2 = pVPt[nLin+1].dGetX();
422 double const dY2 = pVPt[nLin+1].dGetY();
424 double const dXMin =
tMin(dX1, dX2);
425 double const dXMax =
tMax(dX1, dX2);
426 double const dYMin =
tMin(dY1, dY2);
427 double const dYMax =
tMax(dY1, dY2);
431 if ((dX >= dXMin) && (dX <= dXMax) && (dY >= dYMin) && (dY <= dYMax))
Contains CGeom2DPoint definitions.
Contains CGeom2DIPoint definitions.
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 coast profile objects.
void TruncateProfile(int const)
Truncates the profile's CGeomLine (external CRS points)
void AppendPointInProfile(double const, double const)
Appends a point (external CRS) to the profile.
void SetCellsInProfile(vector< CGeom2DIPoint > const *)
Sets the profile's vector of cells (grid CRS)
int nGetProfileID(void) const
Returns the profile's this-coast ID.
CGeom2DIPoint * pPtiGetCellInProfile(int const)
Returns a single cell (grid CRS) in the profile.
bool bIsGridEdge(void) const
Returns true if this is a start-of-coast or an end-of-coast profile.
int nGetNumCellsInProfile(void) const
Returns the number of cells in the profile.
bool bStartOfCoast(void) const
Returns the switch to indicate whether this is a start-of-coast profile.
CGeom2DIPoint * pPtiGetFirstCellInProfile(void)
Returns the first cell (grid CRS) in the profile.
vector< CGeom2DIPoint > * pPtiVGetCellsInProfile(void)
Returns all cells (grid CRS) in the profile.
void SetTruncatedDifferentCoast(bool const)
Sets a switch which indicates whether this profile is truncated, due to hitting another profile from ...
bool bEndOfCoast(void) const
Returns the switch to indicate whether this is an end-of-coast profile.
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,...
CGeomRasterGrid * m_pRasterGrid
Pointer to the raster grid object.
vector< CRWCoast > m_VCoast
The coastline objects.
int nDoMultipleCoastlines(void)
Checks all profiles on all coasts for intersections between profiles belonging to different coasts.
void FindClosestPointOnStraightLine(double const, double const, double const, double const, double const, double const, double &, double &)
For the straight line between two points A and B, and given another point C, this finds the closest p...
int m_nYGridSize
The size of the grid in the y direction.
static double dGetDistanceBetween(CGeom2DPoint const *, CGeom2DPoint const *)
Returns the distance (in external CRS) between two points.
int nTruncateProfileMultiLineDifferentCoasts(CGeomProfile *, double const, double const)
Truncates the CGeomMultiLine (external CRS) of a profile which has hit a different coast,...
int nTruncateProfilesDifferentCoasts(int const, int const, int const, int const, int const, int const)
Truncates two intersecting coast-normal profile belonging to different coasts.
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...
default_random_engine m_Rand[NUMBER_OF_RNGS]
The c++11 random number generators.
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...
int nTruncateProfileHitDifferentCoast(int const, int const, int const, int const)
Truncates a profile which has hit a different coast.
This file contains global definitions for CoastalME.
int const RTN_ERR_POINT_NOT_FOUND_IN_MULTILINE_DIFFERENT_COASTS
int const GAP_BETWEEN_DIFFERENT_COAST_PROFILES
int const LOG_FILE_MIDDLE_DETAIL
int const MIN_PROFILE_SIZE
Contains CRWCoast definitions.
Contains CGeomMultiLine definitions.
Contains CSimulation definitions.
int nRound(double const d)
Correctly rounds doubles, returns an int.