SUMO - Simulation of Urban MObility
NGNode.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A netgen-representation of a node
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <algorithm>
35 #include <netbuild/NBNode.h>
36 #include <netbuild/NBNodeCont.h>
37 #include <netbuild/NBEdge.h>
38 #include <netbuild/NBOwnTLDef.h>
39 #include <netbuild/NBTypeCont.h>
41 #include <netbuild/NBNetBuilder.h>
43 #include <utils/common/ToString.h>
46 #include <utils/options/Option.h>
47 #include "NGNode.h"
48 
49 #ifdef CHECK_MEMORY_LEAKS
50 #include <foreign/nvwa/debug_new.h>
51 #endif // CHECK_MEMORY_LEAKS
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 NGNode::NGNode(const std::string& id)
58  : Named(id), xID(-1), yID(-1), myAmCenter(false) {}
59 
60 
61 NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
62  : Named(id), xID(xIDa), yID(yIDa), myAmCenter(false) {}
63 
64 
65 NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
66  : Named(id), xID(xIDa), yID(yIDa), myAmCenter(amCenter) {}
67 
68 
70  NGEdgeList::iterator li;
71  while (LinkList.size() != 0) {
72  li = LinkList.begin();
73  delete(*li);
74  }
75 }
76 
77 
78 NBNode*
80  Position pos(myPosition);
82  // the center will have no logic!
83  if (myAmCenter) {
84  return new NBNode(myID, pos, NODETYPE_NOJUNCTION);
85  }
86  NBNode* node = 0;
87  std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
88  OptionsCont::getOptions().getString("default-junction-type") : "";
89 
90  if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
92  node = new NBNode(myID, pos, type);
93 
94  // check whether it is a traffic light junction
95  if (NBNode::isTrafficLight(type)) {
97  OptionsCont::getOptions().getString("tls.default-type"));
98  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0, type);
99  if (!nb.getTLLogicCont().insert(tlDef)) {
100  // actually, nothing should fail here
101  delete tlDef;
102  throw ProcessError();
103  }
104  }
105  } else {
106  // otherwise netbuild may guess NODETYPE_TRAFFIC_LIGHT without actually building one
107  node = new NBNode(myID, pos, NODETYPE_PRIORITY);
108  }
109 
110  return node;
111 }
112 
113 
114 void
116  LinkList.push_back(link);
117 }
118 
119 
120 void
122  LinkList.remove(link);
123 }
124 
125 
126 bool
127 NGNode::connected(NGNode* node) const {
128  for (NGEdgeList::const_iterator i = LinkList.begin(); i != LinkList.end(); ++i) {
129  if (find(node->LinkList.begin(), node->LinkList.end(), *i) != node->LinkList.end()) {
130  return true;
131  }
132  }
133  return false;
134 }
135 
136 
137 /****************************************************************************/
138 
static StringBijection< SumoXMLNodeType > NodeTypes
A netgen-representation of an edge.
Definition: NGEdge.h:62
int xID
Integer x-position (x-id)
Definition: NGNode.h:192
bool myAmCenter
Information whether this is the center of a cpider-net.
Definition: NGNode.h:207
bool connected(NGNode *node) const
Returns whether the other node is connected.
Definition: NGNode.cpp:127
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:98
bool x2cartesian(Position &from, bool includeInBoundary=true)
int yID
Integer y-position (y-id)
Definition: NGNode.h:195
The base class for traffic light logic definitions.
void removeLink(NGEdge *link)
Removes the given link.
Definition: NGNode.cpp:121
NBNode * buildNBNode(NBNetBuilder &nb) const
Builds and returns this node&#39;s netbuild-representation.
Definition: NGNode.cpp:79
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
~NGNode()
Destructor.
Definition: NGNode.cpp:69
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static StringBijection< TrafficLightType > TrafficLightTypes
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
Base class for objects which have an id.
Definition: Named.h:46
Position myPosition
The position of the node.
Definition: NGNode.h:201
std::string myID
The name of the object.
Definition: Named.h:136
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
Instance responsible for building networks.
Definition: NBNetBuilder.h:112
NGNode(const std::string &id)
Constructor.
Definition: NGNode.cpp:57
NBTrafficLightLogicCont & getTLLogicCont()
Returns the traffic light logics container.
Definition: NBNetBuilder.h:177
Represents a single node (junction) during network building.
Definition: NBNode.h:74
T get(const std::string &str) const
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
A netgen-representation of a node.
Definition: NGNode.h:58
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:54
NGEdgeList LinkList
List of connected links.
Definition: NGNode.h:198
void addLink(NGEdge *link)
Adds the given link to the internal list.
Definition: NGNode.cpp:115
static bool isTrafficLight(SumoXMLNodeType type)
return whether the given type is a traffic light
Definition: NBNode.cpp:2629
TrafficLightType
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.