|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // References a street of the city and defines a position in this street 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 // activitygen module 00012 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/) 00013 /****************************************************************************/ 00014 // 00015 // This program 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 2 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 #include "AGPosition.h" 00033 #include "AGStreet.h" 00034 #include "router/ROEdge.h" 00035 #include "utils/common/RandHelper.h" 00036 #include <iostream> 00037 #include <limits> 00038 00039 00040 // =========================================================================== 00041 // method definitions 00042 // =========================================================================== 00043 AGPosition::AGPosition(const AGStreet& str, SUMOReal pos) throw() : 00044 street(&str), position(pos), pos2d(compute2dPosition()) { 00045 } 00046 00047 00048 AGPosition::AGPosition(const AGStreet& str) throw() : 00049 street(&str), position(randomPositionInStreet(str)), pos2d(compute2dPosition()) { 00050 } 00051 00052 00053 void 00054 AGPosition::print() const throw() { 00055 std::cout << "- AGPosition: *Street=" << street << " position=" << position << "/" << street->getLength() << std::endl; 00056 } 00057 00058 00059 bool 00060 AGPosition::operator==(const AGPosition& pos) const throw() { 00061 return pos2d.almostSame(pos.pos2d); 00062 } 00063 00064 00065 SUMOReal 00066 AGPosition::distanceTo(const AGPosition& otherPos) const throw() { 00067 return pos2d.distanceTo(otherPos.pos2d); 00068 } 00069 00070 00071 SUMOReal 00072 AGPosition::minDistanceTo(const std::list<AGPosition>& positions) const throw() { 00073 SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity(); 00074 SUMOReal tempDist; 00075 std::list<AGPosition>::const_iterator itt; 00076 00077 for (itt=positions.begin() ; itt!=positions.end() ; ++itt) { 00078 tempDist = this->distanceTo(*itt); 00079 if (tempDist < minDist) { 00080 minDist = tempDist; 00081 } 00082 } 00083 return minDist; 00084 } 00085 00086 00087 SUMOReal 00088 AGPosition::minDistanceTo(const std::map<int, AGPosition>& positions) const throw() { 00089 SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity(); 00090 SUMOReal tempDist; 00091 std::map<int, AGPosition>::const_iterator itt; 00092 00093 for (itt=positions.begin() ; itt!=positions.end() ; ++itt) { 00094 tempDist = this->distanceTo(itt->second); 00095 if (tempDist < minDist) { 00096 minDist = tempDist; 00097 } 00098 } 00099 return minDist; 00100 } 00101 00102 00103 const AGStreet& 00104 AGPosition::getStreet() const throw() { 00105 return *street; 00106 } 00107 00108 00109 SUMOReal 00110 AGPosition::getPosition() const throw() { 00111 return position; 00112 } 00113 00114 00115 SUMOReal 00116 AGPosition::randomPositionInStreet(const AGStreet& s) throw() { 00117 return RandHelper::rand(0.0, s.getLength()); 00118 } 00119 00120 00121 Position 00122 AGPosition::compute2dPosition() const throw() { 00123 // P = From + pos*(To - From) = pos*To + (1-pos)*From 00124 Position From = street->edge->getFromNode()->getPosition(); 00125 Position To = street->edge->getToNode()->getPosition(); 00126 Position position2d(To); 00127 00128 position2d.sub(From); 00129 position2d.mul(position / street->getLength()); 00130 position2d.add(From); 00131 00132 return position2d; 00133 } 00134 00135 /****************************************************************************/