Eclipse SUMO - Simulation of Urban MObility
Junction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2017-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // C++ TraCI client API implementation
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
30 #include <microsim/MSNet.h>
32 #include <libsumo/TraCIConstants.h>
33 #include "Helper.h"
34 #include "Junction.h"
35 
36 
37 namespace libsumo {
38 // ===========================================================================
39 // static member initializations
40 // ===========================================================================
43 
44 
45 // ===========================================================================
46 // member definitions
47 // ===========================================================================
48 std::vector<std::string>
50  std::vector<std::string> ids;
52  return ids;
53 }
54 
55 
56 int
58  return (int)getIDList().size();
59 }
60 
61 
63 Junction::getPosition(const std::string& junctionID, const bool includeZ) {
64  return Helper::makeTraCIPosition(getJunction(junctionID)->getPosition(), includeZ);
65 }
66 
67 
69 Junction::getShape(const std::string& junctionID) {
71 }
72 
73 
75 Junction::getJunction(const std::string& id) {
77  if (j == nullptr) {
78  throw TraCIException("Junction '" + id + "' is not known");
79  }
80  return j;
81 }
82 
83 
85 
86 
89  NamedRTree* t = new NamedRTree();
90  for (const auto& i : MSNet::getInstance()->getJunctionControl()) {
91  Boundary b = i.second->getShape().getBoxBoundary();
92  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
93  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
94  t->Insert(cmin, cmax, i.second);
95  }
96  return t;
97 }
98 
99 
100 void
101 Junction::storeShape(const std::string& id, PositionVector& shape) {
102  shape.push_back(getJunction(id)->getPosition());
103 }
104 
105 
106 std::shared_ptr<VariableWrapper>
108  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
109 }
110 
111 
112 bool
113 Junction::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
114  switch (variable) {
115  case TRACI_ID_LIST:
116  return wrapper->wrapStringList(objID, variable, getIDList());
117  case ID_COUNT:
118  return wrapper->wrapInt(objID, variable, getIDCount());
119  case VAR_POSITION:
120  return wrapper->wrapPosition(objID, variable, getPosition(objID));
121  default:
122  return false;
123  }
124 }
125 
126 
127 }
128 
129 
130 /****************************************************************************/
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:82
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:204
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:131
static int getIDCount()
Definition: Junction.cpp:57
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:125
virtual bool wrapInt(const std::string &objID, const int variable, const int value)=0
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:264
The base class for an intersection.
Definition: MSJunction.h:61
T get(const std::string &id) const
Retrieves an item.
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:64
static LIBSUMO_SUBSCRIPTION_API NamedRTree * getTree()
Returns a tree filled with junction instances.
Definition: Junction.cpp:88
TRACI_CONST int VAR_POSITION
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:205
void insertIDs(std::vector< std::string > &into) const
static TraCIPositionVector makeTraCIPositionVector(const PositionVector &positionVector)
helper functions
Definition: Helper.cpp:224
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
TRACI_CONST int TRACI_ID_LIST
static MSJunction * getJunction(const std::string &id)
Definition: Junction.cpp:75
static TraCIPositionVector getShape(const std::string &junctionID)
Definition: Junction.cpp:69
TRACI_CONST int ID_COUNT
A list of positions.
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Junction.cpp:107
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:119
static TraCIPosition getPosition(const std::string &junctionID, const bool includeZ=false)
Definition: Junction.cpp:63
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:51
Definition: Edge.cpp:30
virtual bool wrapPosition(const std::string &objID, const int variable, const TraCIPosition &value)=0
MSJunctionControl & getJunctionControl()
Returns the junctions control.
Definition: MSNet.h:420
static void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: Junction.cpp:101
static ContextSubscriptionResults myContextSubscriptionResults
Definition: Junction.h:81
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: Junction.cpp:113
virtual bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)=0
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:137
A 3D-position.
Definition: TraCIDefs.h:110
static std::vector< std::string > getIDList()
Definition: Junction.cpp:49
A list of positions.
static SubscriptionResults mySubscriptionResults
Definition: Junction.h:80