NIVissimAbstractEdge.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // -------------------
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 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/Line2D.h>
00037 #include <utils/geom/GeoConvHelper.h>
00038 #include "NIVissimAbstractEdge.h"
00039 
00040 #ifdef CHECK_MEMORY_LEAKS
00041 #include <foreign/nvwa/debug_new.h>
00042 #endif // CHECK_MEMORY_LEAKS
00043 
00044 
00045 NIVissimAbstractEdge::DictType NIVissimAbstractEdge::myDict;
00046 
00047 NIVissimAbstractEdge::NIVissimAbstractEdge(int id,
00048         const Position2DVector &geom)
00049         : myID(id), myNode(-1) {
00050     // convert/publicate geometry
00051     std::deque<Position2D>::const_iterator i;
00052     const std::deque<Position2D> &geomC = geom.getCont();
00053     for (i=geomC.begin(); i!=geomC.end(); ++i) {
00054         Position2D p = *i;
00055         if (!GeoConvHelper::x2cartesian(p)) {
00056             MsgHandler::getWarningInstance()->inform("Unable to project coordinates for edge '" + toString(id) + "'.");
00057         }
00058         myGeom.push_back_noDoublePos(p);
00059     }
00060     //
00061     dictionary(id, this);
00062 }
00063 
00064 
00065 NIVissimAbstractEdge::~NIVissimAbstractEdge() {}
00066 
00067 
00068 bool
00069 NIVissimAbstractEdge::dictionary(int id, NIVissimAbstractEdge *e) {
00070     DictType::iterator i=myDict.find(id);
00071     if (i==myDict.end()) {
00072         myDict[id] = e;
00073         return true;
00074     }
00075     return false;
00076 }
00077 
00078 
00079 NIVissimAbstractEdge *
00080 NIVissimAbstractEdge::dictionary(int id) {
00081     DictType::iterator i=myDict.find(id);
00082     if (i==myDict.end()) {
00083         return 0;
00084     }
00085     return (*i).second;
00086 }
00087 
00088 
00089 
00090 Position2D
00091 NIVissimAbstractEdge::getGeomPosition(SUMOReal pos) const {
00092     if (myGeom.length()>pos) {
00093         return myGeom.positionAtLengthPosition(pos);
00094     } else if (myGeom.length()==pos) {
00095         return myGeom[-1];
00096     } else {
00097         Position2DVector g(myGeom);
00098         SUMOReal amount = pos - myGeom.length();
00099         Position2D ne = GeomHelper::extrapolate_second(g[-2], g[-1], amount*2);
00100         g.pop_back();
00101         g.push_back(ne);
00102         return g.positionAtLengthPosition(pos);
00103     }
00104 }
00105 
00106 
00107 void
00108 NIVissimAbstractEdge::splitAndAssignToNodes() {
00109     for (DictType::iterator i=myDict.begin(); i!=myDict.end(); i++) {
00110         NIVissimAbstractEdge *e = (*i).second;
00111         e->splitAssigning();
00112     }
00113 }
00114 
00115 void
00116 NIVissimAbstractEdge::splitAssigning() {}
00117 
00118 
00119 
00120 
00121 
00122 bool
00123 NIVissimAbstractEdge::crossesEdge(NIVissimAbstractEdge *c) const {
00124     return myGeom.intersects(c->myGeom);
00125 }
00126 
00127 
00128 Position2D
00129 NIVissimAbstractEdge::crossesEdgeAtPoint(NIVissimAbstractEdge *c) const {
00130     return myGeom.intersectsAtPoint(c->myGeom);
00131 }
00132 
00133 
00134 SUMOReal
00135 NIVissimAbstractEdge::crossesAtPoint(const Position2D &p1,
00136                                      const Position2D &p2) const {
00137     // !!! not needed
00138     Position2D p = GeomHelper::intersection_position(
00139                        myGeom.getBegin(), myGeom.getEnd(), p1, p2);
00140     return GeomHelper::nearest_position_on_line_to_point(
00141                myGeom.getBegin(), myGeom.getEnd(), p);
00142 }
00143 
00144 
00145 
00146 IntVector
00147 NIVissimAbstractEdge::getWithin(const AbstractPoly &p, SUMOReal offset) {
00148     IntVector ret;
00149     for (DictType::iterator i=myDict.begin(); i!=myDict.end(); i++) {
00150         NIVissimAbstractEdge *e = (*i).second;
00151         if (e->overlapsWith(p, offset)) {
00152             ret.push_back(e->myID);
00153         }
00154     }
00155     return ret;
00156 }
00157 
00158 
00159 bool
00160 NIVissimAbstractEdge::overlapsWith(const AbstractPoly &p, SUMOReal offset) const {
00161     return myGeom.overlapsWith(p, offset);
00162 }
00163 
00164 
00165 bool
00166 NIVissimAbstractEdge::hasNodeCluster() const {
00167     return myNode!=-1;
00168 }
00169 
00170 
00171 int
00172 NIVissimAbstractEdge::getID() const {
00173     return myID;
00174 }
00175 
00176 void
00177 NIVissimAbstractEdge::clearDict() {
00178     for (DictType::iterator i=myDict.begin(); i!=myDict.end(); i++) {
00179         delete(*i).second;
00180     }
00181     myDict.clear();
00182 }
00183 
00184 
00185 const Position2DVector &
00186 NIVissimAbstractEdge::getGeometry() const {
00187     return myGeom;
00188 }
00189 
00190 
00191 void
00192 NIVissimAbstractEdge::addDisturbance(int disturbance) {
00193     myDisturbances.push_back(disturbance);
00194 }
00195 
00196 
00197 const IntVector &
00198 NIVissimAbstractEdge::getDisturbances() const {
00199     return myDisturbances;
00200 }
00201 
00202 
00203 
00204 /****************************************************************************/
00205 

Generated on Wed May 5 00:06:34 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6