SUMO - Simulation of Urban MObility
Polygon.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 /****************************************************************************/
17 // C++ TraCI client API implementation
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <microsim/MSNet.h>
27 
28 #include "Polygon.h"
29 #include "Helper.h"
30 
31 
32 // ===========================================================================
33 // member definitions
34 // ===========================================================================
35 namespace libsumo {
36 std::vector<std::string> Polygon::getIDList() {
37  std::vector<std::string> ids;
39  shapeCont.getPolygons().insertIDs(ids);
40  return ids;
41 }
42 
43 
44 std::string Polygon::getType(const std::string& polygonID) {
45  return getPolygon(polygonID)->getType();
46 }
47 
48 
49 TraCIPositionVector Polygon::getShape(const std::string& polygonID) {
50  SUMOPolygon* p = getPolygon(polygonID);
52 }
53 
54 
55 bool Polygon::getFilled(const std::string& polygonID) {
56  return getPolygon(polygonID)->getFill();
57 }
58 
59 
60 TraCIColor Polygon::getColor(const std::string& polygonID) {
61  SUMOPolygon* p = getPolygon(polygonID);
62  return Helper::makeTraCIColor(p->getColor());
63 }
64 
65 
66 std::string Polygon::getParameter(const std::string& polygonID, const std::string& paramName) {
67  return getPolygon(polygonID)->getParameter(paramName, "");
68 }
69 
70 
71 void Polygon::setType(const std::string& polygonID, const std::string& setType) {
72  SUMOPolygon* p = getPolygon(polygonID);
73  p->setType(setType);
74 }
75 
76 
77 void Polygon::setShape(const std::string& polygonID, const TraCIPositionVector& shape) {
78  PositionVector positionVector = Helper::makePositionVector(shape);
79  getPolygon(polygonID); // just to check whether it exists
81  shapeCont.reshapePolygon(polygonID, positionVector);
82 }
83 
84 
85 void Polygon::setColor(const std::string& polygonID, const TraCIColor& c) {
87 }
88 
89 
90 void
91 Polygon::add(const std::string& polygonID, const TraCIPositionVector& shape, const TraCIColor& c, bool fill, const std::string& type, int layer) {
95  if (!shapeCont.addPolygon(polygonID, type, col, (double)layer, Shape::DEFAULT_ANGLE, Shape::DEFAULT_IMG_FILE, pShape, false, fill)) {
96  throw TraCIException("Could not add polygon '" + polygonID + "'");
97  }
98 }
99 
100 
101 void Polygon::remove(const std::string& polygonID, int /* layer */) {
102  // !!! layer not used yet (shouldn't the id be enough?)
104  if (!shapeCont.removePolygon(polygonID)) {
105  throw TraCIException("Could not remove polygon '" + polygonID + "'");
106  }
107 }
108 
109 
110 void
111 Polygon::setFilled(std::string polygonID, bool filled) {
112  SUMOPolygon* p = getPolygon(polygonID);
113  p->setFill(filled);
114 }
115 
116 
118 Polygon::getPolygon(const std::string& id) {
120  if (p == 0) {
121  throw TraCIException("Polygon '" + id + "' is not known");
122  }
123  return p;
124 }
125 
126 
127 void
128 Polygon::setParameter(std::string& id, std::string& name, std::string& value) {
129  SUMOPolygon* p = getPolygon(id);
130  p->setParameter(name, value);
131 }
132 
133 NamedRTree*
135  NamedRTree* t = new NamedRTree();
137  for (const auto& i : shapeCont.getPolygons()) {
138  Boundary b = i.second->getShape().getBoxBoundary();
139  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
140  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
141  t->Insert(cmin, cmax, i.second);
142  }
143  return t;
144 }
145 
146 }
147 
148 
149 /****************************************************************************/
static void setColor(const std::string &polygonID, const TraCIColor &c)
Definition: Polygon.cpp:85
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:89
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:137
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:131
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:151
const Polygons & getPolygons() const
Returns all polygons.
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:71
static void setFilled(std::string polygonID, bool filled)
Definition: Polygon.cpp:111
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
const PositionVector & getShape() const
Returns whether the shape of the polygon.
Definition: SUMOPolygon.h:84
Storage for geometrical objects.
static TraCIPositionVector makeTraCIPositionVector(const PositionVector &positionVector)
helper functions
Definition: Helper.cpp:110
static PositionVector makePositionVector(const TraCIPositionVector &vector)
Definition: Helper.cpp:120
void insertIDs(std::vector< std::string > &into) const
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
static std::string getType(const std::string &polygonID)
Definition: Polygon.cpp:44
virtual bool addPolygon(const std::string &id, const std::string &type, const RGBColor &color, double layer, double angle, const std::string &imgFile, const PositionVector &shape, bool geo, bool fill, bool ignorePruning=false)
Builds a polygon using the given values and adds it to the container.
virtual bool removePolygon(const std::string &id)
Removes a polygon from the container.
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:429
A list of positions.
static NamedRTree * getTree()
Returns a tree filled with polygon instances.
Definition: Polygon.cpp:134
static std::string getParameter(const std::string &polygonID, const std::string &paramName)
Definition: Polygon.cpp:66
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: Helper.cpp:130
static void remove(const std::string &polygonID, int layer=0)
Definition: Polygon.cpp:101
static TraCIPositionVector getShape(const std::string &polygonID)
Definition: Polygon.cpp:49
static void setShape(const std::string &polygonID, const TraCIPositionVector &shape)
Definition: Polygon.cpp:77
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:125
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
bool getFill() const
Returns whether the polygon is filled.
Definition: SUMOPolygon.h:92
virtual void reshapePolygon(const std::string &id, const PositionVector &shape)
Assigns a shape to the named polygon.
Definition: Edge.cpp:31
static void setParameter(std::string &name, std::string &value, std::string &string)
Definition: Polygon.cpp:128
const std::string & getType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:70
static std::vector< std::string > getIDList()
Definition: Polygon.cpp:36
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
static void add(const std::string &polygonID, const TraCIPositionVector &shape, const TraCIColor &c, bool fill, const std::string &type, int layer)
Definition: Polygon.cpp:91
static TraCIColor getColor(const std::string &polygonID)
Definition: Polygon.cpp:60
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
static bool getFilled(const std::string &polygonID)
Definition: Polygon.cpp:55
static SUMOPolygon * getPolygon(const std::string &id)
Definition: Polygon.cpp:118
static RGBColor makeRGBColor(const TraCIColor &color)
Definition: Helper.cpp:141
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:143
A list of positions.
void setColor(const RGBColor &col)
Sets a new color.
Definition: Shape.h:120
void setFill(bool fill)
Sets whether the polygon shall be filled.
Definition: SUMOPolygon.h:104
static const double DEFAULT_ANGLE
Definition: Shape.h:150
static void setType(const std::string &polygonID, const std::string &setType)
Definition: Polygon.cpp:71