Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netimport/vissim/tempstructs/NIVissimAbstractEdge.cpp
169684 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file NIVissimAbstractEdge.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Sept 2002
19
///
20
// -------------------
21
/****************************************************************************/
22
#include <config.h>
23
24
25
#include <map>
26
#include <cassert>
27
#include <utils/common/MsgHandler.h>
28
#include <utils/common/ToString.h>
29
#include <utils/geom/GeomHelper.h>
30
#include <utils/geom/GeoConvHelper.h>
31
#include <netbuild/NBNetBuilder.h>
32
#include "NIVissimAbstractEdge.h"
33
34
35
NIVissimAbstractEdge::DictType NIVissimAbstractEdge::myDict;
36
37
NIVissimAbstractEdge::NIVissimAbstractEdge(int id,
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;
43
if (!NBNetBuilder::transformCoordinate(p)) {
44
WRITE_WARNINGF(TL("Unable to project coordinates for edge '%'."), toString(id));
45
}
46
myGeom.push_back_noDoublePos(p);
47
}
48
//
49
dictionary(id, this);
50
}
51
52
53
NIVissimAbstractEdge::~NIVissimAbstractEdge() {}
54
55
56
bool
57
NIVissimAbstractEdge::dictionary(int id, NIVissimAbstractEdge* e) {
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
67
NIVissimAbstractEdge*
68
NIVissimAbstractEdge::dictionary(int id) {
69
DictType::iterator i = myDict.find(id);
70
if (i == myDict.end()) {
71
return nullptr;
72
}
73
return (*i).second;
74
}
75
76
77
78
Position
79
NIVissimAbstractEdge::getGeomPosition(double pos) const {
80
if (myGeom.length() > pos) {
81
return myGeom.positionAtOffset(pos);
82
} else if (myGeom.length() == pos) {
83
return myGeom[-1];
84
} else {
85
PositionVector g(myGeom);
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
94
NIVissimAbstractEdge::splitAndAssignToNodes() {
95
for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
96
NIVissimAbstractEdge* e = (*i).second;
97
e->splitAssigning();
98
}
99
}
100
101
void
102
NIVissimAbstractEdge::splitAssigning() {}
103
104
105
106
107
108
bool
109
NIVissimAbstractEdge::crossesEdge(NIVissimAbstractEdge* c) const {
110
return myGeom.intersects(c->myGeom);
111
}
112
113
114
Position
115
NIVissimAbstractEdge::crossesEdgeAtPoint(NIVissimAbstractEdge* c) const {
116
return myGeom.intersectionPosition2D(c->myGeom);
117
}
118
119
120
std::vector<int>
121
NIVissimAbstractEdge::getWithin(const AbstractPoly& p, double offset) {
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
140
NIVissimAbstractEdge::hasNodeCluster() const {
141
return myNode != -1;
142
}
143
144
145
int
146
NIVissimAbstractEdge::getID() const {
147
return myID;
148
}
149
150
void
151
NIVissimAbstractEdge::clearDict() {
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&
160
NIVissimAbstractEdge::getGeometry() const {
161
return myGeom;
162
}
163
164
165
void
166
NIVissimAbstractEdge::addDisturbance(int disturbance) {
167
myDisturbances.push_back(disturbance);
168
}
169
170
171
const std::vector<int>&
172
NIVissimAbstractEdge::getDisturbances() const {
173
return myDisturbances;
174
}
175
176
177
/****************************************************************************/
178
179