SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBContHelper.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Some methods for traversing lists of edges
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 #ifndef NBContHelper_h
23 #define NBContHelper_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <iostream>
37 #include <cmath>
38 #include <algorithm>
39 #include <cassert>
40 #include "NBHelpers.h"
41 #include "NBCont.h"
42 #include "NBEdge.h"
43 #include "NBNode.h"
44 #include <utils/common/StdDefs.h>
45 #include <utils/geom/GeomHelper.h>
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
56 class NBContHelper {
57 public:
60  static void nextCW(const EdgeVector& edges,
61  EdgeVector::const_iterator& from);
62 
65  static void nextCCW(const EdgeVector& edges,
66  EdgeVector::const_iterator& from);
67 
68  static SUMOReal getMaxSpeed(const EdgeVector& edges);
69 
70  static SUMOReal getMinSpeed(const EdgeVector& edges);
71 
73  static std::ostream& out(std::ostream& os, const std::vector<bool> &v);
74 
75 
85  public:
88  : myEdge(e), myNode(n) {}
89 
90  public:
92  int operator()(NBEdge* e1, NBEdge* e2) const {
93  if (e1 == 0 || e2 == 0) {
94  return -1;
95  }
97  myEdge->getAngle(), e1->getAngle());
99  myEdge->getAngle(), e2->getAngle());
100  return relAngle1 > relAngle2;
101  }
102 
103  private:
106 
109 
110  };
111 
112 
118  public:
120  int operator()(NBEdge* e1, NBEdge* e2) const {
121  if (e1->getPriority() != e2->getPriority()) {
122  return e1->getPriority() > e2->getPriority();
123  }
124  if (e1->getSpeed() != e2->getSpeed()) {
125  return e1->getSpeed() > e2->getSpeed();
126  }
127  return e1->getNumLanes() > e2->getNumLanes();
128  }
129  };
130 
131  // ---------------------------
132 
141  public:
146  explicit edge_opposite_direction_sorter(const NBEdge* const e, const NBNode* const n)
147  : myNode(n) {
148  myAngle = getEdgeAngleAt(e, n);
149  }
150 
156  int operator()(NBEdge* e1, NBEdge* e2) const {
157  SUMOReal d1 = getDiff(e1);
158  SUMOReal d2 = getDiff(e2);
159  return d1 > d2;
160  }
161 
162  protected:
167  SUMOReal getDiff(const NBEdge* const e) const {
170  }
171 
178  SUMOReal getEdgeAngleAt(const NBEdge* const e, const NBNode* const n) const {
179  if (e->getFromNode() == n) {
180  return e->getGeometry().getBegLine().atan2DegreeAngle();
181  } else {
183  }
184  }
185 
186  private:
189 
191  const NBNode* const myNode;
192 
193  };
194 
195  // ---------------------------
196 
204  public:
206  explicit edge_similar_direction_sorter(const NBEdge* const e)
207  : myAngle(e->getAngle()) {}
208 
210  int operator()(NBEdge* e1, NBEdge* e2) const {
213  return d1 < d2;
214  }
215 
216  private:
219  };
220 
221 
226  public:
228  node_with_incoming_finder(const NBEdge* const e);
229 
230  bool operator()(const NBNode* const n) const;
231 
232  private:
233  const NBEdge* const myEdge;
234 
235  private:
238 
239  };
240 
241 
246  public:
248  node_with_outgoing_finder(const NBEdge* const e);
249 
250  bool operator()(const NBNode* const n) const;
251 
252  private:
253  const NBEdge* const myEdge;
254 
255  private:
258 
259  };
260 
261 
262 
263 
265  public:
268 
269  bool operator()(NBEdge* e) const;
270 
271  private:
273 
274  private:
277 
278  };
279 
280 
283  static NBEdge* findConnectingEdge(const EdgeVector& edges,
284  NBNode* from, NBNode* to);
285 
286 
288  static SUMOReal maxSpeed(const EdgeVector& ev);
289 
297  public:
300 
302  int operator()(NBEdge* e1, NBEdge* e2) const {
303  std::pair<SUMOReal, SUMOReal> mm1 = getMinMaxRelAngles(e1);
304  std::pair<SUMOReal, SUMOReal> mm2 = getMinMaxRelAngles(e2);
305  if (mm1.first == mm2.first && mm1.second == mm2.second) {
306  // ok, let's simply sort them arbitrarily
307  return e1->getID() < e2->getID();
308  }
309 
310  assert(
311  (mm1.first <= mm2.first && mm1.second <= mm2.second)
312  ||
313  (mm1.first >= mm2.first && mm1.second >= mm2.second));
314  return (mm1.first >= mm2.first && mm1.second >= mm2.second);
315  }
316 
320  std::pair<SUMOReal, SUMOReal> getMinMaxRelAngles(NBEdge* e) const {
321  SUMOReal min = 360;
322  SUMOReal max = 360;
323  const EdgeVector& ev = e->getConnectedEdges();
324  for (EdgeVector::const_iterator i = ev.begin(); i != ev.end(); ++i) {
326  e->getAngle(), (*i)->getAngle());
327  if (min == 360 || min > angle) {
328  min = angle;
329  }
330  if (max == 360 || max < angle) {
331  max = angle;
332  }
333  }
334  return std::pair<SUMOReal, SUMOReal>(min, max);
335  }
336  };
337 
338 
339  friend std::ostream& operator<<(std::ostream& os, const EdgeVector& ev);
340 
342  public:
344  opposite_finder(NBEdge* edge, const NBNode* n)
345  : myReferenceEdge(edge), myAtNode(n) { }
346 
347  bool operator()(NBEdge* e) const {
350  }
351 
352  private:
354  const NBNode* myAtNode;
355 
356  };
357 
358 
359 };
360 
361 
362 #endif
363 
364 /****************************************************************************/
365