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
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
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 for (unsigned int i = 0; i < prVPrev.size(); i++)
95 nVProfsAffected.push_back(prVPrev[i].first);
96
97 vector<vector<pair<int, int> > >::iterator it;
98 it = m_prVVLineSegment.begin();
99
100 m_prVVLineSegment.insert(it+nSegment+1, prVPrev);
101
102 // 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
103 for (unsigned int m = nSegment+1; m < m_prVVLineSegment.size(); m++)
104 {
105 for (unsigned int n = 0; n < m_prVVLineSegment[m].size(); n++)
106 {
107 for (unsigned int i = 0; i < nVProfsAffected.size(); i++)
108 {
109 if (m_prVVLineSegment[m][n].first == nVProfsAffected[i])
110 m_prVVLineSegment[m][n].second++;
111 }
112 }
113 }
114}
115
117vector<vector<pair<int, int> > > CGeomMultiLine::prVVGetAllLineSegAfter(int const nSegment)
118{
119 vector<vector<pair<int, int> > > prVTmp;
120 for (unsigned int n = nSegment; n < m_prVVLineSegment.size(); n++)
121 prVTmp.push_back(m_prVVLineSegment[n]);
122
123 return prVTmp;
124}
125
127void CGeomMultiLine::RemoveLineSegment(int const nSegment)
128{
129 m_prVVLineSegment.erase(m_prVVLineSegment.begin() + nSegment);
130}
131
134{
135 long unsigned int nSize = m_prVVLineSegment.size();
136 m_prVVLineSegment[nSize-1].push_back(prIn);
137// m_prVVLineSegment.back().push_back(prIn);
138}
139
141void CGeomMultiLine::AddCoincidentProfileToExistingLineSegment(int const nSegment, int const nProfile, int const nLineSeg)
142{
143// assert(nSegment < m_prVVLineSegment.size());
144 m_prVVLineSegment[nSegment].push_back(make_pair(nProfile, nLineSeg));
145}
146
148vector<pair<int, int> >* CGeomMultiLine::pprVGetPairedCoincidentProfilesForLineSegment(int const nSegment)
149{
150 // TODO 055 No check to see if nSegment < size()
151 return &m_prVVLineSegment[nSegment];
152}
153
155int CGeomMultiLine::nGetCoincidentProfileForLineSegment(int const nSegment, int const nCoinc) const
156{
157 // Safety check
158 if ((nSegment < 0) || (nSegment >= static_cast<int>(m_prVVLineSegment.size())))
159 return -1;
160
161 // Safety check
162 if ((nCoinc < 0) || (nCoinc >= static_cast<int>(m_prVVLineSegment[nSegment].size())))
163 return -1;
164
165 return m_prVVLineSegment[nSegment][nCoinc].first;
166}
167
170{
171 // Safety check
172 if (nSegment > static_cast<int>(m_prVVLineSegment.size())-1)
173 return -1;
174
175 return static_cast<int>(m_prVVLineSegment[nSegment].size());
176}
177
180{
181 long unsigned int nLineSegSize = m_prVVLineSegment.size();
182
183 // Note no check to ensure that nLineSegSize < 0
184 long unsigned int nCoincidentSize = m_prVVLineSegment[nLineSegSize-1].size();
185
186 for (unsigned int i = 0; i < nCoincidentSize; i++)
187 {
188 if (m_prVVLineSegment[nLineSegSize-1][i].first == nProfile)
189 return true;
190 }
191
192 return false;
193}
194
196// bool CGeomMultiLine::bFindProfileInCoincidentProfilesOfLineSegment(int const nProfile, int const nSegment)
197// {
198// // Note no check to see if nSegment < m_prVVLineSegment.size()
199// int nCoincidentSize = m_prVVLineSegment[nSegment].size();
200//
201// for (int i = 0; i < nCoincidentSize; i++)
202// if (m_prVVLineSegment[nSegment][i].first == nProfile)
203// return true;
204//
205// return false;
206// }
207
210{
211 int nSegSize = static_cast<int>(m_prVVLineSegment.size());
212 if (nSegSize == 0)
213 return false;
214
215 for (int i = nSegSize-1; i >= 0; i--)
216 {
217 for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
218 {
219 if (m_prVVLineSegment[i][j].first == nProfile)
220 return true;
221 }
222 }
223
224 return false;
225}
226
228void CGeomMultiLine::GetMostCoastwardSharedLineSegment(int const nOtherProfile, int& nThisLineSegment, int& nOtherLineSegment)
229{
230 nThisLineSegment =
231 nOtherLineSegment = -1;
232
233 long unsigned int nSegSize = m_prVVLineSegment.size();
234 if (nSegSize == 0)
235 return;
236
237 for (unsigned int i = 0; i < nSegSize; i++)
238 {
239 for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
240 {
241 if (m_prVVLineSegment[i][j].first == nOtherProfile)
242 {
243 nThisLineSegment = i;
244 nOtherLineSegment = m_prVVLineSegment[i][j].second;
245
246 return;
247 }
248 }
249 }
250}
251
253int CGeomMultiLine::nGetProf(int const nSegment, int const nCoinc) const
254{
255 return m_prVVLineSegment[nSegment][nCoinc].first;
256}
257
259int CGeomMultiLine::nGetProfsLineSeg(int const nSegment, int const nCoinc) const
260{
261 return m_prVVLineSegment[nSegment][nCoinc].second;
262}
263
265void CGeomMultiLine::SetProfsLineSeg(int const nSegment, int const nCoinc, int const nLineSeg)
266{
267 // Note no check to see if nSegment < m_prVVLineSegment.size() or to see if nCoinc < m_prVVLineSegment[nSegment].size()
268 m_prVVLineSegment[nSegment][nCoinc].second = nLineSeg;
269}
270
271// //! Returns the number of the last line segment which includes the given profile number as a co-incident profile
272// int CGeomMultiLine::nFindProfilesLastSeg(int const nProfile) const
273// {
274// int nSeg = -1;
275// for (int i = static_cast<int>(m_prVVLineSegment.size()-1); i >= 0; i--)
276// {
277// for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
278// {
279// if (m_prVVLineSegment[i][j].first == nProfile)
280// nSeg = i;
281// }
282// }
283//
284// return nSeg;
285// }
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.