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;
84 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
91 dCurvature =
m_VCoast[nCoast].dGetSmoothCurvature(nCoastPoint);
97 dCurvature =
m_VCoast[nCoast].dGetDetailedCurvature(nCoastPoint);
100 prVCurvature.push_back(make_pair(nCoastPoint, dCurvature));
118 bVCoastPointDone[n] =
true;
120 int m = nCoastSize - n - 1;
123 bVCoastPointDone[m] =
true;
135 strErr +=
". Check the SWL";
158 m_VCoast[nCoast].InsertProfilesInProfileCoastPointIndex();
179 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
181 if (
m_VCoast[nCoast].bIsProfileAtCoastPoint(nCoastPoint))
183 pThisProfile =
m_VCoast[nCoast].pGetProfileAtCoastPoint(nCoastPoint);
186 if (nCoastPoint == 0)
192 pLastProfile = pThisProfile;
201 if (nCoastPoint == nCoastSize - 1)
206 pLastProfile = pThisProfile;
212 m_VCoast[nCoast].CreateProfileDownCoastIndex();
280 int nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
283 for (
int n = nCoastSize - 1; n >= 0;
287 int nStillToSearch = 0;
289 for (
int m = 0; m < nCoastSize; m++)
290 if (! pbVCoastPointDone->at(m))
293 if (nStillToSearch == 0)
298 int nNormalPoint = prVCurvature->at(n).first;
301 if ((nNormalPoint == 0) || (nNormalPoint == nCoastSize - 1))
306 if (! pbVCoastPointDone->at(nNormalPoint))
309 bool bIntervention =
false;
314 bIntervention =
true;
320 int nRet =
nCreateProfile(nCoast, nCoastSize, nNormalPoint, nProfile, nProfileGlobalID, bIntervention, &PtiThis);
338 pbVCoastPointDone->at(nNormalPoint) =
true;
428 for (
int m = 1; m < dNumToMark; m++)
430 int nTmpPoint = nNormalPoint + m;
432 if (nTmpPoint < nCoastSize)
433 pbVCoastPointDone->at(nTmpPoint) =
true;
435 nTmpPoint = nNormalPoint - m;
438 pbVCoastPointDone->at(nTmpPoint) =
true;
464 int nXEnd = PtiEnd.
nGetX();
465 int nYEnd = PtiEnd.
nGetY();
468 if (!
m_pRasterGrid->m_Cell[nXEnd][nYEnd].bIsInContiguousSea())
486 CGeomProfile* pProfile =
new CGeomProfile(nCoast, nProfileStartPoint, nProfile, ++pnProfileGlobalID, pPtiStart, &PtiEnd, bIntervention);
489 vector<CGeom2DPoint> VNormal;
490 VNormal.push_back(PtStart);
491 VNormal.push_back(PtEnd);
501 m_VCoast[nCoast].AppendProfile(pProfile);
518 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;
528 int nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
529 int nHandedness =
m_VCoast[nCoast].nGetSeaHandedness();
531 int nProfileStartEdge;
534 vector<CGeom2DIPoint> VPtiNormalPoints;
539 PtiProfileStart = *
m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(0);
540 nProfileStartEdge =
m_VCoast[nCoast].nGetStartEdge();
546 PtiProfileStart = *
m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastSize - 1);
547 nProfileStartEdge =
m_VCoast[nCoast].nGetEndEdge();
550 VPtiNormalPoints.push_back(PtiProfileStart);
565 int nPos =
static_cast<int>(it -
m_VEdgeCell.begin());
568 for (
int n = 0; n < nProfileLen; n++)
636 int nProfileStartPoint;
642 nProfileStartPoint = 0;
645 pProfile =
new CGeomProfile(nCoast, nProfileStartPoint, nProfile, ++nProfileGlobalID, &PtiProfileStart, &PtiDummy,
false);
653 nProfileStartPoint = nCoastSize - 1;
656 pProfile =
new CGeomProfile(nCoast, nProfileStartPoint, nProfile, ++nProfileGlobalID, &PtiProfileStart, &PtiDummy,
false);
663 for (
unsigned int n = 0; n < VPtiNormalPoints.size(); n++)
665 int nX = VPtiNormalPoints[n].nGetX();
666 int nY = VPtiNormalPoints[n].nGetY();
679 if ((n == 0) || (n == VPtiNormalPoints.size() - 1))
686 int nEndX = VPtiNormalPoints.back().nGetX();
687 int nEndY = VPtiNormalPoints.back().nGetY();
692 double dDeepWaterWaveHeight =
m_pRasterGrid->m_Cell[nEndX][nEndY].dGetCellDeepWaterWaveHeight();
693 double dDeepWaterWaveAngle =
m_pRasterGrid->m_Cell[nEndX][nEndY].dGetCellDeepWaterWaveAngle();
694 double dDeepWaterWavePeriod =
m_pRasterGrid->m_Cell[nEndX][nEndY].dGetCellDeepWaterWavePeriod();
706 m_VCoast[nCoast].AppendProfile(pProfile);
707 m_VCoast[nCoast].SetProfileAtCoastPoint(nProfileStartPoint, pProfile);
720 int const AVGSIZE = 21;
728 PtBefore = *
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nStartCoastPoint - 1);
729 PtAfter = *
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nStartCoastPoint + 1);
735 vector<CGeom2DPoint> PtBeforeToAverage;
737 for (
int n = 1; n <= AVGSIZE; n++)
739 int nPoint = nStartCoastPoint - n;
744 PtBeforeToAverage.push_back( *
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nPoint));
748 vector<CGeom2DPoint> PtAfterToAverage;
750 for (
int n = 1; n <= AVGSIZE; n++)
752 int nPoint = nStartCoastPoint + n;
754 if (nPoint > nCoastSize - 1)
757 PtAfterToAverage.push_back( *
m_VCoast[nCoast].pPtGetCoastlinePointExtCRS(nPoint));
761 PtBefore =
PtAverage(&PtBeforeToAverage);
766 double dYDiff = PtAfter.
dGetY() - PtBefore.
dGetY();
767 double dXDiff = PtAfter.
dGetX() - PtBefore.
dGetX();
769 double dXEnd1 = 0, dXEnd2 = 0, dYEnd1 = 0, dYEnd2 = 0;
774 dXEnd1 = dXEnd2 = pPtStart->
dGetX();
775 dYEnd1 = pPtStart->
dGetY() + dLineLength;
776 dYEnd2 = pPtStart->
dGetY() - dLineLength;
782 dYEnd1 = dYEnd2 = pPtStart->
dGetY();
783 dXEnd1 = pPtStart->
dGetX() + dLineLength;
784 dXEnd2 = pPtStart->
dGetX() - dLineLength;
790 double dA = dYDiff / dXDiff;
793 double dAPerp = -1 / dA;
794 double dBPerp = pPtStart->
dGetY() - (dAPerp * pPtStart->
dGetX());
797 double dQuadA = 1 + (dAPerp * dAPerp);
798 double dQuadB = 2 * ((dBPerp * dAPerp) - (dAPerp * pPtStart->
dGetY()) - pPtStart->
dGetX());
799 double dQuadC = ((pPtStart->
dGetX() * pPtStart->
dGetX()) + (pPtStart->
dGetY() * pPtStart->
dGetY()) + (dBPerp * dBPerp) - (2 * pPtStart->
dGetY() * dBPerp) - (dLineLength * dLineLength));
802 double dDiscriminant = (dQuadB * dQuadB) - (4 * dQuadA * dQuadC);
804 if (dDiscriminant < 0)
806 LogStream <<
ERR <<
"timestep " <<
m_ulIter <<
": discriminant < 0 when finding profile end point on coastline " << nCoast <<
", from coastline point " << nStartCoastPoint <<
"), ignored" << endl;
810 dXEnd1 = (-dQuadB + sqrt(dDiscriminant)) / (2 * dQuadA);
811 dYEnd1 = (dAPerp * dXEnd1) + dBPerp;
812 dXEnd2 = (-dQuadB - sqrt(dDiscriminant)) / (2 * dQuadA);
813 dYEnd2 = (dAPerp * dXEnd2) + dBPerp;
817 int nSeaHand =
m_VCoast[nCoast].nGetSeaHandedness();
818 * pPtEnd =
PtChooseEndPoint(nSeaHand, &PtBefore, &PtAfter, dXEnd1, dYEnd1, dXEnd2, dYEnd2);
858 PtChosen.
SetX(dXEnd1);
859 PtChosen.
SetY(dYEnd1);
864 PtChosen.
SetX(dXEnd2);
865 PtChosen.
SetY(dYEnd2);
869 else if (PtAfter->
dGetY() < PtBefore->
dGetY())
874 PtChosen.
SetX(dXEnd1);
875 PtChosen.
SetY(dYEnd1);
880 PtChosen.
SetX(dXEnd2);
881 PtChosen.
SetY(dYEnd2);
893 PtChosen.
SetX(dXEnd1);
894 PtChosen.
SetY(dYEnd1);
899 PtChosen.
SetX(dXEnd2);
900 PtChosen.
SetY(dYEnd2);
909 PtChosen.
SetX(dXEnd1);
910 PtChosen.
SetY(dYEnd1);
915 PtChosen.
SetX(dXEnd2);
916 PtChosen.
SetY(dYEnd2);
930 PtChosen.
SetX(dXEnd1);
931 PtChosen.
SetY(dYEnd1);
936 PtChosen.
SetX(dXEnd2);
937 PtChosen.
SetY(dYEnd2);
941 else if (PtAfter->
dGetY() < PtBefore->
dGetY())
946 PtChosen.
SetX(dXEnd1);
947 PtChosen.
SetY(dYEnd1);
952 PtChosen.
SetX(dXEnd2);
953 PtChosen.
SetY(dYEnd2);
965 PtChosen.
SetX(dXEnd1);
966 PtChosen.
SetY(dYEnd1);
971 PtChosen.
SetX(dXEnd2);
972 PtChosen.
SetY(dYEnd2);
981 PtChosen.
SetX(dXEnd1);
982 PtChosen.
SetY(dYEnd1);
987 PtChosen.
SetX(dXEnd2);
988 PtChosen.
SetY(dYEnd2);
1003 int nCoastLines =
static_cast<int>(
m_VCoast.size());
1005 for (
int nCoast = 0; nCoast < nCoastLines; nCoast++)
1007 int nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
1010 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
1012 if (!
m_VCoast[nCoast].bIsProfileAtCoastPoint(nCoastPoint))
1033 nStartPoint = nCoastPoint + 1;
1036 nStartPoint = nCoastPoint - 1;
1038 for (
int nSecondCoastPoint = nStartPoint; (nDirection ==
DIRECTION_DOWNCOAST) ? nSecondCoastPoint < nCoastSize : nSecondCoastPoint >= 0; (nDirection ==
DIRECTION_DOWNCOAST) ? nSecondCoastPoint++ : nSecondCoastPoint--)
1048 if (
m_VCoast[nCoast].bIsProfileAtCoastPoint(nSecondCoastPoint))
1052 int nSecondProfile = pSecondProfile->
nGetCoastID();
1071 int nProf1LineSeg = 0;
1072 int nProf2LineSeg = 0;
1073 double dIntersectX = 0;
1074 double dIntersectY = 0;
1075 double dAvgEndX = 0;
1076 double dAvgEndY = 0;
1078 if (
bCheckForIntersection(pFirstProfile, pSecondProfile, nProf1LineSeg, nProf2LineSeg, dIntersectX, dIntersectY, dAvgEndX, dAvgEndY))
1085 LogStream <<
m_ulIter <<
": profiles " << nFirstProfile <<
" and " << nSecondProfile <<
" intersect, truncate " << nFirstProfile <<
" since it is an intervention profile" << endl;
1093 LogStream <<
m_ulIter <<
": profiles " << nFirstProfile <<
" and " << nSecondProfile <<
" intersect, truncate " << nSecondProfile <<
" since it is an intervention profile" << endl;
1102 LogStream <<
m_ulIter <<
": profiles " << nFirstProfile <<
" and " << nSecondProfile <<
" intersect, but point {" << dIntersectX <<
", " << dIntersectY <<
"} is already present in profile " << nFirstProfile <<
" as point " << nPoint << endl;
1111 LogStream <<
m_ulIter <<
": profiles " << nFirstProfile <<
" and " << nSecondProfile <<
" intersect, but point {" << dIntersectX <<
", " << dIntersectY <<
"} is already present in profile " << nSecondProfile <<
" as point " << nPoint << endl;
1127 if ((nProf1LineSeg == (nFirstProfileLineSegments - 1)) && (nProf2LineSeg == (nSecondProfileLineSegments - 1)))
1130 MergeProfilesAtFinalLineSegments(nCoast, pFirstProfile, pSecondProfile, nFirstProfileLineSegments, nSecondProfileLineSegments, dIntersectX, dIntersectY, dAvgEndX, dAvgEndY);
1169 else if (nFirstProfileLineSegments < nSecondProfileLineSegments)
1177 else if (nFirstProfileLineSegments > nSecondProfileLineSegments)
1223 for (
unsigned int nCoast = 0; nCoast <
m_VCoast.size(); nCoast++)
1225 for (
int n = 0; n <
m_VCoast[nCoast].nGetNumProfiles(); n++)
1238 m_VCoast[nCoast].pGetProfile(nProfile)->SetTooShort(
true);
1239 LogStream <<
"Profile " << nProfile <<
" is too short, size = " << nSize << endl;
1245 int nXEnd = PtiEnd.
nGetX();
1246 int nYEnd = PtiEnd.
nGetY();
1251 nXEnd =
tMax(nXEnd, 0);
1252 nYEnd =
tMax(nYEnd, 0);
1255 m_VCoast[nCoast].pGetProfile(nProfile)->SetEndPoint(&PtiEnd);
1260 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;
1263 m_VCoast[nCoast].pGetProfile(nProfile)->SetTooShort(
true);
1269 int nValidProfiles = 0;
1272 if (nValidProfiles == 0)
1275 cerr <<
m_ulIter <<
": " <<
ERR <<
"no coastline-normal profiles created" << endl;
1341 for (
int i = 0; i < nProfile1NumSegments; i++)
1343 for (
int j = 0; j < nProfile2NumSegments; j++)
1348 double dX2 = pVProfile1->
pPtVGetPoints()->at(i + 1).dGetX();
1349 double dY2 = pVProfile1->
pPtVGetPoints()->at(i + 1).dGetY();
1353 double dX4 = pVProfile2->
pPtVGetPoints()->at(j + 1).dGetX();
1354 double dY4 = pVProfile2->
pPtVGetPoints()->at(j + 1).dGetY();
1357 double dDiffX1 = dX2 - dX1;
1358 double dDiffY1 = dY2 - dY1;
1359 double dDiffX2 = dX4 - dX3;
1360 double dDiffY2 = dY4 - dY3;
1366 dTmp = -dDiffX2 * dDiffY1 + dDiffX1 * dDiffY2;
1369 dS = (-dDiffY1 * (dX1 - dX3) + dDiffX1 * (dY1 - dY3)) / dTmp;
1371 dTmp = -dDiffX2 * dDiffY1 + dDiffX1 * dDiffY2;
1374 dT = (dDiffX2 * (dY1 - dY3) - dDiffY2 * (dX1 - dX3)) / dTmp;
1376 if (dS >= 0 && dS <= 1 && dT >= 0 && dT <= 1)
1379 dXIntersect = dX1 + (dT * dDiffX1);
1380 dYIntersect = dY1 + (dT * dDiffY1);
1383 dXAvgEnd = (dX2 + dX4) / 2;
1384 dYAvgEnd = (dY2 + dY4) / 2;
1387 nProfile1LineSegment = i;
1388 nProfile2LineSegment = j;
1406 int nProfiles =
m_VCoast[nCoast].nGetNumProfiles();
1417 static bool bDownCoast =
true;
1420 for (
int n = 0; n < nProfiles; n++)
1425 pProfile =
m_VCoast[nCoast].pGetProfileWithDownCoastSeq(n);
1428 pProfile =
m_VCoast[nCoast].pGetProfileWithUpCoastSeq(n);
1448 m_VCoast[nCoast].pGetProfile(nProfile)->SetTooShort(
true);
1451 LogStream <<
m_ulIter <<
": coast " << nCoast <<
", profile " << nProfile <<
" is invalid, has only " << nPoints <<
" points" << endl;
1457 vector<CGeom2DIPoint> VCellsToMark;
1458 vector<bool> bVShared;
1459 bool bTooShort =
false;
1460 bool bTruncated =
false;
1461 bool bHitCoast =
false;
1462 bool bHitLand =
false;
1463 bool bHitIntervention =
false;
1464 bool bHitAnotherProfile =
false;
1466 CreateRasterizedProfile(nCoast, pProfile, &VCellsToMark, &bVShared, bTooShort, bTruncated, bHitCoast, bHitLand, bHitIntervention, bHitAnotherProfile);
1468 if ((bTruncated && (!
ACCEPT_TRUNCATED_PROFILES)) || bTooShort || bHitCoast || bHitLand || bHitIntervention || bHitAnotherProfile || VCellsToMark.size() == 0)
1474 for (
unsigned int k = 0; k < VCellsToMark.size(); k++)
1477 if ((k > 0) && (VCellsToMark[k] ==
m_VCoast[nCoast].pGetProfile(nProfile)->pPtiGetLastCellInProfile()))
1481 m_pRasterGrid->m_Cell[VCellsToMark[k].nGetX()][VCellsToMark[k].nGetY()].SetProfileID(nProfile);
1484 m_VCoast[nCoast].pGetProfile(nProfile)->AppendCellInProfile(VCellsToMark[k].nGetX(), VCellsToMark[k].nGetY());
1504 double dDeepWaterWaveHeight =
m_pRasterGrid->m_Cell[VCellsToMark.back().nGetX()][VCellsToMark.back().nGetY()].dGetCellDeepWaterWaveHeight();
1505 double dDeepWaterWaveAngle =
m_pRasterGrid->m_Cell[VCellsToMark.back().nGetX()][VCellsToMark.back().nGetY()].dGetCellDeepWaterWaveAngle();
1506 double dDeepWaterWavePeriod =
m_pRasterGrid->m_Cell[VCellsToMark.back().nGetX()][VCellsToMark.back().nGetY()].dGetCellDeepWaterWavePeriod();
1509 m_VCoast[nCoast].pGetProfile(nProfile)->SetProfileDeepWaterWaveHeight(dDeepWaterWaveHeight);
1510 m_VCoast[nCoast].pGetProfile(nProfile)->SetProfileDeepWaterWaveAngle(dDeepWaterWaveAngle);
1511 m_VCoast[nCoast].pGetProfile(nProfile)->SetProfileDeepWaterWavePeriod(dDeepWaterWavePeriod);
1514 bDownCoast = ! bDownCoast;
1520void CSimulation::CreateRasterizedProfile(
int const nCoast,
CGeomProfile* pProfile, vector<CGeom2DIPoint> *pVIPointsOut, vector<bool>*pbVShared,
bool& bTooShort,
bool& bTruncated,
bool& bHitCoast,
bool& bHitLand,
bool& bHitIntervention,
bool& bHitAnotherProfile)
1526 pVIPointsOut->clear();
1535 for (nSeg = 0; nSeg < nNumSegments; nSeg++)
1560 if (PtiSegStart == PtiSegEnd)
1563 int nXStart = PtiSegStart.
nGetX();
1564 int nYStart = PtiSegStart.
nGetY();
1565 int nXEnd = PtiSegEnd.
nGetX();
1566 int nYEnd = PtiSegEnd.
nGetY();
1568 bool bShared =
false;
1575 if ((nXStart == nXStartLast) && (nYStart == nYStartLast) && (nXEnd == nXEndLast) && (nYEnd == nYEndLast))
1580 double dXInc = nXEnd - nXStart;
1581 double dYInc = nYEnd - nYStart;
1587 double dX = nXStart;
1588 double dY = nYStart;
1591 for (
int m = 0; m <=
nRound(dLength); m++)
1656 bHitIntervention =
true;
1669 int nHitProfile =
m_pRasterGrid->m_Cell[nX][nY].nGetProfileID();
1678 bHitAnotherProfile =
true;
1687 pbVShared->push_back(bShared);
1694 nXStartLast = nXStart;
1695 nYStartLast = nYStart;
1705 if (nSeg < (nNumSegments - 1))
1710 int nLastX = pVIPointsOut->at(pVIPointsOut->size() - 1).nGetX();
1711 int nLastY = pVIPointsOut->at(pVIPointsOut->size() - 1).nGetY();
1725 if (pVIPointsOut->size() < 3)
1734 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;
1745 int nCombinedLastSeg = 0;
1746 vector<pair<int, int>> prVCombinedProfilesCoincidentProfilesLastSeg;
1750 pair<int, int> prTmp;
1754 bool bFound =
false;
1756 for (
unsigned int m = 0; m < prVCombinedProfilesCoincidentProfilesLastSeg.size(); m++)
1758 if (prVCombinedProfilesCoincidentProfilesLastSeg[m].first == prTmp.first)
1767 prVCombinedProfilesCoincidentProfilesLastSeg.push_back(prTmp);
1774 pair<int, int> prTmp;
1778 bool bFound =
false;
1780 for (
unsigned int m = 0; m < prVCombinedProfilesCoincidentProfilesLastSeg.size(); m++)
1782 if (prVCombinedProfilesCoincidentProfilesLastSeg[m].first == prTmp.first)
1791 prVCombinedProfilesCoincidentProfilesLastSeg.push_back(prTmp);
1797 for (
int m = 0; m < nCombinedLastSeg; m++)
1798 prVCombinedProfilesCoincidentProfilesLastSeg[m].second++;
1802 int nNumFirstProfileCoincidentProfilesLastSeg =
static_cast<int>(prVFirstProfileCoincidentProfilesLastSeg.size());
1803 int nNumSecondProfileCoincidentProfilesLastSeg =
static_cast<int>(prVSecondProfileCoincidentProfilesLastSeg.size());
1808 for (
int n = 0; n < nNumFirstProfileCoincidentProfilesLastSeg; n++)
1810 int nThisProfile = prVFirstProfileCoincidentProfilesLastSeg[n].first;
1819 for (
int n = 0; n < nNumSecondProfileCoincidentProfilesLastSeg; n++)
1821 int nThisProfile = prVSecondProfileCoincidentProfilesLastSeg[n].first;
1830 for (
int nThisLineSeg = 0; nThisLineSeg < nNumFirstProfileCoincidentProfilesLastSeg; nThisLineSeg++)
1832 int nThisProfile = prVFirstProfileCoincidentProfilesLastSeg[nThisLineSeg].first;
1841 for (
int m = 0; m < nCombinedLastSeg; m++)
1846 for (
int nThisLineSeg = 0; nThisLineSeg < nNumSecondProfileCoincidentProfilesLastSeg; nThisLineSeg++)
1848 int nThisProfile = prVSecondProfileCoincidentProfilesLastSeg[nThisLineSeg].first;
1857 for (
int m = 0; m < nCombinedLastSeg; m++)
1928 int nRet =
nInsertPointIntoProfilesIfNeededThenUpdate(nCoast, pProfileToRetain, dIntersectX, dIntersectY, nProfileToRetainIntersectLineSeg, pProfileToTruncate, nProfileToTruncateIntersectLineSeg, bAlreadyPresent);
1937 vector<CGeom2DPoint> PtVProfileLastPart;
1938 vector<vector<pair<int, int>>> prVLineSegLastPart;
1940 if (bAlreadyPresent)
1956 TruncateProfileAndAppendNew(nCoast, pProfileToTruncate, nProfileToTruncateIntersectLineSeg, &PtVProfileLastPart, &prVLineSegLastPart);
2032 int nProfileToRetain = pProfileToRetain->
nGetCoastID();
2036 int nNumCoincident =
static_cast<int>(prVCoincidentProfiles.size());
2037 vector<int> nLineSegAfterIntersect(nNumCoincident, -1);
2040 for (
int nn = 0; nn < nNumCoincident; nn++)
2042 int nThisProfile = prVCoincidentProfiles[nn].first;
2043 int nThisLineSeg = prVCoincidentProfiles[nn].second;
2047 if (! bAlreadyPresent)
2053 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;
2062 nLineSegAfterIntersect[nn] = nThisLineSeg + 1;
2070 int nNumToTruncateCoincident =
static_cast<int>(prVToTruncateCoincidentProfiles.size());
2073 for (
int nn = 0; nn < nNumCoincident; nn++)
2075 int nThisProfile = prVCoincidentProfiles[nn].first;
2082 for (
int nLineSeg = nLineSegAfterIntersect[nn], nIncr = 0; nLineSeg < nNumLineSegs; nLineSeg++, nIncr++)
2093 for (
int m = 0; m < nNumToTruncateCoincident; m++)
2095 int nProfileToAdd = prVToTruncateCoincidentProfiles[m].first;
2096 int nProfileToAddLineSeg = prVToTruncateCoincidentProfiles[m].second;
2197 int nNumCoincident =
static_cast<int>(prVCoincidentProfiles.size());
2199 for (
int nn = 0; nn < nNumCoincident; nn++)
2202 int nThisProfile = prVCoincidentProfiles[nn].first;
2203 int nThisProfileLineSeg = prVCoincidentProfiles[nn].second;
2217 for (
unsigned int mm = 0; mm < pPtVProfileLastPart->size(); mm++)
2224 for (
unsigned int mm = 0; mm < pprVLineSegLastPart->size(); mm++)
2226 vector<pair<int, int>> prVTmp = pprVLineSegLastPart->at(mm);
2233 vector<int> nVProfsLineSeg;
2239 int nProf = pThisProfile->
nGetProf(nSeg, nCoinc);
2242 auto it = find(nVProf.begin(), nVProf.end(), nProf);
2244 if (it == nVProf.end())
2247 nVProf.push_back(nProf);
2248 nVProfsLineSeg.push_back(nProfsLineSeg);
2254 int nPos =
static_cast<int>(it - nVProf.begin());
2255 int nNewProfsLineSeg = nVProfsLineSeg[nPos];
2258 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, 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.
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 *)
void SetHitAnotherProfile(bool const)
Sets a switch which indicates whether this profile hits another profile badly.
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.
void SetHitIntervention(bool const)
Sets a switch which indicates whether this profile has hit an intervention.
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.
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 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...
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 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
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...
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,...
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 LocateAndCreateProfiles(int const, int &, 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...
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...
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)
int nCheckAllProfiles(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 RTN_ERR_COAST_CANT_FIND_EDGE_CELL
int const DIRECTION_DOWNCOAST
bool const ACCEPT_TRUNCATED_PROFILES
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
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.