SUMO - Simulation of Urban MObility
NIVissimNodeDef_Edges.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // -------------------
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 
00033 
00034 #include <string>
00035 #include <map>
00036 #include <algorithm>
00037 #include <cassert>
00038 #include <utils/geom/Boundary.h>
00039 #include "NIVissimNodeParticipatingEdgeVector.h"
00040 #include "NIVissimNodeDef.h"
00041 #include "NIVissimEdge.h"
00042 #include "NIVissimNodeDef_Edges.h"
00043 #include "NIVissimDisturbance.h"
00044 #include "NIVissimConnection.h"
00045 
00046 #ifdef CHECK_MEMORY_LEAKS
00047 #include <foreign/nvwa/debug_new.h>
00048 #endif // CHECK_MEMORY_LEAKS
00049 
00050 
00051 // ===========================================================================
00052 // method definitions
00053 // ===========================================================================
00054 NIVissimNodeDef_Edges::NIVissimNodeDef_Edges(int id,
00055         const std::string& name, const NIVissimNodeParticipatingEdgeVector& edges)
00056     : NIVissimNodeDef(id, name), myEdges(edges) {}
00057 
00058 
00059 NIVissimNodeDef_Edges::~NIVissimNodeDef_Edges() {
00060     for (NIVissimNodeParticipatingEdgeVector::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
00061         delete(*i);
00062     }
00063     myEdges.clear();
00064 }
00065 
00066 
00067 bool
00068 NIVissimNodeDef_Edges::dictionary(int id, const std::string& name,
00069                                   const NIVissimNodeParticipatingEdgeVector& edges) {
00070     NIVissimNodeDef_Edges* o = new NIVissimNodeDef_Edges(id, name, edges);
00071     if (!NIVissimNodeDef::dictionary(id, o)) {
00072         delete o;
00073         return false;
00074     }
00075     return true;
00076 }
00077 
00078 
00079 void
00080 NIVissimNodeDef_Edges::searchAndSetConnections() {
00081     std::vector<int> connections;
00082     std::vector<int> edges;
00083     Boundary boundary;
00084     for (NIVissimNodeParticipatingEdgeVector::const_iterator i = myEdges.begin(); i != myEdges.end(); i++) {
00085         NIVissimNodeParticipatingEdge* edge = *i;
00086         NIVissimConnection* c =
00087             NIVissimConnection::dictionary(edge->getID());
00088         NIVissimEdge* e =
00089             NIVissimEdge::dictionary(edge->getID());
00090         if (c != 0) {
00091             connections.push_back(edge->getID());
00092             boundary.add(c->getFromGeomPosition());
00093             boundary.add(c->getToGeomPosition());
00094             c->setNodeCluster(myID);
00095         }
00096         if (e != 0) {
00097             edges.push_back(edge->getID());
00098             boundary.add(e->getGeomPosition(edge->getFromPos()));
00099             boundary.add(e->getGeomPosition(edge->getToPos()));
00100         }
00101     }
00102     NIVissimConnectionCluster* c =
00103         new NIVissimConnectionCluster(connections, boundary, myID, edges);
00104     for (std::vector<int>::iterator j = edges.begin(); j != edges.end(); j++) {
00105         NIVissimEdge* edge = NIVissimEdge::dictionary(*j);
00106         edge->myConnectionClusters.push_back(c);
00107     }
00108 }
00109 
00110 
00111 
00112 SUMOReal
00113 NIVissimNodeDef_Edges::getEdgePosition(int edgeid) const {
00114     for (NIVissimNodeParticipatingEdgeVector::const_iterator i = myEdges.begin(); i != myEdges.end(); i++) {
00115         NIVissimNodeParticipatingEdge* edge = *i;
00116         if (edge->getID() == edgeid) {
00117             return (edge->getFromPos() + edge->getToPos()) / (SUMOReal) 2.0;
00118         }
00119     }
00120     return -1;
00121 }
00122 
00123 
00124 
00125 /****************************************************************************/
00126 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines