SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
PCPolyContainer.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// A storage for loaded polygons and pois
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13
/****************************************************************************/
14
//
15
// This file is part of SUMO.
16
// SUMO is free software: you can redistribute it and/or modify
17
// it under the terms of the GNU General Public License as published by
18
// the Free Software Foundation, either version 3 of the License, or
19
// (at your option) any later version.
20
//
21
/****************************************************************************/
22
23
24
// ===========================================================================
25
// included modules
26
// ===========================================================================
27
#ifdef _MSC_VER
28
#include <
windows_config.h
>
29
#else
30
#include <
config.h
>
31
#endif
32
33
#include <string>
34
#include <algorithm>
35
#include <map>
36
#include <
utils/common/MsgHandler.h
>
37
#include <
utils/common/ToString.h
>
38
#include <
utils/common/UtilExceptions.h
>
39
#include <
utils/common/StringUtils.h
>
40
#include <
utils/shapes/Polygon.h
>
41
#include <
utils/iodevices/OutputDevice.h
>
42
#include <
utils/xml/SUMOSAXAttributes.h
>
43
#include "
PCPolyContainer.h
"
44
45
#ifdef CHECK_MEMORY_LEAKS
46
#include <
foreign/nvwa/debug_new.h
>
47
#endif // CHECK_MEMORY_LEAKS
48
49
50
// ===========================================================================
51
// method definitions
52
// ===========================================================================
53
PCPolyContainer::PCPolyContainer
(
bool
prune,
54
const
Boundary
& prunningBoundary,
55
const
std::vector<std::string>& removeByNames)
56
: myPrunningBoundary(prunningBoundary), myDoPrunne(prune),
57
myRemoveByNames(removeByNames) {}
58
59
60
PCPolyContainer::~PCPolyContainer
() {
61
clear
();
62
}
63
64
65
bool
66
PCPolyContainer::insert
(
const
std::string&
id
,
Polygon
* poly,
67
int
layer,
bool
ignorePrunning) {
68
// check whether the polygon lies within the wished area
69
// - if such an area was given
70
if
(
myDoPrunne
&& !ignorePrunning) {
71
Boundary
b = poly->
getShape
().
getBoxBoundary
();
72
if
(!b.
partialWithin
(
myPrunningBoundary
)) {
73
delete
poly;
74
return
true
;
75
}
76
}
77
// check whether the polygon was named to be a removed one
78
if
(find(
myRemoveByNames
.begin(),
myRemoveByNames
.end(), id) !=
myRemoveByNames
.end()) {
79
delete
poly;
80
return
true
;
81
}
82
//
83
PolyCont::iterator i =
myPolyCont
.find(
id
);
84
if
(i !=
myPolyCont
.end()) {
85
return
false
;
86
}
87
myPolyCont
[id] = poly;
88
myPolyLayerMap
[poly] = layer;
89
return
true
;
90
}
91
92
93
bool
94
PCPolyContainer::insert
(
const
std::string&
id
,
PointOfInterest
* poi,
95
int
layer,
bool
ignorePrunning) {
96
// check whether the poi lies within the wished area
97
// - if such an area was given
98
if
(
myDoPrunne
&& !ignorePrunning) {
99
if
(!
myPrunningBoundary
.
around
(*poi)) {
100
delete
poi;
101
return
true
;
102
}
103
}
104
// check whether the polygon was named to be a removed one
105
if
(find(
myRemoveByNames
.begin(),
myRemoveByNames
.end(), id) !=
myRemoveByNames
.end()) {
106
delete
poi;
107
return
true
;
108
}
109
//
110
POICont::iterator i =
myPOICont
.find(
id
);
111
if
(i !=
myPOICont
.end()) {
112
return
false
;
113
}
114
myPOICont
[id] = poi;
115
myPOILayerMap
[poi] = layer;
116
return
true
;
117
}
118
119
120
bool
121
PCPolyContainer::containsPolygon
(
const
std::string&
id
) {
122
return
myPolyCont
.find(
id
) !=
myPolyCont
.end();
123
}
124
125
126
void
127
PCPolyContainer::clear
() {
128
// polys
129
for
(PolyCont::iterator i =
myPolyCont
.begin(); i !=
myPolyCont
.end(); i++) {
130
delete
(*i).second;
131
}
132
myPolyCont
.clear();
133
myPolyLayerMap
.clear();
134
// pois
135
for
(POICont::iterator i =
myPOICont
.begin(); i !=
myPOICont
.end(); i++) {
136
delete
(*i).second;
137
}
138
myPOICont
.clear();
139
myPOILayerMap
.clear();
140
}
141
142
143
void
144
PCPolyContainer::report
() {
145
WRITE_MESSAGE
(
" "
+
toString
(
getNoPolygons
()) +
" polygons loaded."
);
146
WRITE_MESSAGE
(
" "
+
toString
(
getNoPOIs
()) +
" pois loaded."
);
147
}
148
149
150
void
151
PCPolyContainer::save
(
const
std::string& file) {
152
OutputDevice
& out =
OutputDevice::getDevice
(file);
153
out.
writeXMLHeader
(
"shapes"
,
SUMOSAXAttributes::ENCODING
);
154
// write polygons
155
for
(PolyCont::iterator i =
myPolyCont
.begin(); i !=
myPolyCont
.end(); ++i) {
156
Polygon
* p = i->second;
157
out.
openTag
(
SUMO_TAG_POLY
);
158
out.
writeAttr
(
SUMO_ATTR_ID
,
StringUtils::escapeXML
(p->
getID
()));
159
out.
writeAttr
(
SUMO_ATTR_TYPE
,
StringUtils::escapeXML
(p->
getType
()));
160
out.
writeAttr
(
SUMO_ATTR_COLOR
, p->
getColor
());
161
out.
writeAttr
(
SUMO_ATTR_FILL
, p->
getFill
());
162
out.
writeAttr
(
SUMO_ATTR_LAYER
, p->
getLayer
());
163
out.
writeAttr
(
SUMO_ATTR_SHAPE
, p->
getShape
());
164
if
(p->
getAngle
() !=
Shape::DEFAULT_ANGLE
) {
165
out.
writeAttr
(
SUMO_ATTR_ANGLE
, p->
getAngle
());
166
}
167
if
(p->
getImgFile
() !=
Shape::DEFAULT_IMG_FILE
) {
168
out.
writeAttr
(
SUMO_ATTR_IMGFILE
, p->
getImgFile
());
169
}
170
out.
closeTag
(
true
);
171
}
172
// write pois
173
for
(POICont::iterator i =
myPOICont
.begin(); i !=
myPOICont
.end(); ++i) {
174
PointOfInterest
* p = i->second;
175
out.
openTag
(
SUMO_TAG_POI
);
176
out.
writeAttr
(
SUMO_ATTR_ID
,
StringUtils::escapeXML
(p->
getID
()));
177
out.
writeAttr
(
SUMO_ATTR_TYPE
,
StringUtils::escapeXML
(p->
getType
()));
178
out.
writeAttr
(
SUMO_ATTR_COLOR
, p->
getColor
());
179
out.
writeAttr
(
SUMO_ATTR_LAYER
, p->
getLayer
());
180
out.
writeAttr
(
SUMO_ATTR_X
, p->
x
());
181
out.
writeAttr
(
SUMO_ATTR_Y
, p->
y
());
182
if
(p->
getAngle
() !=
Shape::DEFAULT_ANGLE
) {
183
out.
writeAttr
(
SUMO_ATTR_ANGLE
, p->
getAngle
());
184
}
185
if
(p->
getImgFile
() !=
Shape::DEFAULT_IMG_FILE
) {
186
out.
writeAttr
(
SUMO_ATTR_IMGFILE
, p->
getImgFile
());
187
}
188
if
(p->
getWidth
() !=
Shape::DEFAULT_IMG_WIDTH
) {
189
out.
writeAttr
(
SUMO_ATTR_WIDTH
, p->
getWidth
());
190
}
191
if
(p->
getHeight
() !=
Shape::DEFAULT_IMG_HEIGHT
) {
192
out.
writeAttr
(
SUMO_ATTR_HEIGHT
, p->
getHeight
());
193
}
194
out.
closeTag
(
true
);
195
}
196
out.
close
();
197
}
198
199
200
int
201
PCPolyContainer::getEnumIDFor
(
const
std::string& key) {
202
if
(
myIDEnums
.find(key) ==
myIDEnums
.end()) {
203
myIDEnums
[key] = 0;
204
return
0;
205
}
else
{
206
myIDEnums
[key] =
myIDEnums
[key] + 1;
207
return
myIDEnums
[key];
208
}
209
}
210
211
212
213
/****************************************************************************/
214
build
buildd
sumo-0.16.0~dfsg
src
polyconvert
PCPolyContainer.cpp
Generated on Tue Apr 16 2013 01:32:20 for SUMO - Simulation of Urban MObility by
1.8.3.1