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
12
13/* ===============================================================================================================================
14
15 This file is part of CoastalME, the Coastal Modelling Environment.
16
17 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.
18
19 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.
20
21 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.
22
23===============================================================================================================================*/
24#include <assert.h>
25
26#include <cstdio>
27#include <cmath>
28
29#include <vector>
30using std::vector;
31
32#include <algorithm>
33using std::find;
34
35#include "cme.h"
36#include "cell.h"
37#include "2d_point.h"
38#include "2di_point.h"
39#include "multi_line.h"
40#include "raster_grid.h"
41#include "profile.h"
42
44CGeomProfile::CGeomProfile(int const nCoast, int const nCoastPoint, int const nProfileID, CGeom2DIPoint const* pPtiStart, CGeom2DIPoint const* pPtiEnd, bool const bIntervention)
45 : m_bStartOfCoast(false),
46 m_bEndOfCoast(false),
47 m_bCShoreProblem(false),
48 m_bHitLand(false),
49 m_bHitIntervention(false),
50 m_bHitCoast(false),
51 m_bTooShort(false),
54 m_bIntervention(bIntervention),
55 m_nCoast(nCoast),
56 m_nCoastPoint(nCoastPoint),
57 m_nProfileID(nProfileID),
61 PtiStart(*pPtiStart),
62 PtiEnd(*pPtiEnd),
65{
66}
67
72
75{
76 return m_nCoast;
77}
78
81{
82 return m_nProfileID;
83}
84
87{
88 return m_nCoastPoint;
89}
90
96
99{
100 PtiEnd = *pPtiEnd;
101}
102
108
110void CGeomProfile::SetStartOfCoast(bool const bFlag)
111{
112 m_bStartOfCoast = bFlag;
113}
114
117{
118 return m_bStartOfCoast;
119}
120
122void CGeomProfile::SetEndOfCoast(bool const bFlag)
123{
124 m_bEndOfCoast = bFlag;
125}
126
129{
130 return m_bEndOfCoast;
131}
132
134void CGeomProfile::SetCShoreProblem(bool const bFlag)
135{
136 m_bCShoreProblem = bFlag;
137}
138
141{
142 return m_bCShoreProblem;
143}
144
146void CGeomProfile::SetHitLand(bool const bFlag)
147{
148 m_bHitLand = bFlag;
149}
150
153{
154 return m_bHitLand;
155}
156
159{
160 m_bHitIntervention = bFlag;
161}
162
165{
166 return m_bHitIntervention;
167}
168
170void CGeomProfile::SetHitCoast(bool const bFlag)
171{
172 m_bHitCoast = bFlag;
173}
174
177{
178 return m_bHitCoast;
179}
180
182void CGeomProfile::SetTooShort(bool const bFlag)
183{
184 m_bTooShort = bFlag;
185}
186
189{
190 return m_bTooShort;
191}
192
195{
196 m_bTruncatedSameCoast = bFlag;
197}
198
201{
203}
204
207{
209}
210
216
219{
220 m_bHitAnotherProfile = bFlag;
221}
222
225{
227}
228
231{
232 // All profiles without problems, but not start- or end-of-coast profiles
233 if ((! m_bStartOfCoast) &&
234 (! m_bEndOfCoast) &&
235 (! m_bHitLand) &&
236 (! m_bHitIntervention) &&
237 (! m_bHitCoast) &&
238 (! m_bTooShort) &&
242 return true;
243
244 return false;
245}
246
249{
250 // All profiles without problems, but not start- or end-of-coast profiles
251 if ((! m_bStartOfCoast) &&
252 (! m_bEndOfCoast) &&
253 (! m_bHitLand) &&
254 (! m_bHitIntervention) &&
255 (! m_bHitCoast) &&
256 (! m_bTooShort) &&
259 return true;
260
261 return false;
262}
263
266{
267 // All profiles without problems, including start- and end-of-coast profiles
268 if ((! m_bHitLand) &&
269 (! m_bHitIntervention) &&
270 (! m_bHitCoast) &&
271 (! m_bTooShort) &&
275 return true;
276
277 return false;
278}
279
280// //! Returns true if this is a problem-free profile (however it could still be a start-of-coast profile)
281// bool CGeomProfile::bOKIncStartOfCoast(void) const
282// {
283// // All profiles without problems, including start-of-coast profile (but not end-of-coast profile)
284// if ((! m_bEndOfCoast) &&
285// (! m_bHitLand) &&
286// (! m_bHitIntervention) &&
287// (! m_bHitCoast) &&
288// (! m_bTooShort) &&
289// (! m_bTruncatedSameCoast) &&
290// (! m_bHitAnotherProfile))
291// return true;
292//
293// return false;
294// }
295
297void CGeomProfile::SetPointsInProfile(vector<CGeom2DPoint> const* VNewPoints)
298{
299 CGeomMultiLine::m_VPoints = *VNewPoints;
300}
301
303void CGeomProfile::SetPointInProfile(int const nPoint, double const dNewX, double const dNewY)
304{
305 // TODO 055 No check to see if nPoint < CGeomMultiLine::m_VPoints,size()
306 CGeomMultiLine::m_VPoints[nPoint] = CGeom2DPoint(dNewX, dNewY);
307}
308
310void CGeomProfile::AppendPointInProfile(double const dNewX, double const dNewY)
311{
312 CGeomMultiLine::m_VPoints.push_back(CGeom2DPoint(dNewX, dNewY));
313}
314
317{
318 CGeomMultiLine::m_VPoints.push_back(*pPt);
319}
320
322bool CGeomProfile::bInsertIntersection(double const dX, double const dY, int const nSeg)
323{
324 // Safety check
325 if (nSeg >= nGetNumLineSegments())
326 return false;
327
329 it = CGeomMultiLine::m_VPoints.begin();
330
331 // Do the insertion
332 CGeomMultiLine::m_VPoints.insert(it + nSeg + 1, CGeom2DPoint(dX, dY));
333
334 // Now insert a line segment in the associated multi-line, this will inherit the profile/line seg details from the preceding line segment
336
337 return true;
338}
339
341void CGeomProfile::TruncateProfile(int const nSize)
342{
343 CGeomMultiLine::m_VPoints.resize(nSize);
344}
345
346// void CGeomProfile::TruncateAndSetPointInProfile(int const nPoint, double const dNewX, double const dNewY)
347// {
348// CGeomMultiLine::m_VPoints.resize(nPoint+1);
349// CGeomMultiLine::m_VPoints[nPoint] = CGeom2DPoint(dNewX, dNewY);
350// }
351
352// void CGeomProfile::ShowProfile(void) const
353// {
354// for (int n = 0; n < CGeomMultiLine::m_VPoints.size(); n++)
355// {
356// cout << n << " [" << CGeomMultiLine::m_VPoints[n].dGetX() << "][" << CGeomMultiLine::m_VPoints[n].dGetY() << "]" << endl;
357// }
358// }
359
362{
363 return static_cast<int>(CGeomMultiLine::m_VPoints.size());
364}
365
371
373vector<CGeom2DPoint> CGeomProfile::PtVGetThisPointAndAllAfter(int const nStart)
374{
375 return vector<CGeom2DPoint>(CGeomMultiLine::m_VPoints.begin() + nStart, CGeomMultiLine::m_VPoints.end());
376}
377
379// void CGeomProfile::RemoveLineSegment(int const nPoint)
380// {
381// m_VPoints.erase(CGeomMultiLine::m_VPoints.begin() + nPoint);
382// CGeomMultiLine::RemoveLineSegment(nPoint);
383// }
384
386bool CGeomProfile::bIsPointInProfile(double const dX, double const dY)
387{
388 CGeom2DPoint const Pt(dX, dY);
389 auto it = find(CGeomMultiLine::m_VPoints.begin(), CGeomMultiLine::m_VPoints.end(), &Pt);
390
391 if (it != CGeomMultiLine::m_VPoints.end())
392 return true;
393 else
394 return false;
395}
396
398bool CGeomProfile::bIsPointInProfile(double const dX, double const dY, int& nPoint)
399{
400 CGeom2DPoint const Pt(dX, dY);
401 auto it = find(CGeomMultiLine::m_VPoints.begin(), CGeomMultiLine::m_VPoints.end(), &Pt);
402
403 if (it != CGeomMultiLine::m_VPoints.end())
404 {
405 // Found, so return true and set nPoint to be the index of the point which was found
406 nPoint = static_cast<int>(it - CGeomMultiLine::m_VPoints.begin());
407 return true;
408 }
409
410 else
411 return false;
412}
413
414// int CGeomProfile::nFindInsertionLineSeg(double const dInsertX, double const dInsertY)
415// {
416// for (int n = 0; n < CGeomMultiLine::m_VPoints.back(); n++)
417// {
418// double
419// dThisX = CGeomMultiLine::m_VPoints[n].dGetX(),
420// dThisY = CGeomMultiLine::m_VPoints[n].dGetY(),
421// dNextX = CGeomMultiLine::m_VPoints[n+1].dGetX(),
422// dNextY = CGeomMultiLine::m_VPoints[n+1].dGetY();
423//
424// bool
425// bBetweenX = false,
426// bBetweenY = false;
427//
428// if (dNextX >= dThisX)
429// {
430// // Ascending
431// if ((dInsertX >= dThisX) && (dInsertX <= dNextX))
432// bBetweenX = true;
433// }
434// else
435// {
436// // Descending
437// if ((dInsertX >= dNextX) && (dInsertX <= dThisX))
438// bBetweenX = true;
439// }
440//
441// if (dNextY >= dThisY)
442// {
443// // Ascending
444// if ((dInsertY >= dThisY) && (dInsertY <= dNextY))
445// bBetweenY = true;
446// }
447// else
448// {
449// // Descending
450// if ((dInsertY >= dNextY) && (dInsertY <= dThisY))
451// bBetweenY = true;
452// }
453//
454// if (bBetweenX && bBetweenY)
455// return n;
456// }
457//
458// return -1;
459// }
460
461// void CGeomProfile::AppendPointShared(bool const bShared)
462// {
463// m_bVShared.push_back(bShared);
464// }
465
466// bool CGeomProfile::bPointShared(int const n) const
467// {
468// // TODO 055 No check to see if n < size()
469// return m_bVShared[n];
470// }
471
477
483
489
495
498{
499 m_VCellInProfile.push_back(*pPti);
500}
501
503void CGeomProfile::AppendCellInProfile(int const nX, int const nY)
504{
505 m_VCellInProfile.push_back(CGeom2DIPoint(nX, nY));
506}
507
509void CGeomProfile::SetCellsInProfile(vector<CGeom2DIPoint>* VNewPoints)
510{
511 m_VCellInProfile = *VNewPoints;
512}
513
515vector<CGeom2DIPoint>* CGeomProfile::pPtiVGetCellsInProfile(void)
516{
517 return &m_VCellInProfile;
518}
519
522{
523 // TODO 055 No check to see if n < size()
524 return &m_VCellInProfile[n];
525}
526
529{
530 // In grid CRS
531 return &m_VCellInProfile.back();
532}
533
536{
537 return static_cast<int>(m_VCellInProfile.size());
538}
539
541int CGeomProfile::nGetCellGivenDepth(CGeomRasterGrid const* pGrid, double const dDepthIn)
542{
543 int nIndex = INT_NODATA; // If not found, i.e. if every profile cell has sea depth less than dDepthIn
544
545 for (unsigned int n = 0; n < m_VCellInProfile.size(); n++)
546 {
547 int const nX = m_VCellInProfile[n].nGetX();
548 int const nY = m_VCellInProfile[n].nGetY();
549
550 double const dCellDepth = pGrid->m_Cell[nX][nY].dGetSeaDepth();
551
552 if (dCellDepth >= dDepthIn)
553 {
554 nIndex = n;
555
556 if (n > 0)
557 nIndex = n - 1; // Grid CRS units
558
559 break;
560 }
561 }
562
563 return nIndex;
564}
565
568{
569 m_dDeepWaterWaveHeight = dWaveHeight;
570}
571
577
580{
581 m_dDeepWaterWaveAngle = dWaveAngle;
582}
583
589
592{
593 m_dDeepWaterWavePeriod = dWavePeriod;
594}
595
601
604{
605 return m_bIntervention;
606}
607
609int CGeomProfile::nGetIndexOfCellInProfile(int const nX, int const nY)
610{
611 for (unsigned int n = 0; n < m_VCellInProfile.size(); n++)
612 {
613 if ((m_VCellInProfile[n].nGetX() == nX) && (m_VCellInProfile[n].nGetY() == nY))
614 return n;
615 }
616
617 return INT_NODATA;
618}
619
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:39
Geometry class used to represent 2D point objects with integer coordinates.
Definition 2di_point.h:29
Geometry class used to represent 2D point objects with floating-point coordinates.
Definition 2d_point.h:27
double dGetSeaDepth(void) const
Returns the depth of seawater on this cell.
Definition cell.cpp:503
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:40
void TruncateProfile(int const)
Truncates the profile's CGeomLine (external CRS points)
Definition profile.cpp:341
int m_nCoastPoint
The coastline point at which this profile hits the coast (not necessarily coincident wih the profile ...
Definition profile.h:76
double m_dDeepWaterWaveHeight
The wave height at the end of the profile.
Definition profile.h:82
CGeomProfile * m_pUpCoastAdjacentProfile
Pointer to the adjacent up-coast profile (may be an invalid profile)
Definition profile.h:97
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:541
void SetEndOfCoast(bool const)
Sets a switch to indicate whether this is an end-of-coast profile.
Definition profile.cpp:122
bool m_bHitCoast
Has this profile hit a coastline?
Definition profile.h:55
void AppendPointInProfile(double const, double const)
Appends a point (external CRS) to the profile.
Definition profile.cpp:310
double dGetProfileDeepWaterWaveAngle(void) const
Returns the deep-water wave orientation for this profile.
Definition profile.cpp:585
CGeomProfile(int const, int const, int const, CGeom2DIPoint const *, CGeom2DIPoint const *, bool const)
In external CRS, the coords of cells 'under' this profile (has the same length as m_VCellInProfile)
Definition profile.cpp:44
double dGetProfileDeepWaterWaveHeight(void) const
Returns the deep-water wave height for this profile.
Definition profile.cpp:573
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:79
int nGetProfileID(void) const
Returns the profile's this-coast ID.
Definition profile.cpp:80
int nGetCoastPoint(void) const
Returns the coast point at which the profile starts.
Definition profile.cpp:86
void SetProfileDeepWaterWavePeriod(double const)
Sets the deep-water wave period for this profile.
Definition profile.cpp:591
bool m_bIntervention
Is this an intervention profile?
Definition profile.h:70
bool bIsPointInProfile(double const, double const)
Removes a line segment from the profile.
Definition profile.cpp:386
void SetHitCoast(bool const)
Sets a switch which indicates whether this profile has hit a coast.
Definition profile.cpp:170
CGeomProfile * m_pDownCoastAdjacentProfile
Pointer to the adjacent down-coast profile (may be an invalid profile)
Definition profile.h:100
int nGetCoast(void) const
Returns this profile's coast.
Definition profile.cpp:74
bool m_bCShoreProblem
Has this profile encountered a CShore problem?
Definition profile.h:46
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:248
bool m_bHitAnotherProfile
Has this profile hit another profile?
Definition profile.h:67
void SetStartOfCoast(bool const)
Sets a switch to indicate whether this is a start-of-coast profile.
Definition profile.cpp:110
CGeomProfile * pGetUpCoastAdjacentProfile(void) const
Returns the up-coast adjacent profile, returns NULL if there is no up-coast adjacent profile.
Definition profile.cpp:479
CGeomProfile * pGetDownCoastAdjacentProfile(void) const
Returns the down-coast adjacent profile, returns NULL if there is no down-coast adjacent profile.
Definition profile.cpp:491
void SetUpCoastAdjacentProfile(CGeomProfile *)
Sets the up-coast adjacent profile.
Definition profile.cpp:473
double m_dDeepWaterWaveAngle
The wave orientation at the end of the profile.
Definition profile.h:85
bool bTruncatedDifferentCoast(void) const
Returns the switch which indicates whether this profile has been truncated, due to hitting another pr...
Definition profile.cpp:212
CGeom2DIPoint * pPtiGetCellInProfile(int const)
Returns a single cell (grid CRS) in the profile.
Definition profile.cpp:521
void SetHitAnotherProfile(bool const)
Sets a switch which indicates whether this profile hits another profile badly.
Definition profile.cpp:218
vector< CGeom2DPoint > PtVGetThisPointAndAllAfter(int const)
Returns a given external CRS point from the profile, and all points after this.
Definition profile.cpp:373
bool bHitAnotherProfile(void) const
Returns the switch which indicates whether this profile hits another profile badly.
Definition profile.cpp:224
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:322
CGeom2DIPoint PtiEnd
The seaward end point of the profile in grid CRS.
Definition profile.h:94
bool m_bTruncatedDifferentCoast
Has this profile been truncated by hitting another profile from a different coast?
Definition profile.h:64
bool bHitLand(void) const
Returns the switch which indicates whether this profile has hit land.
Definition profile.cpp:152
void SetTruncatedSameCoast(bool const)
Sets a switch which indicates whether this profile is truncated, due to hitting another profile from ...
Definition profile.cpp:194
CGeom2DIPoint PtiStart
The on-coast start point of the profile in grid CRS.
Definition profile.h:91
int nGetNumCellsInProfile(void) const
Returns the number of cells in the profile.
Definition profile.cpp:535
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:103
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:230
void SetProfileDeepWaterWaveHeight(double const)
Sets the deep-water wave height for this profile.
Definition profile.cpp:567
bool bTooShort(void) const
Returns the switch which indicates whether this profile is too short to be useful.
Definition profile.cpp:188
void SetDownCoastAdjacentProfile(CGeomProfile *)
Sets the down-coast adjacent profile.
Definition profile.cpp:485
bool bHitCoast(void) const
Returns the switch which indicates whether this profile has hit a coast.
Definition profile.cpp:176
bool bIsIntervention(void) const
Returns true if this is an intervention profile.
Definition profile.cpp:603
void SetHitIntervention(bool const)
Sets a switch which indicates whether this profile has hit an intervention.
Definition profile.cpp:158
bool m_bEndOfCoast
Is this an end-of-coast profile?
Definition profile.h:43
~CGeomProfile(void) override
Destructor.
Definition profile.cpp:69
CGeom2DIPoint * pPtiGetEndPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile ends.
Definition profile.cpp:104
void SetCShoreProblem(bool const)
Sets a switch to indicate whether this profile has a CShore problem.
Definition profile.cpp:134
CGeom2DPoint * pPtGetPointInProfile(int const)
Returns a single point (external CRS) from the profile.
Definition profile.cpp:367
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:265
void AppendCellInProfile(CGeom2DIPoint const *)
Appends a cell (grid CRS) to the profile.
Definition profile.cpp:497
void SetPointInProfile(int const, double const, double const)
Sets a single point (external CRS) in the profile.
Definition profile.cpp:303
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:361
CGeom2DIPoint * pPtiGetStartPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile starts.
Definition profile.cpp:92
bool m_bTooShort
Is this profile too short?
Definition profile.h:58
bool bStartOfCoast(void) const
Returns the switch to indicate whether this is a start-of-coast profile.
Definition profile.cpp:116
bool bTruncatedSameCoast(void) const
Returns the switch which indicates whether this profile has been truncated, due to hitting another pr...
Definition profile.cpp:200
void SetEndPoint(CGeom2DIPoint const *)
Sets the the location of the cell (grid CRS) on which the profile ends.
Definition profile.cpp:98
void SetHitLand(bool const)
Sets a switch which indicates whether this profile has hit land.
Definition profile.cpp:146
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:297
int m_nCoast
The coast from which this profile projects.
Definition profile.h:73
vector< CGeom2DIPoint > * pPtiVGetCellsInProfile(void)
Returns all cells (grid CRS) in the profile.
Definition profile.cpp:515
CGeom2DIPoint * pPtiGetLastCellInProfile(void)
Returns the last cell (grid CRS) in the profile.
Definition profile.cpp:528
void SetCellsInProfile(vector< CGeom2DIPoint > *)
Sets the profile's vector of cells (grid CRS)
Definition profile.cpp:509
bool m_bHitIntervention
Has this profile hit an intervention?
Definition profile.h:52
void SetTruncatedDifferentCoast(bool const)
Sets a switch which indicates whether this profile is truncated, due to hitting another profile from ...
Definition profile.cpp:206
bool m_bTruncatedSameCoast
Has this profile been truncated by hitting another profile from the same coast?
Definition profile.h:61
double m_dDeepWaterWavePeriod
The wave period at the end of the profile.
Definition profile.h:88
int nGetIndexOfCellInProfile(int const, int const)
Returns the index of a given cell in the vector of profile cells; returns INT_NODATA if not found.
Definition profile.cpp:609
bool bEndOfCoast(void) const
Returns the switch to indicate whether this is an end-of-coast profile.
Definition profile.cpp:128
double dGetProfileDeepWaterWavePeriod(void) const
Returns the deep-water wave period for this profile.
Definition profile.cpp:597
bool bCShoreProblem(void) const
Returns the switch which indicates whether this profile has a CShore problem.
Definition profile.cpp:140
bool bHitIntervention(void) const
Returns the switch which indicates whether this profile has hit an intervention.
Definition profile.cpp:164
void SetProfileDeepWaterWaveAngle(double const)
Sets the deep-water wave orientation for this profile.
Definition profile.cpp:579
bool m_bHitLand
Has this profile hit land?
Definition profile.h:49
void SetTooShort(bool const)
Sets a switch which indicates whether this profile is too short to be useful.
Definition profile.cpp:182
Geometry cass used to represent the raster grid of cell objects.
Definition raster_grid.h:33
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:54
STL iterator class.
This file contains global definitions for CoastalME.
int const INT_NODATA
Definition cme.h:476
Contains CGeomMultiLine definitions.
Contains CGeomProfile definitions.
Contains CGeomRasterGrid definitions.