LCOV - code coverage report
Current view: top level - src/traci-server/lib - TraCI.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 60 75 80.0 %
Date: 2017-11-11 03:29:50 Functions: 12 17 70.6 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
       3             : // Copyright (C) 2012-2017 German Aerospace Center (DLR) and others.
       4             : /****************************************************************************/
       5             : //
       6             : //   This program and the accompanying materials
       7             : //   are made available under the terms of the Eclipse Public License v2.0
       8             : //   which accompanies this distribution, and is available at
       9             : //   http://www.eclipse.org/legal/epl-v20.html
      10             : //
      11             : /****************************************************************************/
      12             : /// @file    TraCI.cpp
      13             : /// @author  Daniel Krajzewicz
      14             : /// @author  Mario Krumnow
      15             : /// @author  Jakob Erdmann
      16             : /// @author  Michael Behrisch
      17             : /// @author  Robert Hilbrich
      18             : /// @date    30.05.2012
      19             : /// @version $Id$
      20             : ///
      21             : // C++ TraCI client API implementation
      22             : /****************************************************************************/
      23             : 
      24             : 
      25             : // ===========================================================================
      26             : // included modules
      27             : // ===========================================================================
      28             : #ifdef _MSC_VER
      29             : #include <windows_config.h>
      30             : #else
      31             : #include <config.h>
      32             : #endif
      33             : 
      34             : #include <utils/geom/PositionVector.h>
      35             : #include <utils/geom/Position.h>
      36             : #include <utils/common/RGBColor.h>
      37             : #include <utils/options/OptionsCont.h>
      38             : #include <utils/options/OptionsIO.h>
      39             : #include <utils/xml/XMLSubSys.h>
      40             : #include <microsim/MSEdge.h>
      41             : #include <microsim/MSEdgeControl.h>
      42             : #include <microsim/MSFrame.h>
      43             : #include <microsim/MSLane.h>
      44             : #include <microsim/MSRouteHandler.h>
      45             : #include "TraCI.h"
      46             : 
      47             : // ===========================================================================
      48             : // static member definitions
      49             : // ===========================================================================
      50       14518 : std::vector<std::string> TraCI::myLoadArgs;
      51             : 
      52             : // ===========================================================================
      53             : // member definitions
      54             : // ===========================================================================
      55             : /* void
      56             : TraCI::connect(const std::string& host, int port) {
      57             : }*/
      58             : 
      59             : void
      60           7 : TraCI::load(const std::vector<std::string>& args) {
      61           7 :     myLoadArgs = args;
      62           7 : }
      63             : 
      64             : /*
      65             : void
      66             : TraCI::simulationStep(const SUMOTime time) {
      67             : }
      68             : */
      69             : 
      70             : void
      71           0 : TraCI::close() {
      72           0 : }
      73             : 
      74             : /* void
      75             : TraCI::subscribe(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const {
      76             : }
      77             : 
      78             : void
      79             : TraCI::subscribeContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, const std::vector<
      80             :         int>& vars) const {
      81             : } */
      82             : 
      83             : const TraCI::SubscribedValues&
      84           0 : TraCI::getSubscriptionResults() const {
      85           0 :     return mySubscribedValues;
      86             : }
      87             : 
      88             : const TraCI::TraCIValues&
      89           0 : TraCI::getSubscriptionResults(const std::string& objID) const {
      90           0 :     if (mySubscribedValues.find(objID) != mySubscribedValues.end()) {
      91           0 :         return mySubscribedValues.find(objID)->second;
      92             :     } else {
      93           0 :         throw; // Something?
      94             :     }
      95             : }
      96             : 
      97             : const TraCI::SubscribedContextValues&
      98           0 : TraCI::getContextSubscriptionResults() const {
      99           0 :     return mySubscribedContextValues;
     100             : }
     101             : 
     102             : const TraCI::SubscribedValues&
     103           0 : TraCI::getContextSubscriptionResults(const std::string& objID) const {
     104           0 :     if (mySubscribedContextValues.find(objID) != mySubscribedContextValues.end()) {
     105           0 :         return mySubscribedContextValues.find(objID)->second;
     106             :     } else {
     107           0 :         throw; // Something?
     108             :     }
     109             : }
     110             : 
     111             : 
     112             : TraCIPositionVector
     113        6065 : TraCI::makeTraCIPositionVector(const PositionVector& positionVector) {
     114        6065 :     TraCIPositionVector tp;
     115       24377 :     for (int i = 0; i < (int)positionVector.size(); ++i) {
     116       18312 :         tp.push_back(makeTraCIPosition(positionVector[i]));
     117             :     }
     118        6065 :     return tp;
     119             : }
     120             : 
     121             : 
     122             : PositionVector
     123          48 : TraCI::makePositionVector(const TraCIPositionVector& vector) {
     124          48 :     PositionVector pv;
     125         192 :     for (int i = 0; i < (int)vector.size(); i++) {
     126         144 :         pv.push_back(Position(vector[i].x, vector[i].y));
     127             :     }
     128          48 :     return pv;
     129             : }
     130             : 
     131             : 
     132             : TraCIColor
     133         112 : TraCI::makeTraCIColor(const RGBColor& color) {
     134             :     TraCIColor tc;
     135         112 :     tc.a = color.alpha();
     136         112 :     tc.b = color.blue();
     137         112 :     tc.g = color.green();
     138         112 :     tc.r = color.red();
     139         112 :     return tc;
     140             : }
     141             : 
     142             : RGBColor
     143         108 : TraCI::makeRGBColor(const TraCIColor& c) {
     144         108 :     return RGBColor((unsigned char)c.r, (unsigned char)c.g, (unsigned char)c.b, (unsigned char)c.a);
     145             : }
     146             : 
     147             : 
     148             : TraCIPosition
     149     1141692 : TraCI::makeTraCIPosition(const Position& position) {
     150             :     TraCIPosition p;
     151     1141692 :     p.x = position.x();
     152     1141692 :     p.y = position.y();
     153     1141692 :     p.z = position.z();
     154     1141692 :     return p;
     155             : }
     156             : 
     157             : Position
     158          53 : TraCI::makePosition(const TraCIPosition& tpos) {
     159          53 :     Position p;
     160          53 :     p.set(tpos.x, tpos.y, tpos.z);
     161          53 :     return p;
     162             : }
     163             : 
     164             : MSEdge*
     165         108 : TraCI::getEdge(const std::string& edgeID) {
     166         108 :     MSEdge* edge = MSEdge::dictionary(edgeID);
     167         108 :     if (edge == 0) {
     168           0 :         throw TraCIException("Referenced edge '" + edgeID + "' is not known.");
     169             :     }
     170         108 :     return edge;
     171             : }
     172             : 
     173             : const MSLane*
     174         121 : TraCI::getLaneChecking(const std::string& edgeID, int laneIndex, double pos) {
     175         121 :     const MSEdge* edge = MSEdge::dictionary(edgeID);
     176         121 :     if (edge == 0) {
     177           1 :         throw TraCIException("Unknown edge " + edgeID);
     178             :     }
     179         120 :     if (laneIndex < 0 || laneIndex >= (int)edge->getLanes().size()) {
     180           1 :         throw TraCIException("Invalid lane index for " + edgeID);
     181             :     }
     182         119 :     const MSLane* lane = edge->getLanes()[laneIndex];
     183         119 :     if (pos < 0 || pos > lane->getLength()) {
     184           3 :         throw TraCIException("Position on lane invalid");
     185             :     }
     186         116 :     return lane;
     187             : }
     188             : 
     189             : std::pair<MSLane*, double>
     190          11 : TraCI::convertCartesianToRoadMap(Position pos) {
     191             :     /// XXX use rtree instead
     192          11 :     std::pair<MSLane*, double> result;
     193          11 :     std::vector<std::string> allEdgeIds;
     194          11 :     double minDistance = std::numeric_limits<double>::max();
     195             : 
     196          11 :     allEdgeIds = MSNet::getInstance()->getEdgeControl().getEdgeNames();
     197         247 :     for (std::vector<std::string>::iterator itId = allEdgeIds.begin(); itId != allEdgeIds.end(); itId++) {
     198         236 :         const std::vector<MSLane*>& allLanes = MSEdge::dictionary((*itId))->getLanes();
     199         536 :         for (std::vector<MSLane*>::const_iterator itLane = allLanes.begin(); itLane != allLanes.end(); itLane++) {
     200         300 :             const double newDistance = (*itLane)->getShape().distance2D(pos);
     201         300 :             if (newDistance < minDistance) {
     202          40 :                 minDistance = newDistance;
     203          40 :                 result.first = (*itLane);
     204             :             }
     205             :         }
     206             :     }
     207             :     // @todo this may be a place where 3D is required but 2D is delivered
     208          11 :     result.second = result.first->getShape().nearest_offset_to_point2D(pos, false);
     209          11 :     return result;
     210       43554 : }
     211             : 
     212             : 
     213             : 
     214             : /****************************************************************************/

Generated by: LCOV version 1.12