36using std::setiosflags;
37using std::setprecision;
48using std::normal_distribution;
60 return prLeft.second > prRight.second;
71 int nProfileGlobalID = -1;
73 for (
unsigned int nCoast = 0; nCoast <
m_VCoast.size(); nCoast++)
76 int nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
79 vector<bool> bVCoastPointDone(nCoastSize,
false);
82 vector<pair<int, double>> prVCurvature;
83 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
89 dCurvature =
m_VCoast[nCoast].dGetSmoothCurvature(nCoastPoint);
94 dCurvature =
m_VCoast[nCoast].dGetDetailedCurvature(nCoastPoint);
96 prVCurvature.push_back(make_pair(nCoastPoint, dCurvature));
114 bVCoastPointDone[n] =
true;
116 int m = nCoastSize - n - 1;
118 bVCoastPointDone[m] =
true;
129 strErr +=
". Check the SWL";
149 m_VCoast[nCoast].InsertProfilesInProfileCoastPointIndex();
187 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
189 if (
m_VCoast[nCoast].bIsProfileAtCoastPoint(nCoastPoint))
191 pThisProfile =
m_VCoast[nCoast].pGetProfileAtCoastPoint(nCoastPoint);
194 if (nCoastPoint == 0)
200 pLastProfile = pThisProfile;
209 if (nCoastPoint == nCoastSize-1)
214 pLastProfile = pThisProfile;
220 m_VCoast[nCoast].CreateProfileDownCoastIndex();
273void CSimulation::LocateAndCreateProfiles(
int const nCoast,
int& nProfile,
int& nProfileGlobalID,
int const nProfileHalfAvgSpacing, vector<bool>* pbVCoastPointDone, vector<pair<int, double>>
const* prVCurvature)
275 int nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
278 for (
int n = nCoastSize - 1; n >= 0; n--)
281 int nStillToSearch = 0;
282 for (
int m = 0; m < nCoastSize; m++)
283 if (! pbVCoastPointDone->at(m))
286 if (nStillToSearch == 0)
291 int nNormalPoint = prVCurvature->at(n).first;
294 if ((nNormalPoint == 0) || (nNormalPoint == nCoastSize - 1))
299 if (! pbVCoastPointDone->at(nNormalPoint))
302 bool bIntervention =
false;
306 bIntervention =
true;
312 int nRet =
nCreateProfile(nCoast, nCoastSize, nNormalPoint, nProfile, nProfileGlobalID, bIntervention, &PtiThis);
330 pbVCoastPointDone->at(nNormalPoint) =
true;
387 double dNumToMark = nProfileHalfAvgSpacing;
389 dNumToMark = nProfileHalfAvgSpacing / 4;
401 dNumToMark =
tMax(dNumToMark, nProfileHalfAvgSpacing / 4.0);
409 for (
int m = 1; m < dNumToMark; m++)
411 int nTmpPoint = nNormalPoint + m;
412 if (nTmpPoint < nCoastSize)
413 pbVCoastPointDone->at(nTmpPoint) =
true;
415 nTmpPoint = nNormalPoint - m;
417 pbVCoastPointDone->at(nTmpPoint) =
true;
442 int nXEnd = PtiEnd.
nGetX();
443 int nYEnd = PtiEnd.
nGetY();
446 if (!
m_pRasterGrid->m_Cell[nXEnd][nYEnd].bIsInContiguousSea())
464 CGeomProfile* pProfile =
new CGeomProfile(nCoast, nProfileStartPoint, nProfile, ++pnProfileGlobalID, pPtiStart, &PtiEnd, bIntervention);
467 vector<CGeom2DPoint> VNormal;
468 VNormal.push_back(PtStart);
469 VNormal.push_back(PtEnd);
479 m_VCoast[nCoast].AppendProfile(pProfile);
496 LogStream <<
m_ulIter <<
": coast " << nCoast <<
" profile " << nProfile <<
" (nCoastID = " << pProfile->
nGetCoastID() <<
" nGlobalID = " << pProfile->
nGetGlobalID() <<
") created at coast point (" << nProfileStartPoint <<
") from [" << pPtiStart->
nGetX() <<
"][" << pPtiStart->
nGetY() <<
"] = {" << PtStart.
dGetX() <<
", " << PtStart.
dGetY() <<
"} to [" << PtiEnd.
nGetX() <<
"][" << PtiEnd.
nGetY() <<
"] = {" << PtEnd.
dGetX() <<
", " << PtEnd.
dGetY() <<
"}" << (pProfile->
bIsIntervention() ?
", from intervention" :
"") << endl;
506 int nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
507 int nHandedness =
m_VCoast[nCoast].nGetSeaHandedness();
509 int nProfileStartEdge;
512 vector<CGeom2DIPoint> VPtiNormalPoints;
517 PtiProfileStart = *
m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(0);
518 nProfileStartEdge =
m_VCoast[nCoast].nGetStartEdge();
523 PtiProfileStart = *
m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastSize - 1);
524 nProfileStartEdge =
m_VCoast[nCoast].nGetEndEdge();
527 VPtiNormalPoints.push_back(PtiProfileStart);
541 int nPos =
static_cast<int>(it -
m_VEdgeCell.begin());
544 for (
int n = 0; n < nProfileLen; n++)
609 int nProfileStartPoint;
614 nProfileStartPoint = 0;
617 pProfile =
new CGeomProfile(nCoast, nProfileStartPoint, nProfile, ++nProfileGlobalID, &PtiProfileStart, &PtiDummy,
false);
624 nProfileStartPoint = nCoastSize-1;
627 pProfile =
new CGeomProfile(nCoast, nProfileStartPoint, nProfile, ++nProfileGlobalID, &PtiProfileStart, &PtiDummy,
false);
634 for (
unsigned int n = 0; n < VPtiNormalPoints.size(); n++)
636 int nX = VPtiNormalPoints[n].nGetX();
637 int nY = VPtiNormalPoints[n].nGetY();
650 if ((n == 0) || (n == VPtiNormalPoints.size()-1))
657 int nEndX = VPtiNormalPoints.back().nGetX();
658 int nEndY = VPtiNormalPoints.back().nGetY();
663 double dDeepWaterWaveHeight =
m_pRasterGrid->m_Cell[nEndX][nEndY].dGetCellDeepWaterWaveHeight();
664 double dDeepWaterWaveAngle =
m_pRasterGrid->m_Cell[nEndX][nEndY].dGetCellDeepWaterWaveAngle();
665 double dDeepWaterWavePeriod =
m_pRasterGrid->m_Cell[nEndX][nEndY].dGetCellDeepWaterWavePeriod();
677 m_VCoast[nCoast].AppendProfile(pProfile);
678 m_VCoast[nCoast].SetProfileAtCoastPoint(nProfileStartPoint, pProfile);
691 int const AVGSIZE = 21;
699 PtBefore = *
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nStartCoastPoint-1);
700 PtAfter = *
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nStartCoastPoint+1);
705 vector<CGeom2DPoint> PtBeforeToAverage;
706 for (
int n = 1; n <= AVGSIZE; n++)
708 int nPoint = nStartCoastPoint - n;
712 PtBeforeToAverage.push_back(*
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nPoint));
716 vector<CGeom2DPoint> PtAfterToAverage;
717 for (
int n = 1; n <= AVGSIZE; n++)
719 int nPoint = nStartCoastPoint + n;
720 if (nPoint > nCoastSize-1)
723 PtAfterToAverage.push_back(*
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nPoint));
727 PtBefore =
PtAverage(&PtBeforeToAverage);
732 double dYDiff = PtAfter.
dGetY() - PtBefore.
dGetY();
733 double dXDiff = PtAfter.
dGetX() - PtBefore.
dGetX();
735 double dXEnd1 = 0, dXEnd2 = 0, dYEnd1 = 0, dYEnd2 = 0;
740 dXEnd1 = dXEnd2 = pPtStart->
dGetX();
741 dYEnd1 = pPtStart->
dGetY() + dLineLength;
742 dYEnd2 = pPtStart->
dGetY() - dLineLength;
747 dYEnd1 = dYEnd2 = pPtStart->
dGetY();
748 dXEnd1 = pPtStart->
dGetX() + dLineLength;
749 dXEnd2 = pPtStart->
dGetX() - dLineLength;
754 double dA = dYDiff / dXDiff;
757 double dAPerp = -1 / dA;
758 double dBPerp = pPtStart->
dGetY() - (dAPerp * pPtStart->
dGetX());
761 double dQuadA = 1 + (dAPerp * dAPerp);
762 double dQuadB = 2 * ((dBPerp * dAPerp) - (dAPerp * pPtStart->
dGetY()) - pPtStart->
dGetX());
763 double dQuadC = ((pPtStart->
dGetX() * pPtStart->
dGetX()) + (pPtStart->
dGetY() * pPtStart->
dGetY()) + (dBPerp * dBPerp) - (2 * pPtStart->
dGetY() * dBPerp) - (dLineLength * dLineLength));
766 double dDiscriminant = (dQuadB * dQuadB) - (4 * dQuadA * dQuadC);
767 if (dDiscriminant < 0)
769 LogStream <<
ERR <<
"timestep " <<
m_ulIter <<
": discriminant < 0 when finding profile end point on coastline " << nCoast <<
", from coastline point " << nStartCoastPoint <<
"), ignored" << endl;
773 dXEnd1 = (-dQuadB + sqrt(dDiscriminant)) / (2 * dQuadA);
774 dYEnd1 = (dAPerp * dXEnd1) + dBPerp;
775 dXEnd2 = (-dQuadB - sqrt(dDiscriminant)) / (2 * dQuadA);
776 dYEnd2 = (dAPerp * dXEnd2) + dBPerp;
780 int nSeaHand =
m_VCoast[nCoast].nGetSeaHandedness();
781 *pPtEnd =
PtChooseEndPoint(nSeaHand, &PtBefore, &PtAfter, dXEnd1, dYEnd1, dXEnd2, dYEnd2);
818 PtChosen.
SetX(dXEnd1);
819 PtChosen.
SetY(dYEnd1);
823 PtChosen.
SetX(dXEnd2);
824 PtChosen.
SetY(dYEnd2);
827 else if (PtAfter->
dGetY() < PtBefore->
dGetY())
832 PtChosen.
SetX(dXEnd1);
833 PtChosen.
SetY(dYEnd1);
837 PtChosen.
SetX(dXEnd2);
838 PtChosen.
SetY(dYEnd2);
849 PtChosen.
SetX(dXEnd1);
850 PtChosen.
SetY(dYEnd1);
854 PtChosen.
SetX(dXEnd2);
855 PtChosen.
SetY(dYEnd2);
863 PtChosen.
SetX(dXEnd1);
864 PtChosen.
SetY(dYEnd1);
868 PtChosen.
SetX(dXEnd2);
869 PtChosen.
SetY(dYEnd2);
882 PtChosen.
SetX(dXEnd1);
883 PtChosen.
SetY(dYEnd1);
887 PtChosen.
SetX(dXEnd2);
888 PtChosen.
SetY(dYEnd2);
891 else if (PtAfter->
dGetY() < PtBefore->
dGetY())
896 PtChosen.
SetX(dXEnd1);
897 PtChosen.
SetY(dYEnd1);
901 PtChosen.
SetX(dXEnd2);
902 PtChosen.
SetY(dYEnd2);
913 PtChosen.
SetX(dXEnd1);
914 PtChosen.
SetY(dYEnd1);
918 PtChosen.
SetX(dXEnd2);
919 PtChosen.
SetY(dYEnd2);
927 PtChosen.
SetX(dXEnd1);
928 PtChosen.
SetY(dYEnd1);
932 PtChosen.
SetX(dXEnd2);
933 PtChosen.
SetY(dYEnd2);
950 int nCoastLines =
static_cast<int>(
m_VCoast.size());
951 for (
int nCoast = 0; nCoast < nCoastLines; nCoast++)
953 int nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
956 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
958 if (!
m_VCoast[nCoast].bIsProfileAtCoastPoint(nCoastPoint))
974 for (
int nDist = 1; nDist < nMaxDist; nDist++)
979 int nSecondCoastPoint;
981 nSecondCoastPoint = nCoastPoint + nDist;
983 nSecondCoastPoint = nCoastPoint - nDist;
985 if ((nSecondCoastPoint < 0) || (nSecondCoastPoint > nCoastSize-1))
989 if (
m_VCoast[nCoast].bIsProfileAtCoastPoint(nSecondCoastPoint))
993 int nSecondProfile = pSecondProfile->
nGetCoastID();
1011 int nProf1LineSeg = 0;
1012 int nProf2LineSeg = 0;
1013 double dIntersectX = 0;
1014 double dIntersectY = 0;
1015 double dAvgEndX = 0;
1016 double dAvgEndY = 0;
1018 if (
bCheckForIntersection(pFirstProfile, pSecondProfile, nProf1LineSeg, nProf2LineSeg, dIntersectX, dIntersectY, dAvgEndX, dAvgEndY))
1059 if ((nProf1LineSeg == (nFirstProfileLineSegments - 1)) && (nProf2LineSeg == (nSecondProfileLineSegments - 1)))
1062 MergeProfilesAtFinalLineSegments(nCoast, pFirstProfile, pSecondProfile, nFirstProfileLineSegments, nSecondProfileLineSegments, dIntersectX, dIntersectY, dAvgEndX, dAvgEndY);
1092 else if (nFirstProfileLineSegments > nSecondProfileLineSegments)
1096 else if (nFirstProfileLineSegments < nSecondProfileLineSegments)
1139 for (
unsigned int nCoast = 0; nCoast <
m_VCoast.size(); nCoast++)
1141 for (
int n = 0; n <
m_VCoast[nCoast].nGetNumProfiles(); n++)
1154 m_VCoast[nCoast].pGetProfile(nProfile)->SetTooShort(
true);
1155 LogStream <<
"Profile " << nProfile <<
" is too short, size = " << nSize << endl;
1161 int nXEnd = PtiEnd.
nGetX();
1162 int nYEnd = PtiEnd.
nGetY();
1169 m_VCoast[nCoast].pGetProfile(nProfile)->SetEndPoint(&PtiEnd);
1174 LogStream <<
m_ulIter <<
": coast " << nCoast <<
", profile " << nProfile <<
" is invalid, is too short for depth of closure " <<
m_dDepthOfClosure <<
" at end point [" << nXEnd <<
"][" << nYEnd <<
"] = {" << pPtEnd->
dGetX() <<
", " << pPtEnd->
dGetY() <<
"}, flagging as too short" << endl;
1177 m_VCoast[nCoast].pGetProfile(nProfile)->SetTooShort(
true);
1183 int nValidProfiles = 0;
1186 if (nValidProfiles == 0)
1189 cerr <<
m_ulIter <<
": " <<
ERR <<
"no coastline-normal profiles created" << endl;
1255 for (
int i = 0; i < nProfile1NumSegments; i++)
1257 for (
int j = 0; j < nProfile2NumSegments; j++)
1262 double dX2 = pVProfile1->
pPtVGetPoints()->at(i + 1).dGetX();
1263 double dY2 = pVProfile1->
pPtVGetPoints()->at(i + 1).dGetY();
1267 double dX4 = pVProfile2->
pPtVGetPoints()->at(j + 1).dGetX();
1268 double dY4 = pVProfile2->
pPtVGetPoints()->at(j + 1).dGetY();
1271 double dDiffX1 = dX2 - dX1;
1272 double dDiffY1 = dY2 - dY1;
1273 double dDiffX2 = dX4 - dX3;
1274 double dDiffY2 = dY4 - dY3;
1280 dTmp = -dDiffX2 * dDiffY1 + dDiffX1 * dDiffY2;
1282 dS = (-dDiffY1 * (dX1 - dX3) + dDiffX1 * (dY1 - dY3)) / dTmp;
1284 dTmp = -dDiffX2 * dDiffY1 + dDiffX1 * dDiffY2;
1286 dT = (dDiffX2 * (dY1 - dY3) - dDiffY2 * (dX1 - dX3)) / dTmp;
1288 if (dS >= 0 && dS <= 1 && dT >= 0 && dT <= 1)
1291 dXIntersect = dX1 + (dT * dDiffX1);
1292 dYIntersect = dY1 + (dT * dDiffY1);
1295 dXAvgEnd = (dX2 + dX4) / 2;
1296 dYAvgEnd = (dY2 + dY4) / 2;
1299 nProfile1LineSegment = i;
1300 nProfile2LineSegment = j;
1318 int nProfiles =
m_VCoast[nCoast].nGetNumProfiles();
1328 static bool bDownCoast =
true;
1331 for (
int n = 0; n < nProfiles; n++)
1336 pProfile =
m_VCoast[nCoast].pGetProfileWithDownCoastSeq(n);
1338 pProfile =
m_VCoast[nCoast].pGetProfileWithUpCoastSeq(n);
1357 m_VCoast[nCoast].pGetProfile(nProfile)->SetTooShort(
true);
1360 LogStream <<
m_ulIter <<
": coast " << nCoast <<
", profile " << nProfile <<
" is invalid, has only " << nPoints <<
" points" << endl;
1366 vector<CGeom2DIPoint> VCellsToMark;
1367 vector<bool> bVShared;
1368 bool bTooShort =
false;
1369 bool bTruncated =
false;
1370 bool bHitCoast =
false;
1371 bool bHitLand =
false;
1376 CreateRasterizedProfile(nCoast, pProfile, &PtiStart, &PtiEnd, &VCellsToMark, &bVShared, bTooShort, bTruncated, bHitCoast, bHitLand );
1384 for (
unsigned int k = 0; k < VCellsToMark.size(); k++)
1387 m_pRasterGrid->m_Cell[VCellsToMark[k].nGetX()][VCellsToMark[k].nGetY()].SetProfileID(nProfile);
1390 m_VCoast[nCoast].pGetProfile(nProfile)->AppendCellInProfile(VCellsToMark[k].nGetX(), VCellsToMark[k].nGetY());
1410 double dDeepWaterWaveHeight =
m_pRasterGrid->m_Cell[VCellsToMark.back().nGetX()][VCellsToMark.back().nGetY()].dGetCellDeepWaterWaveHeight();
1411 double dDeepWaterWaveAngle =
m_pRasterGrid->m_Cell[VCellsToMark.back().nGetX()][VCellsToMark.back().nGetY()].dGetCellDeepWaterWaveAngle();
1412 double dDeepWaterWavePeriod =
m_pRasterGrid->m_Cell[VCellsToMark.back().nGetX()][VCellsToMark.back().nGetY()].dGetCellDeepWaterWavePeriod();
1415 m_VCoast[nCoast].pGetProfile(nProfile)->SetProfileDeepWaterWaveHeight(dDeepWaterWaveHeight);
1416 m_VCoast[nCoast].pGetProfile(nProfile)->SetProfileDeepWaterWaveAngle(dDeepWaterWaveAngle);
1417 m_VCoast[nCoast].pGetProfile(nProfile)->SetProfileDeepWaterWavePeriod(dDeepWaterWavePeriod);
1420 bDownCoast = ! bDownCoast;
1432 pVIPointsOut->clear();
1435 vector<int> VnOtherProfileOK;
1444 for (nSeg = 0; nSeg < nNumSegments; nSeg++)
1447 vector<CGeom2DPoint> PtVSegment;
1452 bool bShared =
false;
1457 int nXStart = pPtiStart->
nGetX();
1458 int nYStart = pPtiStart->
nGetY();
1461 int nXEnd = pPtiEnd->
nGetX();
1462 int nYEnd = pPtiEnd->
nGetY();
1465 if ((nXStart == nXEnd) && (nYStart == nYEnd))
1469 if ((nXStart == nXStartLast) && (nYStart == nYStartLast) && (nXEnd == nXEndLast) && (nYEnd == nYEndLast))
1473 double dXInc = nXEnd - nXStart;
1474 double dYInc = nYEnd - nYStart;
1480 double dX = nXStart;
1481 double dY = nYStart;
1484 for (
int m = 0; m <=
nRound(dLength); m++)
1555 int nHitProfile =
m_pRasterGrid->m_Cell[nX][nY].nGetProfileID();
1558 if (find(VnOtherProfileOK.begin(), VnOtherProfileOK.end(), nHitProfile) == VnOtherProfileOK.end())
1562 VnOtherProfileOK.push_back(nHitProfile);
1613 int nHitProfile =
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetProfileID();
1616 if (find(VnOtherProfileOK.begin(), VnOtherProfileOK.end(), nHitProfile) == VnOtherProfileOK.end())
1620 VnOtherProfileOK.push_back(nHitProfile);
1667 pbVShared->push_back(bShared);
1674 nXStartLast = nXStart;
1675 nYStartLast = nYStart;
1685 if (nSeg < (nNumSegments - 1))
1690 int nLastX = pVIPointsOut->at(pVIPointsOut->size() - 1).nGetX();
1691 int nLastY = pVIPointsOut->at(pVIPointsOut->size() - 1).nGetY();
1705 if (pVIPointsOut->size() < 3)
1714 LogStream <<
m_ulIter <<
": profile " << nProfile <<
" is invalid, is too short, only " << pVIPointsOut->size() <<
" points, HitLand?" << bHitLand <<
". From [" << pVIPointsOut->at(0).nGetX() <<
"][" << pVIPointsOut->at(0).nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(pVIPointsOut->at(0).nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(pVIPointsOut->at(0).nGetY()) <<
"} to [" << pVIPointsOut->at(pVIPointsOut->size() - 1).nGetX() <<
"][" << pVIPointsOut->at(pVIPointsOut->size() - 1).nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(pVIPointsOut->at(pVIPointsOut->size() - 1).nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(pVIPointsOut->at(pVIPointsOut->size() - 1).nGetY()) <<
"}" << endl;
1725 int nCombinedLastSeg = 0;
1726 vector<pair<int, int>> prVCombinedProfilesCoincidentProfilesLastSeg;
1730 pair<int, int> prTmp;
1734 bool bFound =
false;
1735 for (
unsigned int m = 0; m < prVCombinedProfilesCoincidentProfilesLastSeg.size(); m++)
1737 if (prVCombinedProfilesCoincidentProfilesLastSeg[m].first == prTmp.first)
1746 prVCombinedProfilesCoincidentProfilesLastSeg.push_back(prTmp);
1753 pair<int, int> prTmp;
1757 bool bFound =
false;
1758 for (
unsigned int m = 0; m < prVCombinedProfilesCoincidentProfilesLastSeg.size(); m++)
1760 if (prVCombinedProfilesCoincidentProfilesLastSeg[m].first == prTmp.first)
1769 prVCombinedProfilesCoincidentProfilesLastSeg.push_back(prTmp);
1775 for (
int m = 0; m < nCombinedLastSeg; m++)
1776 prVCombinedProfilesCoincidentProfilesLastSeg[m].second++;
1780 int nNumFirstProfileCoincidentProfilesLastSeg =
static_cast<int>(prVFirstProfileCoincidentProfilesLastSeg.size());
1781 int nNumSecondProfileCoincidentProfilesLastSeg =
static_cast<int>(prVSecondProfileCoincidentProfilesLastSeg.size());
1786 for (
int n = 0; n < nNumFirstProfileCoincidentProfilesLastSeg; n++)
1788 int nThisProfile = prVFirstProfileCoincidentProfilesLastSeg[n].first;
1797 for (
int n = 0; n < nNumSecondProfileCoincidentProfilesLastSeg; n++)
1799 int nThisProfile = prVSecondProfileCoincidentProfilesLastSeg[n].first;
1808 for (
int nThisLineSeg = 0; nThisLineSeg < nNumFirstProfileCoincidentProfilesLastSeg; nThisLineSeg++)
1810 int nThisProfile = prVFirstProfileCoincidentProfilesLastSeg[nThisLineSeg].first;
1818 for (
int m = 0; m < nCombinedLastSeg; m++)
1823 for (
int nThisLineSeg = 0; nThisLineSeg < nNumSecondProfileCoincidentProfilesLastSeg; nThisLineSeg++)
1825 int nThisProfile = prVSecondProfileCoincidentProfilesLastSeg[nThisLineSeg].first;
1833 for (
int m = 0; m < nCombinedLastSeg; m++)
1868 int nRet =
nInsertPointIntoProfilesIfNeededThenUpdate(nCoast, pProfileToRetain, dIntersectX, dIntersectY, nProfileToRetainIntersectLineSeg, pProfileToTruncate, nProfileToTruncateIntersectLineSeg, bAlreadyPresent);
1871 LogStream <<
m_ulIter <<
": error in nInsertPointIntoProfilesIfNeededThenUpdate()" << endl;
1876 vector<CGeom2DPoint> PtVProfileLastPart;
1877 vector<vector<pair<int, int>>> prVLineSegLastPart;
1878 if (bAlreadyPresent)
1893 TruncateProfileAndAppendNew(nCoast, pProfileToTruncate, nProfileToTruncateIntersectLineSeg, &PtVProfileLastPart, &prVLineSegLastPart);
1969 int nProfileToRetain = pProfileToRetain->
nGetCoastID();
1973 int nNumCoincident =
static_cast<int>(prVCoincidentProfiles.size());
1974 vector<int> nLineSegAfterIntersect(nNumCoincident, -1);
1977 for (
int nn = 0; nn < nNumCoincident; nn++)
1979 int nThisProfile = prVCoincidentProfiles[nn].first;
1980 int nThisLineSeg = prVCoincidentProfiles[nn].second;
1984 if (! bAlreadyPresent)
1990 LogStream <<
WARN <<
m_ulIter <<
": cannot insert a line segment after the final line segment (" << nThisLineSeg <<
") for " << (nThisProfile == nProfileToRetain ?
"main" :
"co-incident") <<
" profile (" << nThisProfile <<
"), abandoning" << endl;
1999 nLineSegAfterIntersect[nn] = nThisLineSeg + 1;
2007 int nNumToTruncateCoincident =
static_cast<int>(prVToTruncateCoincidentProfiles.size());
2010 for (
int nn = 0; nn < nNumCoincident; nn++)
2012 int nThisProfile = prVCoincidentProfiles[nn].first;
2019 for (
int nLineSeg = nLineSegAfterIntersect[nn], nIncr = 0; nLineSeg < nNumLineSegs; nLineSeg++, nIncr++)
2030 for (
int m = 0; m < nNumToTruncateCoincident; m++)
2032 int nProfileToAdd = prVToTruncateCoincidentProfiles[m].first;
2033 int nProfileToAddLineSeg = prVToTruncateCoincidentProfiles[m].second;
2134 int nNumCoincident =
static_cast<int>(prVCoincidentProfiles.size());
2136 for (
int nn = 0; nn < nNumCoincident; nn++)
2139 int nThisProfile = prVCoincidentProfiles[nn].first;
2140 int nThisProfileLineSeg = prVCoincidentProfiles[nn].second;
2154 for (
unsigned int mm = 0; mm < pPtVProfileLastPart->size(); mm++)
2161 for (
unsigned int mm = 0; mm < pprVLineSegLastPart->size(); mm++)
2163 vector<pair<int, int>> prVTmp = pprVLineSegLastPart->at(mm);
2170 vector<int> nVProfsLineSeg;
2175 int nProf = pThisProfile->
nGetProf(nSeg, nCoinc);
2178 auto it = find(nVProf.begin(), nVProf.end(), nProf);
2179 if (it == nVProf.end())
2182 nVProf.push_back(nProf);
2183 nVProfsLineSeg.push_back(nProfsLineSeg);
2188 int nPos =
static_cast<int>(it - nVProf.begin());
2189 int nNewProfsLineSeg = nVProfsLineSeg[nPos];
2192 nVProfsLineSeg[nPos] = nNewProfsLineSeg;
vector< CGeom2DPoint > * pPtVGetPoints(void)
Returns the address of the vector which represents 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.
void SetXY(int const, int const)
The two integer parameters set values for the CGeom2DIPoint object's X and Y coordinates.
int nGetX(void) const
Returns the CGeom2DIPoint object's integer X coordinate.
Geometry class used to represent 2D point objects with floating-point coordinates.
void SetY(double const)
The double parameter sets a value for the CGeom2DIPoint object's Y coordinate.
double dGetY(void) const
Returns the CGeom2DPoint object's double Y coordinate.
double dGetX(void) const
Returns the CGeom2DPoint object's double X coordinate.
void SetX(double const)
The double parameter sets a value for the CGeom2DIPoint object's X coordinate.
int nGetProfsLineSeg(int const, int const) const
Returns the profile's own line segment, given a line segment and the index of the co-incident profile...
bool bFindProfileInCoincidentProfilesOfLastLineSegment(int const)
Returns true if the given profile number is amongst the coincident profiles of the CGeomMultiLine obj...
int nGetNumCoincidentProfilesInLineSegment(int const)
Returns the count of coincident profiles in a specified line segment.
void AppendLineSegment(void)
Appends a new empty line segment.
int nGetProf(int const, int const) const
Returns the profile number, given a line segment and the index of the co-incident profile for that li...
void TruncateLineSegments(int const)
Cuts short the number of line segments.
vector< vector< pair< int, int > > > prVVGetAllLineSegAfter(int const)
Returns a vector of the line segments which succeed the specified line segment number.
void AppendCoincidentProfileToLineSegments(pair< int, int > const)
Appends a coincident profile pair to the CGeomMultiLine object's final line segment.
void SetProfsLineSeg(int const, int const, int const)
Sets a profile's own line segment number, given a line segment and the index of the co-incident profi...
vector< pair< int, int > > * pprVGetPairedCoincidentProfilesForLineSegment(int const)
Returns a vector of pairs (a line segment)
void AddCoincidentProfileToExistingLineSegment(int const, int const, int const)
Adds a coincident profile to a pre-existing line segment of the CGeomMultiLine object.
int nGetNumLineSegments(void) const
Appends a line segment which then inherits from the preceding line segments.
Geometry class used to represent coast profile objects.
void TruncateProfile(int const)
Truncates the profile.
void SetEndOfCoast(bool const)
Sets a switch to indicate whether this is an end-of-coast profile.
void AppendPointInProfile(double const, double const)
Appends a point to the profile.
void SetProfileDeepWaterWavePeriod(double const)
Sets the deep-water wave Period for this profile.
bool bIsPointInProfile(double const, double const)
Removes a line segment from the profile.
void SetHitCoast(bool const)
Sets a switch which indicates whether this profile has hit a coast.
bool bProfileOKIncTruncated(void) const
Returns true if this is a problem-free profile, and is not a start-of-coast or an end-of-coast profil...
void SetStartOfCoast(bool const)
Sets a switch to indicate whether this is a start-of-coast profile.
void AppendCellInProfileExtCRS(double const, double const)
Appends a cell (specified in the external coordinate system) to the profile.
void SetUpCoastAdjacentProfile(CGeomProfile *)
vector< CGeom2DPoint > PtVGetThisPointAndAllAfter(int const)
Returns a given point from the profile, and all points after this.
void SetTruncated(bool const)
Sets a switch which indicates whether this profile is truncated.
bool bInsertIntersection(double const, double const, int const)
Inserts an intersection into the profile.
bool bProfileOK(void) const
Returns true if this is a problem-free profile, and is not a start-of-coast or an end-of-coast profil...
void SetProfileDeepWaterWaveHeight(double const)
Sets the deep-water wave height for this profile.
void SetDownCoastAdjacentProfile(CGeomProfile *)
bool bIsIntervention(void) const
Returns true if this is an intervention profile.
int nGetGlobalID(void) const
Returns the profile's global ID.
CGeom2DIPoint * pPtiGetEndPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile ends.
CGeom2DPoint * pPtGetPointInProfile(int const)
Returns a single point in the profile.
int nGetCoastID(void) const
Returns the profile's coast ID.
void AppendCellInProfile(CGeom2DIPoint const *)
Appends a cell to the profile.
void SetPointInProfile(int const, double const, double const)
Sets a single point in the profile.
int nGetProfileSize(void) const
Returns the number of points in the profile.
CGeom2DIPoint * pPtiGetStartPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile starts.
bool bStartOfCoast(void) const
Returns the switch to indicate whether this is a start-of-coast profile.
void SetEndPoint(CGeom2DIPoint const *)
Sets the the location of the cell (grid CRS) on which the profile ends.
void SetHitLand(bool const)
Sets a switch which indicates whether this profile has hit land.
void SetPointsInProfile(vector< CGeom2DPoint > const *)
Sets all points in the profile.
bool bEndOfCoast(void) const
Returns the switch to indicate whether this is an end-of-coast profile.
void SetProfileDeepWaterWaveAngle(double const)
Sets the deep-water wave orientation for this profile.
void SetTooShort(bool const)
Sets a switch which indicates whether this profile is too short to be useful.
int m_nLogFileDetail
The level of detail in the log file output. Can be LOG_FILE_LOW_DETAIL, LOG_FILE_MIDDLE_DETAIL,...
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.
CGeom2DIPoint PtiExtCRSToGridRound(CGeom2DPoint const *) const
Transforms a pointer to a CGeom2DPoint in the external CRS to the equivalent CGeom2DIPoint in the ras...
vector< CRWCoast > m_VCoast
The coastline objects.
double m_dCoastNormalLength
Length of the cost-normal profiles, in m.
default_random_engine m_Rand[NRNG]
The c++11 random number generators.
void MarkProfilesOnGrid(int const, int &)
For this coastline, marks all coastline-normal profiles (apart from the two 'special' ones at the sta...
static CGeom2DPoint PtChooseEndPoint(int const, CGeom2DPoint const *, CGeom2DPoint const *, double const, double const, double const, double const)
Choose which end point to use for the coastline-normal profile.
int m_nYGridSize
The size of the grid in the y direction.
static CGeom2DPoint PtAverage(CGeom2DPoint const *, CGeom2DPoint const *)
Returns a point (external CRS) which is the average of (i.e. is midway between) two other external CR...
int nLocateAndCreateGridEdgeProfile(bool const, int const, int &, int &)
Creates a 'special' profile at each end of a coastline, at the edge of the raster grid....
void MergeProfilesAtFinalLineSegments(int const, CGeomProfile *, CGeomProfile *, int const, int const, double const, double const, double const, double const)
Merges two profiles which intersect at their final (most seaward) line segments, seaward of their poi...
void CheckForIntersectingProfiles(void)
Checks all coastline-normal profiles for intersection, and modifies those that intersect.
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...
vector< CGeom2DIPoint > m_VEdgeCell
Edge cells.
static bool bCheckForIntersection(CGeomProfile *const, CGeomProfile *const, int &, int &, double &, double &, double &, double &)
Checks all line segments of a pair of coastline-normal profiles for intersection. If the lines inters...
normal_distribution< double > m_dUnitNormalDist
c++11 unit normal distribution (mean = 0, stdev = 1)
double m_dCoastNormalAvgSpacing
Average spacing of the cost-normal profiles, in m.
int nGetCoastNormalEndPoint(int const, int const, int const, CGeom2DPoint const *, double const, CGeom2DPoint *, CGeom2DIPoint *, bool const)
Finds the end point of a coastline-normal line, given the start point on the vector coastline....
void TruncateProfileAndAppendNew(int const, CGeomProfile *, int const, vector< CGeom2DPoint > const *, vector< vector< pair< int, int > > > const *)
Truncate a profile at the point of intersection, and do the same for all its co-incident profiles.
double dExtCRSXToGridX(double const) const
Transforms an X-axis ordinate in the external CRS to the equivalent X-axis ordinate in the raster gri...
int nInsertPointIntoProfilesIfNeededThenUpdate(int const, CGeomProfile *, double const, double const, int const, CGeomProfile *, int const, bool const)
Inserts an intersection point into the profile that is to be retained, if that point is not already p...
void KeepWithinValidGrid(int, int, int &, int &) const
Given two points in the grid CRS (the points assumed not to be coincident), this routine modifies the...
int nCreateAllProfiles(void)
Create coastline-normal profiles for all coastlines. The first profiles are created 'around' the most...
void TruncateOneProfileRetainOtherProfile(int const, CGeomProfile *, CGeomProfile *, double const, double const, int const, int const, bool const)
Truncates one intersecting profile at the point of intersection, and retains the other profile.
double dExtCRSYToGridY(double const) const
Transforms a Y-axis ordinate in the external CRS to the equivalent Y-axis ordinate in the raster grid...
double m_dCoastNormalRandSpacingFactor
Random factor for spacing of along-coast normals.
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 nCreateProfile(int const, int const, int const, int const, int &, bool const, CGeom2DIPoint const *)
Creates a single coastline-normal profile (which may be an intervention profile)
void CreateRasterizedProfile(int const, CGeomProfile *, CGeom2DIPoint const *, CGeom2DIPoint const *, vector< CGeom2DIPoint > *, vector< bool > *, bool &, bool &, bool &, bool &)
Given a pointer to a coastline-normal profile, returns an output vector of cells which are 'under' ev...
static void AppendEnsureNoGap(vector< CGeom2DIPoint > *, CGeom2DIPoint const *)
Appends a CGeom2DIPoint to a vector<CGeom2DIPoint>, making sure that the new end point touches the pr...
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...
double m_dCellSide
Length of a cell side (in external CRS units)
int m_nCoastNormalAvgSpacing
Average spacing between cost normals, measured in cells.
double m_dDepthOfClosure
Depth of closure (in m) TODO 007 can be calculated using Hallermeier, R.J. (1978) or Birkemeier (1985...
int nCheckAllProfiles(void)
Check all coastline-normal profiles and modify the profiles if they intersect, then mark valid profil...
void LocateAndCreateProfiles(int const, int &, int &, int const, vector< bool > *, vector< pair< int, double > > const *)
For a single coastline, locate the start points for all coastline-normal profiles (except the grid-ed...
vector< int > m_VEdgeCellEdge
The grid edge that each edge cell belongs to.
This file contains global definitions for CoastalME.
int const RTN_ERR_COAST_CANT_FIND_EDGE_CELL
int const DIRECTION_DOWNCOAST
int const LOG_FILE_MIDDLE_DETAIL
bool bFPIsEqual(const T d1, const T d2, const T dEpsilon)
int const RTN_ERR_PROFILE_END_INSUFFICIENT_DEPTH
int const PROFILE_CHECK_DIST_FROM_COAST
int const RTN_ERR_NO_PROFILES_2
int const PROFILE_CHECK_ALONG_COAST_MULTIPLIER
int const RTN_ERR_PROFILE_ENDPOINT_IS_INLAND
bool const ACCEPT_SHORT_PROFILES
int const RTN_ERR_NO_PROFILES_1
int const RTN_ERR_CANNOT_INSERT_POINT
int const DIRECTION_UPCOAST
string strDblToStr(const T &t)
int const RTN_ERR_NO_SOLUTION_FOR_ENDPOINT
int const RTN_ERR_PROFILE_ENDPOINT_AT_GRID_EDGE
int const LF_CAT_INTERVENTION
Contains CRWCoast definitions.
bool bCurvaturePairCompareDescending(const pair< int, double > &prLeft, const pair< int, double > &prRight)
Function used to sort coastline curvature values when locating start points of normal profiles.
Contains CSimulation definitions.
int nRound(double const d)
Version of the above that returns an int.