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 "multi_line.h"
27
32
37
39vector<CGeom2DPoint>& CGeomMultiLine::pGetPoints(void)
40{
42}
43
45void CGeomMultiLine::SetPoints(vector<CGeom2DPoint>& pVPts)
46{
48}
49
52{
53 m_prVVLineSegment.push_back(vector<pair<int, int>>());
54}
55
57void CGeomMultiLine::AppendLineSegment(vector<pair<int, int>>* pprVIn)
58{
59 m_prVVLineSegment.push_back(*pprVIn);
60}
61
63// void CGeomMultiLine::AppendLineSegmentAndInherit(void)
64// {
65// vector<pair<int, int> > prVNewLineSeg;
66// m_prVVLineSegment.push_back(prVNewLineSeg);
67//
68// // Must inherit any profile numbers stored in earlier (i.e. coastward) line segments
69// int nSize = m_prVVLineSegment.size();
70// if (nSize > 1)
71// {
72// for (int n = 0; n < m_prVVLineSegment[nSize-2].size(); n++)
73// {
74// int
75// nPrevProfile = m_prVVLineSegment[nSize-2][n].first,
76// nPrevLineSeg = m_prVVLineSegment[nSize-2][n].second + 1;
77//
78// m_prVVLineSegment[nSize-1].push_back(make_pair(nPrevProfile, nPrevLineSeg));
79// }
80// }
81// }
82
85{
86 return static_cast<int>(m_prVVLineSegment.size());
87}
88
91{
92 m_prVVLineSegment.resize(nSize);
93}
94
96void CGeomMultiLine::InsertLineSegment(int const nSegment)
97{
98 // assert(nSegment < m_prVVLineSegment.size());
99
100 // 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
101 vector<pair<int, int>> prVPrev = m_prVVLineSegment[nSegment];
102
103 // Store the profile numbers that are in this existing vector of pairs, these are the profiles that will be affected by this insertion
104 vector<int> nVProfsAffected;
105 nVProfsAffected.reserve(prVPrev.size());
106
107 for (unsigned int i = 0; i < prVPrev.size(); i++)
108 nVProfsAffected.push_back(prVPrev[i].first);
109
110 vector<vector<pair<int, int>>>::iterator it;
111 it = m_prVVLineSegment.begin();
112
113 m_prVVLineSegment.insert(it + nSegment + 1, prVPrev);
114
115 // 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
116 for (unsigned int m = nSegment + 1; m < m_prVVLineSegment.size(); m++)
117 {
118 for (unsigned int n = 0; n < m_prVVLineSegment[m].size(); n++)
119 {
120 for (unsigned int i = 0; i < nVProfsAffected.size(); i++)
121 {
122 if (m_prVVLineSegment[m][n].first == nVProfsAffected[i])
123 m_prVVLineSegment[m][n].second++;
124 }
125 }
126 }
127}
128
130vector<vector<pair<int, int>>> CGeomMultiLine::prVVGetAllLineSegAfter(int const nSegment)
131{
132 vector<vector<pair<int, int>>> prVTmp;
133
134 for (unsigned int n = nSegment; n < m_prVVLineSegment.size(); n++)
135 prVTmp.push_back(m_prVVLineSegment[n]);
136
137 return prVTmp;
138}
139
141void CGeomMultiLine::RemoveLineSegment(int const nSegment)
142{
143 m_prVVLineSegment.erase(m_prVVLineSegment.begin() + nSegment);
144}
145
148{
149 long unsigned int const nSize = m_prVVLineSegment.size();
150 m_prVVLineSegment[nSize - 1].push_back(prIn);
151 // m_prVVLineSegment.back().push_back(prIn);
152}
153
155void CGeomMultiLine::AddCoincidentProfileToExistingLineSegment(int const nSegment, int const nProfile, int const nLineSeg)
156{
157 // assert(nSegment < m_prVVLineSegment.size());
158 m_prVVLineSegment[nSegment].push_back(make_pair(nProfile, nLineSeg));
159}
160
162vector<pair<int, int>>* CGeomMultiLine::pprVGetPairedCoincidentProfilesForLineSegment(int const nSegment)
163{
164 // TODO 055 No check to see if nSegment < size()
165 return &m_prVVLineSegment[nSegment];
166}
167
169int CGeomMultiLine::nGetCoincidentProfileForLineSegment(int const nSegment, int const nCoinc) const
170{
171 // Safety check
172 if ((nSegment < 0) || (nSegment >= static_cast<int>(m_prVVLineSegment.size())))
173 return -1;
174
175 // Safety check
176 if ((nCoinc < 0) || (nCoinc >= static_cast<int>(m_prVVLineSegment[nSegment].size())))
177 return -1;
178
179 return m_prVVLineSegment[nSegment][nCoinc].first;
180}
181
184{
185 // Safety check
186 if (nSegment > static_cast<int>(m_prVVLineSegment.size()) - 1)
187 return -1;
188
189 return static_cast<int>(m_prVVLineSegment[nSegment].size());
190}
191
194{
195 long unsigned int const nLineSegSize = m_prVVLineSegment.size();
196
197 // Note no check to ensure that nLineSegSize < 0
198 long unsigned int const nCoincidentSize = m_prVVLineSegment[nLineSegSize - 1].size();
199
200 for (unsigned int i = 0; i < nCoincidentSize; i++)
201 {
202 if (m_prVVLineSegment[nLineSegSize - 1][i].first == nProfile)
203 return true;
204 }
205
206 return false;
207}
208
210// bool CGeomMultiLine::bFindProfileInCoincidentProfilesOfLineSegment(int const nProfile, int const nSegment)
211// {
212// // Note no check to see if nSegment < m_prVVLineSegment.size()
213// int nCoincidentSize = m_prVVLineSegment[nSegment].size();
214//
215// for (int i = 0; i < nCoincidentSize; i++)
216// if (m_prVVLineSegment[nSegment][i].first == nProfile)
217// return true;
218//
219// return false;
220// }
221
224{
225 int const nSegSize = static_cast<int>(m_prVVLineSegment.size());
226
227 if (nSegSize == 0)
228 return false;
229
230 for (int i = nSegSize - 1; i >= 0; i--)
231 {
232 for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
233 {
234 if (m_prVVLineSegment[i][j].first == nProfile)
235 return true;
236 }
237 }
238
239 return false;
240}
241
243void CGeomMultiLine::GetMostCoastwardSharedLineSegment(int const nOtherProfile, int& nThisLineSegment, int& nOtherLineSegment)
244{
245 nThisLineSegment =
246 nOtherLineSegment = -1;
247
248 long unsigned int const nSegSize = m_prVVLineSegment.size();
249
250 if (nSegSize == 0)
251 return;
252
253 for (unsigned int i = 0; i < nSegSize; i++)
254 {
255 for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
256 {
257 if (m_prVVLineSegment[i][j].first == nOtherProfile)
258 {
259 nThisLineSegment = i;
260 nOtherLineSegment = m_prVVLineSegment[i][j].second;
261
262 return;
263 }
264 }
265 }
266}
267
269int CGeomMultiLine::nGetProf(int const nSegment, int const nCoinc) const
270{
271 return m_prVVLineSegment[nSegment][nCoinc].first;
272}
273
275int CGeomMultiLine::nGetProfsLineSeg(int const nSegment, int const nCoinc) const
276{
277 return m_prVVLineSegment[nSegment][nCoinc].second;
278}
279
281void CGeomMultiLine::SetProfsLineSeg(int const nSegment, int const nCoinc, int const nLineSeg)
282{
283 // Note no check to see if nSegment < m_prVVLineSegment.size() or to see if nCoinc < m_prVVLineSegment[nSegment].size()
284 m_prVVLineSegment[nSegment][nCoinc].second = nLineSeg;
285}
286
287// //! Returns the number of the last line segment which includes the given profile number as a co-incident profile
288// int CGeomMultiLine::nFindProfilesLastSeg(int const nProfile) const
289// {
290// int nSeg = -1;
291// for (int i = static_cast<int>(m_prVVLineSegment.size()-1); i >= 0; i--)
292// {
293// for (unsigned int j = 0; j < m_prVVLineSegment[i].size(); j++)
294// {
295// if (m_prVVLineSegment[i][j].first == nProfile)
296// nSeg = i;
297// }
298// }
299//
300// return nSeg;
301// }
vector< CGeom2DPoint > m_VPoints
The points which comprise the float-coordinate 2D shape.
Definition 2d_shape.h:39
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...
vector< CGeom2DPoint > & pGetPoints(void)
Returns a pointer to the points of the CGeomLine.
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 SetPoints(vector< CGeom2DPoint > &)
Replaces the points of the CGeomLine.
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:41
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.
Contains CGeomMultiLine definitions.