SUMO - Simulation of Urban MObility
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.dlr.de/
12 // Copyright (C) 2001-2016 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 
89  public:
91  int operator()(NBEdge* e1, NBEdge* e2) const;
92 
93  private:
96  };
97 
98 
105  public:
108  myReferencePos(e->getLaneShape(0).back()),
109  myReferenceAngle(e->getShapeEndAngle()) {
110  }
111 
112  public:
114  int operator()(NBEdge* e1, NBEdge* e2) const;
115 
116  private:
119  };
120 
121 
130  public:
133 
134  public:
136  int operator()(NBEdge* e1, NBEdge* e2) const;
137 
138  private:
141  };
142 
143 
149  public:
151  int operator()(NBEdge* e1, NBEdge* e2) const {
152  if (e1->getPriority() != e2->getPriority()) {
153  return e1->getPriority() > e2->getPriority();
154  }
155  if (e1->getSpeed() != e2->getSpeed()) {
156  return e1->getSpeed() > e2->getSpeed();
157  }
158  return e1->getNumLanes() > e2->getNumLanes();
159  }
160  };
161 
162  // ---------------------------
163 
172  public:
177  explicit edge_opposite_direction_sorter(const NBEdge* const e, const NBNode* const n)
178  : myNode(n) {
179  myAngle = getEdgeAngleAt(e, n);
180  }
181 
187  int operator()(NBEdge* e1, NBEdge* e2) const {
188  return getDiff(e1) > getDiff(e2);
189  }
190 
191  protected:
196  SUMOReal getDiff(const NBEdge* const e) const {
197  return fabs(GeomHelper::angleDiff(getEdgeAngleAt(e, myNode), myAngle));
198  }
199 
206  SUMOReal getEdgeAngleAt(const NBEdge* const e, const NBNode* const n) const {
207  if (e->getFromNode() == n) {
208  return e->getGeometry().angleAt2D(0);
209  } else {
210  return e->getGeometry()[-1].angleTo2D(e->getGeometry()[-2]);
211  }
212  }
213 
214  private:
217 
219  const NBNode* const myNode;
220 
221  private:
224 
225  };
226 
227  // ---------------------------
228 
236  public:
238  explicit edge_similar_direction_sorter(const NBEdge* const e)
239  : myAngle(e->getTotalAngle()) {}
240 
242  int operator()(NBEdge* e1, NBEdge* e2) const {
245  return d1 < d2;
246  }
247 
248  private:
251  };
252 
253 
258  public:
260  node_with_incoming_finder(const NBEdge* const e);
261 
262  bool operator()(const NBNode* const n) const;
263 
264  private:
265  const NBEdge* const myEdge;
266 
267  private:
270 
271  };
272 
273 
278  public:
280  node_with_outgoing_finder(const NBEdge* const e);
281 
282  bool operator()(const NBNode* const n) const;
283 
284  private:
285  const NBEdge* const myEdge;
286 
287  private:
290 
291  };
292 
293 
294 
295 
297  public:
300 
301  bool operator()(NBEdge* e) const;
302 
303  private:
305 
306  private:
309 
310  };
311 
312 
315  static NBEdge* findConnectingEdge(const EdgeVector& edges,
316  NBNode* from, NBNode* to);
317 
318 
320  static SUMOReal maxSpeed(const EdgeVector& ev);
321 
329  public:
332 
334  int operator()(NBEdge* e1, NBEdge* e2) const {
335  std::pair<SUMOReal, SUMOReal> mm1 = getMinMaxRelAngles(e1);
336  std::pair<SUMOReal, SUMOReal> mm2 = getMinMaxRelAngles(e2);
337  if (mm1.first == mm2.first && mm1.second == mm2.second) {
338  // ok, let's simply sort them arbitrarily
339  return e1->getID() < e2->getID();
340  }
341 
342  assert(
343  (mm1.first <= mm2.first && mm1.second <= mm2.second)
344  ||
345  (mm1.first >= mm2.first && mm1.second >= mm2.second));
346  return (mm1.first >= mm2.first && mm1.second >= mm2.second);
347  }
348 
352  std::pair<SUMOReal, SUMOReal> getMinMaxRelAngles(NBEdge* e) const {
353  SUMOReal min = 360;
354  SUMOReal max = 360;
355  const EdgeVector& ev = e->getConnectedEdges();
356  for (EdgeVector::const_iterator i = ev.begin(); i != ev.end(); ++i) {
358  e->getTotalAngle(), (*i)->getTotalAngle());
359  if (min == 360 || min > angle) {
360  min = angle;
361  }
362  if (max == 360 || max < angle) {
363  max = angle;
364  }
365  }
366  return std::pair<SUMOReal, SUMOReal>(min, max);
367  }
368  };
369 
370 
371  friend std::ostream& operator<<(std::ostream& os, const EdgeVector& ev);
372 
374  public:
377  : myReferenceEdge(edge) { }
378 
379  bool operator()(NBEdge* e) const {
380  return e->isTurningDirectionAt(myReferenceEdge) ||
381  myReferenceEdge->isTurningDirectionAt(e);
382  }
383 
384  private:
386 
387  };
388 
394  public:
396  explicit edge_by_angle_to_nodeShapeCentroid_sorter(const NBNode* n) : myNode(n) {}
397 
398  public:
400  int operator()(const NBEdge* e1, const NBEdge* e2) const;
401 
402  private:
404  const NBNode* myNode;
405  };
406 
407 };
408 
409 
410 #endif
411 
412 /****************************************************************************/
413 
#define min(a, b)
Definition: polyfonts.c:66
NBEdge * myEdge
the edge to compute the relative angle of
Definition: NBContHelper.h:95
static SUMOReal normRelAngle(SUMOReal angle1, SUMOReal angle2)
ensure that reverse relAngles (>=179.999) always count as turnarounds (-180)
Definition: NBHelpers.cpp:69
SUMOReal myAngle
the angle to find the edge with the opposite direction
Definition: NBContHelper.h:250
const NBNode *const myNode
The related node.
Definition: NBContHelper.h:219
straightness_sorter(NBEdge *e)
constructor
Definition: NBContHelper.h:107
friend std::ostream & operator<<(std::ostream &os, const EdgeVector &ev)
The representation of a single edge during network building.
Definition: NBEdge.h:70
Class to sort edges by their angle in relation to the given edge.
Definition: NBContHelper.h:171
opposite_finder(NBEdge *edge)
constructor
Definition: NBContHelper.h:376
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
SUMOReal getDiff(const NBEdge *const e) const
Computes the angle difference between the related and the given edge.
Definition: NBContHelper.h:196
static SUMOReal angleDiff(const SUMOReal angle1, const SUMOReal angle2)
Returns the difference of the second angle to the first angle in radiants.
Definition: GeomHelper.cpp:178
relative_outgoing_edge_sorter(NBEdge *e)
constructor
Definition: NBContHelper.h:87
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
Definition: NBEdge.cpp:881
edge_similar_direction_sorter(const NBEdge *const e)
constructor
Definition: NBContHelper.h:238
edge_opposite_direction_sorter(const NBEdge *const e, const NBNode *const n)
Constructor.
Definition: NBContHelper.h:177
const std::string & getID() const
Returns the id.
Definition: Named.h:66
int operator()(NBEdge *e1, NBEdge *e2) const
comparing operation
Definition: NBContHelper.h:242
#define max(a, b)
Definition: polyfonts.c:65
int getPriority() const
Returns the priority of the edge.
Definition: NBEdge.h:355
static std::ostream & out(std::ostream &os, const std::vector< bool > &v)
int operator()(NBEdge *e1, NBEdge *e2) const
comparing operation
Definition: NBContHelper.h:334
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
static SUMOReal maxSpeed(const EdgeVector &ev)
NBEdge * myEdge
the edge to compute the relative angle of
Definition: NBContHelper.h:140
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:347
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:2038
int operator()(NBEdge *e1, NBEdge *e2) const
Comparing operation.
Definition: NBContHelper.h:187
edge_by_angle_to_nodeShapeCentroid_sorter(const NBNode *n)
constructor
Definition: NBContHelper.h:396
std::pair< SUMOReal, SUMOReal > getMinMaxRelAngles(NBEdge *e) const
Definition: NBContHelper.h:352
int operator()(NBEdge *e1, NBEdge *e2) const
comparing operator
Definition: NBContHelper.h:151
static SUMOReal getMaxSpeed(const EdgeVector &edges)
SUMOReal angleAt2D(int pos) const
get angle in certain position of position vector
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:546
const NBNode * myNode
the edge to compute the relative angle of
Definition: NBContHelper.h:404
static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:172
SUMOReal getTotalAngle() const
get the angle as measure from the start to the end of this edge
Definition: NBEdge.h:417
Represents a single node (junction) during network building.
Definition: NBNode.h:74
#define SUMOReal
Definition: config.h:213
SUMOReal getSpeed() const
Returns the speed allowed on this edge.
Definition: NBEdge.h:451
relative_incoming_edge_sorter(NBEdge *e)
constructor
Definition: NBContHelper.h:132
bool operator()(NBEdge *e) const
Definition: NBContHelper.h:379
static SUMOReal getMinSpeed(const EdgeVector &edges)
static void nextCCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
int operator()(NBEdge *e1, NBEdge *e2) const
comparing operation
SUMOReal myAngle
The angle of the related edge at the given node.
Definition: NBContHelper.h:216
static NBEdge * findConnectingEdge(const EdgeVector &edges, NBNode *from, NBNode *to)
SUMOReal getEdgeAngleAt(const NBEdge *const e, const NBNode *const n) const
Returns the given edge&#39;s angle at the given node.
Definition: NBContHelper.h:206
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:363