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-2013 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  private:
196 
197  };
198 
199  // ---------------------------
200 
208  public:
210  explicit edge_similar_direction_sorter(const NBEdge* const e)
211  : myAngle(e->getAngle()) {}
212 
214  int operator()(NBEdge* e1, NBEdge* e2) const {
217  return d1 < d2;
218  }
219 
220  private:
223  };
224 
225 
230  public:
232  node_with_incoming_finder(const NBEdge* const e);
233 
234  bool operator()(const NBNode* const n) const;
235 
236  private:
237  const NBEdge* const myEdge;
238 
239  private:
242 
243  };
244 
245 
250  public:
252  node_with_outgoing_finder(const NBEdge* const e);
253 
254  bool operator()(const NBNode* const n) const;
255 
256  private:
257  const NBEdge* const myEdge;
258 
259  private:
262 
263  };
264 
265 
266 
267 
269  public:
272 
273  bool operator()(NBEdge* e) const;
274 
275  private:
277 
278  private:
281 
282  };
283 
284 
287  static NBEdge* findConnectingEdge(const EdgeVector& edges,
288  NBNode* from, NBNode* to);
289 
290 
292  static SUMOReal maxSpeed(const EdgeVector& ev);
293 
301  public:
304 
306  int operator()(NBEdge* e1, NBEdge* e2) const {
307  std::pair<SUMOReal, SUMOReal> mm1 = getMinMaxRelAngles(e1);
308  std::pair<SUMOReal, SUMOReal> mm2 = getMinMaxRelAngles(e2);
309  if (mm1.first == mm2.first && mm1.second == mm2.second) {
310  // ok, let's simply sort them arbitrarily
311  return e1->getID() < e2->getID();
312  }
313 
314  assert(
315  (mm1.first <= mm2.first && mm1.second <= mm2.second)
316  ||
317  (mm1.first >= mm2.first && mm1.second >= mm2.second));
318  return (mm1.first >= mm2.first && mm1.second >= mm2.second);
319  }
320 
324  std::pair<SUMOReal, SUMOReal> getMinMaxRelAngles(NBEdge* e) const {
325  SUMOReal min = 360;
326  SUMOReal max = 360;
327  const EdgeVector& ev = e->getConnectedEdges();
328  for (EdgeVector::const_iterator i = ev.begin(); i != ev.end(); ++i) {
330  e->getAngle(), (*i)->getAngle());
331  if (min == 360 || min > angle) {
332  min = angle;
333  }
334  if (max == 360 || max < angle) {
335  max = angle;
336  }
337  }
338  return std::pair<SUMOReal, SUMOReal>(min, max);
339  }
340  };
341 
342 
343  friend std::ostream& operator<<(std::ostream& os, const EdgeVector& ev);
344 
346  public:
348  opposite_finder(NBEdge* edge, const NBNode* n)
349  : myReferenceEdge(edge), myAtNode(n) { }
350 
351  bool operator()(NBEdge* e) const {
354  }
355 
356  private:
358  const NBNode* myAtNode;
359 
360  };
361 
362 
363 };
364 
365 
366 #endif
367 
368 /****************************************************************************/
369