SUMO - Simulation of Urban MObility
NGNode.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // A netgen-representation of a node
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <algorithm>
34 #include <netbuild/NBNode.h>
35 #include <netbuild/NBNodeCont.h>
36 #include <netbuild/NBEdge.h>
37 #include <netbuild/NBOwnTLDef.h>
38 #include <netbuild/NBTypeCont.h>
40 #include <netbuild/NBNetBuilder.h>
42 #include <utils/common/ToString.h>
45 #include <utils/options/Option.h>
46 #include "NGNode.h"
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 NGNode::NGNode(const std::string& id)
53  : Named(id), xID(-1), yID(-1), myAmCenter(false) {}
54 
55 
56 NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
57  : Named(id), xID(xIDa), yID(yIDa), myAmCenter(false) {}
58 
59 
60 NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
61  : Named(id), xID(xIDa), yID(yIDa), myAmCenter(amCenter) {}
62 
63 
65  NGEdgeList::iterator li;
66  while (LinkList.size() != 0) {
67  li = LinkList.begin();
68  delete(*li);
69  }
70 }
71 
72 
73 NBNode*
75  Position pos(myPosition);
77  // the center will have no logic!
78  if (myAmCenter) {
79  return new NBNode(myID, pos, NODETYPE_NOJUNCTION);
80  }
81  NBNode* node = 0;
82  std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
83  OptionsCont::getOptions().getString("default-junction-type") : "";
84 
85  if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
87  node = new NBNode(myID, pos, type);
88 
89  // check whether it is a traffic light junction
90  if (NBNode::isTrafficLight(type)) {
92  OptionsCont::getOptions().getString("tls.default-type"));
93  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0, type);
94  if (!nb.getTLLogicCont().insert(tlDef)) {
95  // actually, nothing should fail here
96  delete tlDef;
97  throw ProcessError();
98  }
99  }
100  } else {
101  // otherwise netbuild may guess NODETYPE_TRAFFIC_LIGHT without actually building one
102  node = new NBNode(myID, pos, NODETYPE_PRIORITY);
103  }
104 
105  return node;
106 }
107 
108 
109 void
111  LinkList.push_back(link);
112 }
113 
114 
115 void
117  LinkList.remove(link);
118 }
119 
120 
121 bool
122 NGNode::connected(NGNode* node) const {
123  for (NGEdgeList::const_iterator i = LinkList.begin(); i != LinkList.end(); ++i) {
124  if (find(node->LinkList.begin(), node->LinkList.end(), *i) != node->LinkList.end()) {
125  return true;
126  }
127  }
128  return false;
129 }
130 
131 
132 /****************************************************************************/
133 
static StringBijection< SumoXMLNodeType > NodeTypes
node types
A netgen-representation of an edge.
Definition: NGEdge.h:61
int xID
Integer x-position (x-id)
Definition: NGNode.h:191
bool myAmCenter
Information whether this is the center of a cpider-net.
Definition: NGNode.h:206
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:90
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
int yID
Integer y-position (y-id)
Definition: NGNode.h:194
The base class for traffic light logic definitions.
void removeLink(NGEdge *link)
Removes the given link.
Definition: NGNode.cpp:116
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
~NGNode()
Destructor.
Definition: NGNode.cpp:64
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
bool connected(NGNode *node) const
Returns whether the other node is connected.
Definition: NGNode.cpp:122
T get(const std::string &str) const
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Base class for objects which have an id.
Definition: Named.h:54
Position myPosition
The position of the node.
Definition: NGNode.h:200
std::string myID
The name of the object.
Definition: Named.h:126
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
NGNode(const std::string &id)
Constructor.
Definition: NGNode.cpp:52
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:171
Represents a single node (junction) during network building.
Definition: NBNode.h:74
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
A netgen-representation of a node.
Definition: NGNode.h:57
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:53
NGEdgeList LinkList
List of connected links.
Definition: NGNode.h:197
void addLink(NGEdge *link)
Adds the given link to the internal list.
Definition: NGNode.cpp:110
static bool isTrafficLight(SumoXMLNodeType type)
return whether the given type is a traffic light
Definition: NBNode.cpp:2793
NBNode * buildNBNode(NBNetBuilder &nb) const
Builds and returns this node&#39;s netbuild-representation.
Definition: NGNode.cpp:74
TrafficLightType