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