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