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 return static_cast<int>(m_prVVLineSegment[nSegment].size());
172}
173
176{
177 long unsigned int nLineSegSize = m_prVVLineSegment.size();
178
179 // Note no check to ensure that nLineSegSize < 0
180 long unsigned int nCoincidentSize = m_prVVLineSegment[nLineSegSize-1].size();
181
182 for (unsigned int i = 0; i < nCoincidentSize; i++)
183 {
184 if (m_prVVLineSegment[nLineSegSize-1][i].first == nProfile)
185 return true;
186 }
187
188 return false;
189}
190
192// bool CGeomMultiLine::bFindProfileInCoincidentProfilesOfLineSegment(int const nProfile, int const nSegment)
193// {
194// // Note no check to see if nSegment < m_prVVLineSegment.size()
195// int nCoincidentSize = m_prVVLineSegment[nSegment].size();
196//
197// for (int i = 0; i < nCoincidentSize; i++)
198// if (m_prVVLineSegment[nSegment][i].first == nProfile)
199// return true;
200//
201// return false;
202// }
203
206{
207 int nSegSize = static_cast<int>(m_prVVLineSegment.size());
208 if (nSegSize == 0)
209 return false;
210
211 for (int i = nSegSize-1; i >= 0; i--)
212 {
213 for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
214 {
215 if (m_prVVLineSegment[i][j].first == nProfile)
216 return true;
217 }
218 }
219
220 return false;
221}
222
224void CGeomMultiLine::GetMostCoastwardSharedLineSegment(int const nOtherProfile, int& nThisLineSegment, int& nOtherLineSegment)
225{
226 nThisLineSegment =
227 nOtherLineSegment = -1;
228
229 long unsigned int nSegSize = m_prVVLineSegment.size();
230 if (nSegSize == 0)
231 return;
232
233 for (unsigned int i = 0; i < nSegSize; i++)
234 {
235 for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
236 {
237 if (m_prVVLineSegment[i][j].first == nOtherProfile)
238 {
239 nThisLineSegment = i;
240 nOtherLineSegment = m_prVVLineSegment[i][j].second;
241
242 return;
243 }
244 }
245 }
246}
247
249int CGeomMultiLine::nGetProf(int const nSegment, int const nCoinc) const
250{
251 return m_prVVLineSegment[nSegment][nCoinc].first;
252}
253
255int CGeomMultiLine::nGetProfsLineSeg(int const nSegment, int const nCoinc) const
256{
257 return m_prVVLineSegment[nSegment][nCoinc].second;
258}
259
261void CGeomMultiLine::SetProfsLineSeg(int const nSegment, int const nCoinc, int const nLineSeg)
262{
263 // Note no check to see if nSegment < m_prVVLineSegment.size() or to see if nCoinc < m_prVVLineSegment[nSegment].size()
264 m_prVVLineSegment[nSegment][nCoinc].second = nLineSeg;
265}
266
267// //! Returns the number of the last line segment which includes the given profile number as a co-incident profile
268// int CGeomMultiLine::nFindProfilesLastSeg(int const nProfile) const
269// {
270// int nSeg = -1;
271// for (int i = static_cast<int>(m_prVVLineSegment.size()-1); i >= 0; i--)
272// {
273// for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
274// {
275// if (m_prVVLineSegment[i][j].first == nProfile)
276// nSeg = i;
277// }
278// }
279//
280// return nSeg;
281// }
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.
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.