SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // ------------------- 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 00023 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 00034 #include <map> 00035 #include <cassert> 00036 #include <utils/common/MsgHandler.h> 00037 #include <utils/common/ToString.h> 00038 #include <utils/geom/GeomHelper.h> 00039 #include <utils/geom/Line.h> 00040 #include <utils/geom/GeoConvHelper.h> 00041 #include <netimport/NILoader.h> 00042 #include "NIVissimAbstractEdge.h" 00043 00044 #ifdef CHECK_MEMORY_LEAKS 00045 #include <foreign/nvwa/debug_new.h> 00046 #endif // CHECK_MEMORY_LEAKS 00047 00048 00049 NIVissimAbstractEdge::DictType NIVissimAbstractEdge::myDict; 00050 00051 NIVissimAbstractEdge::NIVissimAbstractEdge(int id, 00052 const PositionVector& geom) 00053 : myID(id), myNode(-1) 00054 { 00055 // convert/publicate geometry 00056 for (PositionVector::ContType::const_iterator i = geom.begin(); i != geom.end(); ++i) { 00057 Position p = *i; 00058 if (!NILoader::transformCoordinates(p)) { 00059 WRITE_WARNING("Unable to project coordinates for edge '" + toString(id) + "'."); 00060 } 00061 myGeom.push_back_noDoublePos(p); 00062 } 00063 // 00064 dictionary(id, this); 00065 } 00066 00067 00068 NIVissimAbstractEdge::~NIVissimAbstractEdge() {} 00069 00070 00071 bool 00072 NIVissimAbstractEdge::dictionary(int id, NIVissimAbstractEdge* e) { 00073 DictType::iterator i = myDict.find(id); 00074 if (i == myDict.end()) { 00075 myDict[id] = e; 00076 return true; 00077 } 00078 return false; 00079 } 00080 00081 00082 NIVissimAbstractEdge* 00083 NIVissimAbstractEdge::dictionary(int id) { 00084 DictType::iterator i = myDict.find(id); 00085 if (i == myDict.end()) { 00086 return 0; 00087 } 00088 return (*i).second; 00089 } 00090 00091 00092 00093 Position 00094 NIVissimAbstractEdge::getGeomPosition(SUMOReal pos) const { 00095 if (myGeom.length() > pos) { 00096 return myGeom.positionAtLengthPosition(pos); 00097 } else if (myGeom.length() == pos) { 00098 return myGeom[-1]; 00099 } else { 00100 PositionVector g(myGeom); 00101 SUMOReal amount = pos - myGeom.length(); 00102 Position ne = GeomHelper::extrapolate_second(g[-2], g[-1], amount * 2); 00103 g.pop_back(); 00104 g.push_back(ne); 00105 return g.positionAtLengthPosition(pos); 00106 } 00107 } 00108 00109 00110 void 00111 NIVissimAbstractEdge::splitAndAssignToNodes() { 00112 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) { 00113 NIVissimAbstractEdge* e = (*i).second; 00114 e->splitAssigning(); 00115 } 00116 } 00117 00118 void 00119 NIVissimAbstractEdge::splitAssigning() {} 00120 00121 00122 00123 00124 00125 bool 00126 NIVissimAbstractEdge::crossesEdge(NIVissimAbstractEdge* c) const { 00127 return myGeom.intersects(c->myGeom); 00128 } 00129 00130 00131 Position 00132 NIVissimAbstractEdge::crossesEdgeAtPoint(NIVissimAbstractEdge* c) const { 00133 return myGeom.intersectsAtPoint(c->myGeom); 00134 } 00135 00136 00137 SUMOReal 00138 NIVissimAbstractEdge::crossesAtPoint(const Position& p1, 00139 const Position& p2) const { 00140 // !!! not needed 00141 Position p = GeomHelper::intersection_position2D( 00142 myGeom.getBegin(), myGeom.getEnd(), p1, p2); 00143 return GeomHelper::nearest_position_on_line_to_point2D( 00144 myGeom.getBegin(), myGeom.getEnd(), p); 00145 } 00146 00147 00148 00149 std::vector<int> 00150 NIVissimAbstractEdge::getWithin(const AbstractPoly& p, SUMOReal offset) { 00151 std::vector<int> ret; 00152 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) { 00153 NIVissimAbstractEdge* e = (*i).second; 00154 if (e->overlapsWith(p, offset)) { 00155 ret.push_back(e->myID); 00156 } 00157 } 00158 return ret; 00159 } 00160 00161 00162 bool 00163 NIVissimAbstractEdge::overlapsWith(const AbstractPoly& p, SUMOReal offset) const { 00164 return myGeom.overlapsWith(p, offset); 00165 } 00166 00167 00168 bool 00169 NIVissimAbstractEdge::hasNodeCluster() const { 00170 return myNode != -1; 00171 } 00172 00173 00174 int 00175 NIVissimAbstractEdge::getID() const { 00176 return myID; 00177 } 00178 00179 void 00180 NIVissimAbstractEdge::clearDict() { 00181 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) { 00182 delete(*i).second; 00183 } 00184 myDict.clear(); 00185 } 00186 00187 00188 const PositionVector& 00189 NIVissimAbstractEdge::getGeometry() const { 00190 return myGeom; 00191 } 00192 00193 00194 void 00195 NIVissimAbstractEdge::addDisturbance(int disturbance) { 00196 myDisturbances.push_back(disturbance); 00197 } 00198 00199 00200 const std::vector<int>& 00201 NIVissimAbstractEdge::getDisturbances() const { 00202 return myDisturbances; 00203 } 00204 00205 00206 00207 /****************************************************************************/ 00208