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 nCoastID, int const nGlobalID, 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),
52 m_bTruncated(false),
54 m_bIntervention(bIntervention),
55 m_nCoast(nCoast),
56 m_nCoastPoint(nCoastPoint),
57 m_nCoastID(nCoastID),
58 m_nGlobalID(nGlobalID),
62 PtiStart(*pPtiStart),
63 PtiEnd(*pPtiEnd),
66{
67}
68
73
76{
77 return m_nCoastID;
78}
79
82{
83 return m_nGlobalID;
84}
85
88{
89 return m_nCoastPoint;
90}
91
97
100{
101 PtiEnd = *pPtiEnd;
102}
103
109
111void CGeomProfile::SetStartOfCoast(bool const bFlag)
112{
113 m_bStartOfCoast = bFlag;
114}
115
118{
119 return m_bStartOfCoast;
120}
121
123void CGeomProfile::SetEndOfCoast(bool const bFlag)
124{
125 m_bEndOfCoast = bFlag;
126}
127
130{
131 return m_bEndOfCoast;
132}
133
135void CGeomProfile::SetCShoreProblem(bool const bFlag)
136{
137 m_bCShoreProblem = bFlag;
138}
139
142{
143 return m_bCShoreProblem;
144}
145
147void CGeomProfile::SetHitLand(bool const bFlag)
148{
149 m_bHitLand = bFlag;
150}
151
154{
155 return m_bHitLand;
156}
157
160{
161 m_bHitIntervention = bFlag;
162}
163
166{
167 return m_bHitIntervention;
168}
169
171void CGeomProfile::SetHitCoast(bool const bFlag)
172{
173 m_bHitCoast = bFlag;
174}
175
178{
179 return m_bHitCoast;
180}
181
183void CGeomProfile::SetTooShort(bool const bFlag)
184{
185 m_bTooShort = bFlag;
186}
187
190{
191 return m_bTooShort;
192}
193
195void CGeomProfile::SetTruncated(bool const bFlag)
196{
197 m_bTruncated = bFlag;
198}
199
202{
203 return m_bTruncated;
204}
205
208{
209 m_bHitAnotherProfile = bFlag;
210}
211
214{
216}
217
220{
221 // All profiles without problems, but not start- or end-of-coast profiles
222 if ((!m_bStartOfCoast) &&
223 (!m_bEndOfCoast) &&
224 (!m_bHitLand) &&
226 (!m_bHitCoast) &&
227 (!m_bTooShort) &&
228 (!m_bTruncated) &&
231 return true;
232
233 return false;
234}
235
238{
239 // All profiles without problems, but not start- or end-of-coast profiles
240 if ((!m_bStartOfCoast) &&
241 (!m_bEndOfCoast) &&
242 (!m_bHitLand) &&
244 (!m_bHitCoast) &&
245 (!m_bTooShort) &&
248 return true;
249
250 return false;
251}
252
255{
256 // All profiles without problems, including start- and end-of-coast profiles
257 if ((!m_bHitLand) &&
259 (!m_bHitCoast) &&
260 (!m_bTooShort) &&
261 (!m_bTruncated) &&
264 return true;
265
266 return false;
267}
268
269// //! Returns true if this is a problem-free profile (however it could still be a start-of-coast profile)
270// bool CGeomProfile::bOKIncStartOfCoast(void) const
271// {
272// // All profiles without problems, including start-of-coast profile (but not end-of-coast profile)
273// if ((! m_bEndOfCoast) &&
274// (! m_bHitLand) &&
275// (! m_bHitIntervention) &&
276// (! m_bHitCoast) &&
277// (! m_bTooShort) &&
278// (! m_bTruncated) &&
279// (! m_bHitAnotherProfile))
280// return true;
281//
282// return false;
283// }
284
286void CGeomProfile::SetPointsInProfile(vector<CGeom2DPoint> const* VNewPoints)
287{
288 m_VPoints = *VNewPoints;
289}
290
292void CGeomProfile::SetPointInProfile(int const nPoint, double const dNewX, double const dNewY)
293{
294 // TODO 055 No check to see if nPoint < m_VPoints,size()
295 m_VPoints[nPoint] = CGeom2DPoint(dNewX, dNewY);
296}
297
299void CGeomProfile::AppendPointInProfile(double const dNewX, double const dNewY)
300{
301 m_VPoints.push_back(CGeom2DPoint(dNewX, dNewY));
302}
303
306{
307 m_VPoints.push_back(*pPt);
308}
309
311bool CGeomProfile::bInsertIntersection(double const dX, double const dY, int const nSeg)
312{
313 // Safety check
314 if (nSeg >= nGetNumLineSegments())
315 return false;
316
318 it = m_VPoints.begin();
319
320 // Do the insertion
321 m_VPoints.insert(it + nSeg + 1, CGeom2DPoint(dX, dY));
322
323 // Now insert a line segment in the associated multi-line, this will inherit the profile/line seg details from the preceding line segment
325
326 return true;
327}
328
330void CGeomProfile::TruncateProfile(int const nSize)
331{
332 m_VPoints.resize(nSize);
333}
334
335// void CGeomProfile::TruncateAndSetPointInProfile(int const nPoint, double const dNewX, double const dNewY)
336// {
337// m_VPoints.resize(nPoint+1);
338// m_VPoints[nPoint] = CGeom2DPoint(dNewX, dNewY);
339// }
340
341// void CGeomProfile::ShowProfile(void) const
342// {
343// for (int n = 0; n < m_VPoints.size(); n++)
344// {
345// cout << n << " [" << m_VPoints[n].dGetX() << "][" << m_VPoints[n].dGetY() << "]" << endl;
346// }
347// }
348
351{
352 // return CGeomMultiLine::nGetSize();
353 return static_cast<int>(m_VPoints.size());
354}
355
358{
359 return &m_VPoints[n];
360}
361
363vector<CGeom2DPoint> CGeomProfile::PtVGetThisPointAndAllAfter(int const nStart)
364{
365 return vector<CGeom2DPoint>(m_VPoints.begin() + nStart, m_VPoints.end());
366}
367
369// void CGeomProfile::RemoveLineSegment(int const nPoint)
370// {
371// m_VPoints.erase(m_VPoints.begin() + nPoint);
372// CGeomMultiLine::RemoveLineSegment(nPoint);
373// }
374
376bool CGeomProfile::bIsPointInProfile(double const dX, double const dY)
377{
378 CGeom2DPoint const Pt(dX, dY);
379 auto it = find(m_VPoints.begin(), m_VPoints.end(), &Pt);
380
381 if (it != m_VPoints.end())
382 return true;
383
384 else
385 return false;
386}
387
389bool CGeomProfile::bIsPointInProfile(double const dX, double const dY, int& nPoint)
390{
391 CGeom2DPoint const Pt(dX, dY);
392 auto it = find(m_VPoints.begin(), m_VPoints.end(), &Pt);
393
394 if (it != m_VPoints.end())
395 {
396 // Found, so return true and set nPoint to be the index of the point which was found
397 nPoint = static_cast<int>(it - m_VPoints.begin());
398 return true;
399 }
400
401 else
402 return false;
403}
404
405// int CGeomProfile::nFindInsertionLineSeg(double const dInsertX, double const dInsertY)
406// {
407// for (int n = 0; n < m_VPoints.back(); n++)
408// {
409// double
410// dThisX = m_VPoints[n].dGetX(),
411// dThisY = m_VPoints[n].dGetY(),
412// dNextX = m_VPoints[n+1].dGetX(),
413// dNextY = m_VPoints[n+1].dGetY();
414//
415// bool
416// bBetweenX = false,
417// bBetweenY = false;
418//
419// if (dNextX >= dThisX)
420// {
421// // Ascending
422// if ((dInsertX >= dThisX) && (dInsertX <= dNextX))
423// bBetweenX = true;
424// }
425// else
426// {
427// // Descending
428// if ((dInsertX >= dNextX) && (dInsertX <= dThisX))
429// bBetweenX = true;
430// }
431//
432// if (dNextY >= dThisY)
433// {
434// // Ascending
435// if ((dInsertY >= dThisY) && (dInsertY <= dNextY))
436// bBetweenY = true;
437// }
438// else
439// {
440// // Descending
441// if ((dInsertY >= dNextY) && (dInsertY <= dThisY))
442// bBetweenY = true;
443// }
444//
445// if (bBetweenX && bBetweenY)
446// return n;
447// }
448//
449// return -1;
450// }
451
452// void CGeomProfile::AppendPointShared(bool const bShared)
453// {
454// m_bVShared.push_back(bShared);
455// }
456
457// bool CGeomProfile::bPointShared(int const n) const
458// {
459// // TODO 055 No check to see if n < size()
460// return m_bVShared[n];
461// }
462
467
472
477
482
485{
486 // In grid CRS
487 m_VCellInProfile.push_back(*pPti);
488}
489
491void CGeomProfile::AppendCellInProfile(int const nX, int const nY)
492{
493 // In grid CRS
494 m_VCellInProfile.push_back(CGeom2DIPoint(nX, nY));
495}
496
497// void CGeomProfile::SetCellsInProfile(vector<CGeom2DIPoint>* VNewPoints)
498// {
499// // In grid CRS
500// m_VCellInProfile = *VNewPoints;
501// }
502
504vector<CGeom2DIPoint>* CGeomProfile::pPtiVGetCellsInProfile(void)
505{
506 // In grid CRS
507 return &m_VCellInProfile;
508}
509
512{
513 // In grid CRS TODO 055 No check to see if n < size()
514 return &m_VCellInProfile[n];
515}
516
519{
520 // In grid CRS
521 return &m_VCellInProfile.back();
522}
523
526{
527 // In grid CRS
528 return static_cast<int>(m_VCellInProfile.size());
529}
530
531// vector<CGeom2DPoint>* CGeomProfile::PtVGetCellsInProfileExtCRS(void)
532// {
533// // In external CRS
534// return &m_VCellInProfileExtCRS;
535// }
536
538void CGeomProfile::AppendCellInProfileExtCRS(double const dX, double const dY)
539{
540 // In external CRS
541 m_VCellInProfileExtCRS.push_back(CGeom2DPoint(dX, dY));
542}
543
546{
547 // In external CRS
548 m_VCellInProfileExtCRS.push_back(*pPt);
549}
550
552int CGeomProfile::nGetCellGivenDepth(CGeomRasterGrid const* pGrid, double const dDepthIn)
553{
554 int nIndex = INT_NODATA; // If not found, i.e. if every profile cell has sea depth less than dDepthIn
555
556 for (unsigned int n = 0; n < m_VCellInProfile.size(); n++)
557 {
558 int const nX = m_VCellInProfile[n].nGetX();
559 int const nY = m_VCellInProfile[n].nGetY();
560
561 double const dCellDepth = pGrid->m_Cell[nX][nY].dGetSeaDepth();
562
563 if (dCellDepth >= dDepthIn)
564 {
565 nIndex = n;
566
567 if (n > 0)
568 nIndex = n - 1; // Grid CRS units
569
570 break;
571 }
572 }
573
574 // ####################
575 // if (nIndex == INT_NODATA)
576 // {
577 // nIndex = static_cast<int>(m_VCellInProfile.size()) - 1;
578 // }
579
580 return nIndex;
581}
582
585{
586 m_dDeepWaterWaveHeight = dWaveHeight;
587}
588
594
597{
598 m_dDeepWaterWaveAngle = dWaveAngle;
599}
600
606
609{
610 m_dDeepWaterWavePeriod = dWavePeriod;
611}
612
618
621{
622 return m_bIntervention;
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: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:363
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.
Definition profile.cpp:330
int m_nCoastPoint
The coastline point at which this profile hits the coast (not necessarily coincident wih the profile ...
Definition profile.h:73
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:552
void SetEndOfCoast(bool const)
Sets a switch to indicate whether this is an end-of-coast profile.
Definition profile.cpp:123
bool m_bHitCoast
Has this profile hit a coastline?
Definition profile.h:55
void AppendPointInProfile(double const, double const)
Appends a point to the profile.
Definition profile.cpp:299
double dGetProfileDeepWaterWaveAngle(void) const
Returns the deep-water wave orientation for this profile.
Definition profile.cpp:602
double dGetProfileDeepWaterWaveHeight(void) const
Returns the deep-water wave height for this profile.
Definition profile.cpp:590
int m_nCoastID
The this-coast ID of the profile.
Definition profile.h:76
int m_nGlobalID
The global ID of the profile.
Definition profile.h:79
int nGetCoastPoint(void) const
Returns the coast point at which the profile starts.
Definition profile.cpp:87
void SetProfileDeepWaterWavePeriod(double const)
Sets the deep-water wave Period for this profile.
Definition profile.cpp:608
bool m_bIntervention
Is this an intervention profile?
Definition profile.h:67
bool bIsPointInProfile(double const, double const)
Removes a line segment from the profile.
Definition profile.cpp:376
void SetHitCoast(bool const)
Sets a switch which indicates whether this profile has hit a coast.
Definition profile.cpp:171
vector< CGeom2DPoint > m_VCellInProfileExtCRS
In external CRS, the coords of cells 'under' this profile.
Definition profile.h:107
CGeomProfile * m_pDownCoastAdjacentProfile
Pointer to the adjacent down-coast profile (may be an invalid profile)
Definition profile.h:100
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 or an end-of-coast profil...
Definition profile.cpp:237
bool m_bHitAnotherProfile
Has this profile hit another profile?
Definition profile.h:64
void SetStartOfCoast(bool const)
Sets a switch to indicate whether this is a start-of-coast profile.
Definition profile.cpp:111
CGeomProfile * pGetUpCoastAdjacentProfile(void) const
Definition profile.cpp:468
CGeomProfile * pGetDownCoastAdjacentProfile(void) const
Definition profile.cpp:478
void AppendCellInProfileExtCRS(double const, double const)
Appends a cell (specified in the external coordinate system) to the profile.
Definition profile.cpp:538
void SetUpCoastAdjacentProfile(CGeomProfile *)
Definition profile.cpp:463
double m_dDeepWaterWaveAngle
The wave orientation at the end of the profile.
Definition profile.h:85
CGeom2DIPoint * pPtiGetCellInProfile(int const)
Returns a single cell in the profile.
Definition profile.cpp:511
void SetHitAnotherProfile(bool const)
Sets a switch which indicates whether this profile hits another profile badly.
Definition profile.cpp:207
vector< CGeom2DPoint > PtVGetThisPointAndAllAfter(int const)
Returns a given point from the profile, and all points after this.
Definition profile.cpp:363
void SetTruncated(bool const)
Sets a switch which indicates whether this profile is truncated.
Definition profile.cpp:195
bool bHitAnotherProfile(void) const
Returns the switch which indicates whether this profile hits another profile badly.
Definition profile.cpp:213
bool bInsertIntersection(double const, double const, int const)
Inserts an intersection into the profile.
Definition profile.cpp:311
CGeom2DIPoint PtiEnd
The seaward end point of the profile in grid CRS.
Definition profile.h:94
bool bHitLand(void) const
Returns the switch which indicates whether this profile has hit land.
Definition profile.cpp:153
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:525
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:44
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 or an end-of-coast profil...
Definition profile.cpp:219
void SetProfileDeepWaterWaveHeight(double const)
Sets the deep-water wave height for this profile.
Definition profile.cpp:584
bool bTooShort(void) const
Returns the switch which indicates whether this profile is too short to be useful.
Definition profile.cpp:189
void SetDownCoastAdjacentProfile(CGeomProfile *)
Definition profile.cpp:473
bool bHitCoast(void) const
Returns the switch which indicates whether this profile has hit a coast.
Definition profile.cpp:177
bool bIsIntervention(void) const
Returns true if this is an intervention profile.
Definition profile.cpp:620
int nGetGlobalID(void) const
Returns the profile's global ID.
Definition profile.cpp:81
void SetHitIntervention(bool const)
Sets a switch which indicates whether this profile has hit an intervention.
Definition profile.cpp:159
bool m_bEndOfCoast
Is this an end-of-coast profile?
Definition profile.h:43
~CGeomProfile(void) override
Destructor.
Definition profile.cpp:70
bool m_bTruncated
Has this profile been truncated?
Definition profile.h:61
CGeom2DIPoint * pPtiGetEndPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile ends.
Definition profile.cpp:105
void SetCShoreProblem(bool const)
Sets a switch to indicate whether this profile has a CShore problem.
Definition profile.cpp:135
CGeom2DPoint * pPtGetPointInProfile(int const)
Returns a single point in the profile.
Definition profile.cpp:357
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:254
int nGetCoastID(void) const
Returns the profile's coast ID.
Definition profile.cpp:75
void AppendCellInProfile(CGeom2DIPoint const *)
Appends a cell to the profile.
Definition profile.cpp:484
void SetPointInProfile(int const, double const, double const)
Sets a single point in the profile.
Definition profile.cpp:292
int nGetProfileSize(void) const
Returns the number of points in the profile.
Definition profile.cpp:350
CGeom2DIPoint * pPtiGetStartPoint(void)
Returns a pointer to the location of the cell (grid CRS) on which the profile starts.
Definition profile.cpp:93
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:117
void SetEndPoint(CGeom2DIPoint const *)
Sets the the location of the cell (grid CRS) on which the profile ends.
Definition profile.cpp:99
bool bTruncated(void) const
Returns the switch which indicates whether this profile is truncated.
Definition profile.cpp:201
void SetHitLand(bool const)
Sets a switch which indicates whether this profile has hit land.
Definition profile.cpp:147
void SetPointsInProfile(vector< CGeom2DPoint > const *)
Sets all points in the profile.
Definition profile.cpp:286
int m_nCoast
The coast from which this profile projects.
Definition profile.h:70
vector< CGeom2DIPoint > * pPtiVGetCellsInProfile(void)
Returns all cells in the profile.
Definition profile.cpp:504
CGeom2DIPoint * pPtiGetLastCellInProfile(void)
Returns the last cell in the profile.
Definition profile.cpp:518
bool m_bHitIntervention
Has this profile hit an intervention?
Definition profile.h:52
double m_dDeepWaterWavePeriod
The wave period at the end of the profile.
Definition profile.h:88
bool bEndOfCoast(void) const
Returns the switch to indicate whether this is an end-of-coast profile.
Definition profile.cpp:129
double dGetProfileDeepWaterWavePeriod(void) const
Returns the deep-water wave Period for this profile.
Definition profile.cpp:614
bool bCShoreProblem(void) const
Returns the switch which indicates whether this profile has a CShore problem.
Definition profile.cpp:141
bool bHitIntervention(void) const
Returns the switch which indicates whether this profile has hit an intervention.
Definition profile.cpp:165
void SetProfileDeepWaterWaveAngle(double const)
Sets the deep-water wave orientation for this profile.
Definition profile.cpp:596
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:183
Geometry cass used to represent the raster grid of cell objects.
Definition raster_grid.h:34
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:55
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.