SUMO - Simulation of Urban MObility
PCPolyContainer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A storage for loaded polygons and pois
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2005-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
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 <string>
35 #include <algorithm>
36 #include <map>
38 #include <utils/common/ToString.h>
42 #include <utils/shapes/Polygon.h>
46 #include "PCPolyContainer.h"
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
57  const Boundary& pruningBoundary,
58  const std::vector<std::string>& removeByNames)
59  : myPruningBoundary(pruningBoundary), myDoPrune(prune),
60  myRemoveByNames(removeByNames) {}
61 
62 
64  myPolygons.clear();
65  myPOIs.clear();
66 }
67 
68 
69 bool
70 PCPolyContainer::add(SUMO::Polygon* poly, bool ignorePruning) {
71  // check whether the polygon lies within the wished area
72  // - if such an area was given
73  if (myDoPrune && !ignorePruning) {
74  Boundary b = poly->getShape().getBoxBoundary();
76  delete poly;
77  return false;
78  }
79  }
80  // check whether the polygon was named to be a removed one
81  if (find(myRemoveByNames.begin(), myRemoveByNames.end(), poly->getID()) != myRemoveByNames.end()) {
82  delete poly;
83  return false;
84  }
85  return ShapeContainer::add(poly);
86 }
87 
88 
89 bool
90 PCPolyContainer::add(PointOfInterest* poi, bool ignorePruning) {
91  // check whether the poi lies within the wished area
92  // - if such an area was given
93  if (myDoPrune && !ignorePruning) {
94  if (!myPruningBoundary.around(*poi)) {
95  delete poi;
96  return false;
97  }
98  }
99  // check whether the polygon was named to be a removed one
100  if (find(myRemoveByNames.begin(), myRemoveByNames.end(), poi->getID()) != myRemoveByNames.end()) {
101  delete poi;
102  return false;
103  }
104  return ShapeContainer::add(poi);
105 }
106 
107 
108 void
109 PCPolyContainer::addLanePos(const std::string& poiID, const std::string& laneID, SUMOReal lanePos) {
110  myLanePosPois[poiID] = std::make_pair(laneID, lanePos);
111 }
112 
113 
114 void
115 PCPolyContainer::save(const std::string& file, bool useGeo) {
116  const GeoConvHelper& gch = GeoConvHelper::getFinal();
117  if (useGeo && !gch.usingGeoProjection()) {
118  WRITE_WARNING("Ignoring option \"proj.plain-geo\" because no geo-conversion has been defined");
119  useGeo = false;
120  }
122  out.writeXMLHeader("additional", "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/additional_file.xsd\"");
123  if (useGeo) {
125  } else if (gch.usingGeoProjection()) {
127  }
128  // write polygons
129  for (std::map<std::string, SUMO::Polygon*>::const_iterator i = myPolygons.getMyMap().begin(); i != myPolygons.getMyMap().end(); ++i) {
130  i->second->writeXML(out, useGeo);
131  }
132  // write pois
133  const SUMOReal zOffset = OptionsCont::getOptions().getFloat("poi-layer-offset");
134  for (std::map<std::string, PointOfInterest*>::const_iterator i = myPOIs.getMyMap().begin(); i != myPOIs.getMyMap().end(); ++i) {
135  std::map<std::string, std::pair<std::string, SUMOReal> >::const_iterator it = myLanePosPois.find(i->first);
136  if (it == myLanePosPois.end()) {
137  i->second->writeXML(out, useGeo, zOffset);
138  } else {
139  i->second->writeXML(out, useGeo, zOffset, it->second.first, it->second.second);
140  }
141  }
142  out.close();
143 }
144 
145 
146 int
147 PCPolyContainer::getEnumIDFor(const std::string& key) {
148  return myIDEnums[key]++;
149 }
150 
151 
152 
153 /****************************************************************************/
154 
void close()
Closes the device and removes it from the dictionary.
static void writeLocation(OutputDevice &into)
writes the location element
bool around(const Position &p, SUMOReal offset=0) const
Returns whether the boundary contains the given coordinate.
Definition: Boundary.cpp:148
PCPolyContainer(bool prune, const Boundary &pruningBoundary, const std::vector< std::string > &removeByNames)
Constructor.
const PositionVector & getShape() const
Returns whether the shape of the polygon.
Definition: Polygon.h:87
#define GEO_OUTPUT_ACCURACY
Definition: config.h:16
bool partialWithin(const AbstractPoly &poly, SUMOReal offset=0) const
Returns whether the boundary is partially within the given polygon.
Definition: Boundary.cpp:191
POIs myPOIs
stored POIs
Polygons myPolygons
stored Polygons
void setPrecision(int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
void save(const std::string &file, bool useGeo)
Saves the stored polygons and pois into the given file.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
A 2D- or 3D-polygon.
Definition: Polygon.h:57
void clear()
Removes all items from the container (deletes them, too)
Boundary myPruningBoundary
The boundary that described the rectangle within which an object must be in order to be kept...
const std::string & getID() const
Returns the id.
Definition: Named.h:66
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:60
virtual bool add(SUMO::Polygon *poly, bool ignorePruning=false)
~PCPolyContainer()
Destructor.
std::map< std::string, int > myIDEnums
An id to int map for proper enumeration.
bool add(SUMO::Polygon *poly, bool ignorePruning=false)
Adds a polygon to the storage.
const IDMap & getMyMap() const
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
int getEnumIDFor(const std::string &key)
Retuns a unique id for a given name.
void addLanePos(const std::string &poiID, const std::string &laneID, SUMOReal lanePos)
std::map< std::string, std::pair< std::string, SUMOReal > > myLanePosPois
An id to pos map for lane pos specs.
std::vector< std::string > myRemoveByNames
List of names of polygons/pois that shall be removed.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
A point-of-interest.
bool myDoPrune
Information whether the pruning boundary shall be used.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.