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
15This file is part of CoastalME, the Coastal Modelling Environment.
16
17CoastalME 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
19This 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
21You 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#include <cmath>
26
27#include <vector>
28
29#include <algorithm>
30using std::find;
31
32#include "cme.h"
33#include "profile.h"
34
36CGeomProfile::CGeomProfile(int const nCoast,int const nCoastPoint, int const nCoastID, int const nGlobalID, CGeom2DIPoint const* pPtiStart, CGeom2DIPoint const* pPtiEnd, bool const bIntervention)
37 : m_bStartOfCoast(false),
38 m_bEndOfCoast(false),
39 m_bCShoreProblem(false),
40 m_bHitLand(false),
41 m_bHitCoast(false),
42 m_bTooShort(false),
43 m_bTruncated(false),
45 m_bIntervention(bIntervention),
46 m_nCoast(nCoast),
47 m_nCoastPoint(nCoastPoint),
48 m_nCoastID(nCoastID),
49 m_nGlobalID(nGlobalID),
53 PtiStart(*pPtiStart),
54 PtiEnd(*pPtiEnd),
57{
58}
59
64
67{
68 return m_nCoastID;
69}
70
73{
74 return m_nGlobalID;
75}
76
79{
80 return m_nCoastPoint;
81}
82
88
91{
92 PtiEnd = *pPtiEnd;
93}
94
100
102void CGeomProfile::SetStartOfCoast(bool const bFlag)
103{
104 m_bStartOfCoast = bFlag;
105}
106
109{
110 return m_bStartOfCoast;
111}
112
114void CGeomProfile::SetEndOfCoast(bool const bFlag)
115{
116 m_bEndOfCoast = bFlag;
117}
118
121{
122 return m_bEndOfCoast;
123}
124
126void CGeomProfile::SetCShoreProblem(bool const bFlag)
127{
128 m_bCShoreProblem = bFlag;
129}
130
133{
134 return m_bCShoreProblem;
135}
136
138void CGeomProfile::SetHitLand(bool const bFlag)
139{
140 m_bHitLand = bFlag;
141}
142
145{
146 return m_bHitLand;
147}
148
150void CGeomProfile::SetHitCoast(bool const bFlag)
151{
152 m_bHitCoast = bFlag;
153}
154
157{
158 return m_bHitCoast;
159}
160
162void CGeomProfile::SetTooShort(bool const bFlag)
163{
164 m_bTooShort = bFlag;
165}
166
169{
170 return m_bTooShort;
171}
172
174void CGeomProfile::SetTruncated(bool const bFlag)
175{
176 m_bTruncated = bFlag;
177}
178
181{
182 return m_bTruncated;
183}
184
187{
189}
190
196
199{
200 // All profiles without problems, but not start- or end-of-coast profiles
201 if ((! m_bStartOfCoast) &&
202 (! m_bEndOfCoast) &&
203 (! m_bHitLand) &&
204 (! m_bHitCoast) &&
205 (! m_bTooShort) &&
206 (! m_bTruncated) &&
209 return true;
210
211 return false;
212}
213
216{
217 // All profiles without problems, but not start- or end-of-coast profiles
218 if ((! m_bStartOfCoast) &&
219 (! m_bEndOfCoast) &&
220 (! m_bHitLand) &&
221 (! m_bHitCoast) &&
222 (! m_bTooShort) &&
225 return true;
226
227 return false;
228}
229
232{
233 // All profiles without problems, including start- and end-of-coast profiles
234 if ((! m_bHitLand) &&
235 (! m_bHitCoast) &&
236 (! m_bTooShort) &&
237 (! m_bTruncated) &&
240 return true;
241
242 return false;
243}
244
245// //! Returns true if this is a problem-free profile (however it could still be a start-of-coast profile)
246// bool CGeomProfile::bOKIncStartOfCoast(void) const
247// {
248// // All profiles without problems, including start-of-coast profile (but not end-of-coast profile)
249// if ((! m_bEndOfCoast) &&
250// (! m_bHitLand) &&
251// (! m_bHitCoast) &&
252// (! m_bTooShort) &&
253// (! m_bTruncated) &&
254// (! m_bHitAnotherProfileBadly))
255// return true;
256//
257// return false;
258// }
259
261void CGeomProfile::SetPointsInProfile(vector<CGeom2DPoint> const* VNewPoints)
262{
263 m_VPoints = *VNewPoints;
264}
265
267void CGeomProfile::SetPointInProfile(int const nPoint, double const dNewX, double const dNewY)
268{
269 // TODO 055 No check to see if nPoint < m_VPoints,size()
270 m_VPoints[nPoint] = CGeom2DPoint(dNewX, dNewY);
271}
272
274void CGeomProfile::AppendPointInProfile(double const dNewX, double const dNewY)
275{
276 m_VPoints.push_back(CGeom2DPoint(dNewX, dNewY));
277}
278
281{
282 m_VPoints.push_back(*pPt);
283}
284
286bool CGeomProfile::bInsertIntersection(double const dX, double const dY, int const nSeg)
287{
288 // Safety check
289 if (nSeg >= nGetNumLineSegments())
290 return false;
291
293 it = m_VPoints.begin();
294
295 // Do the insertion
296 m_VPoints.insert(it + nSeg + 1, CGeom2DPoint(dX, dY));
297
298 // Now insert a line segment in the associated multi-line, this will inherit the profile/line seg details from the preceding line segment
300
301 return true;
302}
303
305void CGeomProfile::TruncateProfile(int const nSize)
306{
307 m_VPoints.resize(nSize);
308}
309
310// void CGeomProfile::TruncateAndSetPointInProfile(int const nPoint, double const dNewX, double const dNewY)
311// {
312// m_VPoints.resize(nPoint+1);
313// m_VPoints[nPoint] = CGeom2DPoint(dNewX, dNewY);
314// }
315
316// void CGeomProfile::ShowProfile(void) const
317// {
318// for (int n = 0; n < m_VPoints.size(); n++)
319// {
320// cout << n << " [" << m_VPoints[n].dGetX() << "][" << m_VPoints[n].dGetY() << "]" << endl;
321// }
322// }
323
326{
327 // return CGeomMultiLine::nGetSize();
328 return static_cast<int>(m_VPoints.size());
329}
330
333{
334 return &m_VPoints[n];
335}
336
338vector<CGeom2DPoint> CGeomProfile::PtVGetThisPointAndAllAfter(int const nStart)
339{
340 return vector<CGeom2DPoint>(m_VPoints.begin() + nStart, m_VPoints.end());
341}
342
344// void CGeomProfile::RemoveLineSegment(int const nPoint)
345// {
346// m_VPoints.erase(m_VPoints.begin() + nPoint);
347// CGeomMultiLine::RemoveLineSegment(nPoint);
348// }
349
351bool CGeomProfile::bIsPointInProfile(double const dX, double const dY)
352{
353 CGeom2DPoint Pt(dX, dY);
354 auto it = find(m_VPoints.begin(), m_VPoints.end(), &Pt);
355 if (it != m_VPoints.end())
356 return true;
357 else
358 return false;
359}
360
362bool CGeomProfile::bIsPointInProfile(double const dX, double const dY, int& nPoint)
363{
364 CGeom2DPoint Pt(dX, dY);
365 auto it = find(m_VPoints.begin(), m_VPoints.end(), &Pt);
366 if (it != m_VPoints.end())
367 {
368 // Found, so return true and set nPoint to be the index of the point which was found
369 nPoint = static_cast<int>(it - m_VPoints.begin());
370 return true;
371 }
372 else
373 return false;
374}
375
376// int CGeomProfile::nFindInsertionLineSeg(double const dInsertX, double const dInsertY)
377// {
378// for (int n = 0; n < m_VPoints.back(); n++)
379// {
380// double
381// dThisX = m_VPoints[n].dGetX(),
382// dThisY = m_VPoints[n].dGetY(),
383// dNextX = m_VPoints[n+1].dGetX(),
384// dNextY = m_VPoints[n+1].dGetY();
385//
386// bool
387// bBetweenX = false,
388// bBetweenY = false;
389//
390// if (dNextX >= dThisX)
391// {
392// // Ascending
393// if ((dInsertX >= dThisX) && (dInsertX <= dNextX))
394// bBetweenX = true;
395// }
396// else
397// {
398// // Descending
399// if ((dInsertX >= dNextX) && (dInsertX <= dThisX))
400// bBetweenX = true;
401// }
402//
403// if (dNextY >= dThisY)
404// {
405// // Ascending
406// if ((dInsertY >= dThisY) && (dInsertY <= dNextY))
407// bBetweenY = true;
408// }
409// else
410// {
411// // Descending
412// if ((dInsertY >= dNextY) && (dInsertY <= dThisY))
413// bBetweenY = true;
414// }
415//
416// if (bBetweenX && bBetweenY)
417// return n;
418// }
419//
420// return -1;
421// }
422
423// void CGeomProfile::AppendPointShared(bool const bShared)
424// {
425// m_bVShared.push_back(bShared);
426// }
427
428// bool CGeomProfile::bPointShared(int const n) const
429// {
430// // TODO 055 No check to see if n < size()
431// return m_bVShared[n];
432// }
433
438
443
448
453
456{
457 // In grid CRS
458 m_VCellInProfile.push_back(*pPti);
459}
460
462void CGeomProfile::AppendCellInProfile(int const nX, int const nY)
463{
464 // In grid CRS
465 m_VCellInProfile.push_back(CGeom2DIPoint(nX, nY));
466}
467
468// void CGeomProfile::SetCellsInProfile(vector<CGeom2DIPoint>* VNewPoints)
469// {
470// // In grid CRS
471// m_VCellInProfile = *VNewPoints;
472// }
473
475vector<CGeom2DIPoint>* CGeomProfile::pPtiVGetCellsInProfile(void)
476{
477 // In grid CRS
478 return &m_VCellInProfile;
479}
480
483{
484 // In grid CRS TODO 055 No check to see if n < size()
485 return &m_VCellInProfile[n];
486}
487
490{
491 // In grid CRS
492 return static_cast<int>(m_VCellInProfile.size());
493}
494
495// vector<CGeom2DPoint>* CGeomProfile::PtVGetCellsInProfileExtCRS(void)
496// {
497// // In external CRS
498// return &m_VCellInProfileExtCRS;
499// }
500
502void CGeomProfile::AppendCellInProfileExtCRS(double const dX, double const dY)
503{
504 // In external CRS
505 m_VCellInProfileExtCRS.push_back(CGeom2DPoint(dX, dY));
506}
507
510{
511 // In external CRS
512 m_VCellInProfileExtCRS.push_back(*pPt);
513}
514
516int CGeomProfile::nGetCellGivenDepth(CGeomRasterGrid const* pGrid, double const dDepthIn)
517{
518 int nIndex = INT_NODATA; // If not found, i.e. if every profile cell has sea depth less than dDepthIn
519
520 for (unsigned int n = 0; n < m_VCellInProfile.size(); n++)
521 {
522 int nX = m_VCellInProfile[n].nGetX();
523 int nY = m_VCellInProfile[n].nGetY();
524
525 double dCellDepth = pGrid->m_Cell[nX][nY].dGetSeaDepth();
526 if (dCellDepth >= dDepthIn)
527 {
528 nIndex = n;
529
530 if (n > 0)
531 nIndex = n - 1; // Grid CRS units
532
533 break;
534 }
535 }
536
537 // ####################
538 // if (nIndex == INT_NODATA)
539 // {
540 // nIndex = static_cast<int>(m_VCellInProfile.size()) - 1;
541 // }
542
543 return nIndex;
544}
545
548{
549 m_dDeepWaterWaveHeight = dWaveHeight;
550}
551
557
560{
561 m_dDeepWaterWaveAngle = dWaveAngle;
562}
563
569
572{
573 m_dDeepWaterWavePeriod = dWavePeriod;
574}
575
581
584{
585 return m_bIntervention;
586}
vector< CGeom2DPoint > m_VPoints
The points which comprise the float-coordinate 2D shape.
Definition 2d_shape.h:40
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:427
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:38
void TruncateProfile(int const)
Truncates the profile.
Definition profile.cpp:305
int m_nCoastPoint
The coastline point at which this profile hits the coast (not necessarily coincident wih the profile ...
Definition profile.h:68
double m_dDeepWaterWaveHeight
The wave height at the end of the profile.
Definition profile.h:77
CGeomProfile * m_pUpCoastAdjacentProfile
Pointer to the adjacent up-coast profile (may be an invalid profile)
Definition profile.h:92
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:516
void SetEndOfCoast(bool const)
Sets a switch to indicate whether this is an end-of-coast profile.
Definition profile.cpp:114
bool m_bHitCoast
Has this profile hit a coastline?
Definition profile.h:50
void AppendPointInProfile(double const, double const)
Appends a point to the profile.
Definition profile.cpp:274
double dGetProfileDeepWaterWaveAngle(void) const
Returns the deep-water wave orientation for this profile.
Definition profile.cpp:565
double dGetProfileDeepWaterWaveHeight(void) const
Returns the deep-water wave height for this profile.
Definition profile.cpp:553
int m_nCoastID
The this-coast ID of the profile.
Definition profile.h:71
int m_nGlobalID
The global ID of the profile.
Definition profile.h:74
int nGetCoastPoint(void) const
Returns the coast point at which the profile starts.
Definition profile.cpp:78
void SetProfileDeepWaterWavePeriod(double const)
Sets the deep-water wave Period for this profile.
Definition profile.cpp:571
bool m_bIntervention
Is this an intervention profile?
Definition profile.h:62
bool bIsPointInProfile(double const, double const)
Removes a line segment from the profile.
Definition profile.cpp:351
void SetHitCoast(bool const)
Sets a switch which indicates whether this profile has hit a coast.
Definition profile.cpp:150
vector< CGeom2DPoint > m_VCellInProfileExtCRS
In external CRS, the coords of cells 'under' this profile.
Definition profile.h:102
CGeomProfile * m_pDownCoastAdjacentProfile
Pointer to the adjacent down-coast profile (may be an invalid profile)
Definition profile.h:95
bool bHitAnotherProfileBadly(void) const
Returns the switch which indicates whether this profile hits another profile badly.
Definition profile.cpp:192
bool m_bCShoreProblem
Has this profile encountered a CShore problem?
Definition profile.h:44
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...
Definition profile.cpp:215
void SetStartOfCoast(bool const)
Sets a switch to indicate whether this is a start-of-coast profile.
Definition profile.cpp:102
CGeomProfile * pGetUpCoastAdjacentProfile(void) const
Definition profile.cpp:439
CGeomProfile * pGetDownCoastAdjacentProfile(void) const
Definition profile.cpp:449
void AppendCellInProfileExtCRS(double const, double const)
Appends a cell (specified in the external coordinate system) to the profile.
Definition profile.cpp:502
void SetUpCoastAdjacentProfile(CGeomProfile *)
Definition profile.cpp:434
double m_dDeepWaterWaveAngle
The wave orientation at the end of the profile.
Definition profile.h:80
CGeom2DIPoint * pPtiGetCellInProfile(int const)
Returns a single cell in the profile.
Definition profile.cpp:482
bool m_bHitAnotherProfileBadly
Has this profile hit another profile?
Definition profile.h:59
vector< CGeom2DPoint > PtVGetThisPointAndAllAfter(int const)
Returns a given point from the profile, and all points after this.
Definition profile.cpp:338
void SetTruncated(bool const)
Sets a switch which indicates whether this profile is truncated.
Definition profile.cpp:174
bool bInsertIntersection(double const, double const, int const)
Inserts an intersection into the profile.
Definition profile.cpp:286
CGeom2DIPoint PtiEnd
The seaward end point of the profile in grid CRS.
Definition profile.h:89
bool bHitLand(void) const
Returns the switch which indicates whether this profile has hit land.
Definition profile.cpp:144
CGeom2DIPoint PtiStart
The on-coast start point of the profile in grid CRS.
Definition profile.h:86
int nGetNumCellsInProfile(void) const
Returns the number of cells in the profile.
Definition profile.cpp:489
CGeomProfile(int const, int const, int const, int const, CGeom2DIPoint const *, CGeom2DIPoint const *, bool const)
Constructor with initialization list, requires one parameter (the coast point at which the profile st...
Definition profile.cpp:36
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:98
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...
Definition profile.cpp:198
void SetProfileDeepWaterWaveHeight(double const)
Sets the deep-water wave height for this profile.
Definition profile.cpp:547
bool bTooShort(void) const
Returns the switch which indicates whether this profile is too short to be useful.
Definition profile.cpp:168
void SetDownCoastAdjacentProfile(CGeomProfile *)
Definition profile.cpp:444
bool bHitCoast(void) const
Returns the switch which indicates whether this profile has hit a coast.
Definition profile.cpp:156
bool bIsIntervention(void) const
Returns true if this is an intervention profile.
Definition profile.cpp:583
int nGetGlobalID(void) const
Returns the profile's global ID.
Definition profile.cpp:72
bool m_bEndOfCoast
Is this an end-of-coast profile?
Definition profile.h:41
~CGeomProfile(void) override
Destructor.
Definition profile.cpp:61
bool m_bTruncated
Has this profile been truncated?
Definition profile.h:56
CGeom2DIPoint * pPtiGetEndPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile ends.
Definition profile.cpp:96
void SetCShoreProblem(bool const)
Sets a switch to indicate whether this profile has a CShore problem.
Definition profile.cpp:126
CGeom2DPoint * pPtGetPointInProfile(int const)
Returns a single point in the profile.
Definition profile.cpp:332
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:231
int nGetCoastID(void) const
Returns the profile's coast ID.
Definition profile.cpp:66
void AppendCellInProfile(CGeom2DIPoint const *)
Appends a cell to the profile.
Definition profile.cpp:455
void SetPointInProfile(int const, double const, double const)
Sets a single point in the profile.
Definition profile.cpp:267
void SetHitAnotherProfileBadly(bool const)
Sets a switch which indicates whether this profile hits another profile badly.
Definition profile.cpp:186
int nGetProfileSize(void) const
Returns the number of points in the profile.
Definition profile.cpp:325
CGeom2DIPoint * pPtiGetStartPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile starts.
Definition profile.cpp:84
bool m_bTooShort
Is this profile too short?
Definition profile.h:53
bool bStartOfCoast(void) const
Returns the switch to indicate whether this is a start-of-coast profile.
Definition profile.cpp:108
void SetEndPoint(CGeom2DIPoint const *)
Sets the the location of the cell (grid CRS) on which the profile ends.
Definition profile.cpp:90
bool bTruncated(void) const
Returns the switch which indicates whether this profile is truncated.
Definition profile.cpp:180
void SetHitLand(bool const)
Sets a switch which indicates whether this profile has hit land.
Definition profile.cpp:138
void SetPointsInProfile(vector< CGeom2DPoint > const *)
Sets all points in the profile.
Definition profile.cpp:261
int m_nCoast
The coast from which this profile projects.
Definition profile.h:65
vector< CGeom2DIPoint > * pPtiVGetCellsInProfile(void)
Returns all cells in the profile.
Definition profile.cpp:475
double m_dDeepWaterWavePeriod
The wave period at the end of the profile.
Definition profile.h:83
bool bEndOfCoast(void) const
Returns the switch to indicate whether this is an end-of-coast profile.
Definition profile.cpp:120
double dGetProfileDeepWaterWavePeriod(void) const
Returns the deep-water wave Period for this profile.
Definition profile.cpp:577
bool bCShoreProblem(void) const
Returns the switch which indicates whether this profile has a CShore problem.
Definition profile.cpp:132
void SetProfileDeepWaterWaveAngle(double const)
Sets the deep-water wave orientation for this profile.
Definition profile.cpp:559
bool m_bHitLand
Has this profile hit land?
Definition profile.h:47
void SetTooShort(bool const)
Sets a switch which indicates whether this profile is too short to be useful.
Definition profile.cpp:162
Geometry cass used to represent the raster grid of cell objects.
Definition raster_grid.h:35
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:56
STL iterator class.
This file contains global definitions for CoastalME.
int const INT_NODATA
Definition cme.h:362
Contains CGeomProfile definitions.