|
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 00032 #include <string> 00033 #include <map> 00034 #include <algorithm> 00035 #include <cassert> 00036 #include <utils/geom/Boundary.h> 00037 #include "NIVissimNodeParticipatingEdgeVector.h" 00038 #include "NIVissimNodeDef.h" 00039 #include "NIVissimEdge.h" 00040 #include "NIVissimNodeDef_Edges.h" 00041 #include "NIVissimDisturbance.h" 00042 #include "NIVissimConnection.h" 00043 00044 #ifdef CHECK_MEMORY_LEAKS 00045 #include <foreign/nvwa/debug_new.h> 00046 #endif // CHECK_MEMORY_LEAKS 00047 00048 00049 // =========================================================================== 00050 // method definitions 00051 // =========================================================================== 00052 NIVissimNodeDef_Edges::NIVissimNodeDef_Edges(int id, 00053 const std::string& name, const NIVissimNodeParticipatingEdgeVector& edges) 00054 : NIVissimNodeDef(id, name), myEdges(edges) {} 00055 00056 00057 NIVissimNodeDef_Edges::~NIVissimNodeDef_Edges() { 00058 for (NIVissimNodeParticipatingEdgeVector::iterator i=myEdges.begin(); i!=myEdges.end(); i++) { 00059 delete(*i); 00060 } 00061 myEdges.clear(); 00062 } 00063 00064 00065 bool 00066 NIVissimNodeDef_Edges::dictionary(int id, const std::string& name, 00067 const NIVissimNodeParticipatingEdgeVector& edges) { 00068 NIVissimNodeDef_Edges* o = new NIVissimNodeDef_Edges(id, name, edges); 00069 if (!NIVissimNodeDef::dictionary(id, o)) { 00070 delete o; 00071 return false; 00072 } 00073 return true; 00074 } 00075 00076 00077 void 00078 NIVissimNodeDef_Edges::searchAndSetConnections() { 00079 IntVector connections; 00080 IntVector edges; 00081 Boundary boundary; 00082 for (NIVissimNodeParticipatingEdgeVector::const_iterator i=myEdges.begin(); i!=myEdges.end(); i++) { 00083 NIVissimNodeParticipatingEdge* edge = *i; 00084 NIVissimConnection* c = 00085 NIVissimConnection::dictionary(edge->getID()); 00086 NIVissimEdge* e = 00087 NIVissimEdge::dictionary(edge->getID()); 00088 if (c!=0) { 00089 connections.push_back(edge->getID()); 00090 boundary.add(c->getFromGeomPosition()); 00091 boundary.add(c->getToGeomPosition()); 00092 c->setNodeCluster(myID); 00093 } 00094 if (e!=0) { 00095 edges.push_back(edge->getID()); 00096 boundary.add(e->getGeomPosition(edge->getFromPos())); 00097 boundary.add(e->getGeomPosition(edge->getToPos())); 00098 } 00099 } 00100 NIVissimConnectionCluster* c = 00101 new NIVissimConnectionCluster(connections, boundary, myID, edges); 00102 for (IntVector::iterator j=edges.begin(); j!=edges.end(); j++) { 00103 NIVissimEdge* edge = NIVissimEdge::dictionary(*j); 00104 edge->myConnectionClusters.push_back(c); 00105 } 00106 } 00107 00108 00109 00110 SUMOReal 00111 NIVissimNodeDef_Edges::getEdgePosition(int edgeid) const { 00112 for (NIVissimNodeParticipatingEdgeVector::const_iterator i=myEdges.begin(); i!=myEdges.end(); i++) { 00113 NIVissimNodeParticipatingEdge* edge = *i; 00114 if (edge->getID()==edgeid) { 00115 return (edge->getFromPos() + edge->getToPos()) / (SUMOReal) 2.0; 00116 } 00117 } 00118 return -1; 00119 } 00120 00121 00122 00123 /****************************************************************************/ 00124