NBContHelper.h
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef NBContHelper_h
00020 #define NBContHelper_h
00021
00022
00023
00024
00025
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031
00032 #include <vector>
00033 #include <iostream>
00034 #include <cmath>
00035 #include <algorithm>
00036 #include <cassert>
00037 #include "NBHelpers.h"
00038 #include "NBCont.h"
00039 #include "NBEdge.h"
00040 #include "NBNode.h"
00041 #include <utils/common/StdDefs.h>
00042 #include <utils/geom/GeomHelper.h>
00043
00044
00045
00046
00047
00053 class NBContHelper {
00054 public:
00057 static void nextCW(const EdgeVector * edges,
00058 EdgeVector::const_iterator &from);
00059
00062 static void nextCCW(const EdgeVector * edges,
00063 EdgeVector::const_iterator &from);
00064
00065 static SUMOReal getMaxSpeed(const EdgeVector &edges);
00066
00067 static SUMOReal getMinSpeed(const EdgeVector &edges);
00068
00070 static std::ostream &out(std::ostream &os, const std::vector<bool> &v);
00071
00076 class edge_by_junction_angle_sorter {
00077 public:
00079 explicit edge_by_junction_angle_sorter(NBNode *n) : myNode(n) {}
00080
00082 int operator()(NBEdge *e1, NBEdge *e2) const;
00083
00084 private:
00086 SUMOReal getConvAngle(NBEdge *e) const;
00087
00088 private:
00090 NBNode *myNode;
00091
00092 };
00093
00102 class relative_edge_sorter {
00103 public:
00105 explicit relative_edge_sorter(NBEdge *e, NBNode *n)
00106 : myEdge(e), myNode(n) {}
00107
00108 public:
00110 int operator()(NBEdge *e1, NBEdge *e2) const {
00111 if (e1==0||e2==0) {
00112 return -1;
00113 }
00114 SUMOReal relAngle1 = NBHelpers::normRelAngle(
00115 myEdge->getAngle(), e1->getAngle());
00116 SUMOReal relAngle2 = NBHelpers::normRelAngle(
00117 myEdge->getAngle(), e2->getAngle());
00118 return relAngle1 > relAngle2;
00119 }
00120
00121 private:
00123 NBEdge *myEdge;
00124
00126 NBNode *myNode;
00127
00128 };
00129
00130
00135 class edge_by_priority_sorter {
00136 public:
00138 int operator()(NBEdge *e1, NBEdge *e2) const {
00139 if (e1->getPriority()!=e2->getPriority()) {
00140 return e1->getPriority() > e2->getPriority();
00141 }
00142 if (e1->getSpeed()!=e2->getSpeed()) {
00143 return e1->getSpeed() > e2->getSpeed();
00144 }
00145 return e1->getNoLanes() > e2->getNoLanes();
00146 }
00147 };
00148
00155 class edge_opposite_direction_sorter {
00156 public:
00158 explicit edge_opposite_direction_sorter(NBEdge *e)
00159 : myAngle(e->getAngle()), myEdge(e) {}
00160
00161 public:
00163 int operator()(NBEdge *e1, NBEdge *e2) const {
00164 SUMOReal d1 = getDiff(e1);
00165 SUMOReal d2 = getDiff(e2);
00166 return d1 < d2;
00167 }
00168
00172 SUMOReal getDiff(NBEdge *e) const {
00173 SUMOReal d = e->getAngle()+180;
00174 if (d>=360) {
00175 d -= 360;
00176 }
00177 return GeomHelper::getMinAngleDiff(d, myAngle);
00178 }
00179
00180 private:
00182 SUMOReal myAngle;
00183
00185 NBEdge *myEdge;
00186
00187 };
00188
00195 class edge_similar_direction_sorter {
00196 public:
00198 explicit edge_similar_direction_sorter(NBEdge *e)
00199 : myAngle(e->getAngle()) {}
00200
00202 int operator()(NBEdge *e1, NBEdge *e2) const {
00203 SUMOReal d1 = GeomHelper::getMinAngleDiff(e1->getAngle(), myAngle);
00204 SUMOReal d2 = GeomHelper::getMinAngleDiff(e2->getAngle(), myAngle);
00205 return d1 < d2;
00206 }
00207
00208 private:
00210 SUMOReal myAngle;
00211 };
00212
00213
00217 class node_with_incoming_finder {
00218 public:
00220 node_with_incoming_finder(const NBEdge * const e);
00221
00222 bool operator()(const NBNode * const n) const;
00223
00224 private:
00225 const NBEdge * const myEdge;
00226
00227 private:
00229 node_with_incoming_finder &operator=(const node_with_incoming_finder &s);
00230
00231 };
00232
00233
00237 class node_with_outgoing_finder {
00238 public:
00240 node_with_outgoing_finder(const NBEdge * const e);
00241
00242 bool operator()(const NBNode * const n) const;
00243
00244 private:
00245 const NBEdge * const myEdge;
00246
00247 private:
00249 node_with_outgoing_finder &operator=(const node_with_outgoing_finder &s);
00250
00251 };
00252
00253
00254
00255
00256 class edge_with_destination_finder {
00257 public:
00259 edge_with_destination_finder(NBNode *dest);
00260
00261 bool operator()(NBEdge *e) const;
00262
00263 private:
00264 NBNode *myDestinationNode;
00265
00266 private:
00268 edge_with_destination_finder &operator=(const edge_with_destination_finder &s);
00269
00270 };
00271
00272
00275 static NBEdge *findConnectingEdge(const EdgeVector &edges,
00276 NBNode *from, NBNode *to);
00277
00278
00280 static SUMOReal maxSpeed(const EdgeVector &ev);
00281
00288 class same_connection_edge_sorter {
00289 public:
00291 explicit same_connection_edge_sorter() { }
00292
00294 int operator()(NBEdge *e1, NBEdge *e2) const {
00295 std::pair<SUMOReal, SUMOReal> mm1 = getMinMaxRelAngles(e1);
00296 std::pair<SUMOReal, SUMOReal> mm2 = getMinMaxRelAngles(e2);
00297 if (mm1.first==mm2.first && mm1.second==mm2.second) {
00298
00299 return e1->getID() < e2->getID();
00300 }
00301
00302 assert(
00303 (mm1.first<=mm2.first&&mm1.second<=mm2.second)
00304 ||
00305 (mm1.first>=mm2.first&&mm1.second>=mm2.second));
00306 return (mm1.first>=mm2.first&&mm1.second>=mm2.second);
00307 }
00308
00312 std::pair<SUMOReal, SUMOReal> getMinMaxRelAngles(NBEdge *e) const {
00313 SUMOReal min = 360;
00314 SUMOReal max = 360;
00315 const EdgeVector &ev = e->getConnectedEdges();
00316 for (EdgeVector::const_iterator i=ev.begin(); i!=ev.end(); ++i) {
00317 SUMOReal angle = NBHelpers::normRelAngle(
00318 e->getAngle(), (*i)->getAngle());
00319 if (min==360||min>angle) {
00320 min = angle;
00321 }
00322 if (max==360||max<angle) {
00323 max = angle;
00324 }
00325 }
00326 return std::pair<SUMOReal, SUMOReal>(min, max);
00327 }
00328 };
00329
00330
00331 friend std::ostream &operator<<(std::ostream &os, const EdgeVector &ev);
00332
00333 class opposite_finder {
00334 public:
00336 opposite_finder(NBEdge *edge, const NBNode *n)
00337 : myReferenceEdge(edge), myAtNode(n) { }
00338
00339 bool operator()(NBEdge *e) const {
00340 return e->isTurningDirectionAt(myAtNode, myReferenceEdge)||
00341 myReferenceEdge->isTurningDirectionAt(myAtNode, e);
00342 }
00343
00344 private:
00345 NBEdge *myReferenceEdge;
00346 const NBNode *myAtNode;
00347
00348 };
00349
00350
00351 };
00352
00353
00354 #endif
00355
00356
00357