39using std::normal_distribution;
52bool bCurvaturePairCompareDescending(
const pair<int, double>& prLeft,
const pair<int, double>& prRight)
55 return prLeft.second > prRight.second;
67 for (
unsigned int nCoast = 0; nCoast <
m_VCoast.size(); nCoast++)
70 int const nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
73 vector<bool> bVCoastPointDone(nCoastSize,
false);
76 vector<pair<int, double>> prVCurvature;
78 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
82 int const nCat =
m_VCoast[nCoast].pGetCoastLandform(nCoastPoint)->nGetLandFormCategory();
86 dCurvature =
m_VCoast[nCoast].dGetSmoothCurvature(nCoastPoint);
91 dCurvature =
m_VCoast[nCoast].dGetDetailedCurvature(nCoastPoint);
94 prVCurvature.push_back(make_pair(nCoastPoint, dCurvature));
98 sort(prVCurvature.begin(), prVCurvature.end(), bCurvaturePairCompareDescending);
112 bVCoastPointDone[n] =
true;
114 int const m = nCoastSize - n - 1;
117 bVCoastPointDone[m] =
true;
129 strErr +=
". Check the SWL";
152 m_VCoast[nCoast].InsertProfilesInProfileCoastPointIndex();
171 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
173 if (
m_VCoast[nCoast].bIsProfileAtCoastPoint(nCoastPoint))
175 pThisProfile =
m_VCoast[nCoast].pGetProfileAtCoastPoint(nCoastPoint);
178 if (nCoastPoint == 0)
184 pLastProfile = pThisProfile;
192 if (nCoastPoint == nCoastSize - 1)
195 pLastProfile = pThisProfile;
200 m_VCoast[nCoast].CreateProfileDownCoastIndex();
267 int const nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
270 for (
int n = nCoastSize - 1; n >= 0;
274 int nStillToSearch = 0;
276 for (
int m = 0; m < nCoastSize; m++)
277 if (! pbVCoastPointDone->at(m))
280 if (nStillToSearch == 0)
285 int const nNormalPoint = prVCurvature->at(n).first;
288 if ((nNormalPoint == 0) || (nNormalPoint == nCoastSize - 1))
293 if (! pbVCoastPointDone->at(nNormalPoint))
296 bool bIntervention =
false;
298 int const nCat =
m_VCoast[nCoast].pGetCoastLandform(nNormalPoint)->nGetLandFormCategory();
302 bIntervention =
true;
308 int const nRet =
nCreateProfile(nCoast, nCoastSize, nNormalPoint, nProfile, bIntervention, &PtiThis);
326 pbVCoastPointDone->at(nNormalPoint) =
true;
416 for (
int m = 1; m < dNumToMark; m++)
418 int nTmpPoint = nNormalPoint + m;
420 if (nTmpPoint < nCoastSize)
421 pbVCoastPointDone->at(nTmpPoint) =
true;
423 nTmpPoint = nNormalPoint - m;
426 pbVCoastPointDone->at(nTmpPoint) =
true;
451 int const nXEnd = PtiEnd.
nGetX();
452 int const nYEnd = PtiEnd.
nGetY();
455 if (!
m_pRasterGrid->m_Cell[nXEnd][nYEnd].bIsInContiguousSea())
476 vector<CGeom2DPoint> VNormal;
477 VNormal.push_back(PtStart);
478 VNormal.push_back(PtEnd);
488 m_VCoast[nCoast].AppendProfile(pProfile);
507 LogStream <<
m_ulIter <<
": \tcoast " << nCoast <<
" profile " << nProfile <<
" 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;
517 int const nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
518 int const nHandedness =
m_VCoast[nCoast].nGetSeaHandedness();
520 int nProfileStartEdge;
523 vector<CGeom2DIPoint> VPtiNormalPoints;
528 PtiProfileStart = *
m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(0);
529 nProfileStartEdge =
m_VCoast[nCoast].nGetStartEdge();
534 PtiProfileStart = *
m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastSize - 1);
535 nProfileStartEdge =
m_VCoast[nCoast].nGetEndEdge();
538 VPtiNormalPoints.push_back(PtiProfileStart);
553 int nPos =
static_cast<int>(it -
m_VEdgeCell.begin());
556 for (
int n = 0; n < nProfileLen; n++)
621 int nProfileStartPoint;
627 nProfileStartPoint = 0;
630 pProfile =
new CGeomProfile(nCoast, nProfileStartPoint, nProfile,
false);
637 nProfileStartPoint = nCoastSize - 1;
640 pProfile =
new CGeomProfile(nCoast, nProfileStartPoint, nProfile,
false);
647 for (
unsigned int n = 0; n < VPtiNormalPoints.size(); n++)
649 int const nX = VPtiNormalPoints[n].nGetX();
650 int const nY = VPtiNormalPoints[n].nGetY();
653 m_pRasterGrid->m_Cell[nX][nY].SetCoastAndProfileID(nCoast, nProfile);
664 int const nEndX = VPtiNormalPoints.back().nGetX();
665 int const nEndY = VPtiNormalPoints.back().nGetY();
668 double const dDeepWaterWaveHeight =
m_pRasterGrid->m_Cell[nEndX][nEndY].dGetCellDeepWaterWaveHeight();
669 double const dDeepWaterWaveAngle =
m_pRasterGrid->m_Cell[nEndX][nEndY].dGetCellDeepWaterWaveAngle();
670 double const dDeepWaterWavePeriod =
m_pRasterGrid->m_Cell[nEndX][nEndY].dGetCellDeepWaterWavePeriod();
682 m_VCoast[nCoast].AppendProfile(pProfile);
683 m_VCoast[nCoast].SetProfileAtCoastPoint(nProfileStartPoint, pProfile);
698 int const AVGSIZE = 21;
711 PtBefore = *
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nStartCoastPoint - 1);
712 PtAfter = *
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nStartCoastPoint + 1);
717 double const dXStart = pPtStart->
dGetX();
718 double const dYStart = pPtStart->
dGetY();
746 vector<CGeom2DPoint> VPtBeforeToAverage;
748 for (
int n = 1; n <= AVGSIZE; n++)
750 int const nPoint = nStartCoastPoint - n;
754 VPtBeforeToAverage.push_back(*
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nPoint));
758 vector<CGeom2DPoint> VPtAfterToAverage;
760 for (
int n = 1; n <= AVGSIZE; n++)
762 int const nPoint = nStartCoastPoint + n;
763 if (nPoint > nCoastSize - 1)
766 VPtAfterToAverage.push_back(*
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nPoint));
770 PtBefore =
PtAverage(&VPtBeforeToAverage);
774 double const dYDiff = PtAfter.
dGetY() - PtBefore.
dGetY();
775 double const dXDiff = PtAfter.
dGetX() - PtBefore.
dGetX();
780 dXEnd1 = dXEnd2 = pPtStart->
dGetX();
781 dYEnd1 = pPtStart->
dGetY() + dLineLength;
782 dYEnd2 = pPtStart->
dGetY() - dLineLength;
787 dYEnd1 = dYEnd2 = pPtStart->
dGetY();
788 dXEnd1 = pPtStart->
dGetX() + dLineLength;
789 dXEnd2 = pPtStart->
dGetX() - dLineLength;
794 double const dA = dYDiff / dXDiff;
797 double const dAPerp = -1 / dA;
798 double const dBPerp = pPtStart->
dGetY() - (dAPerp * pPtStart->
dGetX());
801 double const dQuadA = 1 + (dAPerp * dAPerp);
802 double const dQuadB = 2 * ((dBPerp * dAPerp) - (dAPerp * pPtStart->
dGetY()) - pPtStart->
dGetX());
803 double const dQuadC = ((pPtStart->
dGetX() * pPtStart->
dGetX()) + (pPtStart->
dGetY() * pPtStart->
dGetY()) + (dBPerp * dBPerp) - (2 * pPtStart->
dGetY() * dBPerp) - (dLineLength * dLineLength));
806 double const dDiscriminant = (dQuadB * dQuadB) - (4 * dQuadA * dQuadC);
808 if (dDiscriminant < 0)
810 LogStream <<
ERR <<
"timestep " <<
m_ulIter <<
": discriminant < 0 when finding profile end point on coastline " << nCoast <<
", from coastline point " << nStartCoastPoint <<
"), ignored" << endl;
814 dXEnd1 = (-dQuadB + sqrt(dDiscriminant)) / (2 * dQuadA);
815 dYEnd1 = (dAPerp * dXEnd1) + dBPerp;
816 dXEnd2 = (-dQuadB - sqrt(dDiscriminant)) / (2 * dQuadA);
817 dYEnd2 = (dAPerp * dXEnd2) + dBPerp;
823 int const nSeaHand =
m_VCoast[nCoast].nGetSeaHandedness();
824 *pPtEnd =
PtChooseEndPoint(nSeaHand, &PtBefore, &PtAfter, dXEnd1, dYEnd1, dXEnd2, dYEnd2);
862 PtChosen.
SetX(dXEnd1);
863 PtChosen.
SetY(dYEnd1);
867 PtChosen.
SetX(dXEnd2);
868 PtChosen.
SetY(dYEnd2);
871 else if (PtAfter->
dGetY() < PtBefore->
dGetY())
876 PtChosen.
SetX(dXEnd1);
877 PtChosen.
SetY(dYEnd1);
881 PtChosen.
SetX(dXEnd2);
882 PtChosen.
SetY(dYEnd2);
893 PtChosen.
SetX(dXEnd1);
894 PtChosen.
SetY(dYEnd1);
898 PtChosen.
SetX(dXEnd2);
899 PtChosen.
SetY(dYEnd2);
907 PtChosen.
SetX(dXEnd1);
908 PtChosen.
SetY(dYEnd1);
912 PtChosen.
SetX(dXEnd2);
913 PtChosen.
SetY(dYEnd2);
926 PtChosen.
SetX(dXEnd1);
927 PtChosen.
SetY(dYEnd1);
931 PtChosen.
SetX(dXEnd2);
932 PtChosen.
SetY(dYEnd2);
935 else if (PtAfter->
dGetY() < PtBefore->
dGetY())
940 PtChosen.
SetX(dXEnd1);
941 PtChosen.
SetY(dYEnd1);
945 PtChosen.
SetX(dXEnd2);
946 PtChosen.
SetY(dYEnd2);
957 PtChosen.
SetX(dXEnd1);
958 PtChosen.
SetY(dYEnd1);
962 PtChosen.
SetX(dXEnd2);
963 PtChosen.
SetY(dYEnd2);
971 PtChosen.
SetX(dXEnd1);
972 PtChosen.
SetY(dYEnd1);
976 PtChosen.
SetX(dXEnd2);
977 PtChosen.
SetY(dYEnd2);
994 int const nCoastLines =
static_cast<int>(
m_VCoast.size());
996 for (
int nCoast = 0; nCoast < nCoastLines; nCoast++)
998 int const nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
1001 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
1003 if (!
m_VCoast[nCoast].bIsProfileAtCoastPoint(nCoastPoint))
1023 nStartPoint = nCoastPoint + 1;
1025 nStartPoint = nCoastPoint - 1;
1027 for (
int nSecondCoastPoint = nStartPoint; (nDirection ==
DIRECTION_DOWNCOAST) ? nSecondCoastPoint < nCoastSize : nSecondCoastPoint >= 0; (nDirection ==
DIRECTION_DOWNCOAST) ? nSecondCoastPoint++ : nSecondCoastPoint--)
1037 if (
m_VCoast[nCoast].bIsProfileAtCoastPoint(nSecondCoastPoint))
1060 int nProf1LineSeg = 0;
1061 int nProf2LineSeg = 0;
1062 double dIntersectX = 0;
1063 double dIntersectY = 0;
1064 double dAvgEndX = 0;
1065 double dAvgEndY = 0;
1067 if (
bCheckForIntersection(pFirstProfile, pSecondProfile, nProf1LineSeg, nProf2LineSeg, dIntersectX, dIntersectY, dAvgEndX, dAvgEndY))
1074 LogStream <<
m_ulIter <<
": profiles " << nFirstProfile <<
" and " << nSecondProfile <<
" intersect, truncate " << nFirstProfile <<
" since it is an intervention profile" << endl;
1081 LogStream <<
m_ulIter <<
": profiles " << nFirstProfile <<
" and " << nSecondProfile <<
" intersect, truncate " << nSecondProfile <<
" since it is an intervention profile" << endl;
1089 LogStream <<
m_ulIter <<
": \t coast " << nCoast <<
" profiles " << nFirstProfile <<
" and " << nSecondProfile <<
" intersect, but point {" << dIntersectX <<
", " << dIntersectY <<
"} is already present in profile " << nFirstProfile <<
" as point " << nPoint << endl;
1097 LogStream <<
m_ulIter <<
": \tcoast " << nCoast <<
" profiles " << nFirstProfile <<
" and " << nSecondProfile <<
" intersect, but point {" << dIntersectX <<
", " << dIntersectY <<
"} is already present in profile " << nSecondProfile <<
" as point " << nPoint << endl;
1112 if ((nProf1LineSeg == (nFirstProfileLineSegments - 1)) && (nProf2LineSeg == (nSecondProfileLineSegments - 1)))
1115 MergeProfilesAtFinalLineSegments(nCoast, pFirstProfile, pSecondProfile, nFirstProfileLineSegments, nSecondProfileLineSegments, dIntersectX, dIntersectY, dAvgEndX, dAvgEndY);
1151 else if (nFirstProfileLineSegments < nSecondProfileLineSegments)
1158 else if (nFirstProfileLineSegments > nSecondProfileLineSegments)
1202 for (
unsigned int nCoast = 0; nCoast <
m_VCoast.size(); nCoast++)
1204 for (
int n = 0; n <
m_VCoast[nCoast].nGetNumProfiles(); n++)
1217 m_VCoast[nCoast].pGetProfile(nProfile)->SetTooShort(
true);
1218 LogStream <<
"Profile " << nProfile <<
" is too short, size = " << nSize << endl;
1224 int nXEnd = PtiEnd.
nGetX();
1225 int nYEnd = PtiEnd.
nGetY();
1230 nXEnd =
tMax(nXEnd, 0);
1231 nYEnd =
tMax(nYEnd, 0);
1236 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;
1239 m_VCoast[nCoast].pGetProfile(nProfile)->SetTooShort(
true);
1245 int nValidProfiles = 0;
1248 if (nValidProfiles == 0)
1251 cerr <<
m_ulIter <<
": " <<
ERR <<
"no coastline-normal profiles created" << endl;
1317 for (
int i = 0; i < nProfile1NumSegments; i++)
1319 for (
int j = 0; j < nProfile2NumSegments; j++)
1322 double const dX1 = pVProfile1->
pPtVGetPoints()->at(i).dGetX();
1323 double const dY1 = pVProfile1->
pPtVGetPoints()->at(i).dGetY();
1324 double const dX2 = pVProfile1->
pPtVGetPoints()->at(i + 1).dGetX();
1325 double const dY2 = pVProfile1->
pPtVGetPoints()->at(i + 1).dGetY();
1327 double const dX3 = pVProfile2->
pPtVGetPoints()->at(j).dGetX();
1328 double const dY3 = pVProfile2->
pPtVGetPoints()->at(j).dGetY();
1329 double const dX4 = pVProfile2->
pPtVGetPoints()->at(j + 1).dGetX();
1330 double const dY4 = pVProfile2->
pPtVGetPoints()->at(j + 1).dGetY();
1333 double const dDiffX1 = dX2 - dX1;
1334 double const dDiffY1 = dY2 - dY1;
1335 double const dDiffX2 = dX4 - dX3;
1336 double const dDiffY2 = dY4 - dY3;
1342 dTmp = -dDiffX2 * dDiffY1 + dDiffX1 * dDiffY2;
1345 dS = (-dDiffY1 * (dX1 - dX3) + dDiffX1 * (dY1 - dY3)) / dTmp;
1347 dTmp = -dDiffX2 * dDiffY1 + dDiffX1 * dDiffY2;
1350 dT = (dDiffX2 * (dY1 - dY3) - dDiffY2 * (dX1 - dX3)) / dTmp;
1352 if (dS >= 0 && dS <= 1 && dT >= 0 && dT <= 1)
1355 dXIntersect = dX1 + (dT * dDiffX1);
1356 dYIntersect = dY1 + (dT * dDiffY1);
1359 dXAvgEnd = (dX2 + dX4) / 2;
1360 dYAvgEnd = (dY2 + dY4) / 2;
1363 nProfile1LineSegment = i;
1364 nProfile2LineSegment = j;
1382 int const nProfiles =
m_VCoast[nCoast].nGetNumProfiles();
1393 static bool bDownCoast =
true;
1396 for (
int n = 0; n < nProfiles; n++)
1401 pProfile =
m_VCoast[nCoast].pGetProfileWithDownCoastSeq(n);
1403 pProfile =
m_VCoast[nCoast].pGetProfileWithUpCoastSeq(n);
1423 m_VCoast[nCoast].pGetProfile(nProfile)->SetTooShort(
true);
1426 LogStream <<
m_ulIter <<
": coast " << nCoast <<
", profile " << nProfile <<
" is invalid, has only " << nPoints <<
" points" << endl;
1432 vector<CGeom2DIPoint> VCellsToMark;
1433 vector<bool> bVShared;
1434 bool bTooShort =
false;
1435 bool bTruncatedSameCoast =
false;
1436 bool bHitCoast =
false;
1437 bool bHitLand =
false;
1438 bool bHitIntervention =
false;
1439 bool bHitAnotherProfile =
false;
1441 CreateRasterizedProfile(nCoast, pProfile, &VCellsToMark, &bVShared, bTooShort, bTruncatedSameCoast, bHitCoast, bHitLand, bHitIntervention, bHitAnotherProfile);
1443 if ((bTruncatedSameCoast && (!
ACCEPT_TRUNCATED_PROFILES)) || bTooShort || bHitCoast || bHitLand || bHitIntervention || bHitAnotherProfile || VCellsToMark.size() == 0)
1449 for (
unsigned int k = 0; k < VCellsToMark.size(); k++)
1452 if ((k > 0) && (VCellsToMark[k] ==
m_VCoast[nCoast].pGetProfile(nProfile)->pPtiGetLastCellInProfile()))
1456 int const nXTmp = VCellsToMark[k].nGetX();
1457 int const nYTmp = VCellsToMark[k].nGetY();
1458 m_pRasterGrid->m_Cell[nXTmp][nYTmp].SetCoastAndProfileID(nCoast, nProfile);
1461 m_VCoast[nCoast].pGetProfile(nProfile)->AppendCellInProfile(nXTmp, nYTmp);
1477 double const dDeepWaterWaveHeight =
m_pRasterGrid->m_Cell[VCellsToMark.back().nGetX()][VCellsToMark.back().nGetY()].dGetCellDeepWaterWaveHeight();
1478 double const dDeepWaterWaveAngle =
m_pRasterGrid->m_Cell[VCellsToMark.back().nGetX()][VCellsToMark.back().nGetY()].dGetCellDeepWaterWaveAngle();
1479 double const dDeepWaterWavePeriod =
m_pRasterGrid->m_Cell[VCellsToMark.back().nGetX()][VCellsToMark.back().nGetY()].dGetCellDeepWaterWavePeriod();
1482 m_VCoast[nCoast].pGetProfile(nProfile)->SetProfileDeepWaterWaveHeight(dDeepWaterWaveHeight);
1483 m_VCoast[nCoast].pGetProfile(nProfile)->SetProfileDeepWaterWaveAngle(dDeepWaterWaveAngle);
1484 m_VCoast[nCoast].pGetProfile(nProfile)->SetProfileDeepWaterWavePeriod(dDeepWaterWavePeriod);
1487 bDownCoast = ! bDownCoast;
1493void CSimulation::CreateRasterizedProfile(
int const nCoast,
CGeomProfile* pProfile, vector<CGeom2DIPoint>* pVIPointsOut, vector<bool>* pbVShared,
bool& bTooShort,
bool& bTruncatedSameCoast,
bool& bHitCoast,
bool& bHitLand,
bool& bHitIntervention,
bool& bHitAnotherProfile)
1499 pVIPointsOut->clear();
1508 for (nSeg = 0; nSeg < nNumSegments; nSeg++)
1517 PtiSegStart =
m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastPoint);
1533 if (PtiSegStart == PtiSegEnd)
1536 int const nXStart = PtiSegStart.
nGetX();
1537 int const nYStart = PtiSegStart.
nGetY();
1538 int const nXEnd = PtiSegEnd.
nGetX();
1539 int const nYEnd = PtiSegEnd.
nGetY();
1541 bool bShared =
false;
1548 if ((nXStart == nXStartLast) && (nYStart == nYStartLast) && (nXEnd == nXEndLast) && (nYEnd == nYEndLast))
1553 double dXInc = nXEnd - nXStart;
1554 double dYInc = nYEnd - nYStart;
1560 double dX = nXStart;
1561 double dY = nYStart;
1564 for (
int m = 0; m <=
nRound(dLength); m++)
1566 int const nX =
nRound(dX);
1567 int const nY =
nRound(dY);
1576 bTruncatedSameCoast =
true;
1595 int const nHitProfileCoast1 =
m_pRasterGrid->m_Cell[nX][nY].nGetProfileCoastID();
1596 int const nHitProfileCoast2 =
m_pRasterGrid->m_Cell[nX][nYTmp].nGetProfileCoastID();
1598 if ((nHitProfileCoast1 == nCoast) || (nHitProfileCoast2 == nCoast))
1601 bHitAnotherProfile =
true;
1616 int const nHitCoast =
m_pRasterGrid->m_Cell[nX][nY].nGetCoastline();
1638 bHitIntervention =
true;
1651 int const nHitProfile =
m_pRasterGrid->m_Cell[nX][nY].nGetProfileID();
1652 int const nHitProfileCoast =
m_pRasterGrid->m_Cell[nX][nY].nGetProfileCoastID();
1655 if (nCoast == nHitProfileCoast)
1662 bHitAnotherProfile =
true;
1672 pbVShared->push_back(bShared);
1679 nXStartLast = nXStart;
1680 nYStartLast = nYStart;
1684 if (bTruncatedSameCoast)
1688 if (bTruncatedSameCoast)
1690 if (nSeg < (nNumSegments - 1))
1695 int const nLastX = pVIPointsOut->at(pVIPointsOut->size() - 1).nGetX();
1696 int const nLastY = pVIPointsOut->at(pVIPointsOut->size() - 1).nGetY();
1710 if (pVIPointsOut->size() < 3)
1719 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;
1730 int nCombinedLastSeg = 0;
1731 vector<pair<int, int>> prVCombinedProfilesCoincidentProfilesLastSeg;
1735 pair<int, int> prTmp;
1739 bool bFound =
false;
1741 for (
unsigned int m = 0; m < prVCombinedProfilesCoincidentProfilesLastSeg.size(); m++)
1743 if (prVCombinedProfilesCoincidentProfilesLastSeg[m].first == prTmp.first)
1752 prVCombinedProfilesCoincidentProfilesLastSeg.push_back(prTmp);
1759 pair<int, int> prTmp;
1763 bool bFound =
false;
1765 for (
unsigned int m = 0; m < prVCombinedProfilesCoincidentProfilesLastSeg.size(); m++)
1767 if (prVCombinedProfilesCoincidentProfilesLastSeg[m].first == prTmp.first)
1776 prVCombinedProfilesCoincidentProfilesLastSeg.push_back(prTmp);
1782 for (
int m = 0; m < nCombinedLastSeg; m++)
1783 prVCombinedProfilesCoincidentProfilesLastSeg[m].second++;
1787 int const nNumFirstProfileCoincidentProfilesLastSeg =
static_cast<int>(prVFirstProfileCoincidentProfilesLastSeg.size());
1788 int const nNumSecondProfileCoincidentProfilesLastSeg =
static_cast<int>(prVSecondProfileCoincidentProfilesLastSeg.size());
1793 for (
int n = 0; n < nNumFirstProfileCoincidentProfilesLastSeg; n++)
1795 int const nThisProfile = prVFirstProfileCoincidentProfilesLastSeg[n].first;
1804 for (
int n = 0; n < nNumSecondProfileCoincidentProfilesLastSeg; n++)
1806 int const nThisProfile = prVSecondProfileCoincidentProfilesLastSeg[n].first;
1815 for (
int nThisLineSeg = 0; nThisLineSeg < nNumFirstProfileCoincidentProfilesLastSeg; nThisLineSeg++)
1817 int const nThisProfile = prVFirstProfileCoincidentProfilesLastSeg[nThisLineSeg].first;
1826 for (
int m = 0; m < nCombinedLastSeg; m++)
1831 for (
int nThisLineSeg = 0; nThisLineSeg < nNumSecondProfileCoincidentProfilesLastSeg; nThisLineSeg++)
1833 int const nThisProfile = prVSecondProfileCoincidentProfilesLastSeg[nThisLineSeg].first;
1842 for (
int m = 0; m < nCombinedLastSeg; m++)
1913 int const nRet =
nInsertPointIntoProfilesIfNeededThenUpdate(nCoast, pProfileToRetain, dIntersectX, dIntersectY, nProfileToRetainIntersectLineSeg, pProfileToTruncate, nProfileToTruncateIntersectLineSeg, bAlreadyPresent);
1922 vector<CGeom2DPoint> PtVProfileLastPart;
1923 vector<vector<pair<int, int>>> prVLineSegLastPart;
1925 if (bAlreadyPresent)
1941 TruncateProfileAndAppendNew(nCoast, pProfileToTruncate, nProfileToTruncateIntersectLineSeg, &PtVProfileLastPart, &prVLineSegLastPart);
2017 int const nProfileToRetain = pProfileToRetain->
nGetProfileID();
2021 int const nNumCoincident =
static_cast<int>(prVCoincidentProfiles.size());
2022 vector<int> nLineSegAfterIntersect(nNumCoincident, -1);
2025 for (
int nn = 0; nn < nNumCoincident; nn++)
2027 int const nThisProfile = prVCoincidentProfiles[nn].first;
2028 int const nThisLineSeg = prVCoincidentProfiles[nn].second;
2032 if (! bAlreadyPresent)
2038 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;
2047 nLineSegAfterIntersect[nn] = nThisLineSeg + 1;
2055 int const nNumToTruncateCoincident =
static_cast<int>(prVToTruncateCoincidentProfiles.size());
2058 for (
int nn = 0; nn < nNumCoincident; nn++)
2060 int const nThisProfile = prVCoincidentProfiles[nn].first;
2067 for (
int nLineSeg = nLineSegAfterIntersect[nn], nIncr = 0; nLineSeg < nNumLineSegs; nLineSeg++, nIncr++)
2078 for (
int m = 0; m < nNumToTruncateCoincident; m++)
2080 int const nProfileToAdd = prVToTruncateCoincidentProfiles[m].first;
2081 int const nProfileToAddLineSeg = prVToTruncateCoincidentProfiles[m].second;
2182 int const nNumCoincident =
static_cast<int>(prVCoincidentProfiles.size());
2184 for (
int nn = 0; nn < nNumCoincident; nn++)
2187 int const nThisProfile = prVCoincidentProfiles[nn].first;
2188 int const nThisProfileLineSeg = prVCoincidentProfiles[nn].second;
2202 for (
unsigned int mm = 0; mm < pPtVProfileLastPart->size(); mm++)
2209 for (
unsigned int mm = 0; mm < pprVLineSegLastPart->size(); mm++)
2211 vector<pair<int, int>> prVTmp = pprVLineSegLastPart->at(mm);
2218 vector<int> nVProfsLineSeg;
2224 int const nProf = pThisProfile->
nGetProf(nSeg, nCoinc);
2227 auto it = find(nVProf.begin(), nVProf.end(), nProf);
2229 if (it == nVProf.end())
2232 nVProf.push_back(nProf);
2233 nVProfsLineSeg.push_back(nProfsLineSeg);
2239 int const nPos =
static_cast<int>(it - nVProf.begin());
2240 int nNewProfsLineSeg = nVProfsLineSeg[nPos];
2243 nVProfsLineSeg[nPos] = nNewProfsLineSeg;
Contains CGeom2DPoint definitions.
Contains CGeom2DIPoint definitions.
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, or -1 if the line segment does ...
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's CGeomLine (external CRS points)
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 (external CRS) to the profile.
int nGetProfileID(void) const
Returns the profile's this-coast ID.
int nGetCoastPoint(void) const
Returns the coast point at which the profile starts.
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 and is not an end-of-coas...
void SetStartOfCoast(bool const)
Sets a switch to indicate whether this is a start-of-coast profile.
void SetUpCoastAdjacentProfile(CGeomProfile *)
Sets the up-coast adjacent profile.
void SetHitAnotherProfile(bool const)
Sets a switch which indicates whether this profile hits another profile badly.
vector< CGeom2DPoint > PtVGetThisPointAndAllAfter(int const)
Returns a given external CRS point from the profile, and all points after this.
bool bInsertIntersection(double const, double const, int const)
Inserts an intersection (at a point specified in external CRS, with a line segment) into the profile.
bool bIsGridEdge(void) const
Returns true if this is a start-of-coast or an end-of-coast profile.
void SetTruncatedSameCoast(bool const)
Sets a switch which indicates whether this profile is truncated, due to hitting another profile from ...
bool bProfileOK(void) const
Returns true if this is a problem-free profile, and is not a start-of-coast and is not an end-of-coas...
void SetProfileDeepWaterWaveHeight(double const)
Sets the deep-water wave height for this profile.
void SetDownCoastAdjacentProfile(CGeomProfile *)
Sets the down-coast adjacent profile.
bool bIsIntervention(void) const
Returns true if this is an intervention profile.
void SetHitIntervention(bool const)
Sets a switch which indicates whether this profile has hit an intervention.
CGeom2DPoint * pPtGetPointInProfile(int const)
Returns a single point (external CRS) from the profile.
void AppendCellInProfile(CGeom2DIPoint const *)
Appends a cell (grid CRS) to the profile.
void SetPointInProfile(int const, double const, double const)
Sets a single point (external CRS) in the profile.
int nGetProfileSize(void) const
Returns the number of external CRS points in the profile (only two, initally; and always just two for...
void SetHitLand(bool const)
Sets a switch which indicates whether this profile has hit land.
void SetPointsInProfile(vector< CGeom2DPoint > const *)
Sets points (external CRS) in the profile. Note that only two points, the start and end point,...
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.
void LocateAndCreateProfiles(int const, int &, vector< bool > *, vector< pair< int, double > > const *)
For a single coastline, locate the start points for all coastline-normal profiles (except the grid-ed...
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 coastline-normal profiles, in m.
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.
normal_distribution< double > m_dGetFromUnitNormalDist
c++11 unit normal distribution (mean = 0, stdev = 1)
void CreateRasterizedProfile(int const, CGeomProfile *, vector< CGeom2DIPoint > *, vector< bool > *, bool &, bool &, bool &, bool &, bool &, bool &)
Given a pointer to a coastline-normal profile, returns an output vector of cells which are 'under' ev...
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...
void KeepWithinValidGrid(int &, int &) const
Constrains the supplied point (in the grid CRS) to be a valid cell within the raster grid.
int m_nCoastNormalSpacing
Average spacing between coastline normals, measured in cells.
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...
int m_nCoastNormalInterventionSpacing
Average spacing between coastline normals on interventions, measured in cells.
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...
int nCreateProfile(int const, int const, int const, int const, bool const, CGeom2DIPoint const *)
Creates a single coastline-normal profile (which may be an intervention profile)
int nConvertMetresToNumCells(double const) const
Given a length in m, this returns the rounded equivalent number of cells.
double dGridYToExtCRSY(double const) const
Given a real-valued Y-axis ordinate in the raster grid CRS (i.e. not the centroid of a cell),...
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...
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...
default_random_engine m_Rand[NUMBER_OF_RNGS]
The c++11 random number generators.
int nCreateAllProfiles(void)
Create coastline-normal profiles for all coastlines. The first profiles are created 'around' the most...
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,...
double dGridXToExtCRSX(double const) const
Given a real-valued X-axis ordinate in the raster grid CRS (i.e. not the centroid of a cell),...
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...
int nLocateAndCreateGridEdgeProfile(bool const, int const, int &)
Creates a 'special' profile at each end of a coastline, at the edge of the raster grid....
void TruncateOneProfileRetainOtherProfile(int const, CGeomProfile *, CGeomProfile *, double, double, int, int, bool const)
Truncates one intersecting profile at the point of intersection, and retains the other profile.
double m_dCellSide
Length of a cell side (in external CRS units)
double m_dDepthOfClosure
Depth of closure (in m) TODO 007 can be calculated using Hallermeier, R.J. (1978) or Birkemeier (1985...
int nCheckAndMarkAllProfiles(void)
Check all coastline-normal profiles and modify the profiles if they intersect, then mark valid profil...
vector< int > m_VEdgeCellEdge
The grid edge that each edge cell belongs to.
This file contains global definitions for CoastalME.
int const LF_INTERVENTION_STRUCT
int const RTN_ERR_COAST_CANT_FIND_EDGE_CELL
int const DIRECTION_DOWNCOAST
bool const ACCEPT_TRUNCATED_PROFILES
int const LF_INTERVENTION_NON_STRUCT
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 RTN_ERR_PROFILE_ENDPOINT_IS_INLAND
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
Contains CRWCoast definitions.
Contains CSimulation definitions.
int nRound(double const d)
Correctly rounds doubles, returns an int.