Eclipse SUMO - Simulation of Urban MObility
NIVissimAbstractEdge.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // -------------------
21 /****************************************************************************/
22 #include <config.h>
23 
24 
25 #include <map>
26 #include <cassert>
28 #include <utils/common/ToString.h>
29 #include <utils/geom/GeomHelper.h>
31 #include <netbuild/NBNetBuilder.h>
32 #include "NIVissimAbstractEdge.h"
33 
34 
36 
38  const PositionVector& geom)
39  : myID(id), myNode(-1) {
40  // convert/publicate geometry
41  for (PositionVector::const_iterator i = geom.begin(); i != geom.end(); ++i) {
42  Position p = *i;
44  WRITE_WARNINGF(TL("Unable to project coordinates for edge '%'."), toString(id));
45  }
47  }
48  //
49  dictionary(id, this);
50 }
51 
52 
54 
55 
56 bool
58  DictType::iterator i = myDict.find(id);
59  if (i == myDict.end()) {
60  myDict[id] = e;
61  return true;
62  }
63  return false;
64 }
65 
66 
69  DictType::iterator i = myDict.find(id);
70  if (i == myDict.end()) {
71  return nullptr;
72  }
73  return (*i).second;
74 }
75 
76 
77 
80  if (myGeom.length() > pos) {
81  return myGeom.positionAtOffset(pos);
82  } else if (myGeom.length() == pos) {
83  return myGeom[-1];
84  } else {
86  const double amount = pos - myGeom.length();
87  g.extrapolate(amount * 2);
88  return g.positionAtOffset(pos + amount * 2);
89  }
90 }
91 
92 
93 void
95  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
96  NIVissimAbstractEdge* e = (*i).second;
97  e->splitAssigning();
98  }
99 }
100 
101 void
103 
104 
105 
106 
107 
108 bool
110  return myGeom.intersects(c->myGeom);
111 }
112 
113 
114 Position
117 }
118 
119 
120 std::vector<int>
122  std::vector<int> ret;
123  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
124  NIVissimAbstractEdge* e = (*i).second;
125  if (e->overlapsWith(p, offset)) {
126  ret.push_back(e->myID);
127  }
128  }
129  return ret;
130 }
131 
132 
133 bool
134 NIVissimAbstractEdge::overlapsWith(const AbstractPoly& p, double offset) const {
135  return myGeom.overlapsWith(p, offset);
136 }
137 
138 
139 bool
141  return myNode != -1;
142 }
143 
144 
145 int
147  return myID;
148 }
149 
150 void
152  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
153  delete (*i).second;
154  }
155  myDict.clear();
156 }
157 
158 
159 const PositionVector&
161  return myGeom;
162 }
163 
164 
165 void
167  myDisturbances.push_back(disturbance);
168 }
169 
170 
171 const std::vector<int>&
173  return myDisturbances;
174 }
175 
176 
177 /****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define TL(string)
Definition: MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=nullptr)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
static bool dictionary(int id, NIVissimAbstractEdge *e)
const PositionVector & getGeometry() const
static std::vector< int > getWithin(const AbstractPoly &p, double offset=0.0)
bool overlapsWith(const AbstractPoly &p, double offset=0.0) const
static void splitAndAssignToNodes()
Position crossesEdgeAtPoint(NIVissimAbstractEdge *c) const
const std::vector< int > & getDisturbances() const
void addDisturbance(int disturbance)
NIVissimAbstractEdge(int id, const PositionVector &geom)
std::map< int, NIVissimAbstractEdge * > DictType
std::vector< int > myDisturbances
bool crossesEdge(NIVissimAbstractEdge *c) const
Position getGeomPosition(double pos) const
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
bool overlapsWith(const AbstractPoly &poly, double offset=0) const
Returns the information whether the given polygon overlaps with this.
double length() const
Returns the length.
Position intersectionPosition2D(const Position &p1, const Position &p2, const double withinDist=0.) const
Returns the position of the intersection.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void extrapolate(const double val, const bool onlyFirst=false, const bool onlyLast=false)
extrapolate position vector
void push_back_noDoublePos(const Position &p)
insert in back a non double position
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.