Line data Source code
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 : /****************************************************************************/ 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 1610 : NIVissimAbstractEdge::NIVissimAbstractEdge(int id, 38 1610 : const PositionVector& geom) 39 1610 : : myID(id), myNode(-1) { 40 : // convert/publicate geometry 41 8043 : for (PositionVector::const_iterator i = geom.begin(); i != geom.end(); ++i) { 42 6433 : Position p = *i; 43 6433 : if (!NBNetBuilder::transformCoordinate(p)) { 44 0 : WRITE_WARNINGF(TL("Unable to project coordinates for edge '%'."), toString(id)); 45 : } 46 6433 : myGeom.push_back_noDoublePos(p); 47 : } 48 : // 49 1610 : dictionary(id, this); 50 1610 : } 51 : 52 : 53 1802 : NIVissimAbstractEdge::~NIVissimAbstractEdge() {} 54 : 55 : 56 : bool 57 1610 : NIVissimAbstractEdge::dictionary(int id, NIVissimAbstractEdge* e) { 58 : DictType::iterator i = myDict.find(id); 59 1610 : if (i == myDict.end()) { 60 1610 : myDict[id] = e; 61 1610 : return true; 62 : } 63 : return false; 64 : } 65 : 66 : 67 : NIVissimAbstractEdge* 68 13148 : NIVissimAbstractEdge::dictionary(int id) { 69 : DictType::iterator i = myDict.find(id); 70 13148 : if (i == myDict.end()) { 71 : return nullptr; 72 : } 73 13148 : return (*i).second; 74 : } 75 : 76 : 77 : 78 : Position 79 9042 : NIVissimAbstractEdge::getGeomPosition(double pos) const { 80 9042 : if (myGeom.length() > pos) { 81 8993 : return myGeom.positionAtOffset(pos); 82 49 : } else if (myGeom.length() == pos) { 83 0 : return myGeom[-1]; 84 : } else { 85 : PositionVector g(myGeom); 86 49 : const double amount = pos - myGeom.length(); 87 49 : g.extrapolate(amount * 2); 88 49 : return g.positionAtOffset(pos + amount * 2); 89 49 : } 90 : } 91 : 92 : 93 : void 94 0 : NIVissimAbstractEdge::splitAndAssignToNodes() { 95 0 : for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) { 96 0 : NIVissimAbstractEdge* e = (*i).second; 97 0 : e->splitAssigning(); 98 : } 99 0 : } 100 : 101 : void 102 0 : NIVissimAbstractEdge::splitAssigning() {} 103 : 104 : 105 : 106 : 107 : 108 : bool 109 1805 : NIVissimAbstractEdge::crossesEdge(NIVissimAbstractEdge* c) const { 110 1805 : return myGeom.intersects(c->myGeom); 111 : } 112 : 113 : 114 : Position 115 806 : NIVissimAbstractEdge::crossesEdgeAtPoint(NIVissimAbstractEdge* c) const { 116 806 : return myGeom.intersectionPosition2D(c->myGeom); 117 : } 118 : 119 : 120 : std::vector<int> 121 0 : NIVissimAbstractEdge::getWithin(const AbstractPoly& p, double offset) { 122 : std::vector<int> ret; 123 0 : for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) { 124 0 : NIVissimAbstractEdge* e = (*i).second; 125 0 : if (e->overlapsWith(p, offset)) { 126 0 : ret.push_back(e->myID); 127 : } 128 : } 129 0 : return ret; 130 : } 131 : 132 : 133 : bool 134 0 : NIVissimAbstractEdge::overlapsWith(const AbstractPoly& p, double offset) const { 135 0 : return myGeom.overlapsWith(p, offset); 136 : } 137 : 138 : 139 : bool 140 1854 : NIVissimAbstractEdge::hasNodeCluster() const { 141 1854 : return myNode != -1; 142 : } 143 : 144 : 145 : int 146 196523 : NIVissimAbstractEdge::getID() const { 147 196523 : return myID; 148 : } 149 : 150 : void 151 36 : NIVissimAbstractEdge::clearDict() { 152 1646 : for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) { 153 1610 : delete (*i).second; 154 : } 155 : myDict.clear(); 156 36 : } 157 : 158 : 159 : const PositionVector& 160 125991 : NIVissimAbstractEdge::getGeometry() const { 161 125991 : return myGeom; 162 : } 163 : 164 : 165 : void 166 830 : NIVissimAbstractEdge::addDisturbance(int disturbance) { 167 830 : myDisturbances.push_back(disturbance); 168 830 : } 169 : 170 : 171 : const std::vector<int>& 172 4977 : NIVissimAbstractEdge::getDisturbances() const { 173 4977 : return myDisturbances; 174 : } 175 : 176 : 177 : /****************************************************************************/