CoastalME (Coastal Modelling Environment)
Simulates the long-term behaviour of complex coastlines
Loading...
Searching...
No Matches
profile.cpp
Go to the documentation of this file.
1
10
11/* ===============================================================================================================================
12 This file is part of CoastalME, the Coastal Modelling Environment.
13
14 CoastalME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19===============================================================================================================================*/
20#include <assert.h>
21
22#include <cstdio>
23
24#include <vector>
25using std::vector;
26
27#include <algorithm>
28using std::find;
29
30#include "cme.h"
31#include "cell.h"
32#include "2d_point.h"
33#include "2di_point.h"
34#include "multi_line.h"
35#include "raster_grid.h"
36#include "profile.h"
37
39CGeomProfile::CGeomProfile(int const nCoast, int const nCoastPoint, int const nProfileID, bool const bIntervention)
40 : m_bStartOfCoast(false),
41 m_bEndOfCoast(false),
42 m_bCShoreProblem(false),
43 m_bHitLand(false),
44 m_bHitIntervention(false),
45 m_bHitCoast(false),
46 m_bTooShort(false),
50 m_bIntervention(bIntervention),
51 m_nCoast(nCoast),
52 m_nCoastPoint(nCoastPoint),
53 m_nProfileID(nProfileID),
59{
60}
61
66
69{
70 return m_nCoast;
71}
72
75{
76 return m_nProfileID;
77}
78
81{
82 return m_nCoastPoint;
83}
84
90
96
98void CGeomProfile::SetStartOfCoast(bool const bFlag)
99{
100 m_bStartOfCoast = bFlag;
101}
102
105{
106 return m_bStartOfCoast;
107}
108
110void CGeomProfile::SetEndOfCoast(bool const bFlag)
111{
112 m_bEndOfCoast = bFlag;
113}
114
117{
118 return m_bEndOfCoast;
119}
120
123{
125 return true;
126
127 return false;
128}
129
131void CGeomProfile::SetCShoreProblem(bool const bFlag)
132{
133 m_bCShoreProblem = bFlag;
134}
135
138{
139 return m_bCShoreProblem;
140}
141
143void CGeomProfile::SetHitLand(bool const bFlag)
144{
145 m_bHitLand = bFlag;
146}
147
150{
151 return m_bHitLand;
152}
153
156{
157 m_bHitIntervention = bFlag;
158}
159
162{
163 return m_bHitIntervention;
164}
165
167void CGeomProfile::SetHitCoast(bool const bFlag)
168{
169 m_bHitCoast = bFlag;
170}
171
174{
175 return m_bHitCoast;
176}
177
179void CGeomProfile::SetTooShort(bool const bFlag)
180{
181 m_bTooShort = bFlag;
182}
183
186{
187 return m_bTooShort;
188}
189
192{
193 m_bTruncatedSameCoast = bFlag;
194}
195
198{
200}
201
204{
206}
207
213
216{
217 m_bHitAnotherProfile = bFlag;
218}
219
222{
224}
225
228{
229 // All profiles without problems, but not start- or end-of-coast profiles
230 if ((! m_bStartOfCoast) &&
231 (! m_bEndOfCoast) &&
232 (! m_bHitLand) &&
233 (! m_bHitIntervention) &&
234 (! m_bHitCoast) &&
235 (! m_bTooShort) &&
239 return true;
240
241 return false;
242}
243
246{
247 // All profiles without problems, but not start- or end-of-coast profiles
248 if ((! m_bStartOfCoast) &&
249 (! m_bEndOfCoast) &&
250 (! m_bHitLand) &&
251 (! m_bHitIntervention) &&
252 (! m_bHitCoast) &&
253 (! m_bTooShort) &&
256 return true;
257
258 return false;
259}
260
263{
264 // All profiles without problems, including start- and end-of-coast profiles
265 if ((! m_bHitLand) &&
266 (! m_bHitIntervention) &&
267 (! m_bHitCoast) &&
268 (! m_bTooShort) &&
272 return true;
273
274 return false;
275}
276
277// //! Returns true if this is a problem-free profile (however it could still be a start-of-coast profile)
278// bool CGeomProfile::bOKIncStartOfCoast(void) const
279// {
280// // All profiles without problems, including start-of-coast profile (but not end-of-coast profile)
281// if ((! m_bEndOfCoast) &&
282// (! m_bHitLand) &&
283// (! m_bHitIntervention) &&
284// (! m_bHitCoast) &&
285// (! m_bTooShort) &&
286// (! m_bTruncatedSameCoast) &&
287// (! m_bHitAnotherProfile))
288// return true;
289//
290// return false;
291// }
292
294void CGeomProfile::SetPointsInProfile(vector<CGeom2DPoint> const* VNewPoints)
295{
296 CGeomMultiLine::m_VPoints = *VNewPoints;
297}
298
300void CGeomProfile::SetPointInProfile(int const nPoint, double const dNewX, double const dNewY)
301{
302 // TODO 055 No check to see if nPoint < CGeomMultiLine::m_VPoints,size()
303 CGeomMultiLine::m_VPoints[nPoint] = CGeom2DPoint(dNewX, dNewY);
304}
305
307void CGeomProfile::AppendPointInProfile(double const dNewX, double const dNewY)
308{
309 CGeomMultiLine::m_VPoints.push_back(CGeom2DPoint(dNewX, dNewY));
310}
311
314{
315 CGeomMultiLine::m_VPoints.push_back(*pPt);
316}
317
319bool CGeomProfile::bInsertIntersection(double const dX, double const dY, int const nSeg)
320{
321 // Safety check
322 if (nSeg >= nGetNumLineSegments())
323 return false;
324
326 it = CGeomMultiLine::m_VPoints.begin();
327
328 // Do the insertion
329 CGeomMultiLine::m_VPoints.insert(it + nSeg + 1, CGeom2DPoint(dX, dY));
330
331 // Now insert a line segment in the associated multi-line, this will inherit the profile/line seg details from the preceding line segment
333
334 return true;
335}
336
338void CGeomProfile::TruncateProfile(int const nSize)
339{
340 CGeomMultiLine::m_VPoints.resize(nSize);
341}
342
343// void CGeomProfile::TruncateAndSetPointInProfile(int const nPoint, double const dNewX, double const dNewY)
344// {
345// CGeomMultiLine::m_VPoints.resize(nPoint+1);
346// CGeomMultiLine::m_VPoints[nPoint] = CGeom2DPoint(dNewX, dNewY);
347// }
348
349// void CGeomProfile::ShowProfile(void) const
350// {
351// for (int n = 0; n < CGeomMultiLine::m_VPoints.size(); n++)
352// {
353// cout << n << " [" << CGeomMultiLine::m_VPoints[n].dGetX() << "][" << CGeomMultiLine::m_VPoints[n].dGetY() << "]" << endl;
354// }
355// }
356
359{
360 return static_cast<int>(CGeomMultiLine::m_VPoints.size());
361}
362
368
370vector<CGeom2DPoint> CGeomProfile::PtVGetThisPointAndAllAfter(int const nStart)
371{
372 return vector<CGeom2DPoint>(CGeomMultiLine::m_VPoints.begin() + nStart, CGeomMultiLine::m_VPoints.end());
373}
374
376// void CGeomProfile::RemoveLineSegment(int const nPoint)
377// {
378// m_VPoints.erase(CGeomMultiLine::m_VPoints.begin() + nPoint);
379// CGeomMultiLine::RemoveLineSegment(nPoint);
380// }
381
383bool CGeomProfile::bIsPointInProfile(double const dX, double const dY)
384{
385 CGeom2DPoint const Pt(dX, dY);
386 auto it = find(CGeomMultiLine::m_VPoints.begin(), CGeomMultiLine::m_VPoints.end(), &Pt);
387
388 if (it != CGeomMultiLine::m_VPoints.end())
389 return true;
390 else
391 return false;
392}
393
395bool CGeomProfile::bIsPointInProfile(double const dX, double const dY, int& nPoint)
396{
397 CGeom2DPoint const Pt(dX, dY);
398 auto it = find(CGeomMultiLine::m_VPoints.begin(), CGeomMultiLine::m_VPoints.end(), &Pt);
399
400 if (it != CGeomMultiLine::m_VPoints.end())
401 {
402 // Found, so return true and set nPoint to be the index of the point which was found
403 nPoint = static_cast<int>(it - CGeomMultiLine::m_VPoints.begin());
404 return true;
405 }
406
407 else
408 return false;
409}
410
411// int CGeomProfile::nFindInsertionLineSeg(double const dInsertX, double const dInsertY)
412// {
413// for (int n = 0; n < CGeomMultiLine::m_VPoints.back(); n++)
414// {
415// double
416// dThisX = CGeomMultiLine::m_VPoints[n].dGetX(),
417// dThisY = CGeomMultiLine::m_VPoints[n].dGetY(),
418// dNextX = CGeomMultiLine::m_VPoints[n+1].dGetX(),
419// dNextY = CGeomMultiLine::m_VPoints[n+1].dGetY();
420//
421// bool
422// bBetweenX = false,
423// bBetweenY = false;
424//
425// if (dNextX >= dThisX)
426// {
427// // Ascending
428// if ((dInsertX >= dThisX) && (dInsertX <= dNextX))
429// bBetweenX = true;
430// }
431// else
432// {
433// // Descending
434// if ((dInsertX >= dNextX) && (dInsertX <= dThisX))
435// bBetweenX = true;
436// }
437//
438// if (dNextY >= dThisY)
439// {
440// // Ascending
441// if ((dInsertY >= dThisY) && (dInsertY <= dNextY))
442// bBetweenY = true;
443// }
444// else
445// {
446// // Descending
447// if ((dInsertY >= dNextY) && (dInsertY <= dThisY))
448// bBetweenY = true;
449// }
450//
451// if (bBetweenX && bBetweenY)
452// return n;
453// }
454//
455// return -1;
456// }
457
458// void CGeomProfile::AppendPointShared(bool const bShared)
459// {
460// m_bVShared.push_back(bShared);
461// }
462
463// bool CGeomProfile::bPointShared(int const n) const
464// {
465// // TODO 055 No check to see if n < size()
466// return m_bVShared[n];
467// }
468
474
475// //! Returns the up-coast adjacent profile, returns NULL if there is no up-coast adjacent profile
476// CGeomProfile* CGeomProfile::pGetUpCoastAdjacentProfile(void) const
477// {
478// return m_pUpCoastAdjacentProfile;
479// }
480
486
492
495{
496 m_VCellInProfile.push_back(*pPti);
497}
498
500void CGeomProfile::AppendCellInProfile(int const nX, int const nY)
501{
502 m_VCellInProfile.push_back(CGeom2DIPoint(nX, nY));
503}
504
506void CGeomProfile::SetCellsInProfile(vector<CGeom2DIPoint> const* VNewPoints)
507{
508 m_VCellInProfile = *VNewPoints;
509}
510
512vector<CGeom2DIPoint>* CGeomProfile::pPtiVGetCellsInProfile(void)
513{
514 return &m_VCellInProfile;
515}
516
519{
520 // TODO 055 No check to see if n < size()
521 return &m_VCellInProfile[n];
522}
523
526{
527 // In grid CRS
528 return &m_VCellInProfile.back();
529}
530
533{
534 // In grid CRS
535 return &m_VCellInProfile.front();
536}
537
540{
541 return static_cast<int>(m_VCellInProfile.size());
542}
543
545int CGeomProfile::nGetCellGivenDepth(CGeomRasterGrid const* pGrid, double const dDepthIn)
546{
547 int nIndex = INT_NODATA; // If not found, i.e. if every profile cell has sea depth less than dDepthIn
548
549 for (unsigned int n = 0; n < m_VCellInProfile.size(); n++)
550 {
551 int const nX = m_VCellInProfile[n].nGetX();
552 int const nY = m_VCellInProfile[n].nGetY();
553
554 double const dCellDepth = pGrid->m_Cell[nX][nY].dGetSeaDepth();
555
556 if (dCellDepth >= dDepthIn)
557 {
558 nIndex = n;
559
560 if (n > 0)
561 nIndex = n - 1; // Grid CRS units
562
563 break;
564 }
565 }
566
567 return nIndex;
568}
569
572{
573 m_dDeepWaterWaveHeight = dWaveHeight;
574}
575
581
584{
585 m_dDeepWaterWaveAngle = dWaveAngle;
586}
587
593
596{
597 m_dDeepWaterWavePeriod = dWavePeriod;
598}
599
605
608{
609 return m_bIntervention;
610}
611
612// //! Returns the index of a given cell in the vector of profile cells; returns INT_NODATA if not found
613// int CGeomProfile::nGetIndexOfCellInProfile(int const nX, int const nY)
614// {
615// for (unsigned int n = 0; n < m_VCellInProfile.size(); n++)
616// {
617// if ((m_VCellInProfile[n].nGetX() == nX) && (m_VCellInProfile[n].nGetY() == nY))
618// return n;
619// }
620//
621// return INT_NODATA;
622// }
623
Contains CGeom2DPoint definitions.
Contains CGeom2DIPoint definitions.
Contains CGeomCell definitions.
vector< CGeom2DPoint > m_VPoints
The points which comprise the float-coordinate 2D shape.
Definition 2d_shape.h:37
Geometry class used to represent 2D point objects with integer coordinates.
Definition 2di_point.h:25
Geometry class used to represent 2D point objects with floating-point coordinates.
Definition 2d_point.h:25
double dGetSeaDepth(void) const
Returns the depth of seawater on this cell.
Definition cell.cpp:513
void InsertLineSegment(int const)
Inserts a line segment, inheriting from preceding line segments.
int nGetNumLineSegments(void) const
Appends a line segment which then inherits from the preceding line segments.
bool m_bStartOfCoast
Is this a start-of-coast profile?
Definition profile.h:36
void TruncateProfile(int const)
Truncates the profile's CGeomLine (external CRS points)
Definition profile.cpp:338
int m_nCoastPoint
The coastline point at which this profile hits the coast (not necessarily coincident wih the profile ...
Definition profile.h:72
double m_dDeepWaterWaveHeight
The wave height at the end of the profile.
Definition profile.h:78
CGeomProfile * m_pUpCoastAdjacentProfile
Pointer to the adjacent up-coast profile (may be an invalid profile)
Definition profile.h:87
int nGetCellGivenDepth(CGeomRasterGrid const *, double const)
Returns the index of the cell on this profile which has a sea depth which is just less than a given d...
Definition profile.cpp:545
void SetEndOfCoast(bool const)
Sets a switch to indicate whether this is an end-of-coast profile.
Definition profile.cpp:110
bool m_bHitCoast
Has this profile hit a coastline?
Definition profile.h:51
void AppendPointInProfile(double const, double const)
Appends a point (external CRS) to the profile.
Definition profile.cpp:307
void SetCellsInProfile(vector< CGeom2DIPoint > const *)
Sets the profile's vector of cells (grid CRS)
Definition profile.cpp:506
double dGetProfileDeepWaterWaveAngle(void) const
Returns the deep-water wave orientation for this profile.
Definition profile.cpp:589
double dGetProfileDeepWaterWaveHeight(void) const
Returns the deep-water wave height for this profile.
Definition profile.cpp:577
int m_nProfileID
The this-coast ID of the profile (note that a profile in a different coast may have the same ID as th...
Definition profile.h:75
int nGetProfileID(void) const
Returns the profile's this-coast ID.
Definition profile.cpp:74
CGeomProfile(int const, int const, int const, bool const)
In external CRS, the coords of cells 'under' this profile (has the same length as m_VCellInProfile)
Definition profile.cpp:39
int nGetCoastPoint(void) const
Returns the coast point at which the profile starts.
Definition profile.cpp:80
void SetProfileDeepWaterWavePeriod(double const)
Sets the deep-water wave period for this profile.
Definition profile.cpp:595
bool m_bIntervention
Is this an intervention profile?
Definition profile.h:66
bool bIsPointInProfile(double const, double const)
Removes a line segment from the profile.
Definition profile.cpp:383
void SetHitCoast(bool const)
Sets a switch which indicates whether this profile has hit a coast.
Definition profile.cpp:167
CGeomProfile * m_pDownCoastAdjacentProfile
Pointer to the adjacent down-coast profile (may be an invalid profile)
Definition profile.h:90
bool m_bCShoreProblem
Has this profile encountered a CShore problem?
Definition profile.h:42
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...
Definition profile.cpp:245
bool m_bHitAnotherProfile
Has this profile hit another profile?
Definition profile.h:63
void SetStartOfCoast(bool const)
Sets a switch to indicate whether this is a start-of-coast profile.
Definition profile.cpp:98
CGeomProfile * pGetDownCoastAdjacentProfile(void) const
Returns the down-coast adjacent profile, returns NULL if there is no down-coast adjacent profile.
Definition profile.cpp:488
void SetUpCoastAdjacentProfile(CGeomProfile *)
Sets the up-coast adjacent profile.
Definition profile.cpp:470
double m_dDeepWaterWaveAngle
The wave orientation at the end of the profile.
Definition profile.h:81
bool bTruncatedDifferentCoast(void) const
Returns the switch which indicates whether this profile has been truncated, due to hitting another pr...
Definition profile.cpp:209
CGeom2DIPoint * pPtiGetCellInProfile(int const)
Returns a single cell (grid CRS) in the profile.
Definition profile.cpp:518
void SetHitAnotherProfile(bool const)
Sets a switch which indicates whether this profile hits another profile badly.
Definition profile.cpp:215
vector< CGeom2DPoint > PtVGetThisPointAndAllAfter(int const)
Returns a given external CRS point from the profile, and all points after this.
Definition profile.cpp:370
bool bHitAnotherProfile(void) const
Returns the switch which indicates whether this profile hits another profile badly.
Definition profile.cpp:221
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.
Definition profile.cpp:319
bool m_bTruncatedDifferentCoast
Has this profile been truncated by hitting another profile from a different coast?
Definition profile.h:60
bool bHitLand(void) const
Returns the switch which indicates whether this profile has hit land.
Definition profile.cpp:149
bool bIsGridEdge(void) const
Returns true if this is a start-of-coast or an end-of-coast profile.
Definition profile.cpp:122
void SetTruncatedSameCoast(bool const)
Sets a switch which indicates whether this profile is truncated, due to hitting another profile from ...
Definition profile.cpp:191
int nGetNumCellsInProfile(void) const
Returns the number of cells in the profile.
Definition profile.cpp:539
vector< CGeom2DIPoint > m_VCellInProfile
In the grid CRS, the integer coordinates of the cells 'under' this profile, point zero is the same as...
Definition profile.h:93
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...
Definition profile.cpp:227
void SetProfileDeepWaterWaveHeight(double const)
Sets the deep-water wave height for this profile.
Definition profile.cpp:571
bool bTooShort(void) const
Returns the switch which indicates whether this profile is too short to be useful.
Definition profile.cpp:185
void SetDownCoastAdjacentProfile(CGeomProfile *)
Sets the down-coast adjacent profile.
Definition profile.cpp:482
bool bHitCoast(void) const
Returns the switch which indicates whether this profile has hit a coast.
Definition profile.cpp:173
bool bIsIntervention(void) const
Returns true if this is an intervention profile.
Definition profile.cpp:607
void SetHitIntervention(bool const)
Sets a switch which indicates whether this profile has hit an intervention.
Definition profile.cpp:155
bool m_bEndOfCoast
Is this an end-of-coast profile?
Definition profile.h:39
~CGeomProfile(void) override
Destructor.
Definition profile.cpp:63
CGeom2DIPoint * pPtiGetEndPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile ends.
Definition profile.cpp:92
void SetCShoreProblem(bool const)
Sets a switch to indicate whether this profile has a CShore problem.
Definition profile.cpp:131
CGeom2DPoint * pPtGetPointInProfile(int const)
Returns a single point (external CRS) from the profile.
Definition profile.cpp:364
bool bOKIncStartAndEndOfCoast(void) const
Returns true if this is a problem-free profile (however it could be a start-of-coast or an end-of-coa...
Definition profile.cpp:262
int nGetCoastID(void) const
Returns this profile's coast ID.
Definition profile.cpp:68
void AppendCellInProfile(CGeom2DIPoint const *)
Appends a cell (grid CRS) to the profile.
Definition profile.cpp:494
void SetPointInProfile(int const, double const, double const)
Sets a single point (external CRS) in the profile.
Definition profile.cpp:300
int nGetProfileSize(void) const
Returns the number of external CRS points in the profile (only two, initally; and always just two for...
Definition profile.cpp:358
CGeom2DIPoint * pPtiGetStartPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile starts.
Definition profile.cpp:86
bool m_bTooShort
Is this profile too short?
Definition profile.h:54
bool bStartOfCoast(void) const
Returns the switch to indicate whether this is a start-of-coast profile.
Definition profile.cpp:104
bool bTruncatedSameCoast(void) const
Returns the switch which indicates whether this profile has been truncated, due to hitting another pr...
Definition profile.cpp:197
void SetHitLand(bool const)
Sets a switch which indicates whether this profile has hit land.
Definition profile.cpp:143
void SetPointsInProfile(vector< CGeom2DPoint > const *)
Sets points (external CRS) in the profile. Note that only two points, the start and end point,...
Definition profile.cpp:294
CGeom2DIPoint * pPtiGetFirstCellInProfile(void)
Returns the first cell (grid CRS) in the profile.
Definition profile.cpp:532
int m_nCoast
The coast from which this profile projects.
Definition profile.h:69
vector< CGeom2DIPoint > * pPtiVGetCellsInProfile(void)
Returns all cells (grid CRS) in the profile.
Definition profile.cpp:512
CGeom2DIPoint * pPtiGetLastCellInProfile(void)
Returns the last cell (grid CRS) in the profile.
Definition profile.cpp:525
bool m_bHitIntervention
Has this profile hit an intervention?
Definition profile.h:48
void SetTruncatedDifferentCoast(bool const)
Sets a switch which indicates whether this profile is truncated, due to hitting another profile from ...
Definition profile.cpp:203
bool m_bTruncatedSameCoast
Has this profile been truncated by hitting another profile from the same coast?
Definition profile.h:57
double m_dDeepWaterWavePeriod
The wave period at the end of the profile.
Definition profile.h:84
bool bEndOfCoast(void) const
Returns the switch to indicate whether this is an end-of-coast profile.
Definition profile.cpp:116
double dGetProfileDeepWaterWavePeriod(void) const
Returns the deep-water wave period for this profile.
Definition profile.cpp:601
bool bCShoreProblem(void) const
Returns the switch which indicates whether this profile has a CShore problem.
Definition profile.cpp:137
bool bHitIntervention(void) const
Returns the switch which indicates whether this profile has hit an intervention.
Definition profile.cpp:161
void SetProfileDeepWaterWaveAngle(double const)
Sets the deep-water wave orientation for this profile.
Definition profile.cpp:583
bool m_bHitLand
Has this profile hit land?
Definition profile.h:45
void SetTooShort(bool const)
Sets a switch which indicates whether this profile is too short to be useful.
Definition profile.cpp:179
Geometry cass used to represent the raster grid of cell objects.
Definition raster_grid.h:29
CGeomCell ** m_Cell
The 2D array of m_Cell objects. A c-style 2D array seems to be faster than using 2D STL vectors.
Definition raster_grid.h:50
STL iterator class.
This file contains global definitions for CoastalME.
int const INT_NODATA
Definition cme.h:380
Contains CGeomMultiLine definitions.
Contains CGeomProfile definitions.
Contains CGeomRasterGrid definitions.