1 package cz.cuni.amis.pogamut.ut2004.communication.worldview.map;
2
3 import cz.cuni.amis.pogamut.unreal.communication.worldview.map.MapInfo;
4 import cz.cuni.amis.pogamut.unreal.communication.worldview.map.Box;
5 import java.io.Serializable;
6 import java.util.Collection;
7 import java.util.Collections;
8 import java.util.HashMap;
9 import java.util.HashSet;
10 import java.util.Map;
11 import java.util.Set;
12 import java.util.Map.Entry;
13
14 import cz.cuni.amis.pogamut.base.communication.worldview.IWorldView;
15 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
16 import cz.cuni.amis.pogamut.unreal.communication.worldview.map.IUnrealMap;
17 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
18
19
20
21
22
23
24
25
26
27 public class UT2004Map implements IUnrealMap<MapInfo> {
28
29 private String name = "";
30 private MapInfo info;
31
32
33
34
35
36 private Map<String, Waypoint> waypoints = new HashMap<String, Waypoint>();
37
38 public UT2004Map(IWorldView worldView) {
39 Collection<NavPoint> navs = worldView.getAll(NavPoint.class).values();
40
41 for (NavPoint nav : navs) {
42 waypoints.put(nav.getId().getStringId(), new Waypoint(nav));
43 }
44
45 for (Waypoint point : waypoints.values()) {
46 for (Waylink link : point.getOutgoingEdges()) {
47 Waypoint end = waypoints.get(link.getEndId());
48 link.setEnd(end);
49 }
50 }
51
52 }
53
54 public void addInfo(MapInfo info) {
55 this.info = info;
56 }
57
58 public MapInfo getInfo() {
59 return info;
60 }
61
62 public void setName(String name) {
63 this.name = name;
64 }
65
66 public String getName() {
67 return name;
68 }
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 public Collection<Waypoint> vertexSet() {
87 return Collections.unmodifiableCollection(waypoints.values());
88 }
89
90 public Set<Waylink> edgeSet() {
91 Set<Waylink> edges = new HashSet<Waylink>();
92
93 for (Waypoint nav : waypoints.values()) {
94 edges.addAll(nav.getOutgoingEdges());
95 }
96
97
98
99 return edges;
100 }
101
102 public void printInfo() {
103 System.out.println("Printing info about map, vers: " + waypoints.size() + ", links: " + this.edgeSet().size());
104 for (Entry<String, Waypoint> entry : this.waypoints.entrySet()) {
105 System.out.println(" * " + entry.getKey() + " " + entry.getValue().getLocation());
106 }
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225 public Box getBox() {
226 double minX = Double.MAX_VALUE;
227 double maxX = Double.MIN_VALUE;
228
229 double minY = Double.MAX_VALUE;
230 double maxY = Double.MIN_VALUE;
231
232 double minZ = Double.MAX_VALUE;
233 double maxZ = Double.MIN_VALUE;
234
235 Collection<Waypoint> navs = this.vertexSet();
236
237 for (Waypoint nav : navs) {
238 Location loc = nav.getLocation();
239
240 if (loc.x < minX) {
241 minX = loc.x;
242 }
243 if (loc.x > maxX) {
244 maxX = loc.x;
245 }
246
247 if (loc.y < minY) {
248 minY = loc.y;
249 }
250 if (loc.y > maxY) {
251 maxY = loc.y;
252 }
253
254 if (loc.z < minZ) {
255 minZ = loc.z;
256 }
257 if (loc.z > maxZ) {
258 maxZ = loc.z;
259 }
260 }
261
262 return new Box(minX, minY, minZ, maxX, maxY, maxZ);
263 }
264 }