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.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // -------------------
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 
27 #include <map>
28 #include <cassert>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
33 #include <netbuild/NBNetBuilder.h>
34 #include "NIVissimAbstractEdge.h"
35 
36 
38 
40  const PositionVector& geom)
41  : myID(id), myNode(-1) {
42  // convert/publicate geometry
43  for (PositionVector::const_iterator i = geom.begin(); i != geom.end(); ++i) {
44  Position p = *i;
46  WRITE_WARNING("Unable to project coordinates for edge '" + toString(id) + "'.");
47  }
49  }
50  //
51  dictionary(id, this);
52 }
53 
54 
56 
57 
58 bool
60  DictType::iterator i = myDict.find(id);
61  if (i == myDict.end()) {
62  myDict[id] = e;
63  return true;
64  }
65  return false;
66 }
67 
68 
71  DictType::iterator i = myDict.find(id);
72  if (i == myDict.end()) {
73  return nullptr;
74  }
75  return (*i).second;
76 }
77 
78 
79 
82  if (myGeom.length() > pos) {
83  return myGeom.positionAtOffset(pos);
84  } else if (myGeom.length() == pos) {
85  return myGeom[-1];
86  } else {
88  const double amount = pos - myGeom.length();
89  g.extrapolate(amount * 2);
90  return g.positionAtOffset(pos + amount * 2);
91  }
92 }
93 
94 
95 void
97  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
98  NIVissimAbstractEdge* e = (*i).second;
99  e->splitAssigning();
100  }
101 }
102 
103 void
105 
106 
107 
108 
109 
110 bool
112  return myGeom.intersects(c->myGeom);
113 }
114 
115 
116 Position
119 }
120 
121 
122 std::vector<int>
124  std::vector<int> ret;
125  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
126  NIVissimAbstractEdge* e = (*i).second;
127  if (e->overlapsWith(p, offset)) {
128  ret.push_back(e->myID);
129  }
130  }
131  return ret;
132 }
133 
134 
135 bool
136 NIVissimAbstractEdge::overlapsWith(const AbstractPoly& p, double offset) const {
137  return myGeom.overlapsWith(p, offset);
138 }
139 
140 
141 bool
143  return myNode != -1;
144 }
145 
146 
147 int
149  return myID;
150 }
151 
152 void
154  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
155  delete(*i).second;
156  }
157  myDict.clear();
158 }
159 
160 
161 const PositionVector&
163  return myGeom;
164 }
165 
166 
167 void
169  myDisturbances.push_back(disturbance);
170 }
171 
172 
173 const std::vector<int>&
175  return myDisturbances;
176 }
177 
178 
179 
180 /****************************************************************************/
181 
Position getGeomPosition(double pos) const
const std::vector< int > & getDisturbances() const
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
static bool dictionary(int id, NIVissimAbstractEdge *e)
void addDisturbance(int disturbance)
Position intersectionPosition2D(const Position &p1, const Position &p2, const double withinDist=0.) const
Returns the position of the intersection.
const PositionVector & getGeometry() const
static void splitAndAssignToNodes()
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
bool overlapsWith(const AbstractPoly &p, double offset=0.0) const
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
NIVissimAbstractEdge(int id, const PositionVector &geom)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
static std::vector< int > getWithin(const AbstractPoly &p, double offset=0.0)
bool overlapsWith(const AbstractPoly &poly, double offset=0) const
Returns the information whether the given polygon overlaps with this.
Position crossesEdgeAtPoint(NIVissimAbstractEdge *c) const
void extrapolate(const double val, const bool onlyFirst=false, const bool onlyLast=false)
extrapolate position vector
double length() const
Returns the length.
std::vector< int > myDisturbances
bool crossesEdge(NIVissimAbstractEdge *c) const
std::map< int, NIVissimAbstractEdge * > DictType
void push_back_noDoublePos(const Position &p)
insert in back a non double position
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.