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_bHitIntervention(false),
42 m_bHitCoast(false),
43 m_bTooShort(false),
44 m_bTruncated(false),
46 m_bIntervention(bIntervention),
47 m_nCoast(nCoast),
48 m_nCoastPoint(nCoastPoint),
49 m_nCoastID(nCoastID),
50 m_nGlobalID(nGlobalID),
54 PtiStart(*pPtiStart),
55 PtiEnd(*pPtiEnd),
58{
59}
60
65
68{
69 return m_nCoastID;
70}
71
74{
75 return m_nGlobalID;
76}
77
80{
81 return m_nCoastPoint;
82}
83
89
92{
93 PtiEnd = *pPtiEnd;
94}
95
101
103void CGeomProfile::SetStartOfCoast(bool const bFlag)
104{
105 m_bStartOfCoast = bFlag;
106}
107
110{
111 return m_bStartOfCoast;
112}
113
115void CGeomProfile::SetEndOfCoast(bool const bFlag)
116{
117 m_bEndOfCoast = bFlag;
118}
119
122{
123 return m_bEndOfCoast;
124}
125
127void CGeomProfile::SetCShoreProblem(bool const bFlag)
128{
129 m_bCShoreProblem = bFlag;
130}
131
134{
135 return m_bCShoreProblem;
136}
137
139void CGeomProfile::SetHitLand(bool const bFlag)
140{
141 m_bHitLand = bFlag;
142}
143
146{
147 return m_bHitLand;
148}
149
152{
153 m_bHitIntervention = bFlag;
154}
155
158{
159 return m_bHitIntervention;
160}
161
163void CGeomProfile::SetHitCoast(bool const bFlag)
164{
165 m_bHitCoast = bFlag;
166}
167
170{
171 return m_bHitCoast;
172}
173
175void CGeomProfile::SetTooShort(bool const bFlag)
176{
177 m_bTooShort = bFlag;
178}
179
182{
183 return m_bTooShort;
184}
185
187void CGeomProfile::SetTruncated(bool const bFlag)
188{
189 m_bTruncated = bFlag;
190}
191
194{
195 return m_bTruncated;
196}
197
200{
201 m_bHitAnotherProfile = bFlag;
202}
203
206{
208}
209
212{
213 // All profiles without problems, but not start- or end-of-coast profiles
214 if ((! m_bStartOfCoast) &&
215 (! m_bEndOfCoast) &&
216 (! m_bHitLand) &&
217 (! m_bHitIntervention) &&
218 (! m_bHitCoast) &&
219 (! m_bTooShort) &&
220 (! m_bTruncated) &&
223 return true;
224
225 return false;
226}
227
230{
231 // All profiles without problems, but not start- or end-of-coast profiles
232 if ((! m_bStartOfCoast) &&
233 (! m_bEndOfCoast) &&
234 (! m_bHitLand) &&
235 (! m_bHitIntervention) &&
236 (! m_bHitCoast) &&
237 (! m_bTooShort) &&
240 return true;
241
242 return false;
243}
244
247{
248 // All profiles without problems, including start- and end-of-coast profiles
249 if ((! m_bHitLand) &&
250 (! m_bHitIntervention) &&
251 (! m_bHitCoast) &&
252 (! m_bTooShort) &&
253 (! m_bTruncated) &&
256 return true;
257
258 return false;
259}
260
261// //! Returns true if this is a problem-free profile (however it could still be a start-of-coast profile)
262// bool CGeomProfile::bOKIncStartOfCoast(void) const
263// {
264// // All profiles without problems, including start-of-coast profile (but not end-of-coast profile)
265// if ((! m_bEndOfCoast) &&
266// (! m_bHitLand) &&
267// (! m_bHitIntervention) &&
268// (! m_bHitCoast) &&
269// (! m_bTooShort) &&
270// (! m_bTruncated) &&
271// (! m_bHitAnotherProfile))
272// return true;
273//
274// return false;
275// }
276
278void CGeomProfile::SetPointsInProfile(vector<CGeom2DPoint> const* VNewPoints)
279{
280 m_VPoints = *VNewPoints;
281}
282
284void CGeomProfile::SetPointInProfile(int const nPoint, double const dNewX, double const dNewY)
285{
286 // TODO 055 No check to see if nPoint < m_VPoints,size()
287 m_VPoints[nPoint] = CGeom2DPoint(dNewX, dNewY);
288}
289
291void CGeomProfile::AppendPointInProfile(double const dNewX, double const dNewY)
292{
293 m_VPoints.push_back(CGeom2DPoint(dNewX, dNewY));
294}
295
298{
299 m_VPoints.push_back(*pPt);
300}
301
303bool CGeomProfile::bInsertIntersection(double const dX, double const dY, int const nSeg)
304{
305 // Safety check
306 if (nSeg >= nGetNumLineSegments())
307 return false;
308
310 it = m_VPoints.begin();
311
312 // Do the insertion
313 m_VPoints.insert(it + nSeg + 1, CGeom2DPoint(dX, dY));
314
315 // Now insert a line segment in the associated multi-line, this will inherit the profile/line seg details from the preceding line segment
317
318 return true;
319}
320
322void CGeomProfile::TruncateProfile(int const nSize)
323{
324 m_VPoints.resize(nSize);
325}
326
327// void CGeomProfile::TruncateAndSetPointInProfile(int const nPoint, double const dNewX, double const dNewY)
328// {
329// m_VPoints.resize(nPoint+1);
330// m_VPoints[nPoint] = CGeom2DPoint(dNewX, dNewY);
331// }
332
333// void CGeomProfile::ShowProfile(void) const
334// {
335// for (int n = 0; n < m_VPoints.size(); n++)
336// {
337// cout << n << " [" << m_VPoints[n].dGetX() << "][" << m_VPoints[n].dGetY() << "]" << endl;
338// }
339// }
340
343{
344 // return CGeomMultiLine::nGetSize();
345 return static_cast<int>(m_VPoints.size());
346}
347
350{
351 return &m_VPoints[n];
352}
353
355vector<CGeom2DPoint> CGeomProfile::PtVGetThisPointAndAllAfter(int const nStart)
356{
357 return vector<CGeom2DPoint>(m_VPoints.begin() + nStart, m_VPoints.end());
358}
359
361// void CGeomProfile::RemoveLineSegment(int const nPoint)
362// {
363// m_VPoints.erase(m_VPoints.begin() + nPoint);
364// CGeomMultiLine::RemoveLineSegment(nPoint);
365// }
366
368bool CGeomProfile::bIsPointInProfile(double const dX, double const dY)
369{
370 CGeom2DPoint Pt(dX, dY);
371 auto it = find(m_VPoints.begin(), m_VPoints.end(), &Pt);
372 if (it != m_VPoints.end())
373 return true;
374 else
375 return false;
376}
377
379bool CGeomProfile::bIsPointInProfile(double const dX, double const dY, int& nPoint)
380{
381 CGeom2DPoint Pt(dX, dY);
382 auto it = find(m_VPoints.begin(), m_VPoints.end(), &Pt);
383 if (it != m_VPoints.end())
384 {
385 // Found, so return true and set nPoint to be the index of the point which was found
386 nPoint = static_cast<int>(it - m_VPoints.begin());
387 return true;
388 }
389 else
390 return false;
391}
392
393// int CGeomProfile::nFindInsertionLineSeg(double const dInsertX, double const dInsertY)
394// {
395// for (int n = 0; n < m_VPoints.back(); n++)
396// {
397// double
398// dThisX = m_VPoints[n].dGetX(),
399// dThisY = m_VPoints[n].dGetY(),
400// dNextX = m_VPoints[n+1].dGetX(),
401// dNextY = m_VPoints[n+1].dGetY();
402//
403// bool
404// bBetweenX = false,
405// bBetweenY = false;
406//
407// if (dNextX >= dThisX)
408// {
409// // Ascending
410// if ((dInsertX >= dThisX) && (dInsertX <= dNextX))
411// bBetweenX = true;
412// }
413// else
414// {
415// // Descending
416// if ((dInsertX >= dNextX) && (dInsertX <= dThisX))
417// bBetweenX = true;
418// }
419//
420// if (dNextY >= dThisY)
421// {
422// // Ascending
423// if ((dInsertY >= dThisY) && (dInsertY <= dNextY))
424// bBetweenY = true;
425// }
426// else
427// {
428// // Descending
429// if ((dInsertY >= dNextY) && (dInsertY <= dThisY))
430// bBetweenY = true;
431// }
432//
433// if (bBetweenX && bBetweenY)
434// return n;
435// }
436//
437// return -1;
438// }
439
440// void CGeomProfile::AppendPointShared(bool const bShared)
441// {
442// m_bVShared.push_back(bShared);
443// }
444
445// bool CGeomProfile::bPointShared(int const n) const
446// {
447// // TODO 055 No check to see if n < size()
448// return m_bVShared[n];
449// }
450
455
460
465
470
473{
474 // In grid CRS
475 m_VCellInProfile.push_back(*pPti);
476}
477
479void CGeomProfile::AppendCellInProfile(int const nX, int const nY)
480{
481 // In grid CRS
482 m_VCellInProfile.push_back(CGeom2DIPoint(nX, nY));
483}
484
485// void CGeomProfile::SetCellsInProfile(vector<CGeom2DIPoint>* VNewPoints)
486// {
487// // In grid CRS
488// m_VCellInProfile = *VNewPoints;
489// }
490
492vector<CGeom2DIPoint>* CGeomProfile::pPtiVGetCellsInProfile(void)
493{
494 // In grid CRS
495 return &m_VCellInProfile;
496}
497
500{
501 // In grid CRS TODO 055 No check to see if n < size()
502 return &m_VCellInProfile[n];
503}
504
507{
508 // In grid CRS
509 return &m_VCellInProfile.back();
510}
511
514{
515 // In grid CRS
516 return static_cast<int>(m_VCellInProfile.size());
517}
518
519// vector<CGeom2DPoint>* CGeomProfile::PtVGetCellsInProfileExtCRS(void)
520// {
521// // In external CRS
522// return &m_VCellInProfileExtCRS;
523// }
524
526void CGeomProfile::AppendCellInProfileExtCRS(double const dX, double const dY)
527{
528 // In external CRS
529 m_VCellInProfileExtCRS.push_back(CGeom2DPoint(dX, dY));
530}
531
534{
535 // In external CRS
536 m_VCellInProfileExtCRS.push_back(*pPt);
537}
538
540int CGeomProfile::nGetCellGivenDepth(CGeomRasterGrid const* pGrid, double const dDepthIn)
541{
542 int nIndex = INT_NODATA; // If not found, i.e. if every profile cell has sea depth less than dDepthIn
543
544 for (unsigned int n = 0; n < m_VCellInProfile.size(); n++)
545 {
546 int nX = m_VCellInProfile[n].nGetX();
547 int nY = m_VCellInProfile[n].nGetY();
548
549 double dCellDepth = pGrid->m_Cell[nX][nY].dGetSeaDepth();
550 if (dCellDepth >= dDepthIn)
551 {
552 nIndex = n;
553
554 if (n > 0)
555 nIndex = n - 1; // Grid CRS units
556
557 break;
558 }
559 }
560
561 // ####################
562 // if (nIndex == INT_NODATA)
563 // {
564 // nIndex = static_cast<int>(m_VCellInProfile.size()) - 1;
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}
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:432
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:322
int m_nCoastPoint
The coastline point at which this profile hits the coast (not necessarily coincident wih the profile ...
Definition profile.h:71
double m_dDeepWaterWaveHeight
The wave height at the end of the profile.
Definition profile.h:80
CGeomProfile * m_pUpCoastAdjacentProfile
Pointer to the adjacent up-coast profile (may be an invalid profile)
Definition profile.h:95
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:540
void SetEndOfCoast(bool const)
Sets a switch to indicate whether this is an end-of-coast profile.
Definition profile.cpp:115
bool m_bHitCoast
Has this profile hit a coastline?
Definition profile.h:53
void AppendPointInProfile(double const, double const)
Appends a point to the profile.
Definition profile.cpp:291
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_nCoastID
The this-coast ID of the profile.
Definition profile.h:74
int m_nGlobalID
The global ID of the profile.
Definition profile.h:77
int nGetCoastPoint(void) const
Returns the coast point at which the profile starts.
Definition profile.cpp:79
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:65
bool bIsPointInProfile(double const, double const)
Removes a line segment from the profile.
Definition profile.cpp:368
void SetHitCoast(bool const)
Sets a switch which indicates whether this profile has hit a coast.
Definition profile.cpp:163
vector< CGeom2DPoint > m_VCellInProfileExtCRS
In external CRS, the coords of cells 'under' this profile.
Definition profile.h:105
CGeomProfile * m_pDownCoastAdjacentProfile
Pointer to the adjacent down-coast profile (may be an invalid profile)
Definition profile.h:98
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:229
bool m_bHitAnotherProfile
Has this profile hit another profile?
Definition profile.h:62
void SetStartOfCoast(bool const)
Sets a switch to indicate whether this is a start-of-coast profile.
Definition profile.cpp:103
CGeomProfile * pGetUpCoastAdjacentProfile(void) const
Definition profile.cpp:456
CGeomProfile * pGetDownCoastAdjacentProfile(void) const
Definition profile.cpp:466
void AppendCellInProfileExtCRS(double const, double const)
Appends a cell (specified in the external coordinate system) to the profile.
Definition profile.cpp:526
void SetUpCoastAdjacentProfile(CGeomProfile *)
Definition profile.cpp:451
double m_dDeepWaterWaveAngle
The wave orientation at the end of the profile.
Definition profile.h:83
CGeom2DIPoint * pPtiGetCellInProfile(int const)
Returns a single cell in the profile.
Definition profile.cpp:499
void SetHitAnotherProfile(bool const)
Sets a switch which indicates whether this profile hits another profile badly.
Definition profile.cpp:199
vector< CGeom2DPoint > PtVGetThisPointAndAllAfter(int const)
Returns a given point from the profile, and all points after this.
Definition profile.cpp:355
void SetTruncated(bool const)
Sets a switch which indicates whether this profile is truncated.
Definition profile.cpp:187
bool bHitAnotherProfile(void) const
Returns the switch which indicates whether this profile hits another profile badly.
Definition profile.cpp:205
bool bInsertIntersection(double const, double const, int const)
Inserts an intersection into the profile.
Definition profile.cpp:303
CGeom2DIPoint PtiEnd
The seaward end point of the profile in grid CRS.
Definition profile.h:92
bool bHitLand(void) const
Returns the switch which indicates whether this profile has hit land.
Definition profile.cpp:145
CGeom2DIPoint PtiStart
The on-coast start point of the profile in grid CRS.
Definition profile.h:89
int nGetNumCellsInProfile(void) const
Returns the number of cells in the profile.
Definition profile.cpp:513
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:101
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:211
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:181
void SetDownCoastAdjacentProfile(CGeomProfile *)
Definition profile.cpp:461
bool bHitCoast(void) const
Returns the switch which indicates whether this profile has hit a coast.
Definition profile.cpp:169
bool bIsIntervention(void) const
Returns true if this is an intervention profile.
Definition profile.cpp:607
int nGetGlobalID(void) const
Returns the profile's global ID.
Definition profile.cpp:73
void SetHitIntervention(bool const)
Sets a switch which indicates whether this profile has hit an intervention.
Definition profile.cpp:151
bool m_bEndOfCoast
Is this an end-of-coast profile?
Definition profile.h:41
~CGeomProfile(void) override
Destructor.
Definition profile.cpp:62
bool m_bTruncated
Has this profile been truncated?
Definition profile.h:59
CGeom2DIPoint * pPtiGetEndPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile ends.
Definition profile.cpp:97
void SetCShoreProblem(bool const)
Sets a switch to indicate whether this profile has a CShore problem.
Definition profile.cpp:127
CGeom2DPoint * pPtGetPointInProfile(int const)
Returns a single point in the profile.
Definition profile.cpp:349
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:246
int nGetCoastID(void) const
Returns the profile's coast ID.
Definition profile.cpp:67
void AppendCellInProfile(CGeom2DIPoint const *)
Appends a cell to the profile.
Definition profile.cpp:472
void SetPointInProfile(int const, double const, double const)
Sets a single point in the profile.
Definition profile.cpp:284
int nGetProfileSize(void) const
Returns the number of points in the profile.
Definition profile.cpp:342
CGeom2DIPoint * pPtiGetStartPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile starts.
Definition profile.cpp:85
bool m_bTooShort
Is this profile too short?
Definition profile.h:56
bool bStartOfCoast(void) const
Returns the switch to indicate whether this is a start-of-coast profile.
Definition profile.cpp:109
void SetEndPoint(CGeom2DIPoint const *)
Sets the the location of the cell (grid CRS) on which the profile ends.
Definition profile.cpp:91
bool bTruncated(void) const
Returns the switch which indicates whether this profile is truncated.
Definition profile.cpp:193
void SetHitLand(bool const)
Sets a switch which indicates whether this profile has hit land.
Definition profile.cpp:139
void SetPointsInProfile(vector< CGeom2DPoint > const *)
Sets all points in the profile.
Definition profile.cpp:278
int m_nCoast
The coast from which this profile projects.
Definition profile.h:68
vector< CGeom2DIPoint > * pPtiVGetCellsInProfile(void)
Returns all cells in the profile.
Definition profile.cpp:492
CGeom2DIPoint * pPtiGetLastCellInProfile(void)
Returns the last cell in the profile.
Definition profile.cpp:506
bool m_bHitIntervention
Has this profile hit an intervention?
Definition profile.h:50
double m_dDeepWaterWavePeriod
The wave period at the end of the profile.
Definition profile.h:86
bool bEndOfCoast(void) const
Returns the switch to indicate whether this is an end-of-coast profile.
Definition profile.cpp:121
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:133
bool bHitIntervention(void) const
Returns the switch which indicates whether this profile has hit an intervention.
Definition profile.cpp:157
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:47
void SetTooShort(bool const)
Sets a switch which indicates whether this profile is too short to be useful.
Definition profile.cpp:175
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:365
Contains CGeomProfile definitions.