CoastalME (Coastal Modelling Environment)
Simulates the long-term behaviour of complex coastlines
Loading...
Searching...
No Matches
multi_line.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 "cme.h"
27#include "multi_line.h"
28
33
38
41{
42 m_prVVLineSegment.push_back(vector<pair<int, int> >());
43}
44
46void CGeomMultiLine::AppendLineSegment(vector<pair<int, int> > *pprVIn)
47{
48 m_prVVLineSegment.push_back( * pprVIn);
49}
50
52// void CGeomMultiLine::AppendLineSegmentAndInherit(void)
53// {
54// vector<pair<int, int> > prVNewLineSeg;
55// m_prVVLineSegment.push_back(prVNewLineSeg);
56//
57// // Must inherit any profile numbers stored in earlier (i.e. coastward) line segments
58// int nSize = m_prVVLineSegment.size();
59// if (nSize > 1)
60// {
61// for (int n = 0; n < m_prVVLineSegment[nSize-2].size(); n++)
62// {
63// int
64// nPrevProfile = m_prVVLineSegment[nSize-2][n].first,
65// nPrevLineSeg = m_prVVLineSegment[nSize-2][n].second + 1;
66//
67// m_prVVLineSegment[nSize-1].push_back(make_pair(nPrevProfile, nPrevLineSeg));
68// }
69// }
70// }
71
74{
75 return static_cast<int>(m_prVVLineSegment.size());
76}
77
80{
81 m_prVVLineSegment.resize(nSize);
82}
83
85void CGeomMultiLine::InsertLineSegment(int const nSegment)
86{
87// assert(nSegment < m_prVVLineSegment.size());
88
89 // The new vector of pairs is identical to the existing vector of pairs i.e. we inherit profile/line seg details from the previous line seg
90 vector<pair<int, int> > prVPrev = m_prVVLineSegment[nSegment];
91
92 // Store the profile numbers that are in this existing vector of pairs, these are the profiles that will be affected by this insertion
93 vector<int> nVProfsAffected;
94
95 for (unsigned int i = 0; i < prVPrev.size(); i++)
96 nVProfsAffected.push_back(prVPrev[i].first);
97
98 vector<vector<pair<int, int> > >::iterator it;
99 it = m_prVVLineSegment.begin();
100
101 m_prVVLineSegment.insert(it + nSegment + 1, prVPrev);
102
103 // Must now increment the profile's own line seg numbers, but only for those profile numbers which were affected by the insertion. Do this for the new line seg and every line seg after that
104 for (unsigned int m = nSegment + 1; m < m_prVVLineSegment.size(); m++)
105 {
106 for (unsigned int n = 0; n < m_prVVLineSegment[m].size(); n++)
107 {
108 for (unsigned int i = 0; i < nVProfsAffected.size(); i++)
109 {
110 if (m_prVVLineSegment[m][n].first == nVProfsAffected[i])
111 m_prVVLineSegment[m][n].second++;
112 }
113 }
114 }
115}
116
118vector<vector<pair<int, int> > > CGeomMultiLine::prVVGetAllLineSegAfter(int const nSegment)
119{
120 vector<vector<pair<int, int> > > prVTmp;
121
122 for (unsigned int n = nSegment; n < m_prVVLineSegment.size(); n++)
123 prVTmp.push_back(m_prVVLineSegment[n]);
124
125 return prVTmp;
126}
127
129void CGeomMultiLine::RemoveLineSegment(int const nSegment)
130{
131 m_prVVLineSegment.erase(m_prVVLineSegment.begin() + nSegment);
132}
133
136{
137 long unsigned int nSize = m_prVVLineSegment.size();
138 m_prVVLineSegment[nSize - 1].push_back(prIn);
139// m_prVVLineSegment.back().push_back(prIn);
140}
141
143void CGeomMultiLine::AddCoincidentProfileToExistingLineSegment(int const nSegment, int const nProfile, int const nLineSeg)
144{
145// assert(nSegment < m_prVVLineSegment.size());
146 m_prVVLineSegment[nSegment].push_back(make_pair(nProfile, nLineSeg));
147}
148
150vector<pair<int, int> > *CGeomMultiLine::pprVGetPairedCoincidentProfilesForLineSegment(int const nSegment)
151{
152 // TODO 055 No check to see if nSegment < size()
153 return &m_prVVLineSegment[nSegment];
154}
155
157int CGeomMultiLine::nGetCoincidentProfileForLineSegment(int const nSegment, int const nCoinc) const
158{
159 // Safety check
160 if ((nSegment < 0) || (nSegment >= static_cast<int>(m_prVVLineSegment.size())))
161 return -1;
162
163 // Safety check
164 if ((nCoinc < 0) || (nCoinc >= static_cast<int>(m_prVVLineSegment[nSegment].size())))
165 return -1;
166
167 return m_prVVLineSegment[nSegment][nCoinc].first;
168}
169
172{
173 // Safety check
174 if (nSegment > static_cast<int>(m_prVVLineSegment.size()) - 1)
175 return -1;
176
177 return static_cast<int>(m_prVVLineSegment[nSegment].size());
178}
179
182{
183 long unsigned int nLineSegSize = m_prVVLineSegment.size();
184
185 // Note no check to ensure that nLineSegSize < 0
186 long unsigned int nCoincidentSize = m_prVVLineSegment[nLineSegSize - 1].size();
187
188 for (unsigned int i = 0; i < nCoincidentSize; i++)
189 {
190 if (m_prVVLineSegment[nLineSegSize - 1][i].first == nProfile)
191 return true;
192 }
193
194 return false;
195}
196
198// bool CGeomMultiLine::bFindProfileInCoincidentProfilesOfLineSegment(int const nProfile, int const nSegment)
199// {
200// // Note no check to see if nSegment < m_prVVLineSegment.size()
201// int nCoincidentSize = m_prVVLineSegment[nSegment].size();
202//
203// for (int i = 0; i < nCoincidentSize; i++)
204// if (m_prVVLineSegment[nSegment][i].first == nProfile)
205// return true;
206//
207// return false;
208// }
209
212{
213 int nSegSize = static_cast<int>(m_prVVLineSegment.size());
214
215 if (nSegSize == 0)
216 return false;
217
218 for (int i = nSegSize - 1; i >= 0; i--)
219 {
220 for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
221 {
222 if (m_prVVLineSegment[i][j].first == nProfile)
223 return true;
224 }
225 }
226
227 return false;
228}
229
231void CGeomMultiLine::GetMostCoastwardSharedLineSegment(int const nOtherProfile, int &nThisLineSegment, int &nOtherLineSegment)
232{
233 nThisLineSegment =
234 nOtherLineSegment = -1;
235
236 long unsigned int nSegSize = m_prVVLineSegment.size();
237
238 if (nSegSize == 0)
239 return;
240
241 for (unsigned int i = 0; i < nSegSize; i++)
242 {
243 for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
244 {
245 if (m_prVVLineSegment[i][j].first == nOtherProfile)
246 {
247 nThisLineSegment = i;
248 nOtherLineSegment = m_prVVLineSegment[i][j].second;
249
250 return;
251 }
252 }
253 }
254}
255
257int CGeomMultiLine::nGetProf(int const nSegment, int const nCoinc) const
258{
259 return m_prVVLineSegment[nSegment][nCoinc].first;
260}
261
263int CGeomMultiLine::nGetProfsLineSeg(int const nSegment, int const nCoinc) const
264{
265 return m_prVVLineSegment[nSegment][nCoinc].second;
266}
267
269void CGeomMultiLine::SetProfsLineSeg(int const nSegment, int const nCoinc, int const nLineSeg)
270{
271 // Note no check to see if nSegment < m_prVVLineSegment.size() or to see if nCoinc < m_prVVLineSegment[nSegment].size()
272 m_prVVLineSegment[nSegment][nCoinc].second = nLineSeg;
273}
274
275// //! Returns the number of the last line segment which includes the given profile number as a co-incident profile
276// int CGeomMultiLine::nFindProfilesLastSeg(int const nProfile) const
277// {
278// int nSeg = -1;
279// for (int i = static_cast<int>(m_prVVLineSegment.size()-1); i >= 0; i--)
280// {
281// for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
282// {
283// if (m_prVVLineSegment[i][j].first == nProfile)
284// nSeg = i;
285// }
286// }
287//
288// return nSeg;
289// }
int nGetProfsLineSeg(int const, int const) const
Returns the profile's own line segment, given a line segment and the index of the co-incident profile...
bool bFindProfileInCoincidentProfilesOfLastLineSegment(int const)
Returns true if the given profile number is amongst the coincident profiles of the CGeomMultiLine obj...
int nGetNumCoincidentProfilesInLineSegment(int const)
Returns the count of coincident profiles in a specified line segment, or -1 if the line segment does ...
bool bFindProfileInCoincidentProfiles(int const)
Returns true if the given profile number is one of the coincident profiles of the a specified line se...
void AppendLineSegment(void)
Appends a new empty line segment.
int nGetCoincidentProfileForLineSegment(int const, int const) const
Returns the numbers of coincident profiles.
int nGetProf(int const, int const) const
Returns the profile number, given a line segment and the index of the co-incident profile for that li...
void TruncateLineSegments(int const)
Cuts short the number of line segments.
void RemoveLineSegment(int const)
Removes a line segment.
vector< vector< pair< int, int > > > prVVGetAllLineSegAfter(int const)
Returns a vector of the line segments which succeed the specified line segment number.
void AppendCoincidentProfileToLineSegments(pair< int, int > const)
Appends a coincident profile pair to the CGeomMultiLine object's final line segment.
void GetMostCoastwardSharedLineSegment(int const, int &, int &)
Finds the number of the most coastward line segment for which the two profiles are coincident,...
void SetProfsLineSeg(int const, int const, int const)
Sets a profile's own line segment number, given a line segment and the index of the co-incident profi...
vector< pair< int, int > > * pprVGetPairedCoincidentProfilesForLineSegment(int const)
Returns a vector of pairs (a line segment)
CGeomMultiLine(void)
Constructor, no parameters.
void InsertLineSegment(int const)
Inserts a line segment, inheriting from preceding line segments.
~CGeomMultiLine(void) override
Destructor.
vector< vector< pair< int, int > > > m_prVVLineSegment
A vector of line segments, each element is a vector of pairs. The first of the pair is a co-incident ...
Definition multi_line.h:38
void AddCoincidentProfileToExistingLineSegment(int const, int const, int const)
Adds a coincident profile to a pre-existing line segment of the CGeomMultiLine object.
int nGetNumLineSegments(void) const
Appends a line segment which then inherits from the preceding line segments.
This file contains global definitions for CoastalME.
Contains CGeomMultiLine definitions.