SUMO - Simulation of Urban MObility
POI.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-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 /****************************************************************************/
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 
36 #include <microsim/MSNet.h>
37 #include "POI.h"
38 #include "Helper.h"
39 
40 
41 
42 
43 // ===========================================================================
44 // member definitions
45 // ===========================================================================
46 namespace libsumo {
47 std::vector<std::string>
49  std::vector<std::string> ids;
51  shapeCont.getPOIs().insertIDs(ids);
52  return ids;
53 }
54 
55 int
57  return (int)getIDList().size();
58 }
59 
60 std::string
61 POI::getType(const std::string& poiID) {
62  return getPoI(poiID)->getType();
63 }
64 
66 POI::getColor(const std::string& poiID) {
67  PointOfInterest* sumoPoi = getPoI(poiID);
68  RGBColor col = sumoPoi->getColor();
69  return Helper::makeTraCIColor(col);
70 }
71 
73 POI::getPosition(const std::string& poiID) {
74  TraCIPosition pos;
75  PointOfInterest* p = getPoI(poiID);
76  pos.x = p->x();
77  pos.y = p->y();
78  pos.z = p->z();
79  return pos;
80 }
81 
82 std::string
83 POI::getParameter(const std::string& poiID, const std::string& param) {
84  PointOfInterest* p = getPoI(poiID);
85  return p->getParameter(param, "");
86 }
87 
88 void
89 POI::setType(const std::string& poiID, const std::string& type) {
90  PointOfInterest* p = getPoI(poiID);
91  p->setType(type);
92 }
93 
94 void
95 POI::setPosition(const std::string& poiID, const TraCIPosition& pos) {
96  PointOfInterest* p = getPoI(poiID);
97  p->set(Helper::makePosition(pos));
98 }
99 
100 void
101 POI::setColor(const std::string& poiID, const TraCIColor& c) {
102  PointOfInterest* p = getPoI(poiID);
104 }
105 
106 bool
107 POI::add(const std::string& poiID, const TraCIPosition& pos, const TraCIColor& c, const std::string& type, int layer) {
109  return shapeCont.addPOI(poiID, type, Helper::makeRGBColor(c), Helper::makePosition(pos), false, "", 0, 0, (double)layer,
114 }
115 
116 bool
117 POI::remove(const std::string& poiID, int /* layer */) {
119  return shapeCont.removePOI(poiID);
120 }
121 
122 void
123 POI::setParameter(const std::string& poiID, const std::string& param, const std::string& value) {
124  PointOfInterest* p = getPoI(poiID);
125  p->setParameter(param, value);
126 }
127 
128 
130 POI::getPoI(const std::string& id) {
132  if (sumoPoi == 0) {
133  throw TraCIException("POI '" + id + "' is not known");
134  }
135  return sumoPoi;
136 }
137 
138 
139 NamedRTree*
141  NamedRTree* t = new NamedRTree();
143  for (const auto& i : shapeCont.getPOIs()) {
144  const float cmin[2] = {(float)i.second->x(), (float)i.second->y()};
145  const float cmax[2] = {(float)i.second->x(), (float)i.second->y()};
146  t->Insert(cmin, cmax, i.second);
147  }
148  return t;
149 }
150 
151 
152 }
153 
154 
155 /****************************************************************************/
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:89
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:151
static NamedRTree * getTree()
Returns a tree filled with PoI instances.
Definition: POI.cpp:140
double z() const
Returns the z-position.
Definition: Position.h:72
static bool remove(const std::string &poiID, int layer=0)
Definition: POI.cpp:117
static void setColor(const std::string &poiID, const TraCIColor &c)
Definition: POI.cpp:101
double y() const
Returns the y-position.
Definition: Position.h:67
T get(const std::string &id) const
Retrieves an item.
static const double DEFAULT_IMG_HEIGHT
Definition: Shape.h:153
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:71
double x() const
Returns the x-position.
Definition: Position.h:62
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
Storage for geometrical objects.
void set(double x, double y)
set positions x and y
Definition: Position.h:92
void insertIDs(std::vector< std::string > &into) const
static bool add(const std::string &poiID, const TraCIPosition &pos, const TraCIColor &c, const std::string &type, int layer)
Definition: POI.cpp:107
static int getIDCount()
Definition: POI.cpp:56
static void setPosition(const std::string &poiID, const TraCIPosition &pos)
Definition: POI.cpp:95
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:429
virtual bool removePOI(const std::string &id)
Removes a PoI from the container.
static TraCIPosition getPosition(const std::string &poiID)
Definition: POI.cpp:73
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: Helper.cpp:130
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
static std::string getParameter(const std::string &poiID, const std::string &param)
Definition: POI.cpp:83
static void setType(const std::string &poiID, const std::string &setType)
Definition: POI.cpp:89
Definition: Edge.cpp:31
static std::vector< std::string > getIDList()
Definition: POI.cpp:48
const std::string & getType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:70
void setType(const std::string &type)
Sets a new type.
Definition: Shape.h:112
const RGBColor & getColor() const
Returns the color of the Shape.
Definition: Shape.h:78
virtual bool addPOI(const std::string &id, const std::string &type, const RGBColor &color, const Position &pos, bool geo, const std::string &lane, double posOverLane, double posLat, double layer, double angle, const std::string &imgFile, double width, double height, bool ignorePruning=false)
Builds a POI using the given values and adds it to the container.
static std::string getType(const std::string &poiID)
Definition: POI.cpp:61
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
static Position makePosition(const TraCIPosition &position)
Definition: Helper.cpp:157
static PointOfInterest * getPoI(const std::string &id)
Definition: POI.cpp:130
static const double DEFAULT_IMG_WIDTH
Definition: Shape.h:152
static RGBColor makeRGBColor(const TraCIColor &color)
Definition: Helper.cpp:141
A point-of-interest.
static void setParameter(const std::string &poiID, const std::string &param, const std::string &value)
Definition: POI.cpp:123
A 3D-position.
Definition: TraCIDefs.h:71
static TraCIColor getColor(const std::string &poiID)
Definition: POI.cpp:66
void setColor(const RGBColor &col)
Sets a new color.
Definition: Shape.h:120
static const double DEFAULT_ANGLE
Definition: Shape.h:150
const POIs & getPOIs() const
Returns all pois.