|
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 const PositionVector::ContType &geomC = geom.getCont(); 00057 for (PositionVector::ContType::const_iterator i = geomC.begin(); i != geomC.end(); ++i) { 00058 Position p = *i; 00059 if (!NILoader::transformCoordinates(p)) { 00060 WRITE_WARNING("Unable to project coordinates for edge '" + toString(id) + "'."); 00061 } 00062 myGeom.push_back_noDoublePos(p); 00063 } 00064 // 00065 dictionary(id, this); 00066 } 00067 00068 00069 NIVissimAbstractEdge::~NIVissimAbstractEdge() {} 00070 00071 00072 bool 00073 NIVissimAbstractEdge::dictionary(int id, NIVissimAbstractEdge* e) { 00074 DictType::iterator i = myDict.find(id); 00075 if (i == myDict.end()) { 00076 myDict[id] = e; 00077 return true; 00078 } 00079 return false; 00080 } 00081 00082 00083 NIVissimAbstractEdge* 00084 NIVissimAbstractEdge::dictionary(int id) { 00085 DictType::iterator i = myDict.find(id); 00086 if (i == myDict.end()) { 00087 return 0; 00088 } 00089 return (*i).second; 00090 } 00091 00092 00093 00094 Position 00095 NIVissimAbstractEdge::getGeomPosition(SUMOReal pos) const { 00096 if (myGeom.length() > pos) { 00097 return myGeom.positionAtLengthPosition(pos); 00098 } else if (myGeom.length() == pos) { 00099 return myGeom[-1]; 00100 } else { 00101 PositionVector g(myGeom); 00102 SUMOReal amount = pos - myGeom.length(); 00103 Position ne = GeomHelper::extrapolate_second(g[-2], g[-1], amount * 2); 00104 g.pop_back(); 00105 g.push_back(ne); 00106 return g.positionAtLengthPosition(pos); 00107 } 00108 } 00109 00110 00111 void 00112 NIVissimAbstractEdge::splitAndAssignToNodes() { 00113 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) { 00114 NIVissimAbstractEdge* e = (*i).second; 00115 e->splitAssigning(); 00116 } 00117 } 00118 00119 void 00120 NIVissimAbstractEdge::splitAssigning() {} 00121 00122 00123 00124 00125 00126 bool 00127 NIVissimAbstractEdge::crossesEdge(NIVissimAbstractEdge* c) const { 00128 return myGeom.intersects(c->myGeom); 00129 } 00130 00131 00132 Position 00133 NIVissimAbstractEdge::crossesEdgeAtPoint(NIVissimAbstractEdge* c) const { 00134 return myGeom.intersectsAtPoint(c->myGeom); 00135 } 00136 00137 00138 SUMOReal 00139 NIVissimAbstractEdge::crossesAtPoint(const Position& p1, 00140 const Position& p2) const { 00141 // !!! not needed 00142 Position p = GeomHelper::intersection_position( 00143 myGeom.getBegin(), myGeom.getEnd(), p1, p2); 00144 return GeomHelper::nearest_position_on_line_to_point2D( 00145 myGeom.getBegin(), myGeom.getEnd(), p); 00146 } 00147 00148 00149 00150 IntVector 00151 NIVissimAbstractEdge::getWithin(const AbstractPoly& p, SUMOReal offset) { 00152 IntVector ret; 00153 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) { 00154 NIVissimAbstractEdge* e = (*i).second; 00155 if (e->overlapsWith(p, offset)) { 00156 ret.push_back(e->myID); 00157 } 00158 } 00159 return ret; 00160 } 00161 00162 00163 bool 00164 NIVissimAbstractEdge::overlapsWith(const AbstractPoly& p, SUMOReal offset) const { 00165 return myGeom.overlapsWith(p, offset); 00166 } 00167 00168 00169 bool 00170 NIVissimAbstractEdge::hasNodeCluster() const { 00171 return myNode != -1; 00172 } 00173 00174 00175 int 00176 NIVissimAbstractEdge::getID() const { 00177 return myID; 00178 } 00179 00180 void 00181 NIVissimAbstractEdge::clearDict() { 00182 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) { 00183 delete(*i).second; 00184 } 00185 myDict.clear(); 00186 } 00187 00188 00189 const PositionVector& 00190 NIVissimAbstractEdge::getGeometry() const { 00191 return myGeom; 00192 } 00193 00194 00195 void 00196 NIVissimAbstractEdge::addDisturbance(int disturbance) { 00197 myDisturbances.push_back(disturbance); 00198 } 00199 00200 00201 const IntVector& 00202 NIVissimAbstractEdge::getDisturbances() const { 00203 return myDisturbances; 00204 } 00205 00206 00207 00208 /****************************************************************************/ 00209