SUMO - Simulation of Urban MObility
AGPosition.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00010 // References a street of the city and defines a position in this street
00011 /****************************************************************************/
00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00014 // activitygen module
00015 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
00016 /****************************************************************************/
00017 //
00018 //   This file is part of SUMO.
00019 //   SUMO is free software: you can redistribute it and/or modify
00020 //   it under the terms of the GNU General Public License as published by
00021 //   the Free Software Foundation, either version 3 of the License, or
00022 //   (at your option) any later version.
00023 //
00024 /****************************************************************************/
00025 
00026 
00027 // ===========================================================================
00028 // included modules
00029 // ===========================================================================
00030 #ifdef _MSC_VER
00031 #include <windows_config.h>
00032 #else
00033 #include <config.h>
00034 #endif
00035 
00036 #include "AGPosition.h"
00037 #include "AGStreet.h"
00038 #include "router/ROEdge.h"
00039 #include "utils/common/RandHelper.h"
00040 #include <iostream>
00041 #include <limits>
00042 
00043 
00044 // ===========================================================================
00045 // method definitions
00046 // ===========================================================================
00047 AGPosition::AGPosition(const AGStreet& str, SUMOReal pos) :
00048     street(&str), position(pos), pos2d(compute2dPosition()) {
00049 }
00050 
00051 
00052 AGPosition::AGPosition(const AGStreet& str) :
00053     street(&str), position(randomPositionInStreet(str)), pos2d(compute2dPosition()) {
00054 }
00055 
00056 
00057 void
00058 AGPosition::print() const {
00059     std::cout << "- AGPosition: *Street=" << street << " position=" << position << "/" << street->getLength() << std::endl;
00060 }
00061 
00062 
00063 bool
00064 AGPosition::operator==(const AGPosition& pos) const {
00065     return pos2d.almostSame(pos.pos2d);
00066 }
00067 
00068 
00069 SUMOReal
00070 AGPosition::distanceTo(const AGPosition& otherPos) const {
00071     return pos2d.distanceTo(otherPos.pos2d);
00072 }
00073 
00074 
00075 SUMOReal
00076 AGPosition::minDistanceTo(const std::list<AGPosition>& positions) const {
00077     SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
00078     SUMOReal tempDist;
00079     std::list<AGPosition>::const_iterator itt;
00080 
00081     for (itt = positions.begin() ; itt != positions.end() ; ++itt) {
00082         tempDist = this->distanceTo(*itt);
00083         if (tempDist < minDist) {
00084             minDist = tempDist;
00085         }
00086     }
00087     return minDist;
00088 }
00089 
00090 
00091 SUMOReal
00092 AGPosition::minDistanceTo(const std::map<int, AGPosition>& positions) const {
00093     SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
00094     SUMOReal tempDist;
00095     std::map<int, AGPosition>::const_iterator itt;
00096 
00097     for (itt = positions.begin() ; itt != positions.end() ; ++itt) {
00098         tempDist = this->distanceTo(itt->second);
00099         if (tempDist < minDist) {
00100             minDist = tempDist;
00101         }
00102     }
00103     return minDist;
00104 }
00105 
00106 
00107 const AGStreet&
00108 AGPosition::getStreet() const {
00109     return *street;
00110 }
00111 
00112 
00113 SUMOReal
00114 AGPosition::getPosition() const {
00115     return position;
00116 }
00117 
00118 
00119 SUMOReal
00120 AGPosition::randomPositionInStreet(const AGStreet& s) {
00121     return RandHelper::rand(0.0, s.getLength());
00122 }
00123 
00124 
00125 Position
00126 AGPosition::compute2dPosition() const {
00127     // P = From + pos*(To - From) = pos*To + (1-pos)*From
00128     Position From = street->edge->getFromNode()->getPosition();
00129     Position To = street->edge->getToNode()->getPosition();
00130     Position position2d(To);
00131 
00132     position2d.sub(From);
00133     position2d.mul(position / street->getLength());
00134     position2d.add(From);
00135 
00136     return position2d;
00137 }
00138 
00139 /****************************************************************************/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines